From patchwork Thu Feb 7 10:53:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1037962 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43wFdr0Gjrz9s9G for ; Thu, 7 Feb 2019 21:57:52 +1100 (AEDT) Received: from localhost ([127.0.0.1]:37793 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grhNO-00071s-40 for incoming@patchwork.ozlabs.org; Thu, 07 Feb 2019 05:57:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43790) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grhJr-0004eu-OJ for qemu-devel@nongnu.org; Thu, 07 Feb 2019 05:54:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grhJq-0008AY-HZ for qemu-devel@nongnu.org; Thu, 07 Feb 2019 05:54:11 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:45071) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1grhJq-00089K-7m for qemu-devel@nongnu.org; Thu, 07 Feb 2019 05:54:10 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MTRhS-1gfgke3lqm-00Thl4; Thu, 07 Feb 2019 11:53:53 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Thu, 7 Feb 2019 11:53:45 +0100 Message-Id: <20190207105347.22337-2-laurent@vivier.eu> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207105347.22337-1-laurent@vivier.eu> References: <20190207105347.22337-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:TBjoqLCGNekDDVGjwUhBrAja8T8gCLddNlM8CBWYjADQxxBIx6b kwmGihLNVuacfCteRNYlZEdSoK3JgaTeWUXamhgfF3mAcsWsn8LQ+Pod532/tS8pxatYJIc D+eiOM8TuEI+LwGwvCzUAOio+jQUBBk8Qdz64+Uxv6s21kzlu6srnST0VEVC+NNS1hS4aHE 6F6ivvM3t3VzeoFyK3YLg== X-UI-Out-Filterresults: notjunk:1; V03:K0:oJPB3OPWz0o=:CkGRDaMF89E/DWrBMBWcXe KSirqoLoEGocoJZLffDcnYUX782oxh9ZZY68360mTduSy9uD7G3lJ5DTfSGitXUIRkNgdX4gJ 5PNBO6OJCqoijFw+3LXrXCJ0r0/DjEl2P895zWZ3KfJdTsFxk5SagVG7JirsI5MSWQqX0uoHC Bby2uGeMZKY+bZJEMkfVLVgc36Q40LetUmXYBoUyna+sAu9Ggu9clhCSVfT165oQi+POkKaEI SSoY5VWTqrqWBZXuIoaKlDjrCB1W+yjGxF5egz6o6eNag+ZIIzxTtLWkbAh73kctwPiq7z1BL AzcEaokkiB7uQOwz8BB9tbNMjB1yPVX9Y6snr1rxhEg4J8o8RHcN05z3aVXS+8sLJarPiYC1e UCQQLYrFTVLFiDmGHPjT/mSrGOJLh7QVwhd/0NOdkyKrQ3DBJ7GW6fSPAdIRuADDAR9U+c41E 1gI41oqeKulz0UliMAw6Zf6l6f8fNwITBVDxBqfBO6/fqVm/1AVgoEHFfgsTJSOs1SIvpDXPx f9EvKK0C0WtAEO0TECrW39RtTxnojvUOzUzOrOKMGI8XqPT3gX2frMZnq3QQ90QNtNPSZBum3 W/ld/IrGq4zxq+OETOCVBfjvEqLO8cMshOUFmx0Lv2cdDi+VR7M81QkugcorAX0U+2zXPd+ff PeYVXRpjaizYFu7Lj1P5DGPBl3NcUTQUfavBn3ymssldwgRhfgrwZVdZNFhcOiXzCJQu40ZSB YgV71CXUPOpWPWjUXL6NaRjQlOAP13K4n3xzgQ== 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 55 ++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index bf076cbf8c..5b9d75fbb4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4187,28 +4187,32 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, uint8_t *buf_temp, unlock_user(argptr, arg, 0); host_ifconf = (struct ifconf *)(unsigned long)buf_temp; - target_ifc_len = host_ifconf->ifc_len; target_ifc_buf = (abi_long)(unsigned long)host_ifconf->ifc_buf; - target_ifreq_size = thunk_type_size(ifreq_arg_type, 0); - nb_ifreq = target_ifc_len / target_ifreq_size; - host_ifc_len = nb_ifreq * sizeof(struct ifreq); - outbufsz = 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 = malloc(outbufsz); - if (!host_ifconf) { - return -TARGET_ENOMEM; + if (target_ifc_buf != 0) { + target_ifc_len = host_ifconf->ifc_len; + nb_ifreq = target_ifc_len / target_ifreq_size; + host_ifc_len = nb_ifreq * sizeof(struct ifreq); + + outbufsz = 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 = malloc(outbufsz); + if (!host_ifconf) { + return -TARGET_ENOMEM; + } + memcpy(host_ifconf, buf_temp, sizeof(*host_ifconf)); + free_buf = 1; } - memcpy(host_ifconf, buf_temp, sizeof(*host_ifconf)); - free_buf = 1; - } - host_ifc_buf = (char*)host_ifconf + sizeof(*host_ifconf); + host_ifc_buf = (char*)host_ifconf + sizeof(*host_ifconf); - host_ifconf->ifc_len = host_ifc_len; + host_ifconf->ifc_len = host_ifc_len; + } else { + host_ifc_buf = NULL; + } host_ifconf->ifc_buf = host_ifc_buf; ret = get_errno(safe_ioctl(fd, ie->host_cmd, host_ifconf)); @@ -4231,15 +4235,16 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, uint8_t *buf_temp, thunk_convert(argptr, host_ifconf, arg_type, THUNK_TARGET); unlock_user(argptr, arg, target_size); - /* copy ifreq[] to target user */ - - argptr = lock_user(VERIFY_WRITE, target_ifc_buf, target_ifc_len, 0); - for (i = 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 != 0) { + /* copy ifreq[] to target user */ + argptr = lock_user(VERIFY_WRITE, target_ifc_buf, target_ifc_len, 0); + for (i = 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); } if (free_buf) {