Skip to content

Commit bdcbbf8

Browse files
cgzonesjwcart2
authored andcommitted
libselinux: limit fcontext regex path length
Limit the length of regular expression paths in fcontext source definitions to reduce the worst case regex compilation time for abnormal inputs. Reported-by: oss-fuzz (issue 393203212) Signed-off-by: Christian Göttsche <[email protected]> Acked-by: James Carter <[email protected]>
1 parent f5a8e05 commit bdcbbf8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

libselinux/src/label_file.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,14 @@ static inline int compile_regex(struct regex_spec *spec, char *errbuf, size_t er
439439
reg_buf = spec->regex_str;
440440
/* Anchor the regular expression. */
441441
len = strlen(reg_buf);
442+
/* Use a sufficient large upper bound for regular expression lengths
443+
* to limit the compilation time on malformed inputs. */
444+
if (len >= 4096) {
445+
__pthread_mutex_unlock(&spec->regex_lock);
446+
snprintf(errbuf, errbuf_size, "regex of length %zu too long", len);
447+
errno = EINVAL;
448+
return -1;
449+
}
442450
cp = anchored_regex = malloc(len + 3);
443451
if (!anchored_regex) {
444452
__pthread_mutex_unlock(&spec->regex_lock);

0 commit comments

Comments
 (0)