From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Laurent Vivier <laurent@vivier.eu>,
Filip Bozuta <Filip.Bozuta@syrmia.com>
Subject: [PATCH v2 2/2] linux-user: fix print_syscall_err() when syscall returned value is negative
Date: Wed, 8 Jul 2020 17:24:35 +0200 [thread overview]
Message-ID: <20200708152435.706070-3-laurent@vivier.eu> (raw)
In-Reply-To: <20200708152435.706070-1-laurent@vivier.eu>
print_syscall_err() relies on the sign of the returned value to know
if it is an errno value or not.
But in some cases the returned value can have the most signicant bit
set without being an errno.
This patch restores previous behaviour that was also checking if
we can decode the errno to validate it.
This patch fixes this kind of problem (qemu-m68k):
root@sid:/# QEMU_STRACE= ls
3 brk(NULL) = -1 errno=21473607683 uname(0x407fff8a) = 0
to become:
root@sid:/# QEMU_STRACE= ls
3 brk(NULL) = 0x8001e000
3 uname(0xffffdf8a) = 0
Fixes: c84be71f6854 ("linux-user: Extend strace support to enable argument printing after syscall execution")
Cc: Filip.Bozuta@syrmia.com
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/strace.c | 36 +++++++++++++-----------------------
1 file changed, 13 insertions(+), 23 deletions(-)
diff --git a/linux-user/strace.c b/linux-user/strace.c
index b42664bbd180..17f2554643f0 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -724,19 +724,20 @@ print_ipc(const struct syscallname *name,
* Variants for the return value output function
*/
-static void
+static bool
print_syscall_err(abi_long ret)
{
- const char *errstr = NULL;
+ const char *errstr;
qemu_log(" = ");
if (ret < 0) {
- qemu_log("-1 errno=%d", (int)-ret);
errstr = target_strerror(-ret);
if (errstr) {
- qemu_log(" (%s)", errstr);
+ qemu_log("-1 errno=%d (%s)", (int)-ret, errstr);
+ return true;
}
}
+ return false;
}
static void
@@ -744,11 +745,10 @@ print_syscall_ret_addr(const struct syscallname *name, abi_long ret,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
- print_syscall_err(ret);
-
- if (ret >= 0) {
- qemu_log("0x" TARGET_ABI_FMT_lx "\n", ret);
+ if (!print_syscall_err(ret)) {
+ qemu_log("0x" TARGET_ABI_FMT_lx, ret);
}
+ qemu_log("\n");
}
#if 0 /* currently unused */
@@ -765,9 +765,7 @@ print_syscall_ret_newselect(const struct syscallname *name, abi_long ret,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
- print_syscall_err(ret);
-
- if (ret >= 0) {
+ if (!print_syscall_err(ret)) {
qemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
print_fdset(arg0, arg1);
qemu_log(",");
@@ -796,9 +794,7 @@ print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
- print_syscall_err(ret);
-
- if (ret >= 0) {
+ if (!print_syscall_err(ret)) {
qemu_log(TARGET_ABI_FMT_ld, ret);
switch (ret) {
case TARGET_TIME_OK:
@@ -833,9 +829,7 @@ print_syscall_ret_listxattr(const struct syscallname *name, abi_long ret,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
- print_syscall_err(ret);
-
- if (ret >= 0) {
+ if (!print_syscall_err(ret)) {
qemu_log(TARGET_ABI_FMT_ld, ret);
qemu_log(" (list = ");
if (arg1 != 0) {
@@ -866,9 +860,7 @@ print_syscall_ret_ioctl(const struct syscallname *name, abi_long ret,
abi_long arg0, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
- print_syscall_err(ret);
-
- if (ret >= 0) {
+ if (!print_syscall_err(ret)) {
qemu_log(TARGET_ABI_FMT_ld, ret);
const IOCTLEntry *ie;
@@ -3189,9 +3181,7 @@ print_syscall_ret(int num, abi_long ret,
arg1, arg2, arg3,
arg4, arg5, arg6);
} else {
- print_syscall_err(ret);
-
- if (ret >= 0) {
+ if (!print_syscall_err(ret)) {
qemu_log(TARGET_ABI_FMT_ld, ret);
}
qemu_log("\n");
--
2.26.2
next prev parent reply other threads:[~2020-07-08 15:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-08 15:24 [PATCH v2 0/2] linux-user: fix print_syscall_err() Laurent Vivier
2020-07-08 15:24 ` [PATCH v2 1/2] linux-user: fix the errno value in print_syscall_err() Laurent Vivier
2020-07-08 15:49 ` Richard Henderson
2020-07-08 16:47 ` Philippe Mathieu-Daudé
2020-07-10 13:48 ` Filip Bozuta
2020-07-13 19:29 ` Laurent Vivier
2020-07-08 15:24 ` Laurent Vivier [this message]
2020-07-08 15:52 ` [PATCH v2 2/2] linux-user: fix print_syscall_err() when syscall returned value is negative Richard Henderson
2020-07-08 16:13 ` Laurent Vivier
2020-07-13 19:34 ` Laurent Vivier
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=20200708152435.706070-3-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=Filip.Bozuta@syrmia.com \
--cc=qemu-devel@nongnu.org \
/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).