aboutsummaryrefslogtreecommitdiffstats
path: root/security/tomoyo/common.h
diff options
context:
space:
mode:
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>2011-06-26 10:19:52 -0400
committerJames Morris <jmorris@namei.org>2011-06-28 19:31:21 -0400
commitbd03a3e4c9a9df0c6b007045fa7fc8889111a478 (patch)
tree9d78290c878e6466fe3e0bda7ee5989c0dc39e40 /security/tomoyo/common.h
parent32997144fd9925fc4d506a16990a0c405f766526 (diff)
TOMOYO: Add policy namespace support.
Mauras Olivier reported that it is difficult to use TOMOYO in LXC environments, for TOMOYO cannot distinguish between environments outside the container and environments inside the container since LXC environments are created using pivot_root(). To address this problem, this patch introduces policy namespace. Each policy namespace has its own set of domain policy, exception policy and profiles, which are all independent of other namespaces. This independency allows users to develop policy without worrying interference among namespaces. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security/tomoyo/common.h')
-rw-r--r--security/tomoyo/common.h63
1 files changed, 51 insertions, 12 deletions
diff --git a/security/tomoyo/common.h b/security/tomoyo/common.h
index 4bc3975516cb..53c8798e38b7 100644
--- a/security/tomoyo/common.h
+++ b/security/tomoyo/common.h
@@ -74,10 +74,6 @@ enum tomoyo_group_id {
74 TOMOYO_MAX_GROUP 74 TOMOYO_MAX_GROUP
75}; 75};
76 76
77/* A domain definition starts with <kernel>. */
78#define TOMOYO_ROOT_NAME "<kernel>"
79#define TOMOYO_ROOT_NAME_LEN (sizeof(TOMOYO_ROOT_NAME) - 1)
80
81/* Index numbers for type of numeric values. */ 77/* Index numbers for type of numeric values. */
82enum tomoyo_value_type { 78enum tomoyo_value_type {
83 TOMOYO_VALUE_TYPE_INVALID, 79 TOMOYO_VALUE_TYPE_INVALID,
@@ -89,6 +85,8 @@ enum tomoyo_value_type {
89/* Index numbers for domain transition control keywords. */ 85/* Index numbers for domain transition control keywords. */
90enum tomoyo_transition_type { 86enum tomoyo_transition_type {
91 /* Do not change this order, */ 87 /* Do not change this order, */
88 TOMOYO_TRANSITION_CONTROL_NO_RESET,
89 TOMOYO_TRANSITION_CONTROL_RESET,
92 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE, 90 TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE,
93 TOMOYO_TRANSITION_CONTROL_INITIALIZE, 91 TOMOYO_TRANSITION_CONTROL_INITIALIZE,
94 TOMOYO_TRANSITION_CONTROL_NO_KEEP, 92 TOMOYO_TRANSITION_CONTROL_NO_KEEP,
@@ -246,6 +244,8 @@ struct tomoyo_shared_acl_head {
246 atomic_t users; 244 atomic_t users;
247} __packed; 245} __packed;
248 246
247struct tomoyo_policy_namespace;
248
249/* Structure for request info. */ 249/* Structure for request info. */
250struct tomoyo_request_info { 250struct tomoyo_request_info {
251 struct tomoyo_domain_info *domain; 251 struct tomoyo_domain_info *domain;
@@ -359,6 +359,8 @@ struct tomoyo_domain_info {
359 struct list_head acl_info_list; 359 struct list_head acl_info_list;
360 /* Name of this domain. Never NULL. */ 360 /* Name of this domain. Never NULL. */
361 const struct tomoyo_path_info *domainname; 361 const struct tomoyo_path_info *domainname;
362 /* Namespace for this domain. Never NULL. */
363 struct tomoyo_policy_namespace *ns;
362 u8 profile; /* Profile number to use. */ 364 u8 profile; /* Profile number to use. */
363 u8 group; /* Group number to use. */ 365 u8 group; /* Group number to use. */
364 bool is_deleted; /* Delete flag. */ 366 bool is_deleted; /* Delete flag. */
@@ -423,6 +425,7 @@ struct tomoyo_mount_acl {
423struct tomoyo_acl_param { 425struct tomoyo_acl_param {
424 char *data; 426 char *data;
425 struct list_head *list; 427 struct list_head *list;
428 struct tomoyo_policy_namespace *ns;
426 bool is_delete; 429 bool is_delete;
427}; 430};
428 431
@@ -443,6 +446,7 @@ struct tomoyo_io_buffer {
443 char __user *read_user_buf; 446 char __user *read_user_buf;
444 int read_user_buf_avail; 447 int read_user_buf_avail;
445 struct { 448 struct {
449 struct list_head *ns;
446 struct list_head *domain; 450 struct list_head *domain;
447 struct list_head *group; 451 struct list_head *group;
448 struct list_head *acl; 452 struct list_head *acl;
@@ -455,14 +459,16 @@ struct tomoyo_io_buffer {
455 u8 w_pos; 459 u8 w_pos;
456 bool eof; 460 bool eof;
457 bool print_this_domain_only; 461 bool print_this_domain_only;
458 bool print_execute_only; 462 bool print_transition_related_only;
459 const char *w[TOMOYO_MAX_IO_READ_QUEUE]; 463 const char *w[TOMOYO_MAX_IO_READ_QUEUE];
460 } r; 464 } r;
461 struct { 465 struct {
466 struct tomoyo_policy_namespace *ns;
462 /* The position currently writing to. */ 467 /* The position currently writing to. */
463 struct tomoyo_domain_info *domain; 468 struct tomoyo_domain_info *domain;
464 /* Bytes available for writing. */ 469 /* Bytes available for writing. */
465 int avail; 470 int avail;
471 bool is_delete;
466 } w; 472 } w;
467 /* Buffer for reading. */ 473 /* Buffer for reading. */
468 char *read_buf; 474 char *read_buf;
@@ -533,8 +539,27 @@ struct tomoyo_time {
533 u8 sec; 539 u8 sec;
534}; 540};
535 541
542/* Structure for policy namespace. */
543struct tomoyo_policy_namespace {
544 /* Profile table. Memory is allocated as needed. */
545 struct tomoyo_profile *profile_ptr[TOMOYO_MAX_PROFILES];
546 /* List of "struct tomoyo_group". */
547 struct list_head group_list[TOMOYO_MAX_GROUP];
548 /* List of policy. */
549 struct list_head policy_list[TOMOYO_MAX_POLICY];
550 /* The global ACL referred by "use_group" keyword. */
551 struct list_head acl_group[TOMOYO_MAX_ACL_GROUPS];
552 /* List for connecting to tomoyo_namespace_list list. */
553 struct list_head namespace_list;
554 /* Profile version. Currently only 20100903 is defined. */
555 unsigned int profile_version;
556 /* Name of this namespace (e.g. "<kernel>", "</usr/sbin/httpd>" ). */
557 const char *name;
558};
559
536/********** Function prototypes. **********/ 560/********** Function prototypes. **********/
537 561
562void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns);
538bool tomoyo_str_starts(char **src, const char *find); 563bool tomoyo_str_starts(char **src, const char *find);
539const char *tomoyo_get_exe(void); 564const char *tomoyo_get_exe(void);
540void tomoyo_normalize_line(unsigned char *buffer); 565void tomoyo_normalize_line(unsigned char *buffer);
@@ -553,7 +578,8 @@ tomoyo_compare_name_union(const struct tomoyo_path_info *name,
553 const struct tomoyo_name_union *ptr); 578 const struct tomoyo_name_union *ptr);
554bool tomoyo_compare_number_union(const unsigned long value, 579bool tomoyo_compare_number_union(const unsigned long value,
555 const struct tomoyo_number_union *ptr); 580 const struct tomoyo_number_union *ptr);
556int tomoyo_get_mode(const u8 profile, const u8 index); 581int tomoyo_get_mode(const struct tomoyo_policy_namespace *ns, const u8 profile,
582 const u8 index);
557void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) 583void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
558 __attribute__ ((format(printf, 2, 3))); 584 __attribute__ ((format(printf, 2, 3)));
559bool tomoyo_correct_domain(const unsigned char *domainname); 585bool tomoyo_correct_domain(const unsigned char *domainname);
@@ -589,8 +615,11 @@ int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
589 __attribute__ ((format(printf, 2, 3))); 615 __attribute__ ((format(printf, 2, 3)));
590struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname); 616struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
591struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname, 617struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
592 const u8 profile); 618 const bool transit);
593struct tomoyo_profile *tomoyo_profile(const u8 profile); 619struct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns,
620 const u8 profile);
621struct tomoyo_policy_namespace *tomoyo_assign_namespace
622(const char *domainname);
594struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param, 623struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param,
595 const u8 idx); 624 const u8 idx);
596unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain, 625unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
@@ -646,6 +675,8 @@ char *tomoyo_read_token(struct tomoyo_acl_param *param);
646bool tomoyo_permstr(const char *string, const char *keyword); 675bool tomoyo_permstr(const char *string, const char *keyword);
647 676
648const char *tomoyo_yesno(const unsigned int value); 677const char *tomoyo_yesno(const unsigned int value);
678void tomoyo_write_log(struct tomoyo_request_info *r, const char *fmt, ...)
679 __attribute__ ((format(printf, 2, 3)));
649void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt, 680void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt,
650 va_list args); 681 va_list args);
651void tomoyo_read_log(struct tomoyo_io_buffer *head); 682void tomoyo_read_log(struct tomoyo_io_buffer *head);
@@ -661,8 +692,6 @@ extern struct srcu_struct tomoyo_ss;
661/* The list for "struct tomoyo_domain_info". */ 692/* The list for "struct tomoyo_domain_info". */
662extern struct list_head tomoyo_domain_list; 693extern struct list_head tomoyo_domain_list;
663 694
664extern struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY];
665extern struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP];
666extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; 695extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
667 696
668/* Lock for protecting policy. */ 697/* Lock for protecting policy. */
@@ -671,10 +700,10 @@ extern struct mutex tomoyo_policy_lock;
671/* Has /sbin/init started? */ 700/* Has /sbin/init started? */
672extern bool tomoyo_policy_loaded; 701extern bool tomoyo_policy_loaded;
673 702
674extern struct list_head tomoyo_acl_group[TOMOYO_MAX_ACL_GROUPS];
675
676/* The kernel's domain. */ 703/* The kernel's domain. */
677extern struct tomoyo_domain_info tomoyo_kernel_domain; 704extern struct tomoyo_domain_info tomoyo_kernel_domain;
705extern struct tomoyo_policy_namespace tomoyo_kernel_namespace;
706extern struct list_head tomoyo_namespace_list;
678 707
679extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION]; 708extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];
680extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION]; 709extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION];
@@ -809,6 +838,16 @@ static inline bool tomoyo_same_number_union
809 a->value_type[1] == b->value_type[1]; 838 a->value_type[1] == b->value_type[1];
810} 839}
811 840
841/**
842 * tomoyo_current_namespace - Get "struct tomoyo_policy_namespace" for current thread.
843 *
844 * Returns pointer to "struct tomoyo_policy_namespace" for current thread.
845 */
846static inline struct tomoyo_policy_namespace *tomoyo_current_namespace(void)
847{
848 return tomoyo_domain()->ns;
849}
850
812#if defined(CONFIG_SLOB) 851#if defined(CONFIG_SLOB)
813 852
814/** 853/**