BPF List
 help / color / mirror / Atom feed
From: Tristan Madani <tristmd@gmail.com>
To: Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <bentiss@kernel.org>
Cc: linux-input@vger.kernel.org, bpf@vger.kernel.org,
	stable@vger.kernel.org,
	Tristan Madani <tristan@talencesecurity.com>
Subject: [PATCH v2] HID: core: fix device cleanup on allocation failure
Date: Wed,  7 Oct 2026 16:28:08 +0000	[thread overview]
Message-ID: <20261007162808.373024-1-tristmd@gmail.com> (raw)
In-Reply-To: <20260904080524.3872926-1-tristmd@gmail.com>

From: Tristan Madani <tristan@talencesecurity.com>

hid_allocate_device() calls hid_destroy_device() in its error path when
hid_bpf_device_init() fails.  hid_destroy_device() invokes
hid_bpf_destroy_device(), which calls synchronize_srcu() and
cleanup_srcu_struct() on the SRCU structure.  However,
hid_bpf_device_init() returns the result of init_srcu_struct(), so
when it fails, init_srcu_struct() was called but did not succeed and
its failure path rolled the SRCU internal pointers back to NULL.
Dereferencing them causes a general protection fault.

Use put_device() directly in the error path to release the device
without invoking SRCU cleanup on the failed state.

Fixes: 6cd735f0e57a ("HID: bpf: protect HID-BPF prog_list access by a SRCU")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---

Changes since v1:
  - Updated commit message to clarify that init_srcu_struct() was called
    but failed (rolled pointers back to NULL), not that it was never called.
  - Updated code comment to match.
  Per bpf-ci bot review feedback.
 drivers/hid/hid-core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index a3ff0514f9cdf..7d1b781c6debf 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -3115,7 +3115,11 @@ struct hid_device *hid_allocate_device(void)
 	return hdev;
 
 out_err:
-	hid_destroy_device(hdev);
+	/* init_srcu_struct() was called but failed; the SRCU struct
+	 * is not usable.  Skip hid_destroy_device() which would call
+	 * cleanup_srcu_struct() on the failed state.
+	 */
+	put_device(&hdev->dev);
 	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(hid_allocate_device);
-- 
2.47.3


      parent reply	other threads:[~2026-10-07 16:28 UTC|newest]

Thread overview: 3+ 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
2026-10-07 16:28 ` Tristan Madani [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=20261007162808.373024-1-tristmd@gmail.com \
    --to=tristmd@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tristan@talencesecurity.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