From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796076200; b=vmWm6DRxKRdmBev52Ij7IwFTi4TpOw/WlskRqJQZL6wqV+87xU/bZ8n6QH9Q+hgro0KY 3byUvysuY6Uas1gtKoHZ8tXGNejZ8ItOLFCcZxIZqGxu8w9hDSf0K/IZpyuUKyKgRFgP2 EV6b6wyLah6yg9iIjTozJuoJXR5/XOAA1vUaDKLQU555uh5YiaurEzz8l79nDo91q+vDU Ybzw6KRDBPSKFF+1VgWWzUt9WM5PTGV7sYQc/MPPYDYxAjrEE4lkdBiEw9SJsT5wmCFVL tXS/b7jwNga7FnbcKCNDG46tUuvGesAbSFky051xJCx1ATZmWrdhoQ8/JFYt+pQOY7w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796076200; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=v5FXVpJqXfI5a6DlowpSgsLYkK96wGTwLURZc5jr1hA=; b=Pz4PezOOW+1Ug4bzHKEk/Yz8chrAWq2Ty2Qw9qj0k5kykCjyGRQK1sKsBv+Nd28sYqDf IpNxZMVE1sb4+QDXhbDDUB8eE8TwsEOeKSByWQDvtni4rcUkCr/q7PBgEz/+25NPMKqbP /rnjq0mmXpeQzevvS3lgKEpLbjqSce88lCA7G8Mdq5NoRi5cVnPXdC8/IyK4FU+ltxt7l PdgXTUg3m4TOR32s6jbnWuf99fxahOM6pb+QDuEMHYTE8AGj05TpV9KjKfpXlwRdcKaU1 SnmgTY6kqqXKlc8Tkkz9hGeBn9gSyXM/LVS0So6d0K6KhRqOfz19oZ7rdQG/XjlR1Xg== 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=fNid3cDY; arc=none smtp.remote-ip=74.125.82.176 Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176]) (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 747EB606A335 for ; Mon, 30 Nov 2026 22:03:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 747EB606A335 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=fNid3cDY Received: by mail-dy1-f176.google.com with SMTP id 5a478bee46e88-38431138772so14973801eec.1 for ; Mon, 30 Nov 2026 14:03:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asu.edu; s=google; t=1796076198; x=1796680998; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=v5FXVpJqXfI5a6DlowpSgsLYkK96wGTwLURZc5jr1hA=; b=fNid3cDYKvLjRNlssKuLj/6dUenYFl6XLp/PCbi80yER8egDniBCPLt4r+rXAZhbwC TGA7ntZf0LNUNXL8C+3nb+yt7QF3YqsSs+kSEGX6alkkRyzJKTLa1MzMmoWB0kjSjYDF WcJeYiz4UVVdhKypA0r8xV8qnbvHSMqPdXnW7EIB7mgaALC46fy6d2n+DOCoopgbLsxb 7egL8R2Ene0tU3QBlRSu0s9JCNP/5UogKd2cGPPD2vgxf8h/oCrimXn8dWLQ2x/oD4XZ rzL3tsFjhI+xM9ExzkwWQ0Nu0GoVLV41SNCXtKEzUvWGcAd27kO15wgx/1baaCh2s6lt 7ziw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796076198; x=1796680998; h=content-transfer-encoding:mime-version: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=v5FXVpJqXfI5a6DlowpSgsLYkK96wGTwLURZc5jr1hA=; b=Hffw/85cOrMoOjhbm1Qrl8AujGHcpKfqwsXiI5C0yfA0kGbxGeeK4ESR0eVPlC46oA 835v30KYKzVm3TokRRWFOFVfUY2H4fZpak1SSenH/uCC7AaEPcZIZk+a58DtJLfS5GL/ cND9d/yN1HOHL/aFFrHU9xxWd1secCqg1D3FOkTKRCl9o3AcQPEPGGqFV1v8beO7QDqR 6Nzae5w+RUkJOeLUcRq4eS/1+6goRQAaGrumuom61/C+GyzGASvtbqBfV7NboY6MZkWN X+4fGcZ8bF1JYKURYa2YtFD72NsdOBduMHtlXtUm2MS7u/0JUzP2JCOYnO6t0vCbOCf+ H9/Q== X-Forwarded-Encrypted: i=1; AL+hErF7RS7L6q1hF+slWXL2aeld5jRT3NNP7EAE5wZlaKNYzKxJjmpqMSxG4Tzi3U0A+EFHMeEwhwZvvLfRdBs=@vger.kernel.org X-Gm-Message-State: APuU4Z/1UyyMhenBXBBW75v1VXSDcymBf+QG6/77Ip+BNDlxGQtC93Xy w+qZbDybJCH1JH6eXXfZpqbzi+Gc65TRlsdOSHQdY5XZi8kMSxGaUl11nQz66BheJQ== X-Gm-Gg: AZFdTZfzEgd4j/61JC57AXNU7vN8OJuL+2jXE5WaE2+qBhwdMMW+X4o3+ad+IfsbPYh HOTgQF3VxUJV0hgFHSGvZOe3782lLvG/6ofpec9JLj2j12Opc1l79vgcAYalfqLY18OGw/vNccp HBwwy5o/bP+CMZwOJ7SXc87u/voNoxM7RuEDY8uaXG+jt2Srt4O1FnqWwLqLJXKd8DFiPaR+zq7 1lHXsMl+FolzvalcFUwl/s5hhjW2G3PemCrzyMxyyn7nlmyEZ2tThzMj2BkpcSNVw3PwF+3dJaL juCyPvcM2YIFtrFkT8UhsPHiYMV/P+YYR8VPQUMtjZuG6rH1xg3EE6TIKImWt1kaYMTXv5IFhS5 ST561eoznlYUhDXjPzNVao+bitUL+knElIbDL8JPLyYYswKrgX1801vP3LS5OtzvlEVxVImcadi LLRUQBert214zBhlL6feH+n8Syk7aqvBzO8LBcB1gybhRiU5GBNUSdUOlnJgxH5da90OB4+XE88 wuLof/6A7OqSAttgm+Im4mIjKmTittCLC+av4t8ZkESLXsbIe/0iXpZ++KK8SH8Y1rl/2MIIHi/ 6CG75x4y3GvfsTKk0I1w04ftQrL8TtgQNTE2RRb+8w3E24JWxhT4PL4P9zP99iHFA+YXDA== X-Received: by 2002:a05:7300:1c95:b0:385:8851:fa4a with SMTP id 5a478bee46e88-385885211c2mr33894469eec.6.1796076198403; Mon, 30 Nov 2026 14:03:18 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 14:03:18 -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 Subject: [PATCH 0/2] HID: bpf: fix stale device_event buffer reuse Date: Mon, 30 Nov 2026 15:03:13 -0700 Message-ID: <20261130220315.659533-1-xmei5@asu.edu> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@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 hdev->bpf.device_data is allocated once, sized from the report descriptor parsed at that moment, and then reused: hid_bpf_allocate_event_data() returns early whenever the pointer is already set. If the buffer outlives the descriptor it was sized for, the next probe binds with a larger descriptor and dispatch_hid_bpf_device_event() copies a full report into the stale buffer. Two paths leave such a buffer behind: 1/2 hid_connect()'s "no listeners" exit returns without freeing the buffer it just allocated (KASAN slab-out-of-bounds write of 1024 bytes into kmalloc-64). The leak was also pointed out by the sashiko review in [1]. 2/2 hid_bpf_reg() allocates for an unbound device, whose report enums are empty, so the buffer is ZERO_SIZE_PTR with allocated_data 0 (NULL-pointer write at 0x10). Both are reachable from userspace with a uhid device and HID-BPF struct_ops programs using ->hid_rdesc_fixup and ->hid_device_event. Each patch was tested against its own reproducer on a KASAN kernel: the crash fires without the patch and does not with it. These fix the buffer lifetime and are independent of the pending change that bounds the memcpy() itself [2]; that one is still needed for uhid reports larger than the descriptor allows. [1] https://lore.kernel.org/all/20260908202056.698371F00A3A@smtp.kernel.org/ [2] https://lore.kernel.org/all/20261102112630.53400-1-alon@botanica.software/ Xiang Mei (2): HID: core: release the HID-BPF event buffer on hid_connect()'s no-listeners exit HID: bpf: don't allocate the event buffer for an unbound device drivers/hid/bpf/hid_bpf_struct_ops.c | 2 +- drivers/hid/hid-core.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) -- 2.43.0