Skip to content

Commit 08ae248

Browse files
Tetsuo HandaTetsuo Handa
authored andcommitted
tomoyo: automatically use patterns for several situations in learning mode
The "file_pattern" keyword was used for automatically recording patternized pathnames when using the learning mode. This keyword was removed in TOMOYO 2.4 because it is impossible to predefine all possible pathname patterns. However, since the numeric part of proc:/$PID/ , pipe:[$INO] and socket:[$INO] has no meaning except $PID == 1, automatically replacing the numeric part with \$ pattern helps reducing frequency of restarting the learning mode due to hitting the quota. Since replacing one digit with \$ pattern requires enlarging string buffer, and several programs access only $PID == 1, replace only two or more digits with \$ pattern. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
1 parent 0476fd4 commit 08ae248

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

security/tomoyo/common.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,36 @@ static void tomoyo_add_entry(struct tomoyo_domain_info *domain, char *header)
20242024
if (!buffer)
20252025
return;
20262026
snprintf(buffer, len - 1, "%s", cp);
2027+
if (*cp == 'f' && strchr(buffer, ':')) {
2028+
/* Automatically replace 2 or more digits with \$ pattern. */
2029+
char *cp2;
2030+
2031+
/* e.g. file read proc:/$PID/stat */
2032+
cp = strstr(buffer, " proc:/");
2033+
if (cp && simple_strtoul(cp + 7, &cp2, 10) >= 10 && *cp2 == '/') {
2034+
*(cp + 7) = '\\';
2035+
*(cp + 8) = '$';
2036+
memmove(cp + 9, cp2, strlen(cp2) + 1);
2037+
goto ok;
2038+
}
2039+
/* e.g. file ioctl pipe:[$INO] $CMD */
2040+
cp = strstr(buffer, " pipe:[");
2041+
if (cp && simple_strtoul(cp + 7, &cp2, 10) >= 10 && *cp2 == ']') {
2042+
*(cp + 7) = '\\';
2043+
*(cp + 8) = '$';
2044+
memmove(cp + 9, cp2, strlen(cp2) + 1);
2045+
goto ok;
2046+
}
2047+
/* e.g. file ioctl socket:[$INO] $CMD */
2048+
cp = strstr(buffer, " socket:[");
2049+
if (cp && simple_strtoul(cp + 9, &cp2, 10) >= 10 && *cp2 == ']') {
2050+
*(cp + 9) = '\\';
2051+
*(cp + 10) = '$';
2052+
memmove(cp + 11, cp2, strlen(cp2) + 1);
2053+
goto ok;
2054+
}
2055+
}
2056+
ok:
20272057
if (realpath)
20282058
tomoyo_addprintf(buffer, len, " exec.%s", realpath);
20292059
if (argv0)

0 commit comments

Comments
 (0)