Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

TOMOYO: Add built-in policy support.

To be able to start using enforcing mode from the early stage of boot sequence,
this patch adds support for built-in policy configuration (and next patch adds
support for activating access control without calling external policy loader
program).

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: James Morris <jmorris@namei.org>

authored by

Tetsuo Handa and committed by
James Morris
efe836ab b22b8b9f

+108 -10
+47
security/tomoyo/Makefile
··· 1 1 obj-y = audit.o common.o domain.o file.o gc.o group.o load_policy.o memory.o mount.o realpath.o securityfs_if.o tomoyo.o util.o 2 + 3 + $(obj)/policy/profile.conf: 4 + @mkdir -p $(obj)/policy/ 5 + @echo Creating an empty policy/profile.conf 6 + @touch $@ 7 + 8 + $(obj)/policy/exception_policy.conf: 9 + @mkdir -p $(obj)/policy/ 10 + @echo Creating a default policy/exception_policy.conf 11 + @echo initialize_domain /sbin/modprobe from any >> $@ 12 + @echo initialize_domain /sbin/hotplug from any >> $@ 13 + 14 + $(obj)/policy/domain_policy.conf: 15 + @mkdir -p $(obj)/policy/ 16 + @echo Creating an empty policy/domain_policy.conf 17 + @touch $@ 18 + 19 + $(obj)/policy/manager.conf: 20 + @mkdir -p $(obj)/policy/ 21 + @echo Creating an empty policy/manager.conf 22 + @touch $@ 23 + 24 + $(obj)/policy/stat.conf: 25 + @mkdir -p $(obj)/policy/ 26 + @echo Creating an empty policy/stat.conf 27 + @touch $@ 28 + 29 + $(obj)/builtin-policy.h: $(obj)/policy/profile.conf $(obj)/policy/exception_policy.conf $(obj)/policy/domain_policy.conf $(obj)/policy/manager.conf $(obj)/policy/stat.conf 30 + @echo Generating built-in policy for TOMOYO 2.4.x. 31 + @echo "static char tomoyo_builtin_profile[] __initdata =" > $@.tmp 32 + @sed -e 's/\\/\\\\/g' -e 's/\"/\\"/g' -e 's/\(.*\)/"\1\\n"/' < $(obj)/policy/profile.conf >> $@.tmp 33 + @echo "\"\";" >> $@.tmp 34 + @echo "static char tomoyo_builtin_exception_policy[] __initdata =" >> $@.tmp 35 + @sed -e 's/\\/\\\\/g' -e 's/\"/\\"/g' -e 's/\(.*\)/"\1\\n"/' < $(obj)/policy/exception_policy.conf >> $@.tmp 36 + @echo "\"\";" >> $@.tmp 37 + @echo "static char tomoyo_builtin_domain_policy[] __initdata =" >> $@.tmp 38 + @sed -e 's/\\/\\\\/g' -e 's/\"/\\"/g' -e 's/\(.*\)/"\1\\n"/' < $(obj)/policy/domain_policy.conf >> $@.tmp 39 + @echo "\"\";" >> $@.tmp 40 + @echo "static char tomoyo_builtin_manager[] __initdata =" >> $@.tmp 41 + @sed -e 's/\\/\\\\/g' -e 's/\"/\\"/g' -e 's/\(.*\)/"\1\\n"/' < $(obj)/policy/manager.conf >> $@.tmp 42 + @echo "\"\";" >> $@.tmp 43 + @echo "static char tomoyo_builtin_stat[] __initdata =" >> $@.tmp 44 + @sed -e 's/\\/\\\\/g' -e 's/\"/\\"/g' -e 's/\(.*\)/"\1\\n"/' < $(obj)/policy/stat.conf >> $@.tmp 45 + @echo "\"\";" >> $@.tmp 46 + @mv $@.tmp $@ 47 + 48 + $(obj)/common.o: $(obj)/builtin-policy.h
+60
security/tomoyo/common.c
··· 2361 2361 tomoyo_read_unlock(idx); 2362 2362 printk(KERN_INFO "Mandatory Access Control activated.\n"); 2363 2363 } 2364 + 2365 + /** 2366 + * tomoyo_load_builtin_policy - Load built-in policy. 2367 + * 2368 + * Returns nothing. 2369 + */ 2370 + void __init tomoyo_load_builtin_policy(void) 2371 + { 2372 + /* 2373 + * This include file is manually created and contains built-in policy 2374 + * named "tomoyo_builtin_profile", "tomoyo_builtin_exception_policy", 2375 + * "tomoyo_builtin_domain_policy", "tomoyo_builtin_manager", 2376 + * "tomoyo_builtin_stat" in the form of "static char [] __initdata". 2377 + */ 2378 + #include "builtin-policy.h" 2379 + u8 i; 2380 + const int idx = tomoyo_read_lock(); 2381 + for (i = 0; i < 5; i++) { 2382 + struct tomoyo_io_buffer head = { }; 2383 + char *start = ""; 2384 + switch (i) { 2385 + case 0: 2386 + start = tomoyo_builtin_profile; 2387 + head.type = TOMOYO_PROFILE; 2388 + head.write = tomoyo_write_profile; 2389 + break; 2390 + case 1: 2391 + start = tomoyo_builtin_exception_policy; 2392 + head.type = TOMOYO_EXCEPTIONPOLICY; 2393 + head.write = tomoyo_write_exception; 2394 + break; 2395 + case 2: 2396 + start = tomoyo_builtin_domain_policy; 2397 + head.type = TOMOYO_DOMAINPOLICY; 2398 + head.write = tomoyo_write_domain; 2399 + break; 2400 + case 3: 2401 + start = tomoyo_builtin_manager; 2402 + head.type = TOMOYO_MANAGER; 2403 + head.write = tomoyo_write_manager; 2404 + break; 2405 + case 4: 2406 + start = tomoyo_builtin_stat; 2407 + head.type = TOMOYO_STAT; 2408 + head.write = tomoyo_write_stat; 2409 + break; 2410 + } 2411 + while (1) { 2412 + char *end = strchr(start, '\n'); 2413 + if (!end) 2414 + break; 2415 + *end = '\0'; 2416 + tomoyo_normalize_line(start); 2417 + head.write_buf = start; 2418 + tomoyo_parse_policy(&head, start); 2419 + start = end + 1; 2420 + } 2421 + } 2422 + tomoyo_read_unlock(idx); 2423 + }
+1
security/tomoyo/common.h
··· 662 662 void tomoyo_convert_time(time_t time, struct tomoyo_time *stamp); 663 663 void tomoyo_update_stat(const u8 index); 664 664 void __init tomoyo_mm_init(void); 665 + void __init tomoyo_load_builtin_policy(void); 665 666 int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, 666 667 const struct tomoyo_path_info *filename); 667 668 int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
-10
security/tomoyo/memory.c
··· 215 215 INIT_LIST_HEAD(&tomoyo_kernel_domain.acl_info_list); 216 216 tomoyo_kernel_domain.domainname = tomoyo_get_name("<kernel>"); 217 217 list_add_tail_rcu(&tomoyo_kernel_domain.list, &tomoyo_domain_list); 218 - #if 0 219 - /* Will be replaced with tomoyo_load_builtin_policy(). */ 220 - { 221 - /* Load built-in policy. */ 222 - tomoyo_write_transition_control("/sbin/hotplug", false, 223 - TOMOYO_TRANSITION_CONTROL_INITIALIZE); 224 - tomoyo_write_transition_control("/sbin/modprobe", false, 225 - TOMOYO_TRANSITION_CONTROL_INITIALIZE); 226 - } 227 - #endif 228 218 }