From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: "Eric Blake" <eblake@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Riku Voipio" <riku.voipio@iki.fi>,
"Laurent Vivier" <laurent@vivier.eu>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH for 2.10 28/35] syscall: check dup/dup2/dup3() errors, return EBADFD/EINVAL if required
Date: Mon, 24 Jul 2017 15:27:44 -0300 [thread overview]
Message-ID: <20170724182751.18261-29-f4bug@amsat.org> (raw)
In-Reply-To: <20170724182751.18261-1-f4bug@amsat.org>
Linux dup(2) manpage:
ERRORS
EBADF
newfd is out of the allowed range for file descriptors (like negative)
EINVAL (dup3())
oldfd was equal to newfd
Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
linux-user/syscall.c | 32 +++++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e79b5baec4..637270a02d 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8336,9 +8336,13 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
break;
#endif
case TARGET_NR_dup:
- ret = get_errno(dup(arg1));
- if (ret >= 0) {
- fd_trans_dup(arg1, ret);
+ if (arg1 < 0) {
+ ret = -TARGET_EBADFD;
+ } else {
+ ret = get_errno(dup(arg1));
+ if (ret >= 0) {
+ fd_trans_dup(arg1, ret);
+ }
}
break;
#ifdef TARGET_NR_pipe
@@ -8436,17 +8440,27 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
#endif
#ifdef TARGET_NR_dup2
case TARGET_NR_dup2:
- ret = get_errno(dup2(arg1, arg2));
- if (ret >= 0) {
- fd_trans_dup(arg1, arg2);
+ if (arg1 < 0 || arg2 < 0) {
+ ret = -TARGET_EBADFD;
+ } else {
+ ret = get_errno(dup2(arg1, arg2));
+ if (ret >= 0) {
+ fd_trans_dup(arg1, arg2);
+ }
}
break;
#endif
#if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)
case TARGET_NR_dup3:
- ret = get_errno(dup3(arg1, arg2, arg3));
- if (ret >= 0) {
- fd_trans_dup(arg1, arg2);
+ if (arg1 < 0 || arg2 < 0) {
+ ret = -TARGET_EBADFD;
+ } else if (arg1 == arg2) {
+ ret = -TARGET_EINVAL;
+ } else {
+ ret = get_errno(dup3(arg1, arg2, arg3));
+ if (ret >= 0) {
+ fd_trans_dup(arg1, arg2);
+ }
}
break;
#endif
--
2.13.3
next prev parent reply other threads:[~2017-07-24 18:29 UTC|newest]
Thread overview: 111+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-24 18:27 [Qemu-devel] [PATCH for 2.10 00/35] fix bugs reported by Clang Static Analyzer Philippe Mathieu-Daudé
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 01/35] tests: add missing dependency to build QTEST_QEMU_BINARY Philippe Mathieu-Daudé
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 02/35] loader: check get_image_size() return value Philippe Mathieu-Daudé
2017-07-24 18:38 ` Eric Blake
2017-07-24 20:59 ` Alistair Francis
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 03/35] thunk: check nb_fields is valid before continuing Philippe Mathieu-Daudé
2017-07-24 18:37 ` Eric Blake
2017-07-26 22:48 ` Philippe Mathieu-Daudé
2017-07-24 21:16 ` Peter Maydell
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 04/35] ivshmem: fix incorrect error handling in ivshmem_recv_msg() Philippe Mathieu-Daudé
2017-07-25 8:18 ` Markus Armbruster
2017-07-27 22:05 ` Paolo Bonzini
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 05/35] nbd: fix memory leak in nbd_opt_go() Philippe Mathieu-Daudé
2017-07-24 18:41 ` Eric Blake
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 06/35] qcow2: remove inconsistent check Philippe Mathieu-Daudé
2017-07-24 18:42 ` Eric Blake
2017-07-25 15:36 ` Paolo Bonzini
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 07/35] qcow2: fix null pointer dereference Philippe Mathieu-Daudé
2017-07-24 18:46 ` Eric Blake
2017-07-25 1:44 ` Philippe Mathieu-Daudé
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 08/35] " Philippe Mathieu-Daudé
2017-07-24 18:52 ` Eric Blake
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 09/35] ui/vnc: fix leak of SocketAddress ** Philippe Mathieu-Daudé
2017-07-25 8:37 ` Daniel P. Berrange
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 10/35] net/eth: fix incorrect check of iov_to_buf() return value Philippe Mathieu-Daudé
2017-07-26 9:51 ` Dmitry Fleytman
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 11/35] i2c/exynos4210: correctly check i2c_recv() " Philippe Mathieu-Daudé
2017-07-24 21:13 ` Peter Maydell
2017-07-25 5:23 ` Philippe Mathieu-Daudé
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 12/35] vfio/platform: fix use of freed memory Philippe Mathieu-Daudé
2017-07-25 15:37 ` Paolo Bonzini
2017-07-26 17:43 ` Alex Williamson
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 13/35] vfio/pci: " Philippe Mathieu-Daudé
2017-07-25 15:38 ` Paolo Bonzini
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 14/35] vfio/ccw: fix incorrect malloc() size Philippe Mathieu-Daudé
2017-07-25 7:20 ` Cornelia Huck
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 15/35] usb: correctly handle Zero Length Packets Philippe Mathieu-Daudé
2018-05-29 14:22 ` Philippe Mathieu-Daudé
2018-05-30 6:16 ` Gerd Hoffmann
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 16/35] usb/dev-mtp: fix use of uninitialized values Philippe Mathieu-Daudé
2017-07-25 12:34 ` Gerd Hoffmann
2017-07-26 23:23 ` Philippe Mathieu-Daudé
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 17/35] " Philippe Mathieu-Daudé
2017-07-26 23:26 ` Philippe Mathieu-Daudé
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 18/35] " Philippe Mathieu-Daudé
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 19/35] usb/dev-mtp: fix use of uninitialized variable Philippe Mathieu-Daudé
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 20/35] arm/boot: fix undefined instruction on secondary smp cpu bootloader Philippe Mathieu-Daudé
2017-07-24 21:06 ` Peter Maydell
2017-07-26 23:00 ` Philippe Mathieu-Daudé
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 21/35] arm/sysbus-fdt: fix null pointer dereference Philippe Mathieu-Daudé
2017-07-24 21:09 ` Peter Maydell
2017-07-24 21:20 ` Philippe Mathieu-Daudé
2017-07-24 21:24 ` Peter Maydell
2017-07-24 21:48 ` Philippe Mathieu-Daudé
2017-07-24 21:52 ` Eric Blake
2017-07-24 21:57 ` Eric Blake
2018-05-29 14:33 ` Philippe Mathieu-Daudé
2018-05-29 15:27 ` Eric Blake
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 22/35] arm/vexpress: fix potential memory leak Philippe Mathieu-Daudé
2017-07-24 21:11 ` Peter Maydell
2017-07-24 21:45 ` Philippe Mathieu-Daudé
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 23/35] m68k/translate: fix incorrect copy/paste Philippe Mathieu-Daudé
2017-07-24 18:54 ` Laurent Vivier
2017-07-24 19:01 ` Richard Henderson
2017-07-24 19:19 ` Philippe Mathieu-Daudé
2017-07-24 19:20 ` Laurent Vivier
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 24/35] linux-user/sh4: fix incorrect memory write Philippe Mathieu-Daudé
2017-07-24 18:59 ` Laurent Vivier
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 25/35] linux-user: extract is_error() out of syscall.c Philippe Mathieu-Daudé
2017-07-24 19:14 ` Laurent Vivier
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 26/35] linux-user: use is_error() to avoid warnings and make the code clearer Philippe Mathieu-Daudé
2017-07-24 19:16 ` Laurent Vivier
2018-05-29 14:25 ` Philippe Mathieu-Daudé
2018-05-29 15:19 ` Laurent Vivier
2018-06-03 23:33 ` Laurent Vivier
2018-06-04 14:20 ` Philippe Mathieu-Daudé
2018-06-04 15:16 ` Laurent Vivier
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 27/35] syscall: fix dereference of undefined pointer Philippe Mathieu-Daudé
2017-07-24 19:33 ` Laurent Vivier
2017-07-25 5:34 ` Philippe Mathieu-Daudé
2017-07-24 21:26 ` Peter Maydell
2017-07-25 7:25 ` Laurent Vivier
2017-07-24 18:27 ` Philippe Mathieu-Daudé [this message]
2017-07-24 19:56 ` [Qemu-devel] [PATCH for 2.10 28/35] syscall: check dup/dup2/dup3() errors, return EBADFD/EINVAL if required Laurent Vivier
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 29/35] syscall: fix out-of-bound memory access Philippe Mathieu-Daudé
2017-07-24 19:41 ` Laurent Vivier
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 30/35] syscall: fix use of uninitialized values Philippe Mathieu-Daudé
2017-07-24 19:51 ` Laurent Vivier
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 31/35] syscall: replace strcpy() by g_strlcpy() Philippe Mathieu-Daudé
2017-07-24 19:28 ` Laurent Vivier
2018-05-29 14:19 ` Philippe Mathieu-Daudé
2018-05-29 15:22 ` Laurent Vivier
2017-07-24 18:27 ` [Qemu-devel] [PATCH for 2.10 32/35] timer/pxa2xx: silent warning about out-of-bound memory access Philippe Mathieu-Daudé
2017-07-24 21:01 ` Peter Maydell
2017-07-24 21:51 ` Philippe Mathieu-Daudé
2017-07-24 18:27 ` [Qemu-devel] [RFC PATCH for 2.10 33/35] configure: clang does not support -Wexpansion-to-defined Philippe Mathieu-Daudé
2017-07-24 20:08 ` Paolo Bonzini
2017-07-24 21:22 ` Peter Maydell
2017-07-24 21:55 ` Philippe Mathieu-Daudé
2017-07-24 18:27 ` [Qemu-devel] [RFC PATCH for 2.10 34/35] docker: add debian 'bleeding' image with gcc7 and clang5 Philippe Mathieu-Daudé
2017-07-25 14:15 ` Alex Bennée
2017-07-25 14:22 ` Daniel P. Berrange
2017-07-25 14:46 ` Alex Bennée
2017-07-25 14:51 ` Philippe Mathieu-Daudé
2017-07-25 15:05 ` Alex Bennée
2017-07-24 18:27 ` [Qemu-devel] [RFC PATCH for 2.10 35/35] script to run docker image Philippe Mathieu-Daudé
2017-07-25 14:12 ` Alex Bennée
2017-07-25 14:41 ` Philippe Mathieu-Daudé
2017-07-25 15:03 ` Alex Bennée
2017-07-25 15:17 ` Philippe Mathieu-Daudé
2017-07-24 21:27 ` [Qemu-devel] [PATCH for 2.10 00/35] fix bugs reported by Clang Static Analyzer Peter Maydell
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=20170724182751.18261-29-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=eblake@redhat.com \
--cc=laurent@vivier.eu \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
/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).