Patch "bpf: Propagate expected_attach_type when verifying freplace programs" has been added to the 5.6-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: Propagate expected_attach_type when verifying freplace programs

to the 5.6-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-propagate-expected_attach_type-when-verifying-fr.patch
and it can be found in the queue-5.6 subdirectory.

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



commit 92f6fcaea5393c453084757f9c3b7f9116ddf43b
Author: Toke Høiland-Jørgensen <toke@xxxxxxxxxx>
Date:   Fri Apr 24 15:34:27 2020 +0200

    bpf: Propagate expected_attach_type when verifying freplace programs
    
    commit 03f87c0b45b177ba5f6b4a9bbe9f95e4aba31026 upstream.
    
    For some program types, the verifier relies on the expected_attach_type of
    the program being verified in the verification process. However, for
    freplace programs, the attach type was not propagated along with the
    verifier ops, so the expected_attach_type would always be zero for freplace
    programs.
    
    This in turn caused the verifier to sometimes make the wrong call for
    freplace programs. For all existing uses of expected_attach_type for this
    purpose, the result of this was only false negatives (i.e., freplace
    functions would be rejected by the verifier even though they were valid
    programs for the target they were replacing). However, should a false
    positive be introduced, this can lead to out-of-bounds accesses and/or
    crashes.
    
    The fix introduced in this patch is to propagate the expected_attach_type
    to the freplace program during verification, and reset it after that is
    done.
    
    Fixes: be8704ff07d2 ("bpf: Introduce dynamic program extensions")
    Signed-off-by: Toke Høiland-Jørgensen <toke@xxxxxxxxxx>
    Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx>
    Link: https://lore.kernel.org/bpf/158773526726.293902.13257293296560360508.stgit@xxxxxxx
    Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1381913cb10ba..1c53ccbd5b5d6 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -9892,6 +9892,7 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
 				return -EINVAL;
 			}
 			env->ops = bpf_verifier_ops[tgt_prog->type];
+			prog->expected_attach_type = tgt_prog->expected_attach_type;
 		}
 		if (!tgt_prog->jited) {
 			verbose(env, "Can attach to only JITed progs\n");
@@ -10225,6 +10226,13 @@ err_release_maps:
 		 * them now. Otherwise free_used_maps() will release them.
 		 */
 		release_maps(env);
+
+	/* extension progs temporarily inherit the attach_type of their targets
+	   for verification purposes, so set it back to zero before returning
+	 */
+	if (env->prog->type == BPF_PROG_TYPE_EXT)
+		env->prog->expected_attach_type = 0;
+
 	*prog = env->prog;
 err_unlock:
 	if (!is_priv)



[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