From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net (zg8tmtyylji0my4xnjqumte4.icoremail.net [162.243.164.118]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C2D983242AC; Sat, 20 Jun 2026 14:22:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.164.118 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781965375; cv=none; b=SAW4FaHCqjLSETup5e5V9fZXqP/CJW3J9ntel1Co6KZCaK2IPfQGzFYW4iJCkH1pzzLkD9B0vkwwxSpF4HdZwnh1HG40I+Qw9ma7y7sb5lZ2eR2GkYZ+/lVmfadz4E9LmkJQuaL1pDUybtrcqDghnBOpakLB9lQvliPttNY7LAg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781965375; c=relaxed/simple; bh=Qq4qRaR6cyuaf8bfnOwlcdMg/K0Eld5LP9Zp59TaI0M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HzN0jXOcChuLgA+0EW+D3dYgyTFhjOoN27XRJSca62zDpVtVLZYLoZO+Xza8Ni2t0Rp6ptYo/yNUObjcnyWjqNt/1/T4hHduiO/zZsVxdmyfafoVj1MVba+kNCJK/K25uY2Jvwk6MM7oV6kmUrp84k8fZSrnNFeKgKD92VjtRZQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mails.tsinghua.edu.cn; spf=pass smtp.mailfrom=mails.tsinghua.edu.cn; dkim=pass (1024-bit key) header.d=mails.tsinghua.edu.cn header.i=@mails.tsinghua.edu.cn header.b=F2MTBXaN; arc=none smtp.client-ip=162.243.164.118 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mails.tsinghua.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mails.tsinghua.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mails.tsinghua.edu.cn header.i=@mails.tsinghua.edu.cn header.b="F2MTBXaN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mails.tsinghua.edu.cn; s=dkim; h=Received:From:To:Cc:Subject: Date:Message-Id:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=/YSzKvP+6OvD5Tjl/dg3jAaqkQM9nPdYE6 tSdOD5rpY=; b=F2MTBXaN6MPAO4gcVY131F+fmg6vQuRcUuoDgMUo++lNioYOap fMw/6Aiy+jq5HZPzhIO/Xoe/yX/MjG/rID5nOjAZTY4emRnS8ASsAlKY+lYRaogk AFus8HmVEmVD4lzDKZF+l21nvTYhpkrnKVm/YHzIPKGHq4UrzwWFOx/ak= Received: from c9a6c405b3f2.. (unknown [202.112.238.121]) by web5 (Coremail) with SMTP id zAQGZQBH0bsbojZqXHGQAg--.53711S2; Sat, 20 Jun 2026 22:22:32 +0800 (CST) From: Yiyang Chen To: Jiri Kosina , Benjamin Tissoires , bpf@vger.kernel.org, linux-input@vger.kernel.org Cc: Yiyang Chen , Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Kumar Kartikeya Dwivedi , Song Liu , Yonghong Song , Jiri Olsa , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2 0/2] HID: bpf: Fix hid_bpf_get_data() range check Date: Sat, 20 Jun 2026 14:22:15 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:zAQGZQBH0bsbojZqXHGQAg--.53711S2 X-Coremail-Antispam: 1UD129KBjvJXoW7CrW5uw1fuFWkZryUCrW3Wrg_yoW8KFy3pa 95Grs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xkxdhvlgxou0/ hid_bpf_get_data() exposes a pointer into the HID-BPF context data when the caller-provided offset and size fit inside ctx->allocated_size. The helper currently checks that range with: rdwr_buf_size + offset > ctx->allocated_size Since both operands are unsigned, a very large size can wrap the sum and make an out-of-range request look valid. Patch 1 changes the helper to reject offset values beyond the allocation and then compare the requested size against the remaining bytes. Patch 2 adds a HID-BPF regression check that asks hid_bpf_get_data() for offset 2 and size ~0ULL from an rdesc_fixup callback and expects NULL. It also adds KHDR_INCLUDES to the HID selftest build so the userspace test sees current kernel UAPI HID definitions. Validation, rebased and tested on bpf-next master e4287bf34f97 ("selftests/bpf: Work around llvm stack overflow in crypto progs"): git diff --check e4287bf34f97..HEAD: OK scripts/checkpatch.pl --strict -g e4287bf34f97..HEAD: OK make O=/root/ebpf-verifier-bug-detection/kernel-build/bpf-next-hidbpf-20260616 \ drivers/hid/bpf/hid_bpf_dispatch.o: OK make -C tools/testing/selftests/hid \ O=/root/ebpf-verifier-bug-detection/kernel-build/bpf-next-hidbpf-20260616 \ OUTPUT=/tmp/hid-selftest-026-v2 \ VMLINUX_BTF=/root/ebpf-verifier-bug-detection/kernel-build/bpf-next-hidbpf-20260616/vmlinux \ KHDR_INCLUDES=-isystem /root/ebpf-verifier-bug-detection/kernel-build/bpf-next-hidbpf-20260616/usr/include \ hid_bpf: OK Changes in v2: - Drop the temporary data variable around the overflow hid_bpf_get_data() call in the selftest callback. - Correct the Fixes tag to commit 658ee5a64fcf ("HID: bpf: allocate data memory for device_event BPF programs"). v1: https://lore.kernel.org/bpf/cover.1781627122.git.chenyy23@mails.tsinghua.edu.cn/ Yiyang Chen (2): HID: bpf: Fix hid_bpf_get_data() range check selftests/hid: Cover hid_bpf_get_data() size overflow drivers/hid/bpf/hid_bpf_dispatch.c | 3 ++- tools/testing/selftests/hid/Makefile | 2 +- tools/testing/selftests/hid/hid_bpf.c | 11 +++++++++++ tools/testing/selftests/hid/progs/hid.c | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) base-commit: e4287bf34f97a88c7d9322f5bde828724c073a6b -- 2.34.1