linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: He Zhe <zhe.he@windriver.com>
To: oleg@redhat.com, linux-kernel@vger.kernel.org, zhe.he@windriver.com
Subject: [PATCH 2/2] ptrace: is_syscall_success: Add syscall return code handling for compat task
Date: Wed, 14 Apr 2021 16:02:45 +0800	[thread overview]
Message-ID: <20210414080245.25476-1-zhe.he@windriver.com> (raw)

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


             reply	other threads:[~2021-04-14  8:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-14  8:02 He Zhe [this message]
2021-04-14 15:08 ` [PATCH 2/2] ptrace: is_syscall_success: Add syscall return code handling for compat task 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210414080245.25476-1-zhe.he@windriver.com \
    --to=zhe.he@windriver.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).