From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D0A93B893A for ; Fri, 10 Jul 2026 07:47:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783669661; cv=none; b=Kw7OPzVRluAoRx00BSYc+Rjx3TvkONCiSIe7GU/PqiCFk8kZetRYi562qvjdRDwUbNLY65eMsZ7zWKL24N/5piMgZF6ghZh3gLdishmFl2wpV+wUtRpaKa4YP8igUaccNxEKIjJfLbWCAzUkOLu8kIH6nNfh4Y+ag69d3ZvTf1M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783669661; c=relaxed/simple; bh=RaIYkUfGrTauNfU/fKxJ6fGfioZ/3/GCN64xoXCFToc=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=BCIyy29DTNXDF1gBIvh9GgOktUFuGpuSLSpjvouoiRf818Ld5MbHnoj642MlRGCkcJjOgeb8AENuOKwylstRrYXriEk7y6kbw82zvQ2LHT5LL62TBoLQNcLSqhSSojqWCUN4M4D2Du+seBgzhEIR+26/7WQtepmBIyh7+nKkX+8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AGkqCKGh; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AGkqCKGh" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-8486672f03cso514213b3a.0 for ; Fri, 10 Jul 2026 00:47:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783669659; x=1784274459; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to:content-type; bh=yjtDP2RXjezG1cG58MMunIqUUp8s3pwkHt+EzmYlVO0=; b=AGkqCKGhxp2zrfXX8V/j47U9yDXbzcmaCAH88bKY/ZZam8uShFydex3Ge6cHVBshJO qyLBN0RtXkCAdRByNj0so2Mncp38IOLtQXTsP0BKaXhiYDQ1X9sI41FoAwJa2ulvXZK8 dLf7RxWRIuggYoH7dT1U+dhfDqcAJHqS8EvS7cTOKpwDwqsu8W0NFvwxcqvoVtj9cOFa NWHWq3DKrtRB48KAmA4T4q6Ku6VV05K8BuVw1oL8yBCZNn8tyFVgHGBN6hTzbQNcqFOq oTNckBxcyA1bMwej6BbIEhkBgeMbQYQjwMsgOuAe3c3ZmQqvqEWlBQ4xMzMmfr7epRg9 8epw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783669659; x=1784274459; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=yjtDP2RXjezG1cG58MMunIqUUp8s3pwkHt+EzmYlVO0=; b=P4FF4bnd98HmhPUkmUBEqEZQA7jTUm0+nCTKKgCff+CyHB1vWHDmqG3VYyoZD0P4EG WzR6KI5yITP1nNanJv4nHlO8LzfqkZPXfWDV2EG2lYeV/LCi8G7rkDED4Z2aPlbZBgvO wdKBDBiGj1gahBhYYohW/Yu6LV5sZrLMsSgO9QvBCKeAG8FlzICeNMC5aXdZHo33iNTt CwWPQ8h+1OOS60F4uykG9Po7X/mvHzx7iSMBkjeaL1UWJqMqaK/KBdlen/yqZPAPwdUw ftIUFu0oftfKYcsz73os5u/Iap0Ov+6bFtTHVAXmNPM5VqTWf6wh6aBCS+VbMfpJB/Q4 vuwQ== X-Forwarded-Encrypted: i=1; AHgh+Rrb3OL3VfKcm4Qz74ieOafNSW3ghYdZ193hubOiFPuKjUU8JtBJG/OXQmGlxX4aKXwJMEk3HSrmzfju8BM=@vger.kernel.org X-Gm-Message-State: AOJu0YyJEgP1MV5tnsttCROirNqxRPZ2ykNPKzy0jgZezGGLv8ooxx2N czlGdb9WqBNpoxKkHeNIrRtbVMFvrqT5yr1YdsDaHD/GgQvLnF7IleTA X-Gm-Gg: AfdE7cl7Y4Zr+gUkS4Jm/Pb+dtFc2XLpKFWz15z82SbKSx+96GHhQpdpKeQf1anBvfN yUgYY0qqYEcXKME2Sidi6Bnua9N0z/T/VcaIsTh8LofSKK2gsACr2wgIBLzXtXqyZ890gXUFDXR RFfowG0kQIAiFBZyckrIGlQUYiI+UwGsJx+erXaHe6KvhdG+WGWhur46pR/hWl8Eqxg89ccCf/W gVhrODIoEPR3UCO8DQGo/V/ebubMS/XC8T8shRH4Un8zKH4fmFKWfAAsatpSDxLQhPVynDi/l7V F1F0XTe311uIw7qKzp7ldv9Mh7sywA0hW4SI09pRP28tuWoKtQwyxfvYkpL1BS0a9OUn/w5TDcs FJAaTHQDJ5Q6GSuz4PjEUmV1tklLQsP6KMsOUCtIHnkhEE86gcRhekbrsN8L/8beWFhASMYtjGT sVnEvh7Eul4D8BQGA9wvVUgyTWCfDJnCG7QZ92V6cd X-Received: by 2002:a05:6a00:8588:b0:848:662c:cb85 with SMTP id d2e1a72fcca58-848662cd2c6mr3665501b3a.6.1783669659223; Fri, 10 Jul 2026 00:47:39 -0700 (PDT) Received: from [192.168.0.13] ([38.34.87.7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-847f6b60571sm9833231b3a.9.2026.07.10.00.47.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 00:47:38 -0700 (PDT) Message-ID: <9732d0d410c8e267fd53f99c5d456eb44be5026b.camel@gmail.com> Subject: Re: [PATCH bpf v4 1/2] bpf: Reject negative const offsets for buffer pointers From: Eduard Zingerman To: sun jian Cc: Shung-Hsi Yu , bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, memxor@gmail.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, shuah@kernel.org, mmullins@fb.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Date: Fri, 10 Jul 2026 00:47:35 -0700 In-Reply-To: References: <20260708090151.151729-1-sun.jian.kdev@gmail.com> <20260708090151.151729-2-sun.jian.kdev@gmail.com> <1f8aad47f61fbf85eb55276e4bb01bfcff61393e.camel@gmail.com> <4349d987d34f9426bdbb09a5d02de61da8f3e746.camel@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2-10 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Fri, 2026-07-10 at 15:25 +0800, sun jian wrote: > On Fri, Jul 10, 2026 at 2:23=E2=80=AFPM Eduard Zingerman wrote: > >=20 > > On Fri, 2026-07-10 at 13:52 +0800, sun jian wrote: > >=20 > > [...] > >=20 > > > There is an observable effect on the target bpf base. I tested it wit= h a > > > temporary raw_tp writable test_run reproducer, not part of the series= . It > > > attaches a raw_tp writable program to bpf_test_finish and triggers it > > > through BPF_PROG_TEST_RUN. The program does: > > >=20 > > > r6 =3D *(u64 *)(r1 + 0) > > > r6 +=3D -8 > > > *(u64 *)(r6 + 0) =3D 0 > > >=20 > > > With KASAN enabled and the BPF JIT disabled, on the bpf base without = the > > > verifier fix, the program loads, attaches, executes, and KASAN report= s: > >=20 > > Could you please identify why the behaviour differs between bpf and bpf= -next? >=20 > I checked the current bpf-next, but I could not reproduce the difference. >=20 > Both the public cgit page and my local bpf-next/master and bpf-next/for-n= ext > point to: > a4553044d1af ("Merge branch 'bpf-bound-rdonly-rdwr_buf_size-kfunc-return-= size'") >=20 > I tested that tree with only the selftest patch applied. The staged diff > only contains: >=20 > tools/testing/selftests/bpf/prog_tests/raw_tp_writable_reject_nbd_invalid= .c > tools/testing/selftests/bpf/progs/verifier_raw_tp_writable.c >=20 > The negative const-offset case is still accepted at load time: >=20 > #637/2 verifier_raw_tp_writable/raw_tracepoint_writable: reject > negative const offset:FAIL > run_subtest:FAIL:unexpected_load_success unexpected success: 0 >=20 > and the verifier log only shows: >=20 > processed 4 insns (limit 1000000) max_states_per_insn 0 total_states 0 > peak_states 0 mark_read 0 Here is the branch: https://github.com/eddyz87/bpf/tree/tp-buffer-negative-offset It is the current bpf-next HEAD [1] plus patches #1,2 and a revert of patch= #1. I have KASAN enabled, the test is passing: #317 raw_tp_writable_reject_nbd_invalid:OK [1] c3d5ef291a2a ("selftests/bpf: Add test for scalar id on sign-extending = stack fill") > The current __check_buffer_access() in that tree still only rejects a > negative instruction offset and a non-constant var_off. It does not check > the folded effective offset, so this case still has off=3D0 and var_off= =3D-8 and > is accepted. >=20 > So, at least on a4553044d1af, I do not see bpf-next rejecting this case. = If > you have a bpf-next commit or verifier log where this case is rejected, I= 'd > be glad to take a look and reconcile; I may well be missing something in = my > setup. >=20 > Thanks, > Sun Jian > >=20 > > [...]