1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/*-
* Copyright (c) 2001 Networks Associates Technology, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
/*
* This file contains functions which update LOMAC's internal
* state in response to system events, such as successful
* system calls. These updates allow LOMAC to keep an accurate
* picture of the kernel's state, enabling LOMAC to make reasonable
* decisions when it mediates processes' use of security-relevant
* system calls. These functions perform no mediation themselves -
* that is, they do not make access control decisions concerning
* whether a given system call should be allowed or denied. This
* mediation is handled by the functions in lomac_mediate.c.
*/
#include "kernel_interface.h"
#include "kernel_monitor.h"
#include "kernel_log.h"
#include "kernel_util.h"
/* monitor_read_object()
*
* in: p_subject - subject that read `p_object'.
* p_object - object read by `p_subject'.
* out: nothing
* return: nothing
*
* This function examines the objects read by subjects. If a subject
* reads from an object with a level lower than its own, this function
* reduces the subject's level to match the object's. This lowering
* is referred to as "demotion" in much of the LOMAC documentation.
* This function performs no mediation.
*
* This function is for the following kinds of objects:
* regular files and FIFOs.
* It is also used to monitor reads on unnamed pipes. LOMAC does not
* consider unnamed pipes to be objects, and treats them differently
* from objects such as files. However, the differences are mostly
* in the write-handling behavior. LOMAC's read-handling behavior is
* the same both for objects and unnamed pipes, so this function
* handles both cases.
*/
int
monitor_read_object(lomac_subject_t *p_subject, lomac_object_t *p_object) {
lattr_t subject_lattr; /* lattr of `p_subject' */
lattr_t object_lattr; /* lattr of `p_object' */
/* Get the lattrs of `p_subject' and `p_object' so we can compare them. */
get_subject_lattr(p_subject, &subject_lattr);
get_object_lattr(p_object, &object_lattr);
/*
* If `p_object's level is less than `p_subject's level,
* we must demote `p_subject'. The level may be 0 to indicate
* existence before LOMAC started.
*/
if (object_lattr.level &&
lomac_must_demote(&subject_lattr, &object_lattr) &&
(subject_lattr.flags & LOMAC_ATTR_NODEMOTE) == 0) {
if (subject_do_not_demote(p_subject))
return (0);
set_subject_lattr(p_subject, object_lattr); /* demote! */
if (lomac_verbose_demote_deny) {
lomac_log_t *s = log_start();
log_append_string(s, "LOMAC: level-");
log_append_int(s, subject_lattr.level);
log_append_string(s, " subject ");
log_append_subject_id(s, p_subject);
log_append_string(s, " demoted to level ");
log_append_int(s, object_lattr.level);
log_append_string(s, " after reading ");
log_append_object_id(s, p_object);
log_append_string(s, "\n");
log_print(s);
}
} /* if we need to demote */
return (0);
} /* monitor_read_object() */
/* monitor_pipe_write()
*
* in: p_subject - subject that just wrote to `p_pipe'.
* p_pipe - pipe `p_subject' has written to.
* out: p_pipe - pipe may have its level adjusted.
* return: 0
*
* This function should be called after a successful write to
* `p_pipe'. If the level of `p_subject' is less than the level of
* `p_pipe', this function reduces `p_pipe's level to match
* `current's.
*
*
*/
int
monitor_pipe_write(lomac_subject_t *p_subject, lomac_object_t *p_pipe) {
lattr_t pipe_lattr; /* lattr of `p_pipe' */
lattr_t subject_lattr; /* lattr of `p_subject' */
get_subject_lattr(p_subject, &subject_lattr);
get_object_lattr(p_pipe, &pipe_lattr);
if (lomac_must_demote(&pipe_lattr, &subject_lattr)) {
subject_lattr.flags = 0;
set_object_lattr(p_pipe, subject_lattr);
#ifdef LOMAC_DEBUG_PIPE
if (lomac_verbose_pipe) {
lomac_log_t *s = log_start();
log_append_string(s, "LOMAC: level-");
log_append_int(s, subject_lattr.level);
log_append_string(s, " subject ");
log_append_subject_id(s, p_subject);
log_append_string(s, " contaminated level-");
log_append_int(s, pipe_lattr.level);
log_append_string(s, " ");
log_append_object_id(s, p_pipe);
log_append_string(s, "\n");
log_print(s);
}
#endif /* LOMAC_DEBUG_PIPE */
}
return (0);
} /* monitor_pipe_write() */
/* monitor_read_net_socket()
*
* in: p_subject - subject that read from network socket.
* out: nothing
* return: 0
*
*
*/
int
monitor_read_net_socket(lomac_subject_t *p_subject) {
lattr_t subject_lattr; /* lattr of `p_subject' */
lattr_t socket_lattr; /* lattr of socket (always lowest) */
socket_lattr.level = LOMAC_LOWEST_LEVEL;
socket_lattr.flags = 0;
get_subject_lattr(p_subject, &subject_lattr);
if (lomac_must_demote(&subject_lattr, &socket_lattr) &&
(subject_lattr.flags &
(LOMAC_ATTR_NODEMOTE | LOMAC_ATTR_NONETDEMOTE)) == 0) {
if (subject_do_not_demote(p_subject))
return (0);
socket_lattr.flags = subject_lattr.flags;
set_subject_lattr(p_subject, socket_lattr); /* demote! */
if (lomac_verbose_demote_deny) {
lomac_log_t *s = log_start();
log_append_string(s, "LOMAC: level-");
log_append_int(s, subject_lattr.level);
log_append_string(s, " subject ");
log_append_subject_id(s, p_subject);
log_append_string(s, " demoted to level ");
log_append_int(s, socket_lattr.level);
log_append_string(s, " after reading from "
"the network\n");
log_print(s);
}
}
return (0);
}
|