Patch "bpf: Ensure reg is PTR_TO_STACK in process_iter_arg" has been added to the 6.12-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    bpf: Ensure reg is PTR_TO_STACK in process_iter_arg

to the 6.12-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     bpf-ensure-reg-is-ptr_to_stack-in-process_iter_arg.patch
and it can be found in the queue-6.12 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 4dd9d039bb37841504d563d41d8213df3a26a44d
Author: Tao Lyu <tao.lyu@xxxxxxx>
Date:   Mon Dec 2 16:02:37 2024 -0800

    bpf: Ensure reg is PTR_TO_STACK in process_iter_arg
    
    [ Upstream commit 12659d28615d606b36e382f4de2dd05550d202af ]
    
    Currently, KF_ARG_PTR_TO_ITER handling missed checking the reg->type and
    ensuring it is PTR_TO_STACK. Instead of enforcing this in the caller of
    process_iter_arg, move the check into it instead so that all callers
    will gain the check by default. This is similar to process_dynptr_func.
    
    An existing selftest in verifier_bits_iter.c fails due to this change,
    but it's because it was passing a NULL pointer into iter_next helper and
    getting an error further down the checks, but probably meant to pass an
    uninitialized iterator on the stack (as is done in the subsequent test
    below it). We will gain coverage for non-PTR_TO_STACK arguments in later
    patches hence just change the declaration to zero-ed stack object.
    
    Fixes: 06accc8779c1 ("bpf: add support for open-coded iterator loops")
    Suggested-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
    Signed-off-by: Tao Lyu <tao.lyu@xxxxxxx>
    [ Kartikeya: move check into process_iter_arg, rewrite commit log ]
    Signed-off-by: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx>
    Link: https://lore.kernel.org/r/20241203000238.3602922-2-memxor@xxxxxxxxx
    Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 91317857ea3ee..8955259112c03 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -8021,6 +8021,11 @@ static int process_iter_arg(struct bpf_verifier_env *env, int regno, int insn_id
 	const struct btf_type *t;
 	int spi, err, i, nr_slots, btf_id;
 
+	if (reg->type != PTR_TO_STACK) {
+		verbose(env, "arg#%d expected pointer to an iterator on stack\n", regno - 1);
+		return -EINVAL;
+	}
+
 	/* For iter_{new,next,destroy} functions, btf_check_iter_kfuncs()
 	 * ensures struct convention, so we wouldn't need to do any BTF
 	 * validation here. But given iter state can be passed as a parameter
diff --git a/tools/testing/selftests/bpf/progs/verifier_bits_iter.c b/tools/testing/selftests/bpf/progs/verifier_bits_iter.c
index 7c881bca9af5c..a7a6ae6c162fe 100644
--- a/tools/testing/selftests/bpf/progs/verifier_bits_iter.c
+++ b/tools/testing/selftests/bpf/progs/verifier_bits_iter.c
@@ -35,9 +35,9 @@ __description("uninitialized iter in ->next()")
 __failure __msg("expected an initialized iter_bits as arg #1")
 int BPF_PROG(next_uninit, struct bpf_iter_meta *meta, struct cgroup *cgrp)
 {
-	struct bpf_iter_bits *it = NULL;
+	struct bpf_iter_bits it = {};
 
-	bpf_iter_bits_next(it);
+	bpf_iter_bits_next(&it);
 	return 0;
 }
 




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux