Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp142053ybc; Mon, 18 Nov 2019 22:04:58 -0800 (PST) X-Google-Smtp-Source: APXvYqxurz6DsvHHW0S+e+lhdFpcRfHbZPac9Nn/v5UAd2LeXIBcOqVBII5QZ8tSzztAu1/CNB0I X-Received: by 2002:a17:906:c293:: with SMTP id r19mr32171084ejz.69.1574143498861; Mon, 18 Nov 2019 22:04:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574143498; cv=none; d=google.com; s=arc-20160816; b=geyAaCPA2CYYUWIT6a7Nsf4VZIbQltIHqKlBNpt79aSnt2ySTZZhqePUYeMol+yRdf dEPsIRBbGHHi370BMBk7v7ejQi2EVvoerVeyViNxjA+0o5ZPN75+9CZIArRtxK5MWD/2 ydWoOmwu2zczOJmYdT82ls37e4EfeBisck4DBI1uQnkIzGccLQlrk2QwKahR+teqaZeP 87oeXLfwp6QLAdp7SY9issdQLiEI2LO2e8ouaK0eYfbPeMFr/6a3KUUhr8Cwe4ywcbxV EkOQKq/wCDQEEBa1Erc0m+Wp4gbZ8/A1EbWVNOcJr6elD1vTc03r7KUJINwyEz2QzAL6 RojQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=XzfbFAHHyOw6FfLMwOYbYpc1KDn8Qk3cQrlK1mqE2tE=; b=xyUt9NsXwfUrT6+RYWrbBUX/bia9t+6FwU+Hg2bIZplwbmlmoLq7kHhZhgX5xFAlV+ J5r9sc1G2a7LKdomyQnasNdRdETP4wJqU6iUS2SxAmE96P5h6wAdMOyxgawyxxV8F9xh lX6DBM64zKIuaVucjnDSYhfn3iys4PQuh7FDZNTLqCrhZqPHdQUPAdHoveXDi7WHxbPk nvKZXvG37l45+77NOs6U5CF6OoUnUmv/sZ6ZTEJwK4iIyEYhh9p0PEn72459QTVgPMMm cQmvtOiHf/vpNJdikQogtYPwfu6Ma5WROI45gk9FKo0VEJlDGunI8OKXCAOTPg4lTLj+ C+xA== 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 y32si15489296ede.209.2019.11.18.22.04.34; Mon, 18 Nov 2019 22:04:58 -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 S1729261AbfKSGCJ (ORCPT + 99 others); Tue, 19 Nov 2019 01:02:09 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:6251 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727310AbfKSGCF (ORCPT ); Tue, 19 Nov 2019 01:02:05 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 919E13E336AF090E4B98; Tue, 19 Nov 2019 14:02:02 +0800 (CST) Received: from huawei.com (10.90.53.225) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 19 Nov 2019 14:01:52 +0800 From: Sun Ke To: , , , , , CC: Subject: [v2] nbd:fix memory leak in nbd_get_socket() Date: Tue, 19 Nov 2019 14:09:11 +0800 Message-ID: <1574143751-138680-1-git-send-email-sunke32@huawei.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before return NULL,put the sock first. Cc: stable@vger.kernel.org Fixes: cf1b2326b734 ("nbd: verify socket is supported during setup") Signed-off-by: Sun Ke --- v2: add cc:stable tag --- drivers/block/nbd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index a94ee45..19e7599 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -993,6 +993,7 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd, if (sock->ops->shutdown == sock_no_shutdown) { dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n"); *err = -EINVAL; + sockfd_put(sock); return NULL; } -- 2.7.4