Skip to content

Commit 4613832

Browse files
committed
selftests/seccomp: powerpc: Fix seccomp return value testing
On powerpc, the errno is not inverted, and depends on ccr.so being set. Add this to a powerpc definition of SYSCALL_RET_SET(). Co-developed-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com> Link: https://lore.kernel.org/linux-kselftest/20200911181012.171027-1-cascardo@canonical.com/ Fixes: 5d83c2b ("selftests/seccomp: Add powerpc support") Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/lkml/20200912110820.597135-13-keescook@chromium.org Reviewed-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent f04cf78 commit 4613832

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,21 @@ TEST_F(TRACE_poke, getpid_runs_normally)
17501750
# define ARCH_REGS struct pt_regs
17511751
# define SYSCALL_NUM(_regs) (_regs).gpr[0]
17521752
# define SYSCALL_RET(_regs) (_regs).gpr[3]
1753+
# define SYSCALL_RET_SET(_regs, _val) \
1754+
do { \
1755+
typeof(_val) _result = (_val); \
1756+
/* \
1757+
* A syscall error is signaled by CR0 SO bit \
1758+
* and the code is stored as a positive value. \
1759+
*/ \
1760+
if (_result < 0) { \
1761+
SYSCALL_RET(_regs) = -result; \
1762+
(_regs).ccr |= 0x10000000; \
1763+
} else { \
1764+
SYSCALL_RET(_regs) = result; \
1765+
(_regs).ccr &= ~0x10000000; \
1766+
} \
1767+
} while (0)
17531768
#elif defined(__s390__)
17541769
# define ARCH_REGS s390_regs
17551770
# define SYSCALL_NUM(_regs) (_regs).gprs[2]

0 commit comments

Comments
 (0)