VYPR
Unrated severityNVD Advisory· Published May 27, 2026· Updated May 27, 2026

CVE-2026-45903

CVE-2026-45903

Description

In the Linux kernel, the following vulnerability has been resolved:

bpf: Fix memory access flags in helper prototypes

After commit 37cce22dbd51 ("bpf: verifier: Refactor helper access type tracking"), 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 args").

Fix these prototypes by adding the correct memory access flags.

Affected products

1

Patches

6
fdfe75161f6e

bpf: Fix memory access flags in helper prototypes

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.gitZesen LiuJan 20, 2026Fixed in 6.18.14via kernel-cna
8 files changed · +30 32
  • kernel/bpf/helpers.c+1 1 modified
    diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
    index 81ef159ef89bd3..68da6dcfb4bb7c 100644
    --- a/kernel/bpf/helpers.c
    +++ b/kernel/bpf/helpers.c
    @@ -1080,7 +1080,7 @@ const struct bpf_func_proto bpf_snprintf_proto = {
     	.func		= bpf_snprintf,
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL,
    +	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_PTR_TO_CONST_STR,
     	.arg4_type	= ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY,
    
  • kernel/bpf/helpers.c+1 1 modified
    diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
    index 81ef159ef89bd3..68da6dcfb4bb7c 100644
    --- a/kernel/bpf/helpers.c
    +++ b/kernel/bpf/helpers.c
    @@ -1080,7 +1080,7 @@ const struct bpf_func_proto bpf_snprintf_proto = {
     	.func		= bpf_snprintf,
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL,
    +	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_PTR_TO_CONST_STR,
     	.arg4_type	= ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY,
    
  • kernel/bpf/syscall.c+1 1 modified
    diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
    index df219e72590997..e9cf69594824c2 100644
    --- a/kernel/bpf/syscall.c
    +++ b/kernel/bpf/syscall.c
    @@ -6396,7 +6396,7 @@ static const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {
     	.func		= bpf_kallsyms_lookup_name,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_ANYTHING,
     	.arg4_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_WRITE | MEM_ALIGNED,
    
  • kernel/bpf/syscall.c+1 1 modified
    diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
    index df219e72590997..e9cf69594824c2 100644
    --- a/kernel/bpf/syscall.c
    +++ b/kernel/bpf/syscall.c
    @@ -6396,7 +6396,7 @@ static const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {
     	.func		= bpf_kallsyms_lookup_name,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_ANYTHING,
     	.arg4_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_WRITE | MEM_ALIGNED,
    
  • kernel/trace/bpf_trace.c+3 3 modified
    diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
    index 49e0bdaa7a1bf1..e7f1fe44352afe 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 = {
     	.func		= bpf_snprintf_btf,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE,
     	.arg3_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg4_type	= ARG_CONST_SIZE,
    @@ -1526,7 +1526,7 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = {
     	.gpl_only       = true,
     	.ret_type       = RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL,
    +	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type      = ARG_ANYTHING,
     };
    @@ -1661,7 +1661,7 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type	= ARG_PTR_TO_CTX,
    -	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
    +	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type	= ARG_ANYTHING,
     };
    
  • kernel/trace/bpf_trace.c+3 3 modified
    diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
    index 49e0bdaa7a1bf1..e7f1fe44352afe 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 = {
     	.func		= bpf_snprintf_btf,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE,
     	.arg3_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg4_type	= ARG_CONST_SIZE,
    @@ -1526,7 +1526,7 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = {
     	.gpl_only       = true,
     	.ret_type       = RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL,
    +	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type      = ARG_ANYTHING,
     };
    @@ -1661,7 +1661,7 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type	= ARG_PTR_TO_CTX,
    -	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
    +	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type	= ARG_ANYTHING,
     };
    
  • net/core/filter.c+10 11 modified
    diff --git a/net/core/filter.c b/net/core/filter.c
    index 88b265f6ccf897..b9a51f322b655d 100644
    --- a/net/core/filter.c
    +++ b/net/core/filter.c
    @@ -6325,7 +6325,7 @@ static const struct bpf_func_proto bpf_xdp_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -6380,7 +6380,7 @@ static const struct bpf_func_proto bpf_skb_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -7934,9 +7934,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -7966,9 +7966,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -7986,9 +7986,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     
    @@ -8010,9 +8010,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     #endif /* CONFIG_SYN_COOKIES */
    -- 
    cgit 1.3-korg
    
    
    
  • net/core/filter.c+10 11 modified
    diff --git a/net/core/filter.c b/net/core/filter.c
    index 88b265f6ccf897..b9a51f322b655d 100644
    --- a/net/core/filter.c
    +++ b/net/core/filter.c
    @@ -6325,7 +6325,7 @@ static const struct bpf_func_proto bpf_xdp_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -6380,7 +6380,7 @@ static const struct bpf_func_proto bpf_skb_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -7934,9 +7934,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -7966,9 +7966,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -7986,9 +7986,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     
    @@ -8010,9 +8010,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     #endif /* CONFIG_SYN_COOKIES */
    -- 
    cgit 1.3-korg
    
    
    
aa3195928920

bpf: Fix memory access flags in helper prototypes

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.gitZesen LiuJan 20, 2026Fixed in 6.19.4via kernel-cna
8 files changed · +30 32
  • kernel/bpf/helpers.c+1 1 modified
    diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
    index db72b96f9c8c85..f66284f8ec2cc9 100644
    --- a/kernel/bpf/helpers.c
    +++ b/kernel/bpf/helpers.c
    @@ -1077,7 +1077,7 @@ const struct bpf_func_proto bpf_snprintf_proto = {
     	.func		= bpf_snprintf,
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL,
    +	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_PTR_TO_CONST_STR,
     	.arg4_type	= ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY,
    
  • kernel/bpf/helpers.c+1 1 modified
    diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
    index db72b96f9c8c85..f66284f8ec2cc9 100644
    --- a/kernel/bpf/helpers.c
    +++ b/kernel/bpf/helpers.c
    @@ -1077,7 +1077,7 @@ const struct bpf_func_proto bpf_snprintf_proto = {
     	.func		= bpf_snprintf,
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL,
    +	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_PTR_TO_CONST_STR,
     	.arg4_type	= ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY,
    
  • kernel/bpf/syscall.c+1 1 modified
    diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
    index 4ff82144f8853d..ee116a3b7baf7d 100644
    --- a/kernel/bpf/syscall.c
    +++ b/kernel/bpf/syscall.c
    @@ -6407,7 +6407,7 @@ static const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {
     	.func		= bpf_kallsyms_lookup_name,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_ANYTHING,
     	.arg4_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_WRITE | MEM_ALIGNED,
    
  • kernel/bpf/syscall.c+1 1 modified
    diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
    index 4ff82144f8853d..ee116a3b7baf7d 100644
    --- a/kernel/bpf/syscall.c
    +++ b/kernel/bpf/syscall.c
    @@ -6407,7 +6407,7 @@ static const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {
     	.func		= bpf_kallsyms_lookup_name,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_ANYTHING,
     	.arg4_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_WRITE | MEM_ALIGNED,
    
  • kernel/trace/bpf_trace.c+3 3 modified
    diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
    index fe28d86f7c3576..59c2394981c721 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 = {
     	.func		= bpf_snprintf_btf,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE,
     	.arg3_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg4_type	= ARG_CONST_SIZE,
    @@ -1526,7 +1526,7 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = {
     	.gpl_only       = true,
     	.ret_type       = RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL,
    +	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type      = ARG_ANYTHING,
     };
    @@ -1661,7 +1661,7 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type	= ARG_PTR_TO_CTX,
    -	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
    +	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type	= ARG_ANYTHING,
     };
    
  • kernel/trace/bpf_trace.c+3 3 modified
    diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
    index fe28d86f7c3576..59c2394981c721 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 = {
     	.func		= bpf_snprintf_btf,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE,
     	.arg3_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg4_type	= ARG_CONST_SIZE,
    @@ -1526,7 +1526,7 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = {
     	.gpl_only       = true,
     	.ret_type       = RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL,
    +	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type      = ARG_ANYTHING,
     };
    @@ -1661,7 +1661,7 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type	= ARG_PTR_TO_CTX,
    -	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
    +	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type	= ARG_ANYTHING,
     };
    
  • net/core/filter.c+10 11 modified
    diff --git a/net/core/filter.c b/net/core/filter.c
    index 029e560e32ce3e..b1f8e2930e1c43 100644
    --- a/net/core/filter.c
    +++ b/net/core/filter.c
    @@ -6401,7 +6401,7 @@ static const struct bpf_func_proto bpf_xdp_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -6456,7 +6456,7 @@ static const struct bpf_func_proto bpf_skb_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -8010,9 +8010,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8042,9 +8042,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8062,9 +8062,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     
    @@ -8086,9 +8086,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     #endif /* CONFIG_SYN_COOKIES */
    -- 
    cgit 1.3-korg
    
    
    
  • net/core/filter.c+10 11 modified
    diff --git a/net/core/filter.c b/net/core/filter.c
    index 029e560e32ce3e..b1f8e2930e1c43 100644
    --- a/net/core/filter.c
    +++ b/net/core/filter.c
    @@ -6401,7 +6401,7 @@ static const struct bpf_func_proto bpf_xdp_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -6456,7 +6456,7 @@ static const struct bpf_func_proto bpf_skb_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -8010,9 +8010,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8042,9 +8042,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8062,9 +8062,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     
    @@ -8086,9 +8086,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     #endif /* CONFIG_SYN_COOKIES */
    -- 
    cgit 1.3-korg
    
    
    
802eef5afb18

bpf: Fix memory access flags in helper prototypes

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.gitZesen LiuJan 20, 2026Fixed in 7.0via kernel-cna
8 files changed · +30 32
  • kernel/bpf/helpers.c+1 1 modified
    diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
    index f8aa1320e2f7cc..4d1af703cfcb28 100644
    --- a/kernel/bpf/helpers.c
    +++ b/kernel/bpf/helpers.c
    @@ -1077,7 +1077,7 @@ const struct bpf_func_proto bpf_snprintf_proto = {
     	.func		= bpf_snprintf,
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL,
    +	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_PTR_TO_CONST_STR,
     	.arg4_type	= ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY,
    
  • kernel/bpf/helpers.c+1 1 modified
    diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
    index f8aa1320e2f7cc..4d1af703cfcb28 100644
    --- a/kernel/bpf/helpers.c
    +++ b/kernel/bpf/helpers.c
    @@ -1077,7 +1077,7 @@ const struct bpf_func_proto bpf_snprintf_proto = {
     	.func		= bpf_snprintf,
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL,
    +	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_PTR_TO_CONST_STR,
     	.arg4_type	= ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY,
    
  • kernel/bpf/syscall.c+1 1 modified
    diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
    index ecc0929ce46293..3c5c03d43f5f74 100644
    --- a/kernel/bpf/syscall.c
    +++ b/kernel/bpf/syscall.c
    @@ -6451,7 +6451,7 @@ static const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {
     	.func		= bpf_kallsyms_lookup_name,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_ANYTHING,
     	.arg4_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_WRITE | MEM_ALIGNED,
    
  • kernel/bpf/syscall.c+1 1 modified
    diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
    index ecc0929ce46293..3c5c03d43f5f74 100644
    --- a/kernel/bpf/syscall.c
    +++ b/kernel/bpf/syscall.c
    @@ -6451,7 +6451,7 @@ static const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {
     	.func		= bpf_kallsyms_lookup_name,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_ANYTHING,
     	.arg4_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_WRITE | MEM_ALIGNED,
    
  • kernel/trace/bpf_trace.c+3 3 modified
    diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
    index f73e08c223b5b3..bd15ff62490b01 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 = {
     	.func		= bpf_snprintf_btf,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE,
     	.arg3_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg4_type	= ARG_CONST_SIZE,
    @@ -1526,7 +1526,7 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = {
     	.gpl_only       = true,
     	.ret_type       = RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL,
    +	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type      = ARG_ANYTHING,
     };
    @@ -1661,7 +1661,7 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type	= ARG_PTR_TO_CTX,
    -	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
    +	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type	= ARG_ANYTHING,
     };
    
  • kernel/trace/bpf_trace.c+3 3 modified
    diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
    index f73e08c223b5b3..bd15ff62490b01 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 = {
     	.func		= bpf_snprintf_btf,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE,
     	.arg3_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg4_type	= ARG_CONST_SIZE,
    @@ -1526,7 +1526,7 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = {
     	.gpl_only       = true,
     	.ret_type       = RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL,
    +	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type      = ARG_ANYTHING,
     };
    @@ -1661,7 +1661,7 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type	= ARG_PTR_TO_CTX,
    -	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
    +	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type	= ARG_ANYTHING,
     };
    
  • net/core/filter.c+10 11 modified
    diff --git a/net/core/filter.c b/net/core/filter.c
    index d43df98e1deda1..d14401193b01d0 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 = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -6454,7 +6454,7 @@ static const struct bpf_func_proto bpf_skb_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -8008,9 +8008,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8040,9 +8040,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8060,9 +8060,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     
    @@ -8084,9 +8084,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     #endif /* CONFIG_SYN_COOKIES */
    -- 
    cgit 1.3-korg
    
    
    
  • net/core/filter.c+10 11 modified
    diff --git a/net/core/filter.c b/net/core/filter.c
    index d43df98e1deda1..d14401193b01d0 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 = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -6454,7 +6454,7 @@ static const struct bpf_func_proto bpf_skb_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -8008,9 +8008,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8040,9 +8040,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8060,9 +8060,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     
    @@ -8084,9 +8084,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     #endif /* CONFIG_SYN_COOKIES */
    -- 
    cgit 1.3-korg
    
    
    
802eef5afb18

bpf: Fix memory access flags in helper prototypes

8 files changed · +30 32
  • kernel/bpf/helpers.c+1 1 modified
    diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
    index f8aa1320e2f7cc..4d1af703cfcb28 100644
    --- a/kernel/bpf/helpers.c
    +++ b/kernel/bpf/helpers.c
    @@ -1077,7 +1077,7 @@ const struct bpf_func_proto bpf_snprintf_proto = {
     	.func		= bpf_snprintf,
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL,
    +	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_PTR_TO_CONST_STR,
     	.arg4_type	= ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY,
    
  • kernel/bpf/helpers.c+1 1 modified
    diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
    index f8aa1320e2f7cc..4d1af703cfcb28 100644
    --- a/kernel/bpf/helpers.c
    +++ b/kernel/bpf/helpers.c
    @@ -1077,7 +1077,7 @@ const struct bpf_func_proto bpf_snprintf_proto = {
     	.func		= bpf_snprintf,
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL,
    +	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_PTR_TO_CONST_STR,
     	.arg4_type	= ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY,
    
  • kernel/bpf/syscall.c+1 1 modified
    diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
    index ecc0929ce46293..3c5c03d43f5f74 100644
    --- a/kernel/bpf/syscall.c
    +++ b/kernel/bpf/syscall.c
    @@ -6451,7 +6451,7 @@ static const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {
     	.func		= bpf_kallsyms_lookup_name,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_ANYTHING,
     	.arg4_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_WRITE | MEM_ALIGNED,
    
  • kernel/bpf/syscall.c+1 1 modified
    diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
    index ecc0929ce46293..3c5c03d43f5f74 100644
    --- a/kernel/bpf/syscall.c
    +++ b/kernel/bpf/syscall.c
    @@ -6451,7 +6451,7 @@ static const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {
     	.func		= bpf_kallsyms_lookup_name,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_ANYTHING,
     	.arg4_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_WRITE | MEM_ALIGNED,
    
  • kernel/trace/bpf_trace.c+3 3 modified
    diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
    index f73e08c223b5b3..bd15ff62490b01 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 = {
     	.func		= bpf_snprintf_btf,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE,
     	.arg3_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg4_type	= ARG_CONST_SIZE,
    @@ -1526,7 +1526,7 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = {
     	.gpl_only       = true,
     	.ret_type       = RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL,
    +	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type      = ARG_ANYTHING,
     };
    @@ -1661,7 +1661,7 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type	= ARG_PTR_TO_CTX,
    -	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
    +	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type	= ARG_ANYTHING,
     };
    
  • kernel/trace/bpf_trace.c+3 3 modified
    diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
    index f73e08c223b5b3..bd15ff62490b01 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 = {
     	.func		= bpf_snprintf_btf,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE,
     	.arg3_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg4_type	= ARG_CONST_SIZE,
    @@ -1526,7 +1526,7 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = {
     	.gpl_only       = true,
     	.ret_type       = RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL,
    +	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type      = ARG_ANYTHING,
     };
    @@ -1661,7 +1661,7 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type	= ARG_PTR_TO_CTX,
    -	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
    +	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type	= ARG_ANYTHING,
     };
    
  • net/core/filter.c+10 11 modified
    diff --git a/net/core/filter.c b/net/core/filter.c
    index d43df98e1deda1..d14401193b01d0 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 = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -6454,7 +6454,7 @@ static const struct bpf_func_proto bpf_skb_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -8008,9 +8008,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8040,9 +8040,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8060,9 +8060,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     
    @@ -8084,9 +8084,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     #endif /* CONFIG_SYN_COOKIES */
    -- 
    cgit 1.3-korg
    
    
    
  • net/core/filter.c+10 11 modified
    diff --git a/net/core/filter.c b/net/core/filter.c
    index d43df98e1deda1..d14401193b01d0 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 = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -6454,7 +6454,7 @@ static const struct bpf_func_proto bpf_skb_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -8008,9 +8008,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8040,9 +8040,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8060,9 +8060,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     
    @@ -8084,9 +8084,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     #endif /* CONFIG_SYN_COOKIES */
    -- 
    cgit 1.3-korg
    
    
    
aa3195928920

bpf: Fix memory access flags in helper prototypes

8 files changed · +30 32
  • kernel/bpf/helpers.c+1 1 modified
    diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
    index db72b96f9c8c85..f66284f8ec2cc9 100644
    --- a/kernel/bpf/helpers.c
    +++ b/kernel/bpf/helpers.c
    @@ -1077,7 +1077,7 @@ const struct bpf_func_proto bpf_snprintf_proto = {
     	.func		= bpf_snprintf,
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL,
    +	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_PTR_TO_CONST_STR,
     	.arg4_type	= ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY,
    
  • kernel/bpf/helpers.c+1 1 modified
    diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
    index db72b96f9c8c85..f66284f8ec2cc9 100644
    --- a/kernel/bpf/helpers.c
    +++ b/kernel/bpf/helpers.c
    @@ -1077,7 +1077,7 @@ const struct bpf_func_proto bpf_snprintf_proto = {
     	.func		= bpf_snprintf,
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL,
    +	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_PTR_TO_CONST_STR,
     	.arg4_type	= ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY,
    
  • kernel/bpf/syscall.c+1 1 modified
    diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
    index 4ff82144f8853d..ee116a3b7baf7d 100644
    --- a/kernel/bpf/syscall.c
    +++ b/kernel/bpf/syscall.c
    @@ -6407,7 +6407,7 @@ static const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {
     	.func		= bpf_kallsyms_lookup_name,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_ANYTHING,
     	.arg4_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_WRITE | MEM_ALIGNED,
    
  • kernel/bpf/syscall.c+1 1 modified
    diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
    index 4ff82144f8853d..ee116a3b7baf7d 100644
    --- a/kernel/bpf/syscall.c
    +++ b/kernel/bpf/syscall.c
    @@ -6407,7 +6407,7 @@ static const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {
     	.func		= bpf_kallsyms_lookup_name,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_ANYTHING,
     	.arg4_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_WRITE | MEM_ALIGNED,
    
  • kernel/trace/bpf_trace.c+3 3 modified
    diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
    index fe28d86f7c3576..59c2394981c721 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 = {
     	.func		= bpf_snprintf_btf,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE,
     	.arg3_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg4_type	= ARG_CONST_SIZE,
    @@ -1526,7 +1526,7 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = {
     	.gpl_only       = true,
     	.ret_type       = RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL,
    +	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type      = ARG_ANYTHING,
     };
    @@ -1661,7 +1661,7 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type	= ARG_PTR_TO_CTX,
    -	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
    +	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type	= ARG_ANYTHING,
     };
    
  • kernel/trace/bpf_trace.c+3 3 modified
    diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
    index fe28d86f7c3576..59c2394981c721 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 = {
     	.func		= bpf_snprintf_btf,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE,
     	.arg3_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg4_type	= ARG_CONST_SIZE,
    @@ -1526,7 +1526,7 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = {
     	.gpl_only       = true,
     	.ret_type       = RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL,
    +	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type      = ARG_ANYTHING,
     };
    @@ -1661,7 +1661,7 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type	= ARG_PTR_TO_CTX,
    -	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
    +	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type	= ARG_ANYTHING,
     };
    
  • net/core/filter.c+10 11 modified
    diff --git a/net/core/filter.c b/net/core/filter.c
    index 029e560e32ce3e..b1f8e2930e1c43 100644
    --- a/net/core/filter.c
    +++ b/net/core/filter.c
    @@ -6401,7 +6401,7 @@ static const struct bpf_func_proto bpf_xdp_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -6456,7 +6456,7 @@ static const struct bpf_func_proto bpf_skb_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -8010,9 +8010,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8042,9 +8042,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8062,9 +8062,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     
    @@ -8086,9 +8086,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     #endif /* CONFIG_SYN_COOKIES */
    -- 
    cgit 1.3-korg
    
    
    
  • net/core/filter.c+10 11 modified
    diff --git a/net/core/filter.c b/net/core/filter.c
    index 029e560e32ce3e..b1f8e2930e1c43 100644
    --- a/net/core/filter.c
    +++ b/net/core/filter.c
    @@ -6401,7 +6401,7 @@ static const struct bpf_func_proto bpf_xdp_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -6456,7 +6456,7 @@ static const struct bpf_func_proto bpf_skb_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -8010,9 +8010,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8042,9 +8042,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -8062,9 +8062,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     
    @@ -8086,9 +8086,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     #endif /* CONFIG_SYN_COOKIES */
    -- 
    cgit 1.3-korg
    
    
    
fdfe75161f6e

bpf: Fix memory access flags in helper prototypes

8 files changed · +30 32
  • kernel/bpf/helpers.c+1 1 modified
    diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
    index 81ef159ef89bd3..68da6dcfb4bb7c 100644
    --- a/kernel/bpf/helpers.c
    +++ b/kernel/bpf/helpers.c
    @@ -1080,7 +1080,7 @@ const struct bpf_func_proto bpf_snprintf_proto = {
     	.func		= bpf_snprintf,
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL,
    +	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_PTR_TO_CONST_STR,
     	.arg4_type	= ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY,
    
  • kernel/bpf/helpers.c+1 1 modified
    diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
    index 81ef159ef89bd3..68da6dcfb4bb7c 100644
    --- a/kernel/bpf/helpers.c
    +++ b/kernel/bpf/helpers.c
    @@ -1080,7 +1080,7 @@ const struct bpf_func_proto bpf_snprintf_proto = {
     	.func		= bpf_snprintf,
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL,
    +	.arg1_type	= ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_PTR_TO_CONST_STR,
     	.arg4_type	= ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY,
    
  • kernel/bpf/syscall.c+1 1 modified
    diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
    index df219e72590997..e9cf69594824c2 100644
    --- a/kernel/bpf/syscall.c
    +++ b/kernel/bpf/syscall.c
    @@ -6396,7 +6396,7 @@ static const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {
     	.func		= bpf_kallsyms_lookup_name,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_ANYTHING,
     	.arg4_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_WRITE | MEM_ALIGNED,
    
  • kernel/bpf/syscall.c+1 1 modified
    diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
    index df219e72590997..e9cf69594824c2 100644
    --- a/kernel/bpf/syscall.c
    +++ b/kernel/bpf/syscall.c
    @@ -6396,7 +6396,7 @@ static const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {
     	.func		= bpf_kallsyms_lookup_name,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg2_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg3_type	= ARG_ANYTHING,
     	.arg4_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_WRITE | MEM_ALIGNED,
    
  • kernel/trace/bpf_trace.c+3 3 modified
    diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
    index 49e0bdaa7a1bf1..e7f1fe44352afe 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 = {
     	.func		= bpf_snprintf_btf,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE,
     	.arg3_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg4_type	= ARG_CONST_SIZE,
    @@ -1526,7 +1526,7 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = {
     	.gpl_only       = true,
     	.ret_type       = RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL,
    +	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type      = ARG_ANYTHING,
     };
    @@ -1661,7 +1661,7 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type	= ARG_PTR_TO_CTX,
    -	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
    +	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type	= ARG_ANYTHING,
     };
    
  • kernel/trace/bpf_trace.c+3 3 modified
    diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
    index 49e0bdaa7a1bf1..e7f1fe44352afe 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 = {
     	.func		= bpf_snprintf_btf,
     	.gpl_only	= false,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_MEM,
    +	.arg1_type	= ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg2_type	= ARG_CONST_SIZE,
     	.arg3_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg4_type	= ARG_CONST_SIZE,
    @@ -1526,7 +1526,7 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = {
     	.gpl_only       = true,
     	.ret_type       = RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL,
    +	.arg2_type      = ARG_PTR_TO_MEM_OR_NULL | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type      = ARG_ANYTHING,
     };
    @@ -1661,7 +1661,7 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type	= ARG_PTR_TO_CTX,
    -	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
    +	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     	.arg4_type	= ARG_ANYTHING,
     };
    
  • net/core/filter.c+10 11 modified
    diff --git a/net/core/filter.c b/net/core/filter.c
    index 88b265f6ccf897..b9a51f322b655d 100644
    --- a/net/core/filter.c
    +++ b/net/core/filter.c
    @@ -6325,7 +6325,7 @@ static const struct bpf_func_proto bpf_xdp_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -6380,7 +6380,7 @@ static const struct bpf_func_proto bpf_skb_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -7934,9 +7934,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -7966,9 +7966,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -7986,9 +7986,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     
    @@ -8010,9 +8010,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     #endif /* CONFIG_SYN_COOKIES */
    -- 
    cgit 1.3-korg
    
    
    
  • net/core/filter.c+10 11 modified
    diff --git a/net/core/filter.c b/net/core/filter.c
    index 88b265f6ccf897..b9a51f322b655d 100644
    --- a/net/core/filter.c
    +++ b/net/core/filter.c
    @@ -6325,7 +6325,7 @@ static const struct bpf_func_proto bpf_xdp_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -6380,7 +6380,7 @@ static const struct bpf_func_proto bpf_skb_fib_lookup_proto = {
     	.gpl_only	= true,
     	.ret_type	= RET_INTEGER,
     	.arg1_type      = ARG_PTR_TO_CTX,
    -	.arg2_type      = ARG_PTR_TO_MEM,
    +	.arg2_type      = ARG_PTR_TO_MEM | MEM_WRITE,
     	.arg3_type      = ARG_CONST_SIZE,
     	.arg4_type	= ARG_ANYTHING,
     };
    @@ -7934,9 +7934,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -7966,9 +7966,9 @@ static const struct bpf_func_proto bpf_tcp_raw_gen_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_init_sequence() is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_MEM,
    +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
     	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
     };
     
    @@ -7986,9 +7986,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv4_proto = {
     	.gpl_only	= true, /* __cookie_v4_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct iphdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     
    @@ -8010,9 +8010,9 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv6_proto = {
     	.gpl_only	= true, /* __cookie_v6_check is GPL */
     	.pkt_access	= true,
     	.ret_type	= RET_INTEGER,
    -	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg1_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg1_size	= sizeof(struct ipv6hdr),
    -	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM,
    +	.arg2_type	= ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY,
     	.arg2_size	= sizeof(struct tcphdr),
     };
     #endif /* CONFIG_SYN_COOKIES */
    -- 
    cgit 1.3-korg
    
    
    

Vulnerability mechanics

Root cause

"Missing MEM_RDONLY or MEM_WRITE access flags in BPF helper function prototypes cause the verifier to incorrectly assume buffer contents are unchanged across helper calls, leading to incorrect memory access optimizations."

Attack vector

An attacker who can load and execute BPF programs (requiring `CAP_BPF` or equivalent privileges) can trigger the bug by calling a helper function whose prototype lacks the correct MEM_RDONLY or MEM_WRITE flag. Because the verifier relies on these flags to track memory access, a missing flag causes the verifier to incorrectly assume the buffer contents are unchanged across the helper call. The verifier may then optimize away subsequent reads of that buffer, leading to incorrect program behavior. The attacker does not need to send network packets or interact with any external interface; the attack vector is purely local through crafted BPF bytecode. [patch_id=2661514]

Affected code

The vulnerability spans multiple files where BPF helper function prototypes are defined. In `net/core/filter.c`, the `bpf_xdp_fib_lookup_proto`, `bpf_skb_fib_lookup_proto`, and the syncookie helper prototypes lacked MEM_RDONLY or MEM_WRITE flags. In `kernel/trace/bpf_trace.c`, `bpf_snprintf_btf_proto`, `bpf_read_branch_records_proto`, and `bpf_get_stack_proto_raw_tp` were missing correct access flags. In `kernel/bpf/helpers.c`, `bpf_snprintf_proto` was missing MEM_WRITE. In `kernel/bpf/syscall.c`, `bpf_kallsyms_lookup_name_proto` was missing MEM_RDONLY on its first argument. [patch_id=2661514]

What the fix does

The patch adds the missing MEM_RDONLY or MEM_WRITE flags to the `argN_type` fields of several `bpf_func_proto` structures. For example, `bpf_xdp_fib_lookup_proto.arg2_type` changed from `ARG_PTR_TO_MEM` to `ARG_PTR_TO_MEM | MEM_WRITE`, and `bpf_tcp_raw_gen_syncookie_ipv4_proto.arg1_type` changed from `ARG_PTR_TO_FIXED_SIZE_MEM` to `ARG_PTR_TO_FIXED_SIZE_MEM | MEM_RDONLY`. For `bpf_get_stack_proto_raw_tp`, the incorrect `ARG_PTR_TO_MEM | MEM_RDONLY` was replaced with `ARG_PTR_TO_UNINIT_MEM`, correctly indicating write access to potentially uninitialized memory. These changes ensure the verifier accurately tracks whether a helper reads, writes, or both reads and writes each memory argument, preventing incorrect optimizations that could skip necessary memory loads. [patch_id=2661514]

Preconditions

  • authThe attacker must have CAP_BPF (or equivalent) to load and execute BPF programs.
  • configThe kernel must have been built with BPF support enabled (CONFIG_BPF).
  • inputThe attacker must craft a BPF program that calls one of the affected helper functions and subsequently reads from the buffer the helper wrote to.

Generated on May 27, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

3

News mentions

0

No linked articles in our index yet.