Yonghong Song
e1a75e94a3
bpf: Fix a rcu warning for bpffs map pretty-print
...
[ Upstream commit ce880cb825fcc22d4e39046a6c3a3a7f6603883d ]
Running selftest
./btf_btf -p
the kernel had the following warning:
[ 51.528185] WARNING: CPU: 3 PID: 1756 at kernel/bpf/hashtab.c:717 htab_map_get_next_key+0x2eb/0x300
[ 51.529217] Modules linked in:
[ 51.529583] CPU: 3 PID: 1756 Comm: test_btf Not tainted 5.9.0-rc1+ #878
[ 51.530346] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.9.3-1.el7.centos 04/01/2014
[ 51.531410] RIP: 0010:htab_map_get_next_key+0x2eb/0x300
...
[ 51.542826] Call Trace:
[ 51.543119] map_seq_next+0x53/0x80
[ 51.543528] seq_read+0x263/0x400
[ 51.543932] vfs_read+0xad/0x1c0
[ 51.544311] ksys_read+0x5f/0xe0
[ 51.544689] do_syscall_64+0x33/0x40
[ 51.545116] entry_SYSCALL_64_after_hwframe+0x44/0xa9
The related source code in kernel/bpf/hashtab.c:
709 static int htab_map_get_next_key(struct bpf_map *map, void *key, void *next_key)
710 {
711 struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
712 struct hlist_nulls_head *head;
713 struct htab_elem *l, *next_l;
714 u32 hash, key_size;
715 int i = 0;
716
717 WARN_ON_ONCE(!rcu_read_lock_held());
In kernel/bpf/inode.c, bpffs map pretty print calls map->ops->map_get_next_key()
without holding a rcu_read_lock(), hence causing the above warning.
To fix the issue, just surrounding map->ops->map_get_next_key() with rcu read lock.
Fixes: a26ca7c982cb ("bpf: btf: Add pretty print support to the basic arraymap")
Reported-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200916004401.146277-1-yhs@fb.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-10-01 13:14:52 +02:00
..
2018-08-13 00:52:45 +02:00
2017-04-17 13:55:52 -04:00
2017-09-01 09:57:39 -07:00
2020-04-02 15:28:23 +02:00
2018-08-07 14:29:55 +02:00
2019-07-10 09:53:47 +02:00
2020-05-02 17:25:53 +02:00
2019-12-01 09:17:01 +01:00
2018-03-23 17:38:57 +01:00
2018-03-23 17:38:57 +01:00
2020-10-01 13:14:34 +02:00
2018-08-03 00:47:32 +02:00
2020-10-01 13:14:52 +02:00
2018-12-17 09:24:33 +01:00
2019-07-03 13:14:48 +02:00
2019-07-26 09:14:06 +02:00
2019-01-31 08:14:41 +01:00
2017-06-29 13:13:25 -04:00
2020-02-28 16:38:59 +01:00
2019-03-13 14:02:36 -07:00
2019-03-13 14:02:36 -07:00
2018-08-11 01:58:46 +02:00
2018-09-22 02:46:41 +02:00
2019-12-31 16:35:20 +01:00
2020-07-16 08:17:27 +02:00
2020-01-23 08:21:32 +01:00
2020-04-23 10:30:24 +02:00
2018-10-11 10:19:01 +02:00