Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2532106ybl; Mon, 20 Jan 2020 04:48:48 -0800 (PST) X-Google-Smtp-Source: APXvYqwS/UBRQcEvjtbU6bupHNs2MkwzxSD00smtqv05OvhEleUjVxkrUTWjKKsKnqx+EQMmb7HX X-Received: by 2002:aca:ad47:: with SMTP id w68mr12271387oie.63.1579524527902; Mon, 20 Jan 2020 04:48:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579524527; cv=none; d=google.com; s=arc-20160816; b=yRlAodF6/WR06rXBrH4Lav1d4oYi+oEzu0Ao5gtWHtzd4L8vEZKeNUpSEB7r31Spxt +yl/1xdl6W8oYio++1DNiBq8ZltWGCS6ZsDdjGQ60woxODR6yjCdRMdoPNsm+AOVwumM 87yjVT4/PpmnvVEGKV+JLSAihSjZHQeTPI7iifjU0mjTa8Ui3yIgJ+2YDR3EM0XxCcCv 0qI8/gZ9zqk/AX9Gl1maWf5fUGUIun73v7umGoEK9l3NpHLI94wROAN79l45S6Og+44N yQBDBhI16p8mMbwU4OGW/8j4Zv/VjaGB2ZXSuMWfuVilaP+4U4H0Lid5ddTZ34N+aBd/ m0XA== 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=1LQ7Ng+pgDEh4yBItdQaaPUdRHbXaBmS4m/IlTnyYRE=; b=K3kF9vaDxB731s0HLkEN6dKWBAboGIx7kknpUN7PtWTVDDNtRDMFG2jSH4erWUoTCc PE1ms7j0rLXQnHRWqmsquTtQ1Qqjnz1aoiVYNv9pD4k7ngX+RX5O0uKyjlfPoJYUQZPQ 4lUsXBBtH0dKzj59uqxtR0lFdKNY0oB4CFi/W2a7CbM/CWhh8EQ6AoL5xcIvmer/J3Yx AXSN/Q9XdJM08SwcKr8KP4kby07hNyQ2CF4OSyIi96w0SCJma2UO9JHUKdSFA+bcFtcR ClZurzGMvcammIo9agKXlLfolWRD3NJ8JLQyrHDCgYwXHAVwEnO5+Oukdpu0pP3dUVsx 05NA== 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 z4si16252654oix.48.2020.01.20.04.48.35; Mon, 20 Jan 2020 04:48:47 -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 S1726954AbgATMqt (ORCPT + 99 others); Mon, 20 Jan 2020 07:46:49 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:53424 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726619AbgATMqt (ORCPT ); Mon, 20 Jan 2020 07:46:49 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 25D258781940879D0680; Mon, 20 Jan 2020 20:46:47 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Mon, 20 Jan 2020 20:46:39 +0800 From: Sun Ke To: , , , CC: , , Subject: [v2] nbd: fix potential NULL pointer fault in nbd_genl_disconnect Date: Mon, 20 Jan 2020 20:45:49 +0800 Message-ID: <20200120124549.27648-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 --- v1 -> v2: add an omitted mutex_unlock. --- drivers/block/nbd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index b4607dd96185..668bc9cb92ed 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -2008,6 +2008,10 @@ static int nbd_genl_disconnect(struct sk_buff *skb, struct genl_info *info) index); return -EINVAL; } + if (!nbd->task_recv) { + mutex_unlock(&nbd_index_mutex); + 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