diff options
author | Paolo Abeni <pabeni@redhat.com> | 2018-06-21 14:02:16 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-06-21 18:24:07 -0400 |
commit | 44a5cd436ec067c9a62988aca3331ac6eee5268d (patch) | |
tree | 064e1f3a283e56e75b9045a97fb5509bc43b2940 | |
parent | 945d015ee0c3095d2290e845565a23dedfd8027c (diff) |
cls_flower: fix use after free in flower S/W path
If flower filter is created without the skip_sw flag, fl_mask_put()
can race with fl_classify() and we can destroy the mask rhashtable
while a lookup operation is accessing it.
BUG: unable to handle kernel paging request at 00000000000911d1
PGD 0 P4D 0
SMP PTI
CPU: 3 PID: 5582 Comm: vhost-5541 Not tainted 4.18.0-rc1.vanilla+ #1950
Hardware name: Dell Inc. PowerEdge R730/072T6D, BIOS 2.1.7 06/16/2016
RIP: 0010:rht_bucket_nested+0x20/0x60
Code: 31 c8 c1 c1 18 29 c8 c3 66 90 8b 4f 04 ba 01 00 00 00 8b 07 48 8b bf 80 00 00 0
RSP: 0018:ffffafc5cfbb7a48 EFLAGS: 00010206
RAX: 0000000000001978 RBX: ffff9f12dff88a00 RCX: 00000000ffff9f12
RDX: 00000000000911d1 RSI: 0000000000000148 RDI: 0000000000000001
RBP: ffff9f12dff88a00 R08: 000000005f1cc119 R09: 00000000a715fae2
R10: ffffafc5cfbb7aa8 R11: ffff9f1cb4be804e R12: ffff9f1265e13000
R13: 0000000000000000 R14: ffffafc5cfbb7b48 R15: ffff9f12dff88b68
FS: 0000000000000000(0000) GS:ffff9f1d3f0c0000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00000000000911d1 CR3: 0000001575a94006 CR4: 00000000001626e0
Call Trace:
fl_lookup+0x134/0x140 [cls_flower]
fl_classify+0xf3/0x180 [cls_flower]
tcf_classify+0x78/0x150
__netif_receive_skb_core+0x69e/0xa50
netif_receive_skb_internal+0x42/0xf0
tun_get_user+0xdd5/0xfd0 [tun]
tun_sendmsg+0x52/0x70 [tun]
handle_tx+0x2b3/0x5f0 [vhost_net]
vhost_worker+0xab/0x100 [vhost]
kthread+0xf8/0x130
ret_from_fork+0x35/0x40
Modules linked in: act_mirred act_gact cls_flower vhost_net vhost tap sch_ingress
CR2: 00000000000911d1
Fix the above waiting for a RCU grace period before destroying the
rhashtable: we need to use tcf_queue_work(), as rhashtable_destroy()
must run in process context, as pointed out by Cong Wang.
v1 -> v2: use tcf_queue_work to run rhashtable_destroy().
Fixes: 05cd271fd61a ("cls_flower: Support multiple masks per priority")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/sched/cls_flower.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index 2b5be42a9f1c..9e8b26a80fb3 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c | |||
@@ -66,7 +66,7 @@ struct fl_flow_mask { | |||
66 | struct rhashtable_params filter_ht_params; | 66 | struct rhashtable_params filter_ht_params; |
67 | struct flow_dissector dissector; | 67 | struct flow_dissector dissector; |
68 | struct list_head filters; | 68 | struct list_head filters; |
69 | struct rcu_head rcu; | 69 | struct rcu_work rwork; |
70 | struct list_head list; | 70 | struct list_head list; |
71 | }; | 71 | }; |
72 | 72 | ||
@@ -203,6 +203,20 @@ static int fl_init(struct tcf_proto *tp) | |||
203 | return rhashtable_init(&head->ht, &mask_ht_params); | 203 | return rhashtable_init(&head->ht, &mask_ht_params); |
204 | } | 204 | } |
205 | 205 | ||
206 | static void fl_mask_free(struct fl_flow_mask *mask) | ||
207 | { | ||
208 | rhashtable_destroy(&mask->ht); | ||
209 | kfree(mask); | ||
210 | } | ||
211 | |||
212 | static void fl_mask_free_work(struct work_struct *work) | ||
213 | { | ||
214 | struct fl_flow_mask *mask = container_of(to_rcu_work(work), | ||
215 | struct fl_flow_mask, rwork); | ||
216 | |||
217 | fl_mask_free(mask); | ||
218 | } | ||
219 | |||
206 | static bool fl_mask_put(struct cls_fl_head *head, struct fl_flow_mask *mask, | 220 | static bool fl_mask_put(struct cls_fl_head *head, struct fl_flow_mask *mask, |
207 | bool async) | 221 | bool async) |
208 | { | 222 | { |
@@ -210,12 +224,11 @@ static bool fl_mask_put(struct cls_fl_head *head, struct fl_flow_mask *mask, | |||
210 | return false; | 224 | return false; |
211 | 225 | ||
212 | rhashtable_remove_fast(&head->ht, &mask->ht_node, mask_ht_params); | 226 | rhashtable_remove_fast(&head->ht, &mask->ht_node, mask_ht_params); |
213 | rhashtable_destroy(&mask->ht); | ||
214 | list_del_rcu(&mask->list); | 227 | list_del_rcu(&mask->list); |
215 | if (async) | 228 | if (async) |
216 | kfree_rcu(mask, rcu); | 229 | tcf_queue_work(&mask->rwork, fl_mask_free_work); |
217 | else | 230 | else |
218 | kfree(mask); | 231 | fl_mask_free(mask); |
219 | 232 | ||
220 | return true; | 233 | return true; |
221 | } | 234 | } |