From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796076201; b=zlfiIWMIvr+GFAZcMD+Xrd0BL1nsapOXc13OSsnH38jnPXD5Oqf7GXw3wddg1uTHmArY A9cyg6oEBLfwxVGkPbG7nCMi+Rg5Vl8EkxSl/rET4MZ7RGUtgYcn9fTGwAHHCFAnM6tTN 3jm0OEgfyjOsz9mfssgKDATefwmx7+4VfMVx+nFi9XTGiw0E1Uv9jhpVZY/gtTFs2ia8L B9ZMYRqY/Iq9EkDDZHhCzGUqMn2SCKruXXnT6ifuVQdo/K9acoX599jKCAtFdf9ujiq0q RG4DTr2HItGbKH21wHrdpsmTDR5jdPOmRIiSFIJ3eC7mX5QKhrw2J2kEqtCBWeWyQaQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796076201; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=IQvKeMXBrMOVEHh1BAFHV1VddIiRcUz3S/b2Bs4Nq7U=; b=0S72TmShqJzHp04fXFpUthzMTdmsEbCuwLnQnXUgqPOCMX0bjJzV4dnv+AFG3/PljId7 Kq/+6FHjJwbYH9bXK0xLntK6yqOWilkxZn6k0+C5OCsserjxUlB6UqgMN5tvJlmkDmKKo XmxJwAsb9URtvy0TDlga2dVKKyf0vrspWqbiltAXrrqb42dfhPSkmllFrExtPSeqw0jlS a2m55w0ngQ4mqraQ7pfT5r/QMGXBLTUCRfSNhamQ4WrKsz2DprFvTFld+yxCu6fO5JuOl CxfPjUkN/03XQw/J/il9l0OxCdPsSGVupadJTAVQDzJX2EMfjcgbIGxOB0nAkv0leIA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=asu.edu; spf=pass smtp.mailfrom=asu.edu; dkim=pass header.d=asu.edu header.i=@asu.edu header.a=rsa-sha256 header.s=google header.b="JRAakY9/"; arc=none smtp.remote-ip=74.125.82.43 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE322606A327 for ; Mon, 30 Nov 2026 22:03:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EE322606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=asu.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=asu.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=asu.edu header.i=@asu.edu header.a=rsa-sha256 header.s=google header.b=JRAakY9/ Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-1b5b910c838so1013830c88.1 for ; Mon, 30 Nov 2026 14:03:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asu.edu; s=google; t=1796076200; x=1796681000; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=IQvKeMXBrMOVEHh1BAFHV1VddIiRcUz3S/b2Bs4Nq7U=; b=JRAakY9/qfyrtnaaKPurVwEgKNFogpCHaSLxzIJ0ZLYZroRLHpiECE8iBwRxGZT9kW FZBF7UOu3hjJPemkA+BWbU0+vrUT/V6VEurKxx39VrXmw32CV2WRR8z15qAsQg7j+MsM NlaCGkHL2hgaW74RS+Vb2lv5jksJRgNI2Z4x2h7Wg+7e4FEg91psVgM1ojUOlM74Lw8m A9fWYASe7lmDzeO+r2pV5RKAOmknvk6VePF/H8as2UBjVyDnX6G6w4tNCdz/fN5yuE+Q apmqV9gxbJHcxZXA+Gi+gjZ/LL03F6r0k3T/Dohyr2kltdM4v4RedODGo3qANkvWg0oW zZ3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796076200; x=1796681000; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=IQvKeMXBrMOVEHh1BAFHV1VddIiRcUz3S/b2Bs4Nq7U=; b=EiMjWZ32noW/G2PfZZcFb14JXBsvhpFJTp0iSH+DEkmrp1/tzb4S6puzd/PGrqELWp OCiKy+JUVXNK1LYzTuj80oyzq47VteJIPe2Zsp3xZudCuqfP8LPnvWWRR9dHruGnXn5N it0gqKvzStMTVcbY8fjl4SnKD9XjShKAPRJhZ9XEc91ydM/t60nItWqYY6A3LU1hiJR0 EmG3XbwqF4xTTQyktesOPcuSWoNF415o8h7yGpH2LD7dkS5iDALXuZm91xXcKjyYvvwd psYdSkmCGMPmY/y4DQSGJKORc1aJmFxGeVblAvvKzzkzi7GvB5hgt23qbRfysRm7P4Ag YTmA== X-Gm-Message-State: APuU4Z9zWXTQd/53KXv0eAHhiRyNiIZ1a+kfG2H4C/MYP8+GprQoSW4O wIj+scljV+9rSaCLBcVX+sNzyk3NCdI0v9bG5V87HtaJVMwqlXvAaAj8GNYFyKX0Tg== X-Gm-Gg: AZFdTZeWtriG2vDWTDt6hFRjh8mlobacMcS2dks7N03ulgPMDicGzz+CjQzufcfGwJy DS+VL6ZcLQZAHXkjlKw+E8OFot+ystOH+ogY1VCu+7rnJI6v2lEBeO1a/gqxSR76uNITfw1ts28 Rc0PdxZu0ab/IC+87cXDpvCIr8dvkyP3c1es6MRQqJt8m7SNIS8WnslB2m0PTHzNz95QC/lK7Qh NntRUPp2JwOEeehs2knlrXe5Z8pu+1mp9sNqA0b/LWkLWe8XCNi145iNzVoVIXNG4jKCbmftQMx 1hglufwD3ug3lx99qm4q/mLUFxfrTNBZJuuUZ1SYM9FEUh2zYZlD2tnn266o+t4e7/suSt10SLa iLmKNDut7MY1uOpSeEr+WJcW6ny+OOiCdZwunqJvDPdPEb/EQ15V8z0rQJ5068/Y9K8JXSKkgoB mqdtfvChja+ol/nWUM2Hsp/du5uvx8DEtU1mWVbU5kpB2/cllA9652zVa7YHtkqjfiO38ODN5On UheRMOsNHn4w+pZJ/wSBB33YKg1eg+qyRrEktkaRQJtuKbxZSXglQXpL+SuEkbZVukfRzsvxB9b wxBl9uUcsu7JyKY98UDfkij4ZXez9IjzkjUg0T9vkzBDRTzrNp8RpIi9Phcfj5FTied8 X-Received: by 2002:a05:7301:240a:b0:386:de41:be4e with SMTP id 5a478bee46e88-386de41bf8fmr14778805eec.27.1796076199854; Mon, 30 Nov 2026 14:03:19 -0800 (PST) Received: from p1.. (209-147-138-4.nat.asu.edu. [209.147.138.4]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-386f6651e2asm28885641eec.27.2026.11.30.14.03.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 14:03:19 -0800 (PST) From: Xiang Mei To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Sashiko , co+86678873d3803945@bugs.sh, co+9a1ebd50dd939705@bugs.sh, Xiang Mei , stable@vger.kernel.org Subject: [PATCH 1/2] HID: core: release the HID-BPF event buffer on hid_connect()'s no-listeners exit Date: Mon, 30 Nov 2026 15:03:14 -0700 Message-ID: <20261130220315.659533-2-xmei5@asu.edu> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130220315.659533-1-xmei5@asu.edu> References: <20261130220315.659533-1-xmei5@asu.edu> X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit hid_connect() allocates hdev->bpf.device_data in hid_bpf_connect_device(), but its "device has no listeners" exit returns -ENODEV without freeing it. hid_hw_start() then only calls ll_driver->stop(), so hid_disconnect(), the sole caller of hid_bpf_disconnect_device(), never runs. The stale buffer and its allocated_data are reused by the next successful probe, since hid_bpf_allocate_event_data() returns early when device_data is set, and dispatch_hid_bpf_device_event() copies a full report into it unclamped. A HID-BPF program with ->hid_rdesc_fixup and ->hid_device_event can do this: attaching it reprobes with a small, listener-less descriptor (64-byte buffer leaked), detaching reprobes with the original one, and a 1024-byte UHID_INPUT2 overflows the buffer: BUG: KASAN: slab-out-of-bounds in dispatch_hid_bpf_device_event (drivers/hid/bpf/hid_bpf_dispatch.c:54) Write of size 1024 at addr ffff88800a401480 by task exploit/87 Call Trace: ... __asan_memcpy (mm/kasan/shadow.c:106 (discriminator 1)) dispatch_hid_bpf_device_event (drivers/hid/bpf/hid_bpf_dispatch.c:54) __hid_input_report (drivers/hid/hid-core.c:2150) hid_safe_input_report (drivers/hid/hid-core.c:2227) uhid_char_write (drivers/hid/uhid.c:609 drivers/hid/uhid.c:767) vfs_write (fs/read_write.c:665) ksys_write (fs/read_write.c:719) do_syscall_64 (arch/x86/entry/syscall_64.c:61 arch/x86/entry/syscall_64.c:89) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) ... which belongs to the cache kmalloc-64 of size 64 ... Oops: general protection fault, probably for non-canonical address 0x4847464544434261: ... RIP: 0010:__refill_objects_node (mm/slub.c:584 mm/slub.c:597 mm/slub.c:7420) Call Trace: ... __kmalloc_noprof (mm/slub.c:4887 mm/slub.c:5021 mm/slub.c:5530 mm/slub.c:5556) __hid_bpf_allocate_data (... drivers/hid/bpf/hid_bpf_dispatch.c:254) hid_connect (drivers/hid/hid-core.c:2309) hid_hw_start (drivers/hid/hid-core.c:2436 drivers/hid/hid-core.c:2427) hid_device_probe (drivers/hid/hid-core.c:2839 drivers/hid/hid-core.c:2878) ... device_reprobe (drivers/base/bus.c:873 drivers/base/bus.c:907) hid_bpf_reg (drivers/hid/bpf/hid_bpf_struct_ops.c:239) bpf_struct_ops_map_update_elem (kernel/bpf/bpf_struct_ops.c:925) ... __sys_bpf (kernel/bpf/syscall.c:6443) ... do_syscall_64 (arch/x86/entry/syscall_64.c:61 arch/x86/entry/syscall_64.c:89) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) Kernel panic - not syncing: Fatal exception Release the buffer on that exit. hid_bpf_disconnect_device() also clears device_data, so later paths through hid_disconnect() are unaffected. Cc: stable@vger.kernel.org Fixes: 658ee5a64fcf ("HID: bpf: allocate data memory for device_event BPF programs") Reported-by: Sashiko Closes: https://lore.kernel.org/all/20260908202056.698371F00A3A@smtp.kernel.org/ Reported-by: co+86678873d3803945@bugs.sh Signed-off-by: Xiang Mei --- drivers/hid/hid-core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 4a47deb9d833..3f93b0d48537 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -2339,6 +2339,7 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask) * to any other listener. */ if (!hdev->claimed && !hdev->driver->raw_event) { hid_err(hdev, "device has no listeners, quitting\n"); + hid_bpf_disconnect_device(hdev); return -ENODEV; } -- 2.43.0