Skip to content

Commit a207516

Browse files
Tetsuo HandaTetsuo Handa
authored andcommitted
tomoyo: Loosen pathname/domainname validation.
Since commit e2dc9bf ("umd: Transform fork_usermode_blob into fork_usermode_driver") started calling execve() on a program written in a local mount which is not connected to mount tree, tomoyo_realpath_from_path() started returning a pathname in "$fsname:/$pathname" format which violates TOMOYO's domainname rule that it must start with "<$namespace>" followed by zero or more repetitions of pathnames which start with '/'. Since $fsname must not contain '.' since commit 79c0b2d ("add filesystem subtype support"), tomoyo_correct_path() can recognize a token which appears '/' before '.' appears (e.g. proc:/self/exe ) as a pathname while rejecting a token which appears '.' before '/' appears (e.g. exec.realpath="/bin/bash" ) as a condition parameter. Therefore, accept domainnames which contain pathnames which do not start with '/' but contain '/' before '.' (e.g. <kernel> tmpfs:/bpfilter_umh ). Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
1 parent bbf5c97 commit a207516

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

security/tomoyo/util.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ char *tomoyo_read_token(struct tomoyo_acl_param *param)
143143
return pos;
144144
}
145145

146+
static bool tomoyo_correct_path2(const char *filename, const size_t len);
147+
146148
/**
147149
* tomoyo_get_domainname - Read a domainname from a line.
148150
*
@@ -157,10 +159,10 @@ const struct tomoyo_path_info *tomoyo_get_domainname
157159
char *pos = start;
158160

159161
while (*pos) {
160-
if (*pos++ != ' ' || *pos++ == '/')
162+
if (*pos++ != ' ' ||
163+
tomoyo_correct_path2(pos, strchrnul(pos, ' ') - pos))
161164
continue;
162-
pos -= 2;
163-
*pos++ = '\0';
165+
*(pos - 1) = '\0';
164166
break;
165167
}
166168
param->data = pos;
@@ -513,6 +515,22 @@ bool tomoyo_correct_word(const char *string)
513515
return tomoyo_correct_word2(string, strlen(string));
514516
}
515517

518+
/**
519+
* tomoyo_correct_path2 - Check whether the given pathname follows the naming rules.
520+
*
521+
* @filename: The pathname to check.
522+
* @len: Length of @filename.
523+
*
524+
* Returns true if @filename follows the naming rules, false otherwise.
525+
*/
526+
static bool tomoyo_correct_path2(const char *filename, const size_t len)
527+
{
528+
const char *cp1 = memchr(filename, '/', len);
529+
const char *cp2 = memchr(filename, '.', len);
530+
531+
return cp1 && (!cp2 || (cp1 < cp2)) && tomoyo_correct_word2(filename, len);
532+
}
533+
516534
/**
517535
* tomoyo_correct_path - Validate a pathname.
518536
*
@@ -523,7 +541,7 @@ bool tomoyo_correct_word(const char *string)
523541
*/
524542
bool tomoyo_correct_path(const char *filename)
525543
{
526-
return *filename == '/' && tomoyo_correct_word(filename);
544+
return tomoyo_correct_path2(filename, strlen(filename));
527545
}
528546

529547
/**
@@ -545,8 +563,7 @@ bool tomoyo_correct_domain(const unsigned char *domainname)
545563

546564
if (!cp)
547565
break;
548-
if (*domainname != '/' ||
549-
!tomoyo_correct_word2(domainname, cp - domainname))
566+
if (!tomoyo_correct_path2(domainname, cp - domainname))
550567
return false;
551568
domainname = cp + 1;
552569
}

0 commit comments

Comments
 (0)