Skip to content

Commit 484ca79

Browse files
Tetsuo Handaxjamesmorris
authored andcommitted
TOMOYO: Use pathname specified by policy rather than execve()
Commit c9e69318 "TOMOYO: Allow wildcard for execute permission." changed execute permission and domainname to accept wildcards. But tomoyo_find_next_domain() was using pathname passed to execve() rather than pathname specified by the execute permission. As a result, processes were not able to transit to domains which contain wildcards in their domainnames. This patch passes pathname specified by the execute permission back to tomoyo_find_next_domain() so that processes can transit to domains which contain wildcards in their domainnames. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: James Morris <jmorris@namei.org>
1 parent 4d6ec10 commit 484ca79

5 files changed

Lines changed: 48 additions & 23 deletions

File tree

‎security/tomoyo/common.h‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ struct tomoyo_request_info {
246246
union {
247247
struct {
248248
const struct tomoyo_path_info *filename;
249+
/* For using wildcards at tomoyo_find_next_domain(). */
250+
const struct tomoyo_path_info *matched_path;
249251
u8 operation;
250252
} path;
251253
struct {
@@ -718,8 +720,9 @@ bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
718720
/* Print out of memory warning message. */
719721
void tomoyo_warn_oom(const char *function);
720722
/* Check whether the given name matches the given name_union. */
721-
bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
722-
const struct tomoyo_name_union *ptr);
723+
const struct tomoyo_path_info *
724+
tomoyo_compare_name_union(const struct tomoyo_path_info *name,
725+
const struct tomoyo_name_union *ptr);
723726
/* Check whether the given number matches the given number_union. */
724727
bool tomoyo_compare_number_union(const unsigned long value,
725728
const struct tomoyo_number_union *ptr);
@@ -736,8 +739,9 @@ bool tomoyo_domain_def(const unsigned char *buffer);
736739
bool tomoyo_parse_name_union(const char *filename,
737740
struct tomoyo_name_union *ptr);
738741
/* Check whether the given filename matches the given path_group. */
739-
bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
740-
const struct tomoyo_group *group);
742+
const struct tomoyo_path_info *
743+
tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
744+
const struct tomoyo_group *group);
741745
/* Check whether the given value matches the given number_group. */
742746
bool tomoyo_number_matches_group(const unsigned long min,
743747
const unsigned long max,
@@ -879,7 +883,7 @@ int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
879883
const struct tomoyo_acl_head
880884
*));
881885
void tomoyo_check_acl(struct tomoyo_request_info *r,
882-
bool (*check_entry) (const struct tomoyo_request_info *,
886+
bool (*check_entry) (struct tomoyo_request_info *,
883887
const struct tomoyo_acl_info *));
884888

885889
/********** External variable definitions. **********/

‎security/tomoyo/domain.c‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
110110
}
111111

112112
void tomoyo_check_acl(struct tomoyo_request_info *r,
113-
bool (*check_entry) (const struct tomoyo_request_info *,
113+
bool (*check_entry) (struct tomoyo_request_info *,
114114
const struct tomoyo_acl_info *))
115115
{
116116
const struct tomoyo_domain_info *domain = r->domain;
@@ -465,6 +465,19 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
465465
goto retry;
466466
if (retval < 0)
467467
goto out;
468+
/*
469+
* To be able to specify domainnames with wildcards, use the
470+
* pathname specified in the policy (which may contain
471+
* wildcard) rather than the pathname passed to execve()
472+
* (which never contains wildcard).
473+
*/
474+
if (r.param.path.matched_path) {
475+
if (need_kfree)
476+
kfree(rn.name);
477+
need_kfree = false;
478+
/* This is OK because it is read only. */
479+
rn = *r.param.path.matched_path;
480+
}
468481

469482
/* Calculate domain to transit to. */
470483
switch (tomoyo_transition_type(old_domain->domainname, &rn)) {

‎security/tomoyo/file.c‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,15 @@ void tomoyo_put_name_union(struct tomoyo_name_union *ptr)
9595
tomoyo_put_name(ptr->filename);
9696
}
9797

98-
bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
99-
const struct tomoyo_name_union *ptr)
98+
const struct tomoyo_path_info *
99+
tomoyo_compare_name_union(const struct tomoyo_path_info *name,
100+
const struct tomoyo_name_union *ptr)
100101
{
101102
if (ptr->is_group)
102103
return tomoyo_path_matches_group(name, ptr->group);
103-
return tomoyo_path_matches_pattern(name, ptr->filename);
104+
if (tomoyo_path_matches_pattern(name, ptr->filename))
105+
return ptr->filename;
106+
return NULL;
104107
}
105108

106109
void tomoyo_put_number_union(struct tomoyo_number_union *ptr)
@@ -504,16 +507,21 @@ int tomoyo_write_no_rewrite(char *data, const bool is_delete)
504507
return tomoyo_update_no_rewrite_entry(data, is_delete);
505508
}
506509

507-
static bool tomoyo_check_path_acl(const struct tomoyo_request_info *r,
510+
static bool tomoyo_check_path_acl(struct tomoyo_request_info *r,
508511
const struct tomoyo_acl_info *ptr)
509512
{
510513
const struct tomoyo_path_acl *acl = container_of(ptr, typeof(*acl),
511514
head);
512-
return (acl->perm & (1 << r->param.path.operation)) &&
513-
tomoyo_compare_name_union(r->param.path.filename, &acl->name);
515+
if (acl->perm & (1 << r->param.path.operation)) {
516+
r->param.path.matched_path =
517+
tomoyo_compare_name_union(r->param.path.filename,
518+
&acl->name);
519+
return r->param.path.matched_path != NULL;
520+
}
521+
return false;
514522
}
515523

516-
static bool tomoyo_check_path_number_acl(const struct tomoyo_request_info *r,
524+
static bool tomoyo_check_path_number_acl(struct tomoyo_request_info *r,
517525
const struct tomoyo_acl_info *ptr)
518526
{
519527
const struct tomoyo_path_number_acl *acl =
@@ -525,7 +533,7 @@ static bool tomoyo_check_path_number_acl(const struct tomoyo_request_info *r,
525533
&acl->name);
526534
}
527535

528-
static bool tomoyo_check_path2_acl(const struct tomoyo_request_info *r,
536+
static bool tomoyo_check_path2_acl(struct tomoyo_request_info *r,
529537
const struct tomoyo_acl_info *ptr)
530538
{
531539
const struct tomoyo_path2_acl *acl =
@@ -536,7 +544,7 @@ static bool tomoyo_check_path2_acl(const struct tomoyo_request_info *r,
536544
&acl->name2);
537545
}
538546

539-
static bool tomoyo_check_mkdev_acl(const struct tomoyo_request_info *r,
547+
static bool tomoyo_check_mkdev_acl(struct tomoyo_request_info *r,
540548
const struct tomoyo_acl_info *ptr)
541549
{
542550
const struct tomoyo_mkdev_acl *acl =

‎security/tomoyo/group.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,24 @@ int tomoyo_write_group(char *data, const bool is_delete, const u8 type)
8080
* @pathname: The name of pathname.
8181
* @group: Pointer to "struct tomoyo_path_group".
8282
*
83-
* Returns true if @pathname matches pathnames in @group, false otherwise.
83+
* Returns matched member's pathname if @pathname matches pathnames in @group,
84+
* NULL otherwise.
8485
*
8586
* Caller holds tomoyo_read_lock().
8687
*/
87-
bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
88-
const struct tomoyo_group *group)
88+
const struct tomoyo_path_info *
89+
tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
90+
const struct tomoyo_group *group)
8991
{
9092
struct tomoyo_path_group *member;
91-
bool matched = false;
9293
list_for_each_entry_rcu(member, &group->member_list, head.list) {
9394
if (member->head.is_deleted)
9495
continue;
9596
if (!tomoyo_path_matches_pattern(pathname, member->member_name))
9697
continue;
97-
matched = true;
98-
break;
98+
return member->member_name;
9999
}
100-
return matched;
100+
return NULL;
101101
}
102102

103103
/**

‎security/tomoyo/mount.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static int tomoyo_audit_mount_log(struct tomoyo_request_info *r)
6060
flags);
6161
}
6262

63-
static bool tomoyo_check_mount_acl(const struct tomoyo_request_info *r,
63+
static bool tomoyo_check_mount_acl(struct tomoyo_request_info *r,
6464
const struct tomoyo_acl_info *ptr)
6565
{
6666
const struct tomoyo_mount_acl *acl =

0 commit comments

Comments
 (0)