Patch "bpf: Don't do bpf_cgroup_storage_set() for kuprobe/tp programs" has been added to the 5.10-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: Don't do bpf_cgroup_storage_set() for kuprobe/tp programs

to the 5.10-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-don-t-do-bpf_cgroup_storage_set-for-kuprobe-tp-p.patch
and it can be found in the queue-5.10 subdirectory.

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



commit bc340339b4e0e5968cb949deaf47b962c88d6fe4
Author: Sasha Levin <sashal@xxxxxxxxxx>
Date:   Sat Mar 27 18:27:53 2021 -0400

    bpf: Don't do bpf_cgroup_storage_set() for kuprobe/tp programs
    
    [ Upstream commit 05a68ce5fa51a83c360381630f823545c5757aa2 ]
    
    For kuprobe and tracepoint bpf programs, kernel calls
    trace_call_bpf() which calls BPF_PROG_RUN_ARRAY_CHECK()
    to run the program array. Currently, BPF_PROG_RUN_ARRAY_CHECK()
    also calls bpf_cgroup_storage_set() to set percpu
    cgroup local storage with NULL value. This is
    due to Commit 394e40a29788 ("bpf: extend bpf_prog_array to store
    pointers to the cgroup storage") which modified
    __BPF_PROG_RUN_ARRAY() to call bpf_cgroup_storage_set()
    and this macro is also used by BPF_PROG_RUN_ARRAY_CHECK().
    
    kuprobe and tracepoint programs are not allowed to call
    bpf_get_local_storage() helper hence does not
    access percpu cgroup local storage. Let us
    change BPF_PROG_RUN_ARRAY_CHECK() not to
    modify percpu cgroup local storage.
    
    The issue is observed when I tried to debug [1] where
    percpu data is overwritten due to
      preempt_disable -> migration_disable
    change. This patch does not completely fix the above issue,
    which will be addressed separately, e.g., multiple cgroup
    prog runs may preempt each other. But it does fix
    any potential issue caused by tracing program
    overwriting percpu cgroup storage:
     - in a busy system, a tracing program is to run between
       bpf_cgroup_storage_set() and the cgroup prog run.
     - a kprobe program is triggered by a helper in cgroup prog
       before bpf_get_local_storage() is called.
    
     [1] https://lore.kernel.org/bpf/CAKH8qBuXCfUz=w8L+Fj74OaUpbosO29niYwTki7e3Ag044_aww@xxxxxxxxxxxxxx/T
    
    Fixes: 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage")
    Signed-off-by: Yonghong Song <yhs@xxxxxx>
    Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx>
    Acked-by: Roman Gushchin <guro@xxxxxx>
    Link: https://lore.kernel.org/bpf/20210309185028.3763817-1-yhs@xxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 76322b6452c8..dd236ef59db3 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -1059,7 +1059,7 @@ int bpf_prog_array_copy(struct bpf_prog_array *old_array,
 			struct bpf_prog *include_prog,
 			struct bpf_prog_array **new_array);
 
-#define __BPF_PROG_RUN_ARRAY(array, ctx, func, check_non_null)	\
+#define __BPF_PROG_RUN_ARRAY(array, ctx, func, check_non_null, set_cg_storage) \
 	({						\
 		struct bpf_prog_array_item *_item;	\
 		struct bpf_prog *_prog;			\
@@ -1072,7 +1072,8 @@ int bpf_prog_array_copy(struct bpf_prog_array *old_array,
 			goto _out;			\
 		_item = &_array->items[0];		\
 		while ((_prog = READ_ONCE(_item->prog))) {		\
-			bpf_cgroup_storage_set(_item->cgroup_storage);	\
+			if (set_cg_storage)		\
+				bpf_cgroup_storage_set(_item->cgroup_storage);	\
 			_ret &= func(_prog, ctx);	\
 			_item++;			\
 		}					\
@@ -1133,10 +1134,10 @@ _out:							\
 	})
 
 #define BPF_PROG_RUN_ARRAY(array, ctx, func)		\
-	__BPF_PROG_RUN_ARRAY(array, ctx, func, false)
+	__BPF_PROG_RUN_ARRAY(array, ctx, func, false, true)
 
 #define BPF_PROG_RUN_ARRAY_CHECK(array, ctx, func)	\
-	__BPF_PROG_RUN_ARRAY(array, ctx, func, true)
+	__BPF_PROG_RUN_ARRAY(array, ctx, func, true, false)
 
 #ifdef CONFIG_BPF_SYSCALL
 DECLARE_PER_CPU(int, bpf_prog_active);



[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