Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2460711ybl; Mon, 20 Jan 2020 03:25:30 -0800 (PST) X-Google-Smtp-Source: APXvYqyFi139samtp83SrhjPyt/PmQnY+GALbDPgXVwKoOGKsevRVj1ew9MuLtV8ppvcJM3ZTqeD X-Received: by 2002:a05:6808:a11:: with SMTP id n17mr12131096oij.94.1579519530035; Mon, 20 Jan 2020 03:25:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579519530; cv=none; d=google.com; s=arc-20160816; b=OnNSVvHav74K2WBmYyOEA89N7qoH/3KJag0TdxWUXrPMsAng2aFLMX99ktvx+T6bdh zxY96XtLgarbzcG06v3gbmrksCmYJbO7FzkAVWsNX/OQj8pwe/YjPYDxDysYTzzvNQRS ymQtPhhpmY/9Hezlyg0bHcotikiK9uhJP9ACqVwNejxJ+Xf2VafyW0gT8ui1ScD49CyC 8J9qzQEFdcBwUiRJ8b6Jjorqrb0KQ6TEwZh8qJFBlpWRu6EnIaZvi68WRUdp5b4a1LE4 8Tutk6U5H1lMH3Z/IXzxUnTBMyTjfonSWkOYqRvgrkHLeoaYOFsNeMm+NtTP68vyi5Ex nX/Q== 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=L2KUYMEN6dMsQeI4cIkx8PZ3Y1zGOCxwlWznYbuPbGo=; b=Nt+h/HvCunbAN0uSmzuGKqZskdzjAf4dUEL7aY9IY/Jbsm/gTJgicYEBhfqbSaYSOo CV6ROzc97shyEsOobapjCsOZL2mGjhuP/4GLCiLOpnfE72PHDZasYjyJ/BFmLTdaze/f t7L8hwpI/Pxatc671iaHGGXoa/xflESLRLWEDXhXrdJHhYWT0oKTyOyuWbptO5PZhNDe PLfuielOJV9mpBKepjYwz37JcahLPWEGJ5EqwebeRSsyWa19SaPYuIi3u0fvN08T4rgC jdV0R6ol3zUWyOHmArNOB4KXHAc4v/fFfIfD9OxGEeiKA7VafeRlNDs71wcYy4BuQu+i XXEQ== 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 z25si16696472oic.23.2020.01.20.03.25.17; Mon, 20 Jan 2020 03:25:30 -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 S1726798AbgATLYX (ORCPT + 99 others); Mon, 20 Jan 2020 06:24:23 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:60554 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726573AbgATLYX (ORCPT ); Mon, 20 Jan 2020 06:24:23 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id D72B8D65E07C0BA4D496; Mon, 20 Jan 2020 19:24:20 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Mon, 20 Jan 2020 19:24:12 +0800 From: Sun Ke To: , , , CC: , , Subject: [PATCH] nbd: fix potential NULL pointer fault in nbd_genl_disconnect Date: Mon, 20 Jan 2020 19:23:20 +0800 Message-ID: <20200120112320.7375-1-sunke32@huawei.com> X-Mailer: git-send-email 2.17.2 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Open /dev/nbdX first, the config_refs will be 1 and the pointers in nbd_device are still null. Disconnect /dev/nbdX, then reference a null recv_workq. The protection by config_refs in nbd_genl_disconnect is useless. To fix it, just add a check for a non null task_recv in nbd_genl_disconnect. Signed-off-by: Sun Ke --- drivers/block/nbd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index b4607dd96185..5e1530bcb81a 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -2008,6 +2008,8 @@ static int nbd_genl_disconnect(struct sk_buff *skb, struct genl_info *info) index); return -EINVAL; } + if (!nbd->task_recv) + return -EINVAL; if (!refcount_inc_not_zero(&nbd->refs)) { mutex_unlock(&nbd_index_mutex); printk(KERN_ERR "nbd: device at index %d is going down\n", -- 2.17.2