From nobody Mon Feb 9 05:52:57 2026 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68F8F342C80 for ; Tue, 28 Oct 2025 15:20:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761664824; cv=none; b=G8xQDvpXvCdFgDYYqfZFbPQ0cLeTon0Hnh6xA/OYbHOmAc8xA8oAM2cttM3YCGr31c+OZYw9Txblt1jhkv2X1L0brbcCdGIV+3QtAMeuySeDS0xOqvu8qN6jKWRbYTIKMQqiV66ECgyVzgDRm/wJyqv4gtvJDnH0AFlwi9h8lW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761664824; c=relaxed/simple; bh=e6HN/dKZ+u/7a8MHlTVFNNkvjRiIo/c13bcuG1xwNJQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DWYhsGU/0ixWp9AEK8gk/fQhfZjlemclgUncmulhRIkt9LZmJHjEeijYXNG3r3l9fKNfM3cCx08hyu9njZKDw9vEozpHHZv8HC+j9wO6FwzDsEf8ygu39MyVKAihPcPr+Yv9jd9tTX/pEuL3xv2aRA1t4kI295MvN5/tUAPODrE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=jLzo1Wps; arc=none smtp.client-ip=95.215.58.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jLzo1Wps" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1761664820; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iwl7rDXJIzJ2WczqQvEPGztzATA3rpnK5twYsIF3gag=; b=jLzo1Wpsk75CWojoi00GapRaZEz7bp8J9YWi4T7MOrR7LTBGbBtktHriZwi+oHKCTGimjY MwpeeETfswZHR2WSyUN2Rsmlvp83ggfpvfcpDe9ZV9Ic4D/wMtUdT9H/FKWEV7lavfrFnq K456k+rBInD3/3X/98cRS/Ch5s4Opgc= From: KaFai Wan To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, paul.chaignon@gmail.com, m.shachnai@gmail.com, kafai.wan@linux.dev, harishankar.vishwanathan@gmail.com, colin.i.king@gmail.com, luis.gerhorst@fau.de, shung-hsi.yu@suse.com, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: syzbot+c950cc277150935cc0b5@syzkaller.appspotmail.com Subject: [PATCH bpf-next v2 1/2] bpf: Fix tnum_overlap to check for zero mask intersection Date: Tue, 28 Oct 2025 23:19:37 +0800 Message-ID: <20251028151938.3872003-2-kafai.wan@linux.dev> In-Reply-To: <20251028151938.3872003-1-kafai.wan@linux.dev> References: <20251028151938.3872003-1-kafai.wan@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Syzbot reported a kernel warning due to a range invariant violation in the BPF verifier. The issue occurs when tnum_overlap() fails to detect that two tnums don't have any overlapping bits. The problematic BPF program: 0: call bpf_get_prandom_u32 1: r6 =3D r0 2: r6 &=3D 0xFFFFFFFFFFFFFFF0 3: r7 =3D r0 4: r7 &=3D 0x07 5: r7 -=3D 0xFF 6: if r6 =3D=3D r7 goto After instruction 5, R7 has the range: R7: u64=3D[0xffffffffffffff01, 0xffffffffffffff08] var_off=3D(0xffffffff= ffffff00; 0xf) R6 and R7 don't overlap since they have no agreeing bits. However, is_branch_taken() fails to recognize this, causing the verifier to refine register bounds and trigger range bounds violation: 6: if r6 =3D=3D r7 goto true_reg1: u64=3D[0xffffffffffffff01, 0xffffffffffffff00] var_off=3D(0xf= fffffffffffff00, 0x0) true_reg2: u64=3D[0xffffffffffffff01, 0xffffffffffffff00] var_off=3D(0xf= fffffffffffff00, 0x0) The root cause is that tnum_overlap() doesn't properly handle the case where the masks have no overlapping bits. Fix this by adding an early check for zero mask intersection in tnum_overla= p(). Reported-by: syzbot+c950cc277150935cc0b5@syzkaller.appspotmail.com Fixes: f41345f47fb2 ("bpf: Use tnums for JEQ/JNE is_branch_taken logic") Signed-off-by: KaFai Wan --- kernel/bpf/tnum.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/bpf/tnum.c b/kernel/bpf/tnum.c index f8e70e9c3998..1a75b7c9a73a 100644 --- a/kernel/bpf/tnum.c +++ b/kernel/bpf/tnum.c @@ -163,6 +163,8 @@ bool tnum_overlap(struct tnum a, struct tnum b) { u64 mu; =20 + if (a.mask && b.mask && !(a.mask & b.mask)) + return false; mu =3D ~a.mask & ~b.mask; return (a.value & mu) =3D=3D (b.value & mu); } --=20 2.43.0 From nobody Mon Feb 9 05:52:57 2026 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB61333FE0A for ; Tue, 28 Oct 2025 15:20:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761664832; cv=none; b=A79bVvWqfQV7UqCvZzdLvQdQ58rRw5ZSBarWks1hpJ6I3WSrC3/sjcbnEL4EXr9YfJalcQxGD8n+srZIX9yHOQG0T+6GobxSE0XaTGoe4u7GlSXXbPggd/c14n+FFwrlYBS8O3VNMOFcUhjmzEFv8Xun+gfP1+Xt0eupGBcDwfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761664832; c=relaxed/simple; bh=HYd2qH7FWSYKEo+EVxagg1RUtl38TekujFQnRYEMBtY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jS6M6HfgWajnhYo9/6l7Scv9D2+TXciaUsw/0ok2o96XUEWY8jKv1m+9BpQag4gPElyrGeJ/BuNxrlG2fdg+766/MKy+LDuyKHXqYIsvQ5ZUd5pD2VMuLCFnJe8+22MRXkn13yuCMAVI5tZx24In61PbUwRRCIGRlK6U1NwnaLs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ZVlRfk5d; arc=none smtp.client-ip=95.215.58.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ZVlRfk5d" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1761664829; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FBxBqu3N+DlOX27bsFsVYIxqbBpbd6ybHXvJvZNNT5E=; b=ZVlRfk5d74WPMBIH8ldQdIY8hxKmUlxbUA639saRb9HsLjkj5W/H2wzvsovLXZCn2jeoqc 2zFv0ACVKfYwSjpC2wv/xLwWOjqMhs9Yb+JaoKBuVsO9prkrAKL1KaUzgOeV04DmdE1z4t ZXcDrxnAeNJOCUSTmGWi/q7BAZnlG8s= From: KaFai Wan To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, paul.chaignon@gmail.com, m.shachnai@gmail.com, kafai.wan@linux.dev, harishankar.vishwanathan@gmail.com, colin.i.king@gmail.com, luis.gerhorst@fau.de, shung-hsi.yu@suse.com, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 2/2] selftests/bpf: Range analysis test case for JEQ Date: Tue, 28 Oct 2025 23:19:38 +0800 Message-ID: <20251028151938.3872003-3-kafai.wan@linux.dev> In-Reply-To: <20251028151938.3872003-1-kafai.wan@linux.dev> References: <20251028151938.3872003-1-kafai.wan@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" This patch adds coverage for the warning detected by syzkaller and fixed in the previous patch. Without the previous patch, this test fails with: verifier bug: REG INVARIANTS VIOLATION (true_reg1): range bounds violation u64=3D[0xffffffffffffff01, 0xffffffffffffff00] s64=3D[0xffffffffffffff01, 0xffffffffffffff00] u32=3D[0xffffff01, 0xffffff00] s32=3D[0xffffff00, 0xffffff00] var_off=3D(0xffffffffffffff00, 0x0) verifier bug: REG INVARIANTS VIOLATION (true_reg2): range bounds violation u64=3D[0xffffffffffffff01, 0xffffffffffffff00] s64=3D[0xffffffffffffff01, 0xffffffffffffff00] u32=3D[0xffffff01, 0xffffff00] s32=3D[0xffffff01, 0xffffff00] var_off=3D(0xffffffffffffff00, 0x0) Signed-off-by: KaFai Wan --- .../selftests/bpf/progs/verifier_bounds.c | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/verifier_bounds.c b/tools/te= sting/selftests/bpf/progs/verifier_bounds.c index 0a72e0228ea9..304ab5a07a3b 100644 --- a/tools/testing/selftests/bpf/progs/verifier_bounds.c +++ b/tools/testing/selftests/bpf/progs/verifier_bounds.c @@ -1550,6 +1550,29 @@ l0_%=3D: r0 =3D 0; \ : __clobber_all); } =20 +SEC("socket") +__description("dead branch on jeq, does not result in invariants violation= error") +__success __log_level(2) +__retval(0) __flag(BPF_F_TEST_REG_INVARIANTS) +__naked void jeq_range_analysis(void) +{ + asm volatile (" \ + call %[bpf_get_prandom_u32]; \ + r6 =3D r0; \ + r6 &=3D 0xFFFFFFFFFFFFFFF0; \ + r7 =3D r0; \ + r7 &=3D 0x07; \ + r7 -=3D 0xFF; \ + if r6 =3D=3D r7 goto l1_%=3D; \ +l0_%=3D: r0 =3D 0; \ + exit; \ +l1_%=3D: r0 =3D 1; \ + exit; \ +" : + : __imm(bpf_get_prandom_u32) + : __clobber_all); +} + /* This test covers the bounds deduction on 64bits when the s64 and u64 ra= nges * overlap on the negative side. At instruction 7, the ranges look as foll= ows: * --=20 2.43.0