Skip to content

Commit b274279

Browse files
committed
Merge tag 'tomoyo-pr-20201012' of git://git.osdn.net/gitroot/tomoyo/tomoyo-test1
Pull tomoyo fix from Tetsuo HandaL "One patch to make it possible to execute usermode-driver's path" * tag 'tomoyo-pr-20201012' of git://git.osdn.net/gitroot/tomoyo/tomoyo-test1: tomoyo: Loosen pathname/domainname validation.
2 parents d594d8f + a207516 commit b274279

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)