From patchwork Sat Nov 10 14:09:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 150740 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1097736ljp; Sat, 10 Nov 2018 06:25:40 -0800 (PST) X-Google-Smtp-Source: AJdET5ehvwYQ6qclqClbaEGOsz7iGROh0WCfWkCjHtP0dTbi57RnjWLvVeX/qTEvBIPvlOtRzilr X-Received: by 2002:aed:25a6:: with SMTP id x35mr12452716qtc.228.1541859940159; Sat, 10 Nov 2018 06:25:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541859940; cv=none; d=google.com; s=arc-20160816; b=gWCoe2zCdMetN90IVA9HcSjZY3nuPaFAd0kkB82NKwQygugUQgZFL+uluymLdQZWwG n48OXlzihgGnkR6Nd/KZUe2uPcgw4bQ8UGz868ib0/W/eVo7uwkFifb3+s8nvqFLoVYO svxwWHtsuOyA2fpu0+dJHLeihib5guBkBuC+TSOVPHkE8sR9DYQRMMegDK/WgElDXap9 qKft7Iwgl/EuYPouP9QFvIn5+mf/+8+vfPuIo0Fq43eJdhuskRzDr1x8DMQIzUbEuyO0 xyoUOdD3v2qNcvMY8HsoA2g3j78VTvi1rZEyKuIcABTQjkMagLzW80nxrjVajbS9iCi5 aS3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from; bh=Hr0aXM2/+3n2IT/MiPV2m0oa58McSimfQU4r9t9zAd0=; b=F4i5w1l8VCrSi0PepQnmy0La5VtqtLhoFoPwQ6Ida3BdtYk/9HevxkxX5qfXwumwme Lg6K7aVmgV6SviLlJjuE55tPCSZTzVuq3ayrr/4XfceUxtJ+lDhC0mdscMIfhyurpwJ8 wVt3rsRLK4FPInQNPsy00ky4MQ4f8N/pPn/Xd/2av5BO/Y0zpuxfFnCKfpnKSWxWLD3g zq7fFiRtXDGBRoPww+D40aT7OefxsvhK9rns/MnxJwAbKNXpnKuNCXq0XVqnRiLZnsb5 Nbum2UMgcS3L4IQ/8bGtGI0aMaPOgKwc67V7KnpPlHp7DmBXVcQm3P2tXbzq9qrctgc3 QlDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id h2-v6si2316189qkd.169.2018.11.10.06.25.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 10 Nov 2018 06:25:40 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:38658 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLUCh-000370-Hf for patch@linaro.org; Sat, 10 Nov 2018 09:25:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLU9C-0006GG-2U for qemu-devel@nongnu.org; Sat, 10 Nov 2018 09:22:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTxG-0000Qw-JE for qemu-devel@nongnu.org; Sat, 10 Nov 2018 09:09:45 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:44360) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTxG-0000Fp-87 for qemu-devel@nongnu.org; Sat, 10 Nov 2018 09:09:42 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 8C4F32EC2; Sat, 10 Nov 2018 15:09:28 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vJ-2fZAy0MI7; Sat, 10 Nov 2018 15:09:26 +0100 (CET) Received: from function (lfbn-bor-1-169-137.w90-50.abo.wanadoo.fr [90.50.25.137]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 67D412EA3; Sat, 10 Nov 2018 15:09:26 +0100 (CET) Received: from samy by function with local (Exim 4.91) (envelope-from ) id 1gLTwz-0005r0-Nu; Sat, 10 Nov 2018 15:09:25 +0100 From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Sat, 10 Nov 2018 15:09:22 +0100 Message-Id: <20181110140925.22457-2-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181110140925.22457-1-samuel.thibault@ens-lyon.org> References: <20181110140925.22457-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULL 1/4] slirp: Don't pass possibly -1 fd to send() 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: jan.kiszka@siemens.com, stefanha@redhat.com, Samuel Thibault Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Coverity complains (CID 1005726) that we might pass -1 as the fd argument to send() in slirp_send(), because we previously checked for "so->s == -1 && so->extra". The case of "so->s == -1 but so->extra NULL" should not in theory happen, but it is hard to guarantee because various places in the code do so->s = qemu_socket(...) and so will end up with so->s == -1 on failure, and not all the paths which call that always throw away the socket in that case (eg tcp_fconnect()). So just check specifically for the condition and fail slirp_send(). Signed-off-by: Peter Maydell Signed-off-by: Samuel Thibault --- slirp/slirp.c | 11 +++++++++++ 1 file changed, 11 insertions(+) -- 2.19.1 diff --git a/slirp/slirp.c b/slirp/slirp.c index 51de41fc02..3c3c03b22f 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -1091,6 +1091,17 @@ ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags) return len; } + if (so->s == -1) { + /* + * This should in theory not happen but it is hard to be + * sure because some code paths will end up with so->s == -1 + * on a failure but don't dispose of the struct socket. + * Check specifically, so we don't pass -1 to send(). + */ + errno = EBADF; + return -1; + } + return send(so->s, buf, len, flags); }