From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796076202; b=tSBOqf3Eh+MnM4daD97i/o8sh+bhMmjiG7kbQinxV+4x516QzYzNcans0ERLLlTeKnGT Sm6PKLwZGW7fgSmo+Rc8mVypXhMs5evBPX15bxV3eaVUSvlyeTvbSaJuVsMYGXIij8hot WmydUfge1fE4NvevOWTrNhhbwT28By/DajOsx7xeILn6tpsZUItqSHS9YqNLpvjOV86rr nRkRroJTaC2r2nE1I4cEcEMhIr+Fxxx4+RVYZ8pyL/4GnAJH3uE2PAtOaFCfvswd86+9s PmT2xpodGZ3HX9jvH3EWpjjeselcQAEhg/OsxmtYapQ0z0ypMtQTW9Gsn9jOeOguJZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796076202; 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:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=kgwewPqHXLWmM2LyYGcmQt9tU1Au77refe9bUwkaAIU=; b=k7aKVjQv/Waw4p2J6AWP9Zz8fCrMW9YUBg0zcFFCOl5mxZiUNg7igfamHPoNSACe8d5E 9l9BYNsTHZ0wbFnPLsLyRIZx6NHQhLVqxBE1O1v7aro9+rTa6HMmCcNpxncmghihaG/+h Emq+ldM0LQ3KISZudEhNSjiYmBL849xZaQ5TmyWdSnCODT3fMKFgQ7KmEjGCK8wpFut2g BdQDP3wLiCAHlmHRRYlzWoLXtGrvhAJ+VPfVVbDXVYkWT9/3cafO/3n+rqPBdrGalZ5gB NF6LaUqs2Nf68GFMZAsEqS71U5pUoi+/aV64y1yj6G08rG+yT3r3Iai+SG8ClCgyXuA== 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=o89e93UO; arc=none smtp.remote-ip=74.125.82.42 Received: from mail-dl1-f42.google.com (mail-dl1-f42.google.com [74.125.82.42]) (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 394AA606A32E for ; Mon, 30 Nov 2026 22:03:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 394AA606A32E 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=o89e93UO Received: by mail-dl1-f42.google.com with SMTP id a92af1059eb24-1b5ade5e0c1so3934266c88.1 for ; Mon, 30 Nov 2026 14:03:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asu.edu; s=google; t=1796076201; x=1796681001; 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=kgwewPqHXLWmM2LyYGcmQt9tU1Au77refe9bUwkaAIU=; b=o89e93UOmkqAN+hrADDXS1kafhF1cvllox3c4AkFb9tiBq0RG7SvarWtQBNIObEXhg MOkWubU1g07z1dCOvE+y3vexhKmgD3wPPlLrs/vsa0ZkXps02zUDfXgXoDpO+9r1Rn9c c4uTbhn03joYd3+ghClgrn3eH5RXP8Qzky96MnaVtWdJsioGaKArNUe4nKQQ1wfarU8k oPAWYaD0d/4t6jatQvTFuuSAKuEQRHlnXuYwY0Em9ixgVOCHY9p9F/hq+/Hmf7feBv0b mNKGTXeEdfWtPX3Frr6CUjJPekPIxqXA2EZ7+brPqWat06mojv0rya6GotqkO8M/y99F H3UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796076201; x=1796681001; 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=kgwewPqHXLWmM2LyYGcmQt9tU1Au77refe9bUwkaAIU=; b=mzDE2zobmIZheX/Wr3+w8jmfc8iOhSz9t+hAXeUfBLftfXrLhKWFNClEqH7puKnwVu LA9KhJv3NYiHyRkoC3mre8DMDhSfeseko3rS3hy4F8MppOoVMZ0ipHv9LrS+KraMKVwk Oi0O45tUfwkCSJX1jovh/BvtKaLY/QqTzq14uVxHfn3mw/ZSHN+HejGZCOdQKCVONWRK 7m4f6qZ7Oz02VklzIj6X//V6YdT4udhNvGBnnA9CobjfY3nFFvU9bg1nHccR/vfiIe+X CyrtZo+Tuz54AImfQkLWFQtEqUXXPzBG58Q1YdmCkLPwlEQrHeHebwaIhY9lon5JY8lk oGRQ== X-Forwarded-Encrypted: i=1; AL+hErF9ALbNYptnEwwzLZXi1lG3hCEFqxQoLXzqZW5Kd7xhWYkwkMyQP7imok0X8mqPGqkzFyN6DnERnDUmVbo=@vger.kernel.org X-Gm-Message-State: APuU4Z+6V9zBuWevgV916pr/j4osTXroW3BQgLcLzbhyjrvGdW6Aa03n i9ma20pIqbcKZgugkn9jNCQxPKPOdVZe7JCemi0AbiJ5gRmmqrBGnkhgdG8gRLG2Kg== X-Gm-Gg: AZFdTZe8nIP+Tnv0dKv1Uq+F+xplF+3Sh27fCcLDqMz/f/OEkKU5lNDFKRS1asO92ZS Ymafidjh06Sg9pjTFoSGPwuVh+Sp1JmR6uPG06R5v0zZoLxq8N8LmhY1mquZ/dsAv+gJJmMJusd q2s2QULPCzbHOp4kNrpuAtOby1AFGfVa6OGiI8wZo+xO9T/9n3/UtVPAaWyXNyR6yDc29ivApkV AX/y5W6o5NI2qRD+urg/thk6rjE+26oyigxH7iko/airNLzzumcnDfNW8iNQXF497CReyU1tOBT YNY6GTr/jISk3MbM+kAc8Pudw6wrNsD5JEL2pWMbOqPHfdq5FwTQIQRSzzh5PhY5sUo7hCgL6BL f6NRspa6SZ0j5mcK97/D3czo6+TJrJvapf1autcWHEEJOaq8qiOMWMZvtcnbqCfSmAPaJqR2XAw GN0jKIow4gx+G7pJY6vOBRxO7qUuAZvZcThk7KlTFeJ6psyuiyxsN8KTVfg+repi7+5E29efQDG L0Em54OZohL9v1HZ4OoJdfw4MPf6lkQatN8a9lfwsJhJqCMTsqIVmHnqqZPuRWWZ9v0AKoMJpa/ uccGELx2dNJavFPWAa+rj3XauK46Aw1RVDN0KUg+PgvUQEMAT1cMzRYb+x7adS93qiRr8KlmtMS vv6dkLnJdCW5Q+U8= X-Received: by 2002:a05:701b:2051:20b0:1b2:4998:a0df with SMTP id a92af1059eb24-1b5568fa273mr34178950c88.35.1796076201213; Mon, 30 Nov 2026 14:03:21 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 14:03:20 -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 2/2] HID: bpf: don't allocate the event buffer for an unbound device Date: Mon, 30 Nov 2026 15:03:15 -0700 Message-ID: <20261130220315.659533-3-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-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 hid_bpf_reg() allocates hdev->bpf.device_data for a ->hid_device_event program even when the device is not bound. hid_close_report() has then cleared the report enums, so the buffer is sized for no reports: kzalloc(0) returns ZERO_SIZE_PTR and allocated_data is 0. The next successful hid_connect() keeps it, because hid_bpf_allocate_event_data() returns early when device_data is set, and the first input report is copied into it. Attaching a ->hid_device_event program while a ->hid_rdesc_fixup program keeps the device unbound, then detaching the latter, rebinds it with the original descriptor: BUG: KASAN: null-ptr-deref in dispatch_hid_bpf_device_event (drivers/hid/bpf/hid_bpf_dispatch.c:54) Write of size 1024 at addr 0000000000000010 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) ... BUG: kernel NULL pointer dereference, address: 0000000000000010 Oops: Oops: 0002 [#1] SMP KASAN NOPTI RIP: 0010:memcpy (arch/x86/lib/memcpy_64.S:37) Call Trace: 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) Kernel panic - not syncing: Fatal exception Only allocate when the report descriptor is parsed; otherwise hid_bpf_connect_device() allocates it when the device binds. Cc: stable@vger.kernel.org Fixes: ebc0d8093e8c ("HID: bpf: implement HID-BPF through bpf_struct_ops") Reported-by: co+9a1ebd50dd939705@bugs.sh Signed-off-by: Xiang Mei --- drivers/hid/bpf/hid_bpf_struct_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/bpf/hid_bpf_struct_ops.c b/drivers/hid/bpf/hid_bpf_struct_ops.c index c90b68956cb3..1039adeac8ae 100644 --- a/drivers/hid/bpf/hid_bpf_struct_ops.c +++ b/drivers/hid/bpf/hid_bpf_struct_ops.c @@ -216,7 +216,7 @@ static int hid_bpf_reg(void *kdata, struct bpf_link *link) hdev->bpf.rdesc_ops = ops; } - if (ops->hid_device_event) { + if (ops->hid_device_event && (hdev->status & HID_STAT_PARSED)) { err = hid_bpf_allocate_event_data(hdev); if (err) goto out_unlock; -- 2.43.0