From nobody Thu Nov 6 01:18:10 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539093006037934.5745626039475; Tue, 9 Oct 2018 06:50:06 -0700 (PDT) Received: from localhost ([::1]:51661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9sOi-0007uP-Su for importer@patchew.org; Tue, 09 Oct 2018 09:50:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9mSg-0005ZK-2p for qemu-devel@nongnu.org; Tue, 09 Oct 2018 03:29:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9mSc-0000VV-JS for qemu-devel@nongnu.org; Tue, 09 Oct 2018 03:29:46 -0400 Received: from mail7-212.sinamail.sina.com.cn ([202.108.7.212]:48990) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1g9mSc-0000S4-8g for qemu-devel@nongnu.org; Tue, 09 Oct 2018 03:29:42 -0400 Received: from c-24-130-69-251.hsd1.ca.comcast.net (HELO 0929ab6a2822.hsd1.ca.comcast.net)([24.130.69.251]) by sina.com with ESMTP id 5BBC58D3000053CF; Tue, 9 Oct 2018 15:29:34 +0800 (CST) X-Sender: likan_999.student@sina.com X-Auth-ID: likan_999.student@sina.com X-SMAIL-MID: 892393393893 From: Kan Li To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 07:29:23 +0000 Message-Id: <20181009072923.871-1-likan_999.student@sina.com> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 202.108.7.212 X-Mailman-Approved-At: Tue, 09 Oct 2018 09:45:57 -0400 Subject: [Qemu-devel] [PATCH] 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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 ae3c0dfef7..fbab98d4f7 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4134,28 +4134,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; =20 - 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); + if (target_ifc_buf !=3D 0) { + target_ifc_len =3D host_ifconf->ifc_len; =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; + 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); + + 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)); @@ -4178,15 +4183,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.17.1