]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: net: netfilter: drop dead NULL checks
authorPuranjay Mohan <puranjay@kernel.org>
Fri, 2 Jan 2026 18:00:29 +0000 (10:00 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 2 Jan 2026 20:04:28 +0000 (12:04 -0800)
bpf_xdp_ct_lookup() and bpf_skb_ct_lookup() receive bpf_tuple and opts
parameter that are expected to be not NULL for real usages (see doc
string above functions). They return an error if NULL is passed for opts
or tuple.

The verifier will now reject programs that pass NULL to these
parameters, the kfuns can assume that these are always valid pointer, so
drop the NULL checks for these parameters.

Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Link: https://lore.kernel.org/r/20260102180038.2708325-4-puranjay@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
net/netfilter/nf_conntrack_bpf.c

index a630139bd0c3164d0f3d16a58d5adb6c373f74c7..be654363f53fbde4e47d5026ab622158c925d4ba 100644 (file)
@@ -114,8 +114,6 @@ __bpf_nf_ct_alloc_entry(struct net *net, struct bpf_sock_tuple *bpf_tuple,
        struct nf_conn *ct;
        int err;
 
-       if (!opts || !bpf_tuple)
-               return ERR_PTR(-EINVAL);
        if (!(opts_len == NF_BPF_CT_OPTS_SZ || opts_len == 12))
                return ERR_PTR(-EINVAL);
        if (opts_len == NF_BPF_CT_OPTS_SZ) {
@@ -299,8 +297,7 @@ bpf_xdp_ct_alloc(struct xdp_md *xdp_ctx, struct bpf_sock_tuple *bpf_tuple,
        nfct = __bpf_nf_ct_alloc_entry(dev_net(ctx->rxq->dev), bpf_tuple, tuple__sz,
                                       opts, opts__sz, 10);
        if (IS_ERR(nfct)) {
-               if (opts)
-                       opts->error = PTR_ERR(nfct);
+               opts->error = PTR_ERR(nfct);
                return NULL;
        }
 
@@ -334,8 +331,7 @@ bpf_xdp_ct_lookup(struct xdp_md *xdp_ctx, struct bpf_sock_tuple *bpf_tuple,
        caller_net = dev_net(ctx->rxq->dev);
        nfct = __bpf_nf_ct_lookup(caller_net, bpf_tuple, tuple__sz, opts, opts__sz);
        if (IS_ERR(nfct)) {
-               if (opts)
-                       opts->error = PTR_ERR(nfct);
+               opts->error = PTR_ERR(nfct);
                return NULL;
        }
        return nfct;
@@ -367,8 +363,7 @@ bpf_skb_ct_alloc(struct __sk_buff *skb_ctx, struct bpf_sock_tuple *bpf_tuple,
        net = skb->dev ? dev_net(skb->dev) : sock_net(skb->sk);
        nfct = __bpf_nf_ct_alloc_entry(net, bpf_tuple, tuple__sz, opts, opts__sz, 10);
        if (IS_ERR(nfct)) {
-               if (opts)
-                       opts->error = PTR_ERR(nfct);
+               opts->error = PTR_ERR(nfct);
                return NULL;
        }
 
@@ -402,8 +397,7 @@ bpf_skb_ct_lookup(struct __sk_buff *skb_ctx, struct bpf_sock_tuple *bpf_tuple,
        caller_net = skb->dev ? dev_net(skb->dev) : sock_net(skb->sk);
        nfct = __bpf_nf_ct_lookup(caller_net, bpf_tuple, tuple__sz, opts, opts__sz);
        if (IS_ERR(nfct)) {
-               if (opts)
-                       opts->error = PTR_ERR(nfct);
+               opts->error = PTR_ERR(nfct);
                return NULL;
        }
        return nfct;