mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai1@huaweicloud.com>
To: Wentao Liang <vulab@iscas.ac.cn>,
	tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk
Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	"yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH] block: Check blkg_to_lat return value to avoid NULL dereference
Date: Thu, 13 Feb 2025 09:27:08 +0800	[thread overview]
Message-ID: <8793e238-1b12-5ce9-e9d6-e936750109b2@huaweicloud.com> (raw)
In-Reply-To: <20250212083203.1030-1-vulab@iscas.ac.cn>

Hi,

在 2025/02/12 16:32, Wentao Liang 写道:
> The function blkg_to_lat() may return NULL if the blkg is not associated
> with an iolatency group. In iolatency_set_min_lat_nsec() and
> iolatency_pd_init(), the return values are not checked, leading to
> potential NULL pointer dereferences.
> 
> This patch adds checks for the return values of blkg_to_lat and let it
> returns early if it is NULL, preventing the NULL pointer dereference.
> 
> Fixes: d70675121546 ("block: introduce blk-iolatency io controller")
> Cc: stable@vger.kernel.org # 4.19+
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>   block/blk-iolatency.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/block/blk-iolatency.c b/block/blk-iolatency.c
> index ebb522788d97..398f0a1747c4 100644
> --- a/block/blk-iolatency.c
> +++ b/block/blk-iolatency.c
> @@ -787,6 +787,8 @@ static int blk_iolatency_init(struct gendisk *disk)
>   static void iolatency_set_min_lat_nsec(struct blkcg_gq *blkg, u64 val)
>   {
>   	struct iolatency_grp *iolat = blkg_to_lat(blkg);
> +	if (!iolat)
> +		return;
>   	struct blk_iolatency *blkiolat = iolat->blkiolat;
>   	u64 oldval = iolat->min_lat_nsec;

This is not needed, this is called from iolatency_set_limit() or
iolatency_pd_offline() where the policy data can't be NULL.
>   
> @@ -1013,6 +1015,8 @@ static void iolatency_pd_init(struct blkg_policy_data *pd)
>   	 */
>   	if (blkg->parent && blkg_to_pd(blkg->parent, &blkcg_policy_iolatency)) {
>   		struct iolatency_grp *parent = blkg_to_lat(blkg->parent);
> +		if (!parent)
> +			return;

blkg_to_pd() already checked, how can this be NULL?

Thanks,
Kuai
>   		atomic_set(&iolat->scale_cookie,
>   			   atomic_read(&parent->child_lat.scale_cookie));
>   	} else {
> 


      parent reply	other threads:[~2025-02-13  1:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12  8:32 Wentao Liang
2025-02-12  9:02 ` Johannes Thumshirn
2025-02-12 13:02 ` [PATCH] block: Check blkg_to_lat() " Markus Elfring
2025-02-13  1:27 ` Yu Kuai [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=8793e238-1b12-5ce9-e9d6-e936750109b2@huaweicloud.com \
    --to=yukuai1@huaweicloud.com \
    --cc=axboe@kernel.dk \
    --cc=cgroups@vger.kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=vulab@iscas.ac.cn \
    --cc=yukuai3@huawei.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

all inboxes | Powered by JetHome®