All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sean Young" <sean@mess.org>
Cc: media-ci@linuxtv.org, bpf@vger.kernel.org
Subject: Re: [PATCH v4 12/15] media: rc: Fix use after free in bpf progs
Date: Mon, 27 Jul 2026 15:44:03 +0000	[thread overview]
Message-ID: <20260727154404.558C81F000E9@smtp.kernel.org> (raw)
In-Reply-To: <dfacc746477c6b05da4a0b1479c93d33bc310c3b.1785158244.git.sean@mess.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Replacing the `!raw` check with `!rcdev->registered` introduces a reproducible NULL pointer dereference in `lirc_bpf_attach`, `lirc_bpf_detach`, and `lirc_prog_query` during the `rc_register_device` error path.
--

--- Patch [12]: [PATCH v4 12/15] media: rc: Fix use after free in bpf progs ---
commit 73b698ccc4730e811a156a8f7b37bb4afb95af66
Author: Sean Young <sean@mess.org>

media: rc: Fix use after free in bpf progs

This commit replaces the NULL check on rcdev->raw with a check on
rcdev->registered to address a potential use-after-free issue when
unregistering devices. It also moves lirc_bpf_free() inside the
ir_raw_handler_lock.

> diff --git a/drivers/media/rc/bpf-lirc.c b/drivers/media/rc/bpf-lirc.c
> index 2f7564f26445c..14ab611e74457 100644
> --- a/drivers/media/rc/bpf-lirc.c
> +++ b/drivers/media/rc/bpf-lirc.c
> @@ -148,12 +148,13 @@ static int lirc_bpf_attach(struct rc_dev *rcdev, struct bpf_prog *prog)
>  	if (ret)
>  		return ret;
>  
> -	raw = rcdev->raw;
> -	if (!raw) {
> +	if (!rcdev->registered) {
>  		ret = -ENODEV;
>  		goto unlock;
>  	}
>  
> +	raw = rcdev->raw;
> +
>  	old_array = lirc_rcu_dereference(raw->progs);

[Severity: High]
Can replacing this !raw check with !rcdev->registered cause a NULL pointer
dereference?

In rc_register_device(), dev->registered is set to true. If lirc_register()
succeeds, the character device is created and can be opened by userspace. If a
subsequent initialization step fails (e.g., ir_raw_event_register()), the error
path calls ir_raw_event_free(), which frees dev->raw and sets it to NULL.
However, the error path never sets dev->registered to false.

If a userspace process opens the device and races to call the bpf() syscall
during this failure, will !rcdev->registered incorrectly evaluate to false,
leading to a dereference of raw->progs when raw is NULL?

[ ... ]

> @@ -186,12 +187,13 @@ static int lirc_bpf_detach(struct rc_dev *rcdev, struct bpf_prog *prog)
>  	if (ret)
>  		return ret;
>  
> -	raw = rcdev->raw;
> -	if (!raw) {
> +	if (!rcdev->registered) {
>  		ret = -ENODEV;
>  		goto unlock;
>  	}
>  
> +	raw = rcdev->raw;
> +
>  	old_array = lirc_rcu_dereference(raw->progs);

[Severity: High]
Does this face the same NULL pointer dereference issue during the 
rc_register_device() error path as lirc_bpf_attach()?

[ ... ]

> @@ -316,6 +319,11 @@ int lirc_prog_query(const union bpf_attr *attr, union bpf_attr __user *uattr)
>  	if (ret)
>  		goto put;
>  
> +	if (!rcdev->registered) {
> +		ret = -ENODEV;
> +		goto unlock;
> +	}
> +
>  	progs = lirc_rcu_dereference(rcdev->raw->progs);

[Severity: High]
Could lirc_prog_query() also crash here if rcdev->raw is NULL but
rcdev->registered remains true during a registration failure?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1785158244.git.sean@mess.org?part=12

  reply	other threads:[~2026-07-27 15:44 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27 13:18 [PATCH v4 00/15] Fix leaks in rc core Sean Young
2026-07-27 13:18 ` [PATCH v4 01/15] media: streamzap: Add missing rc_unregister_device() Sean Young
2026-07-27 13:18 ` [PATCH v4 02/15] media: redrat3: Ensure rc device is freed if enable_detector() fails Sean Young
2026-07-27 13:18 ` [PATCH v4 03/15] media: redrat3: Ensure we don't read beyond the end of the packet Sean Young
2026-07-27 13:18 ` [PATCH v4 04/15] media: redrat3: Ensure all urbs are suspended Sean Young
2026-07-27 13:18 ` [PATCH v4 05/15] media: redrat3: Error path leaves device in transmitting state Sean Young
2026-07-27 15:57   ` Markus Elfring
2026-07-27 13:18 ` [PATCH v4 06/15] media: sunxi-cir: Ensure no more interrupts can occur before free Sean Young
2026-07-27 14:40   ` sashiko-bot
2026-07-27 13:18 ` [PATCH v4 07/15] media: meson-ir-tx: Ensure clock is disabled on unbind Sean Young
2026-07-27 13:18   ` Sean Young
2026-07-27 14:51   ` sashiko-bot
2026-07-27 13:18 ` [PATCH v4 08/15] media: meson-ir-tx: Ensure rc_free_device() is called " Sean Young
2026-07-27 13:18   ` Sean Young
2026-07-27 13:18 ` [PATCH v4 09/15] media: meson-ir-tx: Ensure probe error is propagated Sean Young
2026-07-27 13:18   ` Sean Young
2026-07-27 13:18 ` [PATCH v4 10/15] media: ir-hix5hd2: Ensure rdev is setup before interrupts are enabled Sean Young
2026-07-27 13:18 ` [PATCH v4 11/15] media: rc: Use after free in ir_raw_event_handle() Sean Young
2026-07-27 13:18 ` [PATCH v4 12/15] media: rc: Fix use after free in bpf progs Sean Young
2026-07-27 15:44   ` sashiko-bot [this message]
2026-07-27 13:18 ` [PATCH v4 13/15] media: cx88: Specify rc type at rc_allocate_type() Sean Young
2026-07-27 13:18 ` [PATCH v4 14/15] media: saa7134: " Sean Young
2026-07-27 13:18 ` [PATCH v4 15/15] media: rc: Fix race condition during rc_register_device() Sean Young

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=20260727154404.558C81F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=media-ci@linuxtv.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sean@mess.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.