Skip to content

Commit 3df9d80

Browse files
author
Alexei Starovoitov
committed
Merge branch 'bpf: fix a bpf_timer initialization issue'
Yonghong Song says: ==================== The patch [1] exposed a bpf_timer initialization bug in function check_and_init_map_value(). With bug fix here, the patch [1] can be applied with all selftests passed. Please see individual patches for fix details. [1] https://lore.kernel.org/bpf/[email protected]/ Changelog: v3 -> v4: . move header file in patch #1 to avoid bpf-next merge conflict v2 -> v3: . switch patch #1 and patch #2 for better bisecting v1 -> v2: . add Fixes tag for patch #1 . rebase against bpf tree ==================== Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents acc3c47 + 5eaed6e commit 3df9d80

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

include/linux/bpf.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,9 @@ static inline bool map_value_has_timer(const struct bpf_map *map)
209209
static inline void check_and_init_map_value(struct bpf_map *map, void *dst)
210210
{
211211
if (unlikely(map_value_has_spin_lock(map)))
212-
*(struct bpf_spin_lock *)(dst + map->spin_lock_off) =
213-
(struct bpf_spin_lock){};
212+
memset(dst + map->spin_lock_off, 0, sizeof(struct bpf_spin_lock));
214213
if (unlikely(map_value_has_timer(map)))
215-
*(struct bpf_timer *)(dst + map->timer_off) =
216-
(struct bpf_timer){};
214+
memset(dst + map->timer_off, 0, sizeof(struct bpf_timer));
217215
}
218216

219217
/* copy everything but bpf_spin_lock and bpf_timer. There could be one of each. */

kernel/bpf/helpers.c

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
33
*/
44
#include <linux/bpf.h>
5+
#include <linux/btf.h>
56
#include <linux/bpf-cgroup.h>
67
#include <linux/rcupdate.h>
78
#include <linux/random.h>
@@ -1075,6 +1076,7 @@ static enum hrtimer_restart bpf_timer_cb(struct hrtimer *hrtimer)
10751076
void *key;
10761077
u32 idx;
10771078

1079+
BTF_TYPE_EMIT(struct bpf_timer);
10781080
callback_fn = rcu_dereference_check(t->callback_fn, rcu_read_lock_bh_held());
10791081
if (!callback_fn)
10801082
goto out;

0 commit comments

Comments
 (0)