From nobody Tue Feb 10 06:58:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549545322673859.2806377527601; Thu, 7 Feb 2019 05:15:22 -0800 (PST) Received: from localhost ([127.0.0.1]:39835 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grjWP-00042J-Kf for importer@patchew.org; Thu, 07 Feb 2019 08:15:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grjV1-00035P-TX for qemu-devel@nongnu.org; Thu, 07 Feb 2019 08:13:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grjV0-0006W3-8G for qemu-devel@nongnu.org; Thu, 07 Feb 2019 08:13:51 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:39953) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1grjUx-0006NC-Jh for qemu-devel@nongnu.org; Thu, 07 Feb 2019 08:13:48 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MOiLp-1gTKa81Dbz-00QEo9; Thu, 07 Feb 2019 14:13:27 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Thu, 7 Feb 2019 14:13:14 +0100 Message-Id: <20190207131316.2957-2-laurent@vivier.eu> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207131316.2957-1-laurent@vivier.eu> References: <20190207131316.2957-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:z1eJG/QPRllngUqpG7+RRm/tE756n9xSTh6dj8/pROw1vMaNPAh umD57KndAFR+l1ufOdK2M6xaY/D86FgBHsN0Kw1jtdcLM4RkzD8jpjqpEbmYmorqTIk8SqL BzfLP8Vqo+Hm5Wbyhffy+SwEDOefPv/typRy8OL8oiHEKZUIoc5uSxLC/zUYGTxGHSsv+bS 0wzrFWzClEcnG7457felw== X-UI-Out-Filterresults: notjunk:1;V03:K0:guRrH92YyYU=:EFnMWg11eFAj0xxoYmao+O yTzToKzs+TWFhbD+DrsVdSzfql6rOM8L6vCo34+/z8RHylLWIkHPG7qdCH95CJebeVGRuSv7S 59Y8T2wyhYj8Sl+2z5yRuxzUTBMUhRnf6uVPuk5eYb0WoFuYznMtIfQVyz3RTOPcMvzPwgxGz aB7TjlvSbHG1vHh85Hg9g+yeGBpME0C65RyMfnsYqau/cEeRAuc5mq2dyOXOAUhXK9AiKL4yK Ys6aPs4gnJjvnviLoAw677TAzMQkh3kbQdmrKLDHGu9SSGUS6rc9+YQPhXG+qeYfwJP3afHYp rQY88wyLBdDsVhwYh52l5hjXKn9Cu8ARuUi4T4Q1wYnvd8UCZoD0rmeL/v/NV74S2KR2GlZyl 27bYtzIlplWDZtfHfQlXiPSs8l67ZK2eIyTUotkq+4cGVwp3RBW+p6+W690TBPaGbc1CuuWAh MLDDh0S6DSqlmLAEZ8vEzZlzTrV8gc0c5KJB4s9cZWJpa9XrR2Vt3LkXU5hrY2V+xe0fYWCPf yU1ml2A8OQIVbHLspESfZyiCKKZzsJ9Wo/WgqdFHiCtzNU2MPKjHwsKr1UtTSh2oFd6Rk+6jD sWBDIqQvPgja9DderZNkunOB+rTM+mH8spYK1xlelkdLTPJLOQP9ELSpZBeTDcxIyT3/oVd35 iMcTNM9XmXGs4kM79ut+etW0VDa0L4fPwQTWo4RzLk6Q4Nyu6zxVnoKk5C5Yh6bilkb6rAbWo pYGRDa4uGuDeJ0aSERZoiOPFUz6QOrHTDvoIQA== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PULL v2 1/3] Fix linux-user crashes in ioctl(SIOCGIFCONF) when ifc_buf is NULL. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kan Li , Laurent Vivier , Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Kan Li Summary: This is to fix bug https://bugs.launchpad.net/qemu/+bug/1796754. It is valid for ifc_buf to be NULL according to http://man7.org/linux/man-pages/man7/netdevice.7.html. Signed-off-by: Kan Li Reviewed-by: Laurent Vivier Message-Id: <20181024201303.114-1-likan_999.student@sina.com> [lv: fix errors reported by checkpatch.pl] Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 56 ++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index bf076cbf8c..08acc4d860 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4187,28 +4187,33 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry *i= e, uint8_t *buf_temp, unlock_user(argptr, arg, 0); =20 host_ifconf =3D (struct ifconf *)(unsigned long)buf_temp; - target_ifc_len =3D host_ifconf->ifc_len; target_ifc_buf =3D (abi_long)(unsigned long)host_ifconf->ifc_buf; - target_ifreq_size =3D thunk_type_size(ifreq_arg_type, 0); - nb_ifreq =3D target_ifc_len / target_ifreq_size; - host_ifc_len =3D nb_ifreq * sizeof(struct ifreq); =20 - outbufsz =3D sizeof(*host_ifconf) + host_ifc_len; - if (outbufsz > MAX_STRUCT_SIZE) { - /* We can't fit all the extents into the fixed size buffer. - * Allocate one that is large enough and use it instead. - */ - host_ifconf =3D malloc(outbufsz); - if (!host_ifconf) { - return -TARGET_ENOMEM; + if (target_ifc_buf !=3D 0) { + target_ifc_len =3D host_ifconf->ifc_len; + nb_ifreq =3D target_ifc_len / target_ifreq_size; + host_ifc_len =3D nb_ifreq * sizeof(struct ifreq); + + outbufsz =3D sizeof(*host_ifconf) + host_ifc_len; + if (outbufsz > MAX_STRUCT_SIZE) { + /* + * We can't fit all the extents into the fixed size buffer. + * Allocate one that is large enough and use it instead. + */ + host_ifconf =3D malloc(outbufsz); + if (!host_ifconf) { + return -TARGET_ENOMEM; + } + memcpy(host_ifconf, buf_temp, sizeof(*host_ifconf)); + free_buf =3D 1; } - memcpy(host_ifconf, buf_temp, sizeof(*host_ifconf)); - free_buf =3D 1; - } - host_ifc_buf =3D (char*)host_ifconf + sizeof(*host_ifconf); + host_ifc_buf =3D (char *)host_ifconf + sizeof(*host_ifconf); =20 - host_ifconf->ifc_len =3D host_ifc_len; + host_ifconf->ifc_len =3D host_ifc_len; + } else { + host_ifc_buf =3D NULL; + } host_ifconf->ifc_buf =3D host_ifc_buf; =20 ret =3D get_errno(safe_ioctl(fd, ie->host_cmd, host_ifconf)); @@ -4231,15 +4236,16 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry *i= e, uint8_t *buf_temp, thunk_convert(argptr, host_ifconf, arg_type, THUNK_TARGET); unlock_user(argptr, arg, target_size); =20 - /* copy ifreq[] to target user */ - - argptr =3D lock_user(VERIFY_WRITE, target_ifc_buf, target_ifc_len,= 0); - for (i =3D 0; i < nb_ifreq ; i++) { - thunk_convert(argptr + i * target_ifreq_size, - host_ifc_buf + i * sizeof(struct ifreq), - ifreq_arg_type, THUNK_TARGET); + if (target_ifc_buf !=3D 0) { + /* copy ifreq[] to target user */ + argptr =3D lock_user(VERIFY_WRITE, target_ifc_buf, target_ifc_= len, 0); + for (i =3D 0; i < nb_ifreq ; i++) { + thunk_convert(argptr + i * target_ifreq_size, + host_ifc_buf + i * sizeof(struct ifreq), + ifreq_arg_type, THUNK_TARGET); + } + unlock_user(argptr, target_ifc_buf, target_ifc_len); } - unlock_user(argptr, target_ifc_buf, target_ifc_len); } =20 if (free_buf) { --=20 2.20.1