lkml.org 
[lkml]   [2021]   [Apr]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] ptrace: is_syscall_success: Add syscall return code handling for compat task
Date
When 32-bit userspace application is running on 64-bit kernel, the 32-bit
syscall return code would be changed from u32 to u64 in regs_return_value
and then changed to s64. Hence the negative return code would be treated
as a positive number and results in a non-error in, for example, audit
like below.

type=SYSCALL msg=audit(1611110715.887:582): arch=40000028 syscall=322
success=yes exit=4294967283

This patch forces the u32->s32->s64 for compat tasks.

Signed-off-by: He Zhe <zhe.he@windriver.com>
---
include/linux/ptrace.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
index b5ebf6c01292..bc3056fff8a6 100644
--- a/include/linux/ptrace.h
+++ b/include/linux/ptrace.h
@@ -260,7 +260,9 @@ static inline void ptrace_release_task(struct task_struct *task)
* is an error value. On some systems like ia64 and powerpc they have different
* indicators of success/failure and must define their own.
*/
-#define is_syscall_success(regs) (!IS_ERR_VALUE((unsigned long)(regs_return_value(regs))))
+#define is_syscall_success(regs) (!IS_ERR_VALUE(is_compat_task() ? \
+ (unsigned long)(s64)(s32)(regs_return_value(regs)) : \
+ (unsigned long)(regs_return_value(regs))))
#endif

/*
--
2.17.1
\
 
 \ /
  Last update: 2021-04-14 10:05    [W:0.054 / U:0.804 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site