Skip to content

Commit fe4bfff

Browse files
committed
seccomp: Use -1 marker for end of mode 1 syscall list
The terminator for the mode 1 syscalls list was a 0, but that could be a valid syscall number (e.g. x86_64 __NR_read). By luck, __NR_read was listed first and the loop construct would not test it, so there was no bug. However, this is fragile. Replace the terminator with -1 instead, and make the variable name for mode 1 syscall lists more descriptive. Cc: Andy Lutomirski <[email protected]> Cc: Will Drewry <[email protected]> Signed-off-by: Kees Cook <[email protected]>
1 parent 47e33c0 commit fe4bfff

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

arch/mips/include/asm/seccomp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ static inline const int *get_compat_mode1_syscalls(void)
99
static const int syscalls_O32[] = {
1010
__NR_O32_Linux + 3, __NR_O32_Linux + 4,
1111
__NR_O32_Linux + 1, __NR_O32_Linux + 193,
12-
0, /* null terminated */
12+
-1, /* negative terminated */
1313
};
1414
static const int syscalls_N32[] = {
1515
__NR_N32_Linux + 0, __NR_N32_Linux + 1,
1616
__NR_N32_Linux + 58, __NR_N32_Linux + 211,
17-
0, /* null terminated */
17+
-1, /* negative terminated */
1818
};
1919

2020
if (IS_ENABLED(CONFIG_MIPS32_O32) && test_thread_flag(TIF_32BIT_REGS))

include/asm-generic/seccomp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static inline const int *get_compat_mode1_syscalls(void)
3333
static const int mode1_syscalls_32[] = {
3434
__NR_seccomp_read_32, __NR_seccomp_write_32,
3535
__NR_seccomp_exit_32, __NR_seccomp_sigreturn_32,
36-
0, /* null terminated */
36+
-1, /* negative terminated */
3737
};
3838
return mode1_syscalls_32;
3939
}

kernel/seccomp.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,20 +742,20 @@ static inline void seccomp_log(unsigned long syscall, long signr, u32 action,
742742
*/
743743
static const int mode1_syscalls[] = {
744744
__NR_seccomp_read, __NR_seccomp_write, __NR_seccomp_exit, __NR_seccomp_sigreturn,
745-
0, /* null terminated */
745+
-1, /* negative terminated */
746746
};
747747

748748
static void __secure_computing_strict(int this_syscall)
749749
{
750-
const int *syscall_whitelist = mode1_syscalls;
750+
const int *allowed_syscalls = mode1_syscalls;
751751
#ifdef CONFIG_COMPAT
752752
if (in_compat_syscall())
753-
syscall_whitelist = get_compat_mode1_syscalls();
753+
allowed_syscalls = get_compat_mode1_syscalls();
754754
#endif
755755
do {
756-
if (*syscall_whitelist == this_syscall)
756+
if (*allowed_syscalls == this_syscall)
757757
return;
758-
} while (*++syscall_whitelist);
758+
} while (*++allowed_syscalls != -1);
759759

760760
#ifdef SECCOMP_DEBUG
761761
dump_stack();

0 commit comments

Comments
 (0)