]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: Reject passing scalar NULL to nonnull arg of a global subprog
authorAmery Hung <ameryhung@gmail.com>
Thu, 23 Jul 2026 22:18:14 +0000 (15:18 -0700)
committerEduard Zingerman <eddyz87@gmail.com>
Thu, 23 Jul 2026 23:09:07 +0000 (16:09 -0700)
A global subprogram argument tagged __arg_nonnull is set up as a
non-nullable PTR_TO_MEM. However the verifier does not check against a
scalar NULL, leading to real NULL pointer dereference. Reject it as
well.

Fixes: 94e1c70a3452 ("bpf: support 'arg:xxx' btf_decl_tag-based hints for global subprog args")
Signed-off-by: Amery Hung <ameryhung@gmail.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://patch.msgid.link/20260723221815.367797-1-ameryhung@gmail.com
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
kernel/bpf/verifier.c

index 99444eae917e4821aa997df5f3b66eb0fc6cc600..7aa47342dc659cc9b19eb69ae7bc551daed894ba 100644 (file)
@@ -9189,7 +9189,8 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog,
                                return ret;
                        if (check_mem_reg(env, reg, argno, arg->mem_size))
                                return -EINVAL;
-                       if (!(arg->arg_type & PTR_MAYBE_NULL) && (reg->type & PTR_MAYBE_NULL)) {
+                       if (!(arg->arg_type & PTR_MAYBE_NULL) &&
+                           (type_may_be_null(reg->type) || bpf_register_is_null(reg))) {
                                bpf_log(log, "%s is expected to be non-NULL\n",
                                        reg_arg_name(env, argno));
                                return -EINVAL;