From nobody Mon Feb 9 14:33:54 2026 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 B0BEC330661 for ; Wed, 7 Jan 2026 13:22:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767792157; cv=none; b=EcuygMyXZ1uPc9z59SSEYviduxKj/EFnR+xZjdehpCiRnxE3v5R6WpzuKx1Ru01WkHjYiwhTO+QNuRe9rAFQdvy49TRAGyfuWzCIKoUXSUSYM02juBJOWXWzVnNg0RKHhdkZkPzDNkSfFUg48upIX6xxeopPwtC3cWV44+aTiv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767792157; c=relaxed/simple; bh=xXffxQvzK07hZEuFa1ysfLfvbEICjMUXdPizVEPinUA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TOKiIEXROTINm6NkneDBv/RcNZFKgVj+ZJd0NnLZC6wa9dfXjDMQ5d5SHsrIvcgVoVR4Uu2b2v7a05abpj/Qvc2SdDc9OTIfr/kRHDmk3oRRcEZMXrE1iAsig4ymuQu/oGtjlGkLjmzFrdHMv/dbyYK8tN6A1MYtzjDc+8VmGTE= 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=EfBIHpwA; arc=none smtp.client-ip=209.85.214.169 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="EfBIHpwA" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2a0d67f1877so20341895ad.2 for ; Wed, 07 Jan 2026 05:22:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767792155; x=1768396955; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=eqap0FeAOULyYnI/LBiMZE3yIuHyBVsfjaQkrDWyRwY=; b=EfBIHpwA6hNRHXEyrVew6UgI6bIFjo/TK4MpytvSWf4dUaZjU2KKoGmlFPrt9hRuzq 34bE4Gdm0SDmybVWaL18ZUMG+xBJCU7FnxBNoC3DQS4tqkNBhGBVBNN7Nsvb1lJRG25Y OxVt+9Qx7U4KfeZ6XIKl+DsFKfWb0oldWoNipghQLkHgnSQl8OfpN26kjcuQvV2P4ZWx k5xY9yh0uTcjyq+LFFi+v4abuO+yLADeXMQYgIiLDI2PfkBFDb1/CGW9v3jnp6DXTZSE X99ArM/mlrxFt6wpNBI/3EeeI025h6gr+cxiT9/ez5wlDb3b9pkOEZY8LoCeajR5aam9 3jow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767792155; x=1768396955; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=eqap0FeAOULyYnI/LBiMZE3yIuHyBVsfjaQkrDWyRwY=; b=qUf54l3FGXm3Mqp2LO0k4kKLO34vz0JQCMES2HIub+239+3OcMl+OkU9K73hs4UQ2H m1JhUQ3nTnZqRpZ3IQ5cw9z1N+/H6kRv4Bxdo0IiO6cJ2LaqGlgyXbgEh2Sy+MfH01Mr 8ZUwfwLymxJ6d4+AWl+4n0buze7GKnNsEEaCGGkF5XHJfIRysRCDcUBAa6VeBixYfJwV P3hzW34h9fvSC+77dAdoPOnNp9lwCJrrUbSQw4MMz6XgmENc1YJs59zd9BjPMsbqzlyg bwlzmigDOtwxNb73S/YI/y30UlDXMfZAp1bVDsP6v3WlT8MTx6KAiSxDibXW7EuCLM+2 NEew== X-Forwarded-Encrypted: i=1; AJvYcCVnaPZftYQvXipKxBef0SHK68hrGylrZnirtSs7EJ4CKZcbpdkXtP58rQWVku7TFYP+N5SyGXSXRP+bxDk=@vger.kernel.org X-Gm-Message-State: AOJu0YzAk7CFbLd+fyKM2LEemsHd64WZeyXPzLArTy6PjATJJjul3Hfg QOkUKgbp7JEH+EuTKE0pHjatPHhtum0eeXgRD948AwIZ9CDWv1VOp1At X-Gm-Gg: AY/fxX5FR9gnEUhGLrWzQ3SAPlkN68CtVY/l0DDN7f23C2AxkBxCzN9gQU0O+rxRKNk chygx91Put6hZKPi9XRCScxAy0zhSZVRFl6EMLs9OUxR1o6tiyKQVpoo3OkJPplZtbvvHpTsHDm S2enMPamzWoxM4XUu3acxr9E64K39EJvyPZWnFVzzePaU6MC+PAAqT7RArvhUgUQZflUz/+l1Zo l1LSR0UaX/HHwfoI7hoUgBEiPQOh8QbeKaO5eSyVcAwDpJcQXlCD9IN3AEuEmeEO2Z7lw2GRavl ggB+y8SfBD7U0n/AiclkTxt/YjaDiwXh8kLxs8zv/hP8LYdqTTTQaR9le4jRk+NK00zFc64acan eFV82PMM8gGTohoc5VBriI5Xa/QAkA8beHOQ3fSbWlL8Zy/LTw27Cn7S4jQ9XSoC1JnuJavJFep x86QZdut4jX6s= X-Google-Smtp-Source: AGHT+IF8Z1XvPvEU9JH+6nhbgTh4mdDGv3c2qONLwulOVFY8IweNdpleopMfrZyDj6NNn080mcCIAA== X-Received: by 2002:a17:903:384d:b0:2a0:ea4c:51f3 with SMTP id d9443c01a7336-2a3ee4332aemr25418905ad.6.1767792154338; Wed, 07 Jan 2026 05:22:34 -0800 (PST) Received: from [127.0.0.1] ([188.253.121.152]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a3e3cc7912sm52511685ad.67.2026.01.07.05.22.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 05:22:33 -0800 (PST) From: Zesen Liu Date: Wed, 07 Jan 2026 21:21:42 +0800 Subject: [PATCH bpf v2 1/2] bpf: Fix memory access flags in helper prototypes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260107-helper_proto-v2-1-4c562bcca5a8@gmail.com> References: <20260107-helper_proto-v2-0-4c562bcca5a8@gmail.com> In-Reply-To: <20260107-helper_proto-v2-0-4c562bcca5a8@gmail.com> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Matt Bobrowski , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Daniel Xu Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, Shuran Liu , Peili Gao , Haoran Ni , Zesen Liu X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6857; i=ftyghome@gmail.com; h=from:subject:message-id; bh=xXffxQvzK07hZEuFa1ysfLfvbEICjMUXdPizVEPinUA=; b=owGbwMvMwCXWI1/u+8bXqJ3xtFoSQ2ZcHGeVyc4r2Y929ex7/c9jTtyy191dc5b1bmxQnlda4 yF10uRVRykLgxgXg6yYIkvvD8O7KzPNjbfZLDgIM4eVCWQIAxenAEzk6VdGhjNXWWekyVexd8a1 2ZYfan+x6lcW4x2zfltty4a4p9b3MhkZbviz7/q7WeDvmbMH0pftqdlaWr9mi5HTaucqI40JmmJ uHAA= X-Developer-Key: i=ftyghome@gmail.com; a=openpgp; fpr=8DF831DDA9693733B63CA0C18C1F774DEC4D3287 After commit 37cce22dbd51 ("bpf: verifier: Refactor helper access type trac= king"), the verifier started relying on the access type flags in helper function prototypes to perform memory access optimizations. Currently, several helper functions utilizing ARG_PTR_TO_MEM lack the corresponding MEM_RDONLY or MEM_WRITE flags. This omission causes the verifier to incorrectly assume that the buffer contents are unchanged across the helper call. Consequently, the verifier may optimize away subsequent reads based on this wrong assumption, leading to correctness issues. For bpf_get_stack_proto_raw_tp, the original MEM_RDONLY was incorrect since the helper writes to the buffer. Change it to ARG_PTR_TO_UNINIT_MEM which correctly indicates write access to potentially uninitialized memory. Similar issues were recently addressed for specific helpers in commit ac44dcc788b9 ("bpf: Fix verifier assumptions of bpf_d_path's output buffer") and commit 2eb7648558a7 ("bpf: Specify access type of bpf_sysctl_get_name a= rgs"). Fix these prototypes by adding the correct memory access flags. Fixes: 37cce22dbd51 ("bpf: verifier: Refactor helper access type tracking") Co-developed-by: Shuran Liu Signed-off-by: Shuran Liu Co-developed-by: Peili Gao Signed-off-by: Peili Gao Co-developed-by: Haoran Ni Signed-off-by: Haoran Ni Signed-off-by: Zesen Liu --- kernel/bpf/helpers.c | 2 +- kernel/bpf/syscall.c | 2 +- kernel/trace/bpf_trace.c | 6 +++--- net/core/filter.c | 20 ++++++++++---------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index db72b96f9c8c..f66284f8ec2c 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -1077,7 +1077,7 @@ const struct bpf_func_proto bpf_snprintf_proto =3D { .func =3D bpf_snprintf, .gpl_only =3D true, .ret_type =3D RET_INTEGER, - .arg1_type =3D ARG_PTR_TO_MEM_OR_NULL, + .arg1_type =3D ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE, .arg2_type =3D ARG_CONST_SIZE_OR_ZERO, .arg3_type =3D ARG_PTR_TO_CONST_STR, .arg4_type =3D ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY, diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 4ff82144f885..ee116a3b7baf 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -6407,7 +6407,7 @@ static const struct bpf_func_proto bpf_kallsyms_looku= p_name_proto =3D { .func =3D bpf_kallsyms_lookup_name, .gpl_only =3D false, .ret_type =3D RET_INTEGER, - .arg1_type =3D ARG_PTR_TO_MEM, + .arg1_type =3D ARG_PTR_TO_MEM | MEM_RDONLY, .arg2_type =3D ARG_CONST_SIZE_OR_ZERO, .arg3_type =3D ARG_ANYTHING, .arg4_type =3D ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_WRITE | MEM_A= LIGNED, diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index fe28d86f7c35..59c2394981c7 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1022,7 +1022,7 @@ const struct bpf_func_proto bpf_snprintf_btf_proto = =3D { .func =3D bpf_snprintf_btf, .gpl_only =3D false, .ret_type =3D RET_INTEGER, - .arg1_type =3D ARG_PTR_TO_MEM, + .arg1_type =3D ARG_PTR_TO_MEM | MEM_WRITE, .arg2_type =3D ARG_CONST_SIZE, .arg3_type =3D ARG_PTR_TO_MEM | MEM_RDONLY, .arg4_type =3D ARG_CONST_SIZE, @@ -1526,7 +1526,7 @@ static const struct bpf_func_proto bpf_read_branch_re= cords_proto =3D { .gpl_only =3D true, .ret_type =3D RET_INTEGER, .arg1_type =3D ARG_PTR_TO_CTX, - .arg2_type =3D ARG_PTR_TO_MEM_OR_NULL, + .arg2_type =3D ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE, .arg3_type =3D ARG_CONST_SIZE_OR_ZERO, .arg4_type =3D ARG_ANYTHING, }; @@ -1661,7 +1661,7 @@ static const struct bpf_func_proto bpf_get_stack_prot= o_raw_tp =3D { .gpl_only =3D true, .ret_type =3D RET_INTEGER, .arg1_type =3D ARG_PTR_TO_CTX, - .arg2_type =3D ARG_PTR_TO_MEM | MEM_RDONLY, + .arg2_type =3D ARG_PTR_TO_UNINIT_MEM, .arg3_type =3D ARG_CONST_SIZE_OR_ZERO, .arg4_type =3D ARG_ANYTHING, }; diff --git a/net/core/filter.c b/net/core/filter.c index 616e0520a0bb..18174e0d3fcf 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -6399,7 +6399,7 @@ static const struct bpf_func_proto bpf_xdp_fib_lookup= _proto =3D { .gpl_only =3D true, .ret_type =3D RET_INTEGER, .arg1_type =3D ARG_PTR_TO_CTX, - .arg2_type =3D ARG_PTR_TO_MEM, + .arg2_type =3D ARG_PTR_TO_MEM | MEM_WRITE, .arg3_type =3D ARG_CONST_SIZE, .arg4_type =3D ARG_ANYTHING, }; @@ -6454,7 +6454,7 @@ static const struct bpf_func_proto bpf_skb_fib_lookup= _proto =3D { .gpl_only =3D true, .ret_type =3D RET_INTEGER, .arg1_type =3D ARG_PTR_TO_CTX, - .arg2_type =3D ARG_PTR_TO_MEM, + .arg2_type =3D ARG_PTR_TO_MEM | MEM_WRITE, .arg3_type =3D ARG_CONST_SIZE, .arg4_type =3D ARG_ANYTHING, }; @@ -8008,9 +8008,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_sy= ncookie_ipv4_proto =3D { .gpl_only =3D true, /* __cookie_v4_init_sequence() is GPL */ .pkt_access =3D true, .ret_type =3D RET_INTEGER, - .arg1_type =3D ARG_PTR_TO_FIXED_SIZE_MEM, + .arg1_type =3D ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY, .arg1_size =3D sizeof(struct iphdr), - .arg2_type =3D ARG_PTR_TO_MEM, + .arg2_type =3D ARG_PTR_TO_MEM | MEM_RDONLY, .arg3_type =3D ARG_CONST_SIZE_OR_ZERO, }; =20 @@ -8040,9 +8040,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_sy= ncookie_ipv6_proto =3D { .gpl_only =3D true, /* __cookie_v6_init_sequence() is GPL */ .pkt_access =3D true, .ret_type =3D RET_INTEGER, - .arg1_type =3D ARG_PTR_TO_FIXED_SIZE_MEM, + .arg1_type =3D ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY, .arg1_size =3D sizeof(struct ipv6hdr), - .arg2_type =3D ARG_PTR_TO_MEM, + .arg2_type =3D ARG_PTR_TO_MEM | MEM_RDONLY, .arg3_type =3D ARG_CONST_SIZE_OR_ZERO, }; =20 @@ -8060,9 +8060,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_= syncookie_ipv4_proto =3D { .gpl_only =3D true, /* __cookie_v4_check is GPL */ .pkt_access =3D true, .ret_type =3D RET_INTEGER, - .arg1_type =3D ARG_PTR_TO_FIXED_SIZE_MEM, + .arg1_type =3D ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY, .arg1_size =3D sizeof(struct iphdr), - .arg2_type =3D ARG_PTR_TO_FIXED_SIZE_MEM, + .arg2_type =3D ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY, .arg2_size =3D sizeof(struct tcphdr), }; =20 @@ -8084,9 +8084,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_= syncookie_ipv6_proto =3D { .gpl_only =3D true, /* __cookie_v6_check is GPL */ .pkt_access =3D true, .ret_type =3D RET_INTEGER, - .arg1_type =3D ARG_PTR_TO_FIXED_SIZE_MEM, + .arg1_type =3D ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY, .arg1_size =3D sizeof(struct ipv6hdr), - .arg2_type =3D ARG_PTR_TO_FIXED_SIZE_MEM, + .arg2_type =3D ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY, .arg2_size =3D sizeof(struct tcphdr), }; #endif /* CONFIG_SYN_COOKIES */ --=20 2.43.0