From patchwork Thu Feb 7 13:13:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1038058 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 43wJgb0DWzz9s4V for ; Fri, 8 Feb 2019 00:14:35 +1100 (AEDT) Received: from localhost ([127.0.0.1]:39828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grjVg-00037V-W7 for incoming@patchwork.ozlabs.org; Thu, 07 Feb 2019 08:14:33 -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 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+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> [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 *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 +4236,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) {