From: Greg KH <gregkh@linuxfoundation.org>
To: Zhang Wensheng <zhangwensheng@huaweicloud.com>
Cc: stable@vger.kernel.org, axboe@kernel.dk, ast@kernel.org,
daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com,
songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com,
kpsingh@kernel.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, zhangwensheng5@huawei.com,
yukuai3@huawei.com
Subject: Re: [PATCH 5.10] block: fix null-deref in percpu_ref_put
Date: Fri, 29 Jul 2022 09:48:46 +0200 [thread overview]
Message-ID: <YuOQ3mzvtDyQHeLB@kroah.com> (raw)
In-Reply-To: <20220729065243.1786222-1-zhangwensheng@huaweicloud.com>
On Fri, Jul 29, 2022 at 02:52:43PM +0800, Zhang Wensheng wrote:
> From: Zhang Wensheng <zhangwensheng5@huawei.com>
>
> In the use of q_usage_counter of request_queue, blk_cleanup_queue using
> "wait_event(q->mq_freeze_wq, percpu_ref_is_zero(&q->q_usage_counter))"
> to wait q_usage_counter becoming zero. however, if the q_usage_counter
> becoming zero quickly, and percpu_ref_exit will execute and ref->data
> will be freed, maybe another process will cause a null-defef problem
> like below:
>
> CPU0 CPU1
> blk_cleanup_queue
> blk_freeze_queue
> blk_mq_freeze_queue_wait
> scsi_end_request
> percpu_ref_get
> ...
> percpu_ref_put
> atomic_long_sub_and_test
> percpu_ref_exit
> ref->data -> NULL
> ref->data->release(ref) -> null-deref
>
> Fix it by setting flag(QUEUE_FLAG_USAGE_COUNT_SYNC) to add synchronization
> mechanism, when ref->data->release is called, the flag will be setted,
> and the "wait_event" in blk_mq_freeze_queue_wait must wait flag becoming
> true as well, which will limit percpu_ref_exit to execute ahead of time.
>
> Signed-off-by: Zhang Wensheng <zhangwensheng5@huawei.com>
> ---
> block/blk-core.c | 4 +++-
> block/blk-mq.c | 7 +++++++
> include/linux/blk-mq.h | 1 +
> include/linux/blkdev.h | 2 ++
> 4 files changed, 13 insertions(+), 1 deletion(-)
<formletter>
This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
prev parent reply other threads:[~2022-07-29 7:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-29 6:52 [PATCH 5.10] block: fix null-deref in percpu_ref_put Zhang Wensheng
2022-07-29 7:48 ` Greg KH [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YuOQ3mzvtDyQHeLB@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=axboe@kernel.dk \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=stable@vger.kernel.org \
--cc=yhs@fb.com \
--cc=yukuai3@huawei.com \
--cc=zhangwensheng5@huawei.com \
--cc=zhangwensheng@huaweicloud.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).