1
------------------------------------------------------------
3
fixes bug: https://launchpad.net/bugs/1218099
4
committer: Steve Beattie <sbeattie@ubuntu.com>
6
timestamp: Thu 2013-08-29 12:34:13 -0700
8
parser - add support for variable expansion in dbus rules
9
Bug: https://bugs.launchpad.net/bugs/1218099
11
This patch adds support for expanding variables with dbus rules.
12
Specifically, they can expanded within the bus, name, path, member,
13
interface, and peer label fields.
15
Parser test cases and regression test cases are added as well.
18
v1: initial version of patch
19
v2: add equality.sh tests to verify that the results of using
20
variable expansion is the same as what should be equivalent rules
22
Signed-off-by: Steve Beattie <sbeattie@ubuntu.com>
23
Acked-by: Tyler Hicks <tyhicks@canonical.com>
24
Acked-by: Seth Arnold <seth.arnold@canonical.com>
26
=== modified file 'parser/dbus.c'
27
Index: apparmor-2.8.0/parser/dbus.c
28
===================================================================
29
--- apparmor-2.8.0.orig/parser/dbus.c 2013-08-29 16:28:18.000000000 -0500
30
+++ apparmor-2.8.0/parser/dbus.c 2013-08-29 16:28:18.000000000 -0500
35
+#define DUP_STRING(orig, new, field) \
36
+ (new)->field = (orig)->field ? strdup((orig)->field) : NULL
38
+struct dbus_entry *dup_dbus_entry(struct dbus_entry *orig)
40
+ struct dbus_entry *ent = NULL;
41
+ ent = (struct dbus_entry *) calloc(1, sizeof(struct dbus_entry));
45
+ DUP_STRING(orig, ent, bus);
46
+ DUP_STRING(orig, ent, name);
47
+ DUP_STRING(orig, ent, peer_label);
48
+ DUP_STRING(orig, ent, path);
49
+ DUP_STRING(orig, ent, interface);
50
+ DUP_STRING(orig, ent, member);
51
+ ent->mode = orig->mode;
52
+ ent->audit = orig->audit;
53
+ ent->deny = orig->deny;
55
+ ent->next = orig->next;
60
void print_dbus_entry(struct dbus_entry *ent)
62
Index: apparmor-2.8.0/parser/dbus.h
63
===================================================================
64
--- apparmor-2.8.0.orig/parser/dbus.h 2013-08-29 16:28:18.000000000 -0500
65
+++ apparmor-2.8.0/parser/dbus.h 2013-08-29 16:28:18.000000000 -0500
67
void free_dbus_entry(struct dbus_entry *ent);
68
struct dbus_entry *new_dbus_entry(int mode, struct cond_entry *conds,
69
struct cond_entry *peer_conds);
70
+struct dbus_entry *dup_dbus_entry(struct dbus_entry *ent);
71
void print_dbus_entry(struct dbus_entry *ent);
73
#endif /* __AA_DBUS_H */
74
Index: apparmor-2.8.0/parser/parser_variable.c
75
===================================================================
76
--- apparmor-2.8.0.orig/parser/parser_variable.c 2013-08-29 16:28:18.000000000 -0500
77
+++ apparmor-2.8.0/parser/parser_variable.c 2013-08-29 16:28:18.000000000 -0500
84
static inline char *get_var_end(char *var)
90
+int clone_and_chain_dbus(void *v)
92
+ struct dbus_entry *entry = v;
94
+ struct dbus_entry *dup = dup_dbus_entry(entry);
103
static int process_variables_in_entries(struct cod_entry *entry_list)
110
+static int process_dbus_variables(struct dbus_entry *entry_list)
112
+ int ret = TRUE, rc;
113
+ struct dbus_entry *entry;
115
+ list_for_each(entry_list, entry) {
116
+ rc = expand_entry_variables(&entry->bus, entry,
117
+ clone_and_chain_dbus);
120
+ rc = expand_entry_variables(&entry->name, entry,
121
+ clone_and_chain_dbus);
124
+ rc = expand_entry_variables(&entry->peer_label, entry,
125
+ clone_and_chain_dbus);
128
+ rc = expand_entry_variables(&entry->path, entry,
129
+ clone_and_chain_dbus);
132
+ rc = expand_entry_variables(&entry->interface, entry,
133
+ clone_and_chain_dbus);
136
+ rc = expand_entry_variables(&entry->member, entry,
137
+ clone_and_chain_dbus);
146
int process_variables(struct codomain *cod)
153
+ if (!process_dbus_variables(cod->dbus_ents)) {
157
if (process_hat_variables(cod) != 0) {
160
Index: apparmor-2.8.0/parser/tst/equality.sh
161
===================================================================
162
--- apparmor-2.8.0.orig/parser/tst/equality.sh 2013-08-29 16:28:18.000000000 -0500
163
+++ apparmor-2.8.0/parser/tst/equality.sh 2013-08-29 16:28:18.000000000 -0500
165
"/t { dbus (send,receive,,,,,,,,,,,,,,,,bind), }" \
166
"/t { dbus (send,send,send,send send receive,bind), }" \
168
+verify_binary_equality "dbus variable expansion" \
169
+ "/t { dbus (send, receive) path=/com/foo member=spork interface=org.foo peer=(name=com.foo label=/com/foo), }" \
171
+ /t { dbus (send, receive) path=/com/@{FOO} member=spork interface=org.@{FOO} peer=(name=com.@{FOO} label=/com/@{FOO}), }" \
174
+ /t { dbus (send, receive) path=/com/@{FOO} member=@{SPORK} interface=org.@{FOO} peer=(name=com.@{FOO} label=/com/@{FOO}), }" \
176
+ /t { dbus (send, receive) path=@{FOO} member=spork interface=org.foo peer=(name=com.foo label=@{FOO}), }" \
178
+ /t { dbus (send, receive) path=/@{FOO}/foo member=spork interface=org.foo peer=(name=@{FOO}.foo label=/@{FOO}/foo), }"
180
+verify_binary_equality "dbus variable expansion, multiple values/rules" \
181
+ "/t { dbus (send, receive) path=/com/foo, dbus (send, receive) path=/com/bar, }" \
183
+ /t { dbus (send, receive) path=/com/@{FOO}, dbus (send, receive) path=/com/bar, }" \
185
+ /t { dbus (send, receive) path=/com/@{FOO}, }" \
187
+ /t { dbus (send, receive) path=/com/@{FOO}, }"
189
+verify_binary_equality "dbus variable expansion, ensure rule de-duping occurs" \
190
+ "/t { dbus (send, receive) path=/com/foo, dbus (send, receive) path=/com/bar, }" \
191
+ "/t { dbus (send, receive) path=/com/foo, dbus (send, receive) path=/com/bar, dbus (send, receive) path=/com/bar, }" \
192
+ "@{FOO}=bar foo bar foo
193
+ /t { dbus (send, receive) path=/com/@{FOO}, }" \
194
+ "@{FOO}=bar foo bar foo
195
+ /t { dbus (send, receive) path=/com/@{FOO}, dbus (send, receive) path=/com/@{FOO}, }"
197
if [ $fails -ne 0 -o $errors -ne 0 ]
199
printf "ERRORS: %d\nFAILS: %d\n" $errors $fails 2>&1
200
Index: apparmor-2.8.0/parser/tst/simple_tests/vars/vars_dbus_1.sd
201
===================================================================
202
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
203
+++ apparmor-2.8.0/parser/tst/simple_tests/vars/vars_dbus_1.sd 2013-08-29 16:28:18.000000000 -0500
205
+#=DESCRIPTION reference variables in dbus rules
214
+ path="/com/canonical/hud/applications/@{BAR}",
216
Index: apparmor-2.8.0/parser/tst/simple_tests/vars/vars_dbus_2.sd
217
===================================================================
218
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
219
+++ apparmor-2.8.0/parser/tst/simple_tests/vars/vars_dbus_2.sd 2013-08-29 16:28:18.000000000 -0500
221
+#=DESCRIPTION reference variables in dbus rules, interfaces
224
+@{ORGS}=freedesktop ubuntu gnome kde
229
+ interface=org.@{ORGS}.DBus.Properties
230
+ path="/com/canonical/hud/applications/bar",
232
Index: apparmor-2.8.0/parser/tst/simple_tests/vars/vars_dbus_3.sd
233
===================================================================
234
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
235
+++ apparmor-2.8.0/parser/tst/simple_tests/vars/vars_dbus_3.sd 2013-08-29 16:28:18.000000000 -0500
237
+#=DESCRIPTION reference variables in dbus rules, bus fields
240
+@{BUSES}=session system accessability choochoo
245
+ path="/com/canonical/hud/applications/baz",
247
Index: apparmor-2.8.0/parser/tst/simple_tests/vars/vars_dbus_4.sd
248
===================================================================
249
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
250
+++ apparmor-2.8.0/parser/tst/simple_tests/vars/vars_dbus_4.sd 2013-08-29 16:28:18.000000000 -0500
252
+#=DESCRIPTION reference variables in dbus rules, members
255
+@{MEMBERS}=blurt blirt @{BAR}
257
+@{FOO}=bink bank bonk blurry*
263
+ path="/com/canonical/hud/applications/biff",
265
Index: apparmor-2.8.0/parser/tst/simple_tests/vars/vars_dbus_5.sd
266
===================================================================
267
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
268
+++ apparmor-2.8.0/parser/tst/simple_tests/vars/vars_dbus_5.sd 2013-08-29 16:28:18.000000000 -0500
270
+#=DESCRIPTION reference variables in dbus rules, with peers
277
+ dbus (send, receive)
279
+ path="/foo/bar" member="bar"
280
+ peer=(name="com.@{FOO}" label="/usr/bin/app.@{FOO}"),
282
Index: apparmor-2.8.0/parser/tst/simple_tests/vars/vars_dbus_6.sd
283
===================================================================
284
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
285
+++ apparmor-2.8.0/parser/tst/simple_tests/vars/vars_dbus_6.sd 2013-08-29 16:28:18.000000000 -0500
287
+#=DESCRIPTION reference variables in dbus rules, with name
296
+ name="com.@{BAR}.@{FOO}",
298
Index: apparmor-2.8.0/parser/tst/simple_tests/vars/vars_dbus_7.sd
299
===================================================================
300
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
301
+++ apparmor-2.8.0/parser/tst/simple_tests/vars/vars_dbus_7.sd 2013-08-29 16:28:18.000000000 -0500
303
+#=DESCRIPTION reference variables in dbus rules, with duplicates
312
+ name="com.@{BAR}.@{FOO}",
314
Index: apparmor-2.8.0/tests/regression/apparmor/dbus.inc
315
===================================================================
316
--- apparmor-2.8.0.orig/tests/regression/apparmor/dbus.inc 2013-08-29 16:28:18.000000000 -0500
317
+++ apparmor-2.8.0/tests/regression/apparmor/dbus.inc 2013-08-29 16:28:18.000000000 -0500
321
genprofile --stdin <<EOF
328
+ unset __dbus_var_decl
331
+# the arguments passed are emitted in the profile's prologue, for
332
+# setting profile variables, e.g.
333
+# set_dbus_var "@{MY_DBUS_VAR}=stuff"
334
+# the saved variable declaration gets unset after each test run
341
Index: apparmor-2.8.0/tests/regression/apparmor/dbus_message.sh
342
===================================================================
343
--- apparmor-2.8.0.orig/tests/regression/apparmor/dbus_message.sh 2013-08-29 16:28:18.000000000 -0500
344
+++ apparmor-2.8.0/tests/regression/apparmor/dbus_message.sh 2013-08-29 16:28:18.000000000 -0500
346
runtestfg "message (send allowed w/ bus, dest, path, interface, method)" pass $confined_args
347
checktestfg "compare_logs $unconfined_log eq $confined_log"
349
+# Make sure send is allowed when confined with appropriate permissions along
350
+# with conditionals and variables (same tests as above, with vars)
352
+set_dbus_var "@{BUSES}=session system"
353
+message_gendbusprofile "dbus send bus=@{BUSES},"
354
+runtestfg "message (send allowed w/ bus)" pass $confined_args
355
+checktestfg "compare_logs $unconfined_log eq $confined_log"
357
+set_dbus_var "@{PEERNAMES}=com.ubuntu.what net.apparmor.wiki org.freedesktop.DBus"
358
+message_gendbusprofile "dbus send bus=session peer=(name=@{PEERNAMES}),"
359
+runtestfg "message (send allowed w/ bus, dest)" pass $confined_args
360
+checktestfg "compare_logs $unconfined_log eq $confined_log"
362
+set_dbus_var "@{PATHNAMES}=DBus spork spoon spork"
363
+message_gendbusprofile "dbus send bus=session path=/org/freedesktop/@{PATHNAMES} peer=(name=org.freedesktop.DBus),"
364
+runchecktest "message (send allowed w/ bus, dest, path)" pass $confined_args
365
+checktestfg "compare_logs $unconfined_log eq $confined_log"
367
+set_dbus_var "@{INTERFACE_NAMES}=DBus spork spoon spork"
368
+message_gendbusprofile "dbus send bus=session path=/org/freedesktop/DBus interface=org.freedesktop.@{INTERFACE_NAMES} peer=(name=org.freedesktop.DBus),"
369
+runtestfg "message (send allowed w/ bus, dest, path, interface)" pass $confined_args
370
+checktestfg "compare_logs $unconfined_log eq $confined_log"
372
+set_dbus_var "@{MEMBERS}=Hello ListNames Spork Spoon"
373
+message_gendbusprofile "dbus send bus=session path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=@{MEMBERS} peer=(name=org.freedesktop.DBus),"
374
+runtestfg "message (send allowed w/ bus, dest, path, interface, method)" pass $confined_args
375
+checktestfg "compare_logs $unconfined_log eq $confined_log"
377
# Make sure send is denied when confined with appropriate permissions along
378
# with incorrect conditionals