linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] ptrace: is_syscall_success: Add syscall return code handling for compat task
@ 2021-04-14  8:02 He Zhe
  2021-04-14 15:08 ` Oleg Nesterov
  0 siblings, 1 reply; 7+ messages in thread
From: He Zhe @ 2021-04-14  8:02 UTC (permalink / raw)
  To: oleg, linux-kernel, zhe.he

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-04-15  5:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-14  8:02 [PATCH 2/2] ptrace: is_syscall_success: Add syscall return code handling for compat task He Zhe
2021-04-14 15:08 ` Oleg Nesterov
2021-04-14 16:17   ` David Laight
2021-04-14 16:55     ` Oleg Nesterov
2021-04-14 21:39       ` David Laight
2021-04-15  5:12       ` He Zhe
2021-04-15  5:48         ` Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).