Article View: linux.kernel.netdev
Article #16623[PATCH bpf-next 0/2] bpf: Fix the array map gen_lookup index bounds check
From: Yuan Chen
Date: Sun, 15 Nov 2026 10:25
Date: Sun, 15 Nov 2026 10:25
24 lines
9361 bytes
9361 bytes
The inlined bpf_map_lookup_elem() of the array map flavors bounds the index with a 64-bit JGE against map->max_entries. The index is a zero-extended u32, but the immediate of a 64-bit JGE is sign-extended, so for max_entries >= 0x80000000 the compare is never true. With bypass_spec_v1 the inlined code then addresses the array out of bounds; without it the index_mask AND keeps the access in bounds, but an out-of-range key returns a masked element instead of NULL. Patch 1 switches the three compares to BPF_JMP32_IMM(). Patch 2 adds a selftest that checks the emitted compare in the translated program. Yuan Chen (2): bpf: Use a 32-bit compare in the array map gen_lookups selftests/bpf: Test the emitted bounds check of the array gen_lookup kernel/bpf/arraymap.c | 12 +- .../bpf/prog_tests/array_gen_lookup_jmp32.c | 204 ++++++++++++++++++ 2 files changed, 210 insertions(+), 6 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/array_gen_lookup_jmp32.c -- 2.54.0
Technical Details
Message-ID:
<20261115102559.465375-1-chenyuan@kylinos.cn>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363664-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363664-linux-kernel-netdev=dewy.ru From: chenyuan@kylinos.cn (Yuan Chen) Newsgroups: linux.kernel.netdev Subject: [PATCH bpf-next 0/2] bpf: Fix the array map gen_lookup index bounds check Date: Sun, 15 Nov 2026 18:25:57 +0800 Organization: Usenet Network Sender: chenyuan_fl@163.com Message-ID: <20261115102559.465375-1-chenyuan@kylinos.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1773485"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:c18gZC4TElDaBKcBjSPEeYhKHN0= sha256:3rMSogzA4+93zxpSuPGXhqOBdXUZlHRjgQZHmt5XmBg= sha1:STuzoqa3xgeuzPfa7kIohPgKdSs= sha256:3dx3xBzuuKiBEik/j5GipSP+wMogose2ZJbUR6y0Jbs= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 59C871149A6; Sun, 15 Nov 2026 13:27:23 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.95 X-Spam-Status: No, score=-2.95 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=163.com X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eB20U7tqmxSF; Sun, 15 Nov 2026 13:27:19 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-363664-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=kylinos.cn X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 134151149A0; Sun, 15 Nov 2026 13:27:09 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id A2BB1372D6; Sun, 15 Nov 2026 10:27:06 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794738422; b=GTT2lAiNGq4s8TNxuGaTidi7q0R3wlRCkPpTiKs/dNgMPkERqmoxeXZARKBPDS3pUdUp GICZmsDEBQoZEM1WJS3csJRsAdeg4vFOE4tdvALsBetNFQREvyh4oiyZRWWNL+xX2NtwI wNRXhcP6/jdekh5HepLoVeKDzq3f1vDLoXaUm720vKOYk7cGI+qpz+DpHLhi8pq25dO72 iVcRQOxi44SHyoZVA1+uWqyfkVMjuV5FwnOEk/cCHYE1EmtRvBLyDQ++tfZT5bNLPdvdD f+DnHfQXppXb2l0j+8Q0ZM0hBTpDkHXFWDA7BphVIfglwEDP2nCilkHCEL/auLXXHkQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794738422; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To: Cc:Subject:Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Transfer-Encoding:X-CM-TRANSID: X-Coremail-Antispam:Sender:X-CM-SenderInfo; bh=1azWyhbD9K52O9zP67BPxVg08oy4qhI69qmDlV855Hg=; b=1ncm6EZg8gIo6p5zwlc+FjImNjGysiwpmNfUYIF2YoYT18yuZIoroSStnDnv+XvPz94k H00LRkcCWXoXg8rXRrl+F5zC47ga3a2X/KADsFEjZTqwkakmQy/0+RCOXKBGvI7J0/9y+ 399v9P0QnlS8h05ZCkwiUe5zHuKtZN52yN/J/82JVcBwc0KzxNMY1riP0xZnevpu2XYYp IAimECD3i0n8lBf2AMb95a8rqBGLz60dxkg3fv6hzgX1phOKMSVvWhhyqUcbONWqro9gf 2pTxdDcbB74lGMt9V7xr+Qn16Tl9khMOdCrqzgRQDyb53KztR8My4AS0vaxgeYWGVrQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=azqiNrDc; dmarc=none header.from=kylinos.cn; spf=pass smtp.mailfrom=163.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8821606A332; Sun, 15 Nov 2026 10:27:02 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=azqiNrDc X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.5 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794738422; b=oUTe9DM5NDpuGv5xt/BWbFx3fNYyNIi+oD2JEGi6W9UnTS7vLxtXEZKN8Dni4IKYaI/U moVFVjU3ihhrvZQxl1TnRMpNjYpGcSwKlyAqJPEMYSgAPJogID43yxTUiY7Gpr/sFAoEK 5MdF80A4ox0On3pqJTllNllOQW04yNyr1njZkw2r/n/ES5qgUaDK8m0m8ph4En11FGOrb u3xzY9f/ddjG0gZ52EefjpFCVCsJm/7lBwfGs6p7rpYv4Sq0CEzVJjcUOAnyV6HXACUH2 4FyuOuA5pXpKBEYV5YTBMcox+V9qV+i52sEFkERkPmVy6ysCWIYhxX+jwZWqV2fiMZw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794738422; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding: X-CM-TRANSID:X-Coremail-Antispam:Sender:X-CM-SenderInfo; bh=1azWyhbD9K52O9zP67BPxVg08oy4qhI69qmDlV855Hg=; b=ntFx1EUq34rQzz0U2SyoyCqV8YEHWLXy4EQ1Mca7UyZr0NhdfkE2Q39gVHMJN5jZkzra kIdlQftxB2mDpFobHtz1zPKB2/9fSNM5dbWs3fI7pJE7ywstjcMbYuT99mwFyJh+0YtMj HSCDUIYFrwNstOlDnk+tIg0//OsfhN+APHsIfYMs0KQCflN7b4+h6PNtFNDkroBouNeqT /zpQEVNQ+wKYRhf8Qx2da1A+uXoTtwTRHHz3/ocEXDn9bacq2GDOAYIA1jKo5QeqZKlbh d0H/eVquk9n/F3vUSVrq8ke5LllAnkpYjt9YpejjmZjpelLSoJiMkIHbVzlwQPv3OGQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=kylinos.cn; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=azqiNrDc; arc=none smtp.remote-ip=220.197.31.5 X-Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67885606A31E; Sun, 15 Nov 2026 10:26:58 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 67885606A31E X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=1a zWyhbD9K52O9zP67BPxVg08oy4qhI69qmDlV855Hg=; b=azqiNrDchmfxqCncY8 zL+iBeSsl2dUTJmpG5X1P1kurzY8yzH2rb3OxBmNwhN6BE6s1kWE8oL2ts9ZmAzS YCoPleTDznK81DD/2+gbfZNwlYZX18QNiRGdH4icHNLsRskTN0EaX+ck/7qRO9Pn srel+EJHyBtqLt6UVwuZzYyO8= X-Received: from nec8-i7 (unknown []) by gzsmtp5 (Coremail) with SMTP id QCgvCgD3X7S+iPlqHVcuGA--.3517S2; Sun, 15 Nov 2026 18:26:08 +0800 (CST) X-Cc: netdev@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Andrii Nakryiko <andrii@kernel.org>, Eduard Zingerman <eddyz87@gmail.com>, Martin KaFai Lau <martin.lau@linux.dev>, Shuah Khan <shuah@kernel.org>, linux-kselftest@vger.kernel.org, Yuan Chen <chenyuan@kylinos.cn> X-Mailer: git-send-email 2.54.0 X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-CM-TRANSID: QCgvCgD3X7S+iPlqHVcuGA--.3517S2 X-Coremail-Antispam: 1Uf129KBjvdXoWrtw48KF13Gw18tFykJw1kXwb_yoWDAFXE93 yqkr97Xr4Yka4jqFWI9r1Yy3s3Ca1UCFykAFykXr17Wr4rXF45Cr4kCFykX3s7GrW3Xr93 Zrn0qa4Ivr1j9jkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU8wa93UUUUU== X-CM-SenderInfo: xfkh05pxdqswro6rljoofrz/xtbC5QFrKWr5iMGXSQAA3i