BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tao Cui" <cui.tao@linux.dev>
Cc: mkoutny@suse.com, hannes@cmpxchg.org, bpf@vger.kernel.org, tj@kernel.org
Subject: Re: [RFC PATCH v5 1/5] blk-iocost: add BPF struct_ops cost model support
Date: Fri, 18 Sep 2026 03:29:49 +0000	[thread overview]
Message-ID: <20260918032949.C3A401F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260918031751.1255420-2-cui.tao@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] block: double put of BPF model refcount causes UAF
--

commit 2eda7a01a5e699f80e0a5c6532ed592350e8c63c
Author: Tao Cui <cuitao@kylinos.cn>

blk-iocost: add BPF struct_ops cost model support

This commit adds the iocost_model_ops struct_ops to allow a bound BPF
model to replace the builtin linear model on a device.

> diff --git a/block/blk-iocost.c b/block/blk-iocost.c
> index 2745bffcd5eef..c4e8c8e09bf23 100644
> --- a/block/blk-iocost.c
> +++ b/block/blk-iocost.c
[ ... ]
> @@ -3550,19 +3695,42 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input,
[ ... ]
>  unlock:
>  	spin_unlock_irq(&ioc->lock);
>  
> +	/* resolve the name outside ioc->lock; see ioc_bpf_model_prepare() */
> +	if (!ret) {
> +		const struct iocost_model_ops *new, *old;
> +
> +		new = ioc_bpf_model_prepare(bpf_model);
> +		if (IS_ERR(new)) {
> +			ret = PTR_ERR(new);
> +		} else {
> +			spin_lock_irq(&ioc->lock);
> +			if (user) {
> +				memcpy(ioc->params.i_lcoefs, u, sizeof(u));
> +				ioc->user_cost_model = true;
> +			} else {
> +				ioc->user_cost_model = false;
> +			}
> +			ioc_refresh_params(ioc, true);
> +			old = ioc_bpf_model_commit(ioc, new);
> +			spin_unlock_irq(&ioc->lock);
> +			if (IS_ENABLED(CONFIG_BLK_CGROUP_IOCOST_BPF) && old) {
> +				iocost_bpf_model_put(old);
> +				/*
> +				 * a racing writer may have committed the same
> +				 * model after we resolved it; our resolved
> +				 * reference is then redundant
> +				 */
> +				if (old == new)
> +					iocost_bpf_model_put(new);

[Severity: Critical]
In ioc_cost_model_write(), if a user writes the same model name twice, or
writes parameter updates to an already bound model, ioc_bpf_model_commit()
will return the same pointer as new (so old == new).

Since we only acquired one new reference in ioc_bpf_model_prepare(), calling
iocost_bpf_model_put() on both old and new will drop two references from the
same object.

Can this underflow the reference count and cause a use-after-free on the IO
submission path in calc_cost()?

> +			}
> +		}
> +	}
> +
>  	blk_mq_unquiesce_queue(q);
>  	blk_mq_unfreeze_queue(q, memflags);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260918031751.1255420-1-cui.tao@linux.dev?part=1

  reply	other threads:[~2026-09-18  3:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18  3:17 [RFC PATCH v5 0/5] blk-iocost: BPF struct_ops cost model Tao Cui
2026-09-18  3:17 ` [RFC PATCH v5 1/5] blk-iocost: add BPF struct_ops cost model support Tao Cui
2026-09-18  3:29   ` sashiko-bot [this message]
2026-09-18 15:43   ` Alexei Starovoitov
2026-09-19  7:34     ` Tao Cui
2026-09-18  3:17 ` [RFC PATCH v5 2/5] selftests/bpf: add iocost cost model test Tao Cui
2026-09-18  3:17 ` [RFC PATCH v5 3/5] blk-iocost: add iocost_ioc_tick tracepoint for per-period device summary Tao Cui
2026-09-18  3:17 ` [RFC PATCH v5 4/5] selftests/bpf: add multi-stream sequentiality example model Tao Cui
2026-09-18  3:17 ` [RFC PATCH v5 5/5] docs: cgroup-v2: document io.cost model=<name> binding Tao Cui
2026-09-18  5:48 ` [RFC PATCH v5 0/5] blk-iocost: BPF struct_ops cost model Tao Cui

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=20260918032949.C3A401F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cui.tao@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=mkoutny@suse.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tj@kernel.org \
    /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