From 858df15ea6354b6a75979720bce057b696545fd0 Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Tue, 30 Jun 2020 08:16:38 -0600 Subject: arch: Use bitwise math rather than arithmetic The arm and x32 architecture files were using arithmetic to set/clear bits in their syscall numbers. This could erroneously double add or double subtract these bits. This commit uses bitwise logic to ensure the bits are properly set/cleared. Signed-off-by: Tom Hromatka Signed-off-by: Paul Moore --- src/arch-arm.c | 4 ++-- src/arch-x32.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/arch-arm.c b/src/arch-arm.c index 3465111..4dd4b63 100644 --- a/src/arch-arm.c +++ b/src/arch-arm.c @@ -54,7 +54,7 @@ int arm_syscall_resolve_name_munge(const char *name) if (sys == __NR_SCMP_ERROR) return sys; - return sys + __SCMP_NR_BASE; + return (sys | __SCMP_NR_BASE); } /** @@ -68,7 +68,7 @@ int arm_syscall_resolve_name_munge(const char *name) */ const char *arm_syscall_resolve_num_munge(int num) { - return arm_syscall_resolve_num(num - __SCMP_NR_BASE); + return arm_syscall_resolve_num(num & (~__SCMP_NR_BASE)); } const struct arch_def arch_def_arm = { diff --git a/src/arch-x32.c b/src/arch-x32.c index 7b97fb3..3890968 100644 --- a/src/arch-x32.c +++ b/src/arch-x32.c @@ -43,7 +43,7 @@ int x32_syscall_resolve_name_munge(const char *name) if (sys == __NR_SCMP_ERROR) return sys; - return sys + X32_SYSCALL_BIT; + return (sys | X32_SYSCALL_BIT); } /** @@ -57,7 +57,7 @@ int x32_syscall_resolve_name_munge(const char *name) */ const char *x32_syscall_resolve_num_munge(int num) { - return x32_syscall_resolve_num(num - X32_SYSCALL_BIT); + return x32_syscall_resolve_num(num & (~X32_SYSCALL_BIT)); } const struct arch_def arch_def_x32 = { -- cgit v1.2.1