Skip to content

Commit

Permalink
selftests/seccomp: Avoid redundant register flushes
Browse files Browse the repository at this point in the history
When none of the registers have changed, don't flush them back. This can
happen if the architecture uses a non-register way to change the syscall
(e.g. arm64) , and a return value hasn't been written.

Signed-off-by: Kees Cook <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]
Acked-by: Christian Brauner <[email protected]>
  • Loading branch information
kees committed Sep 19, 2020
1 parent dc2ad16 commit e4e8e5d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tools/testing/selftests/seccomp/seccomp_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1859,11 +1859,12 @@ int get_syscall(struct __test_metadata *_metadata, pid_t tracee)
void change_syscall(struct __test_metadata *_metadata,
pid_t tracee, int syscall, int result)
{
ARCH_REGS regs;
ARCH_REGS orig, regs;

EXPECT_EQ(0, ARCH_GETREGS(regs)) {
return;
}
orig = regs;

SYSCALL_NUM_SET(regs, syscall);

Expand All @@ -1876,7 +1877,8 @@ void change_syscall(struct __test_metadata *_metadata,
#endif

/* Flush any register changes made. */
EXPECT_EQ(0, ARCH_SETREGS(regs));
if (memcmp(&orig, &regs, sizeof(orig)) != 0)
EXPECT_EQ(0, ARCH_SETREGS(regs));
}

void tracer_seccomp(struct __test_metadata *_metadata, pid_t tracee,
Expand Down

0 comments on commit e4e8e5d

Please sign in to comment.