Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3319366imu; Sun, 11 Nov 2018 12:16:37 -0800 (PST) X-Google-Smtp-Source: AJdET5cZ6eBQyhBLFelaQ2GiStP/wyxPhmdiD+GFt6PM0vqG+EeckmT0v/FUodWeHXmVXD30V9GQ X-Received: by 2002:a63:2315:: with SMTP id j21mr15188089pgj.297.1541967397390; Sun, 11 Nov 2018 12:16:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541967397; cv=none; d=google.com; s=arc-20160816; b=EY7gjAWAi9Tor4ndxyd3pXogAVmhbu5gre+5umqcITg7GYeahaVFuSEulc5zWuW74W H8BrwppqlXSjvYz40kohQS5weyHSQJYxUQaHqDUQ8Pt6yrWDD/10yIeALLnMJ2magBV0 1P1AdtJVw7YEXRQcqZPdKBoawW9SEVpn14i6wfnyAmaoVUVhjLnIE2B8jr3SyMuQWMl9 htM9TKWq8qIqcJM2Sskn3C3nMw83F2DFRhx53twSDHCla1v04fM3BJuKLuJEQ+aIc1C5 z2vopBWwhcqwyTyoRC8QOfZwzh6IEmMSxWcxbB4ypqMS3MxCMcYiLUFlpwrpnyq1q/BU h2dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=IW3JggVIUcYPrDUupiqqsgZnAmwEd4eZ+QpnpQAvInA=; b=Xuy2k4rs5/G4HgadWikkUlmPXNbBMvC8CnfpjtGkgWvFtqqaAclX8WpLNg17mDXZnA K9CneO19sOSr9Nlx/svj3t2sSnKzQ4RiDBhKCKGP4uI4F4+e7wT3IzKLb7ZZHCaq9YDS MnpcvA2eTRrNPBkt+CPyzPaAQ6QlzM+XSqwqCKzPCCqgHG+Zomx8PO+ZwwbdHtyT1K4x cLvm/f4cXYXuBYuSAqzg26QJwlE2n21NxkOubzKJe5vc98h51UlgEi0tImos7oVxe4jB 23sLdy3ku3HsZwHhttA37TMcRl+HtUPdleAel7kCNBQSX4dyoo+io2bwsiI/sGJuyLKB yL7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g2-v6si14717410plp.298.2018.11.11.12.16.22; Sun, 11 Nov 2018 12:16:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731729AbeKLGEU (ORCPT + 99 others); Mon, 12 Nov 2018 01:04:20 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:52912 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726816AbeKLGEU (ORCPT ); Mon, 12 Nov 2018 01:04:20 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsy-0000oF-WC; Sun, 11 Nov 2018 19:59:09 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsT-0001cQ-Ny; Sun, 11 Nov 2018 19:58:37 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "David S. Miller" , "Dan Carpenter" , "Jason Wang" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 184/366] vhost_net: validate sock before trying to put its fd In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Jason Wang commit b8f1f65882f07913157c44673af7ec0b308d03eb upstream. Sock will be NULL if we pass -1 to vhost_net_set_backend(), but when we meet errors during ubuf allocation, the code does not check for NULL before calling sockfd_put(), this will lead NULL dereferencing. Fixing by checking sock pointer before. Fixes: bab632d69ee4 ("vhost: vhost TX zero-copy support") Reported-by: Dan Carpenter Signed-off-by: Jason Wang Signed-off-by: David S. Miller Signed-off-by: Ben Hutchings --- drivers/vhost/net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -983,7 +983,8 @@ err_used: if (ubufs) vhost_net_ubuf_put_wait_and_free(ubufs); err_ubufs: - sockfd_put(sock); + if (sock) + sockfd_put(sock); err_vq: mutex_unlock(&vq->mutex); err: