Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1936476pxb; Fri, 10 Sep 2021 18:42:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyR+AkfzOcgTf3lWZcJmV18yrg7ZRwSbGgpmn4FBPgIK+rKz0wjwiMHjtnpJkOzy58OoakA X-Received: by 2002:a02:cc59:: with SMTP id i25mr510089jaq.125.1631324526024; Fri, 10 Sep 2021 18:42:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631324526; cv=none; d=google.com; s=arc-20160816; b=ata1q29oShAJ7F+jIKUad9q6r69qrUyLgHpIZMYF83Yq3lVQH1UZVfCPUunwUjpF6J M4FN84xO01WyzbUgLRHr4tm4D/a6oE3DT+yshWpAx1xSDqDP9lSOrTXqiBqck0qgEawH cSCpY7CoHR1L8vYCu+8kfaKqxd4ccyYbGJ7zEhNqyOl5Pw3f87M0JhXKZKCX5ZYkH3kl e2DkATJDK3IUKTuQR+6FBBcn3nFuW7+OOZaWy8jh1GZ2FSCUCZkx0JvZvZ5hXKlD9WPS xuJbEL6hBH9uezbKXW1Qd5qEjtZyaBD6TilYl2TYnTsfJIEriFU/yQGZrZxgDPhgg4iZ CO5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=L4jVYjndZSncKcbtSac2RGG851a+7gYW3AJFoXn//ys=; b=mVi95fsZH+pzYFdD1RXN4wzptffHCKEPKUlRvuOVMIQwtkwDDIpWApS2Xbgjoky4Ae YJG1TvRhPiPjOhJNTS1aJvyY2NQW5negwE2HaTMHJCf/YA8KE2fGNuyHSezocbhi4t3n zzwhZYouVzAuM1TI1qesb+vdMDj1L/Lyx6jVFmDdFkHvVlFU27KsDwAmAzdwMEU0YAFK 8g/RUkFcWIq0Mf0PzAQtyjHOXeErDhYYH9Z5jp74HnxWL8xg/lJ/djAIbLmr7iMp8/eb 2EX8lEavPCQr3J4YtkF5rVl1ElN22cxWsq5B8arMasqIr4gcSBWXSnfnZtFyOpqf8fQY RHxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x6si284739ilv.42.2021.09.10.18.41.53; Fri, 10 Sep 2021 18:42:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235104AbhIKBmY (ORCPT + 99 others); Fri, 10 Sep 2021 21:42:24 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:9028 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231864AbhIKBmU (ORCPT ); Fri, 10 Sep 2021 21:42:20 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H5wRH077jzVmty; Sat, 11 Sep 2021 09:40:11 +0800 (CST) Received: from dggema764-chm.china.huawei.com (10.1.198.206) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.8; Sat, 11 Sep 2021 09:41:06 +0800 Received: from [10.174.185.179] (10.174.185.179) by dggema764-chm.china.huawei.com (10.1.198.206) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Sat, 11 Sep 2021 09:41:04 +0800 Subject: Re: [PATCH] scsi: bsg: Fix device unregistration To: Johan Hovold CC: , , , , , , , , References: <20210909034608.1435-1-yuzenghui@huawei.com> From: Zenghui Yu Message-ID: <0506e034-e186-a73b-3046-6b0e1f397756@huawei.com> Date: Sat, 11 Sep 2021 09:41:03 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.185.179] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggema764-chm.china.huawei.com (10.1.198.206) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/9/10 20:45, Johan Hovold wrote: > On Thu, Sep 09, 2021 at 11:46:08AM +0800, Zenghui Yu wrote: >> @@ -218,6 +226,7 @@ struct bsg_device *bsg_register_queue(struct request_queue *q, >> out_device_del: >> cdev_device_del(&bd->cdev, &bd->device); >> out_ida_remove: >> + put_device(&bd->device); >> ida_simple_remove(&bsg_minor_ida, MINOR(bd->device.devt)); >> out_kfree: >> kfree(bd); > > Ehh, what about the blatant use-after-free and double-free you just > added here? Yeah, whoops. That's definitely wrong. I'm squash the following fix in this patch. Thanks for the heads up! |diff --git a/block/bsg.c b/block/bsg.c |index c3bb92b9af7e..882f56bff14f 100644 |--- a/block/bsg.c |+++ b/block/bsg.c |@@ -200,7 +200,8 @@ struct bsg_device *bsg_register_queue(struct request_queue *q, | if (ret < 0) { | if (ret == -ENOSPC) | dev_err(parent, "bsg: too many bsg devices\n"); |- goto out_kfree; |+ kfree(bd); |+ return ERR_PTR(ret); | } | bd->device.devt = MKDEV(bsg_major, ret); | bd->device.class = bsg_class; |@@ -213,7 +214,7 @@ struct bsg_device *bsg_register_queue(struct request_queue *q, | bd->cdev.owner = THIS_MODULE; | ret = cdev_device_add(&bd->cdev, &bd->device); | if (ret) |- goto out_ida_remove; |+ goto out_put_device; | | if (q->kobj.sd) { | ret = sysfs_create_link(&q->kobj, &bd->device.kobj, "bsg"); |@@ -225,11 +226,8 @@ struct bsg_device *bsg_register_queue(struct request_queue *q, | | out_device_del: | cdev_device_del(&bd->cdev, &bd->device); |-out_ida_remove: |+out_put_device: | put_device(&bd->device); |- ida_simple_remove(&bsg_minor_ida, MINOR(bd->device.devt)); |-out_kfree: |- kfree(bd); | return ERR_PTR(ret); | } | EXPORT_SYMBOL_GPL(bsg_register_queue);