Unverified Commit da325ff7 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!7235 bpf: Check rcu_read_lock_trace_held() before calling bpf map helpers

parents 3fd44f97 42320311
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include <linux/pid_namespace.h>
#include <linux/proc_ns.h>
#include <linux/security.h>
#include <linux/rcupdate_trace.h>

#include "../../lib/kstrtox.h"

@@ -24,12 +25,12 @@
 *
 * Different map implementations will rely on rcu in map methods
 * lookup/update/delete, therefore eBPF programs must run under rcu lock
 * if program is allowed to access maps, so check rcu_read_lock_held in
 * all three functions.
 * if program is allowed to access maps, so check rcu_read_lock_held() or
 * rcu_read_lock_trace_held() in all three functions.
 */
BPF_CALL_2(bpf_map_lookup_elem, struct bpf_map *, map, void *, key)
{
	WARN_ON_ONCE(!rcu_read_lock_held());
	WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held());
	return (unsigned long) map->ops->map_lookup_elem(map, key);
}

@@ -45,7 +46,7 @@ const struct bpf_func_proto bpf_map_lookup_elem_proto = {
BPF_CALL_4(bpf_map_update_elem, struct bpf_map *, map, void *, key,
	   void *, value, u64, flags)
{
	WARN_ON_ONCE(!rcu_read_lock_held());
	WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held());
	return map->ops->map_update_elem(map, key, value, flags);
}

@@ -62,7 +63,7 @@ const struct bpf_func_proto bpf_map_update_elem_proto = {

BPF_CALL_2(bpf_map_delete_elem, struct bpf_map *, map, void *, key)
{
	WARN_ON_ONCE(!rcu_read_lock_held());
	WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held());
	return map->ops->map_delete_elem(map, key);
}