BPF List
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: tristmd@gmail.com,jikos@kernel.org,bentiss@kernel.org
Cc: linux-input@vger.kernel.org,bpf@vger.kernel.org,linux-kernel@vger.kernel.org,tristan@talencesecurity.com,stable@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH] HID: core: fix device cleanup on allocation failure
Date: Fri,  4 Sep 2026 22:21:54 +0000 (UTC)	[thread overview]
Message-ID: <d6eed7bdb5d4ba036cfcc7255b9e01fb111cd936be81ee00fff57d3cae7b02ce@mail.kernel.org> (raw)
In-Reply-To: <20260904080524.3872926-1-tristmd@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2585 bytes --]

> hid_allocate_device() calls hid_destroy_device() in its error path when
> hid_bpf_device_init() fails.  hid_destroy_device() in turn calls
> hid_bpf_destroy_device() which invokes synchronize_srcu() and
> cleanup_srcu_struct() on the SRCU structure.  However, at this point
> init_srcu_struct() has not been called (or has failed), so the SRCU
> internal pointers are all zeroed from kzalloc.  Dereferencing them
> causes a general protection fault:

Is the reasoning here fully accurate?

Looking at hid_bpf_device_init() in drivers/hid/bpf/hid_bpf_dispatch.c,
it returns the result of init_srcu_struct(&hdev->bpf.srcu), so
init_srcu_struct() is always called before the error path is taken.

When init_srcu_struct() fails (specifically init_srcu_struct_fields() in
kernel/rcu/srcutree.c), the failure paths explicitly free and NULL the
pointers:

kernel/rcu/srcutree.c:init_srcu_struct_fields() {
    ...
err_free_sda:
    free_percpu(ssp->sda);
    ssp->sda = NULL;
err_free_sup:
    kfree(ssp->srcu_sup);
    ssp->srcu_sup = NULL;
    ...
}

So the SRCU internal pointers are NULL due to init_srcu_struct()'s
rollback on failure, not because init_srcu_struct() was never called or
because they are still zeroed from kzalloc.

Could the commit message be more precise? Something like:
"init_srcu_struct() was called but failed, and it rolled the SRCU
internal pointers back to NULL"

> diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> index a3ff0514f9cd..d8df23f67f1f 100644
> --- a/drivers/hid/hid-core.c
> +++ b/drivers/hid/hid-core.c
> @@ -3115,7 +3115,12 @@ struct hid_device *hid_allocate_device(void)
>  	return hdev;
>
>  out_err:
> -	hid_destroy_device(hdev);
> +	/*
> +	 * hid_destroy_device() cannot be used here because
> +	 * hid_bpf_device_init() failed and the SRCU struct was never
> +	 * initialized.  Release the device directly.
> +	 */
> +	put_device(&hdev->dev);
>  	return ERR_PTR(ret);
>  }

Should the comment say "was never successfully initialized" rather than
"was never initialized"?

As shown above, hid_bpf_device_init() returns init_srcu_struct()'s
result, so init_srcu_struct() is always called before reaching this
error path. It failed after partially initializing, then rolled back.

The distinction matters for future readers trying to understand the
ordering inside hid_bpf_device_init().


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33923149618

      reply	other threads:[~2026-09-04 22:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04  8:05 [PATCH] HID: core: fix device cleanup on allocation failure Tristan Madani
2026-09-04 22:21 ` bot+bpf-ci [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=d6eed7bdb5d4ba036cfcc7255b9e01fb111cd936be81ee00fff57d3cae7b02ce@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bentiss@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=mason@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tristan@talencesecurity.com \
    --cc=tristmd@gmail.com \
    --cc=yonghong.song@linux.dev \
    /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