]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.112/net-sched-act_sample-fix-divide-by-zero-in-the-traffic-path.patch
Linux 4.9.169
[thirdparty/kernel/stable-queue.git] / releases / 4.14.112 / net-sched-act_sample-fix-divide-by-zero-in-the-traffic-path.patch
1 From foo@baz Mon Apr 15 07:47:06 CEST 2019
2 From: Davide Caratti <dcaratti@redhat.com>
3 Date: Thu, 4 Apr 2019 12:31:35 +0200
4 Subject: net/sched: act_sample: fix divide by zero in the traffic path
5
6 From: Davide Caratti <dcaratti@redhat.com>
7
8 [ Upstream commit fae2708174ae95d98d19f194e03d6e8f688ae195 ]
9
10 the control path of 'sample' action does not validate the value of 'rate'
11 provided by the user, but then it uses it as divisor in the traffic path.
12 Validate it in tcf_sample_init(), and return -EINVAL with a proper extack
13 message in case that value is zero, to fix a splat with the script below:
14
15 # tc f a dev test0 egress matchall action sample rate 0 group 1 index 2
16 # tc -s a s action sample
17 total acts 1
18
19 action order 0: sample rate 1/0 group 1 pipe
20 index 2 ref 1 bind 1 installed 19 sec used 19 sec
21 Action statistics:
22 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
23 backlog 0b 0p requeues 0
24 # ping 192.0.2.1 -I test0 -c1 -q
25
26 divide error: 0000 [#1] SMP PTI
27 CPU: 1 PID: 6192 Comm: ping Not tainted 5.1.0-rc2.diag2+ #591
28 Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011
29 RIP: 0010:tcf_sample_act+0x9e/0x1e0 [act_sample]
30 Code: 6a f1 85 c0 74 0d 80 3d 83 1a 00 00 00 0f 84 9c 00 00 00 4d 85 e4 0f 84 85 00 00 00 e8 9b d7 9c f1 44 8b 8b e0 00 00 00 31 d2 <41> f7 f1 85 d2 75 70 f6 85 83 00 00 00 10 48 8b 45 10 8b 88 08 01
31 RSP: 0018:ffffae320190ba30 EFLAGS: 00010246
32 RAX: 00000000b0677d21 RBX: ffff8af1ed9ec000 RCX: 0000000059a9fe49
33 RDX: 0000000000000000 RSI: 000000000c7e33b7 RDI: ffff8af23daa0af0
34 RBP: ffff8af1ee11b200 R08: 0000000074fcaf7e R09: 0000000000000000
35 R10: 0000000000000050 R11: ffffffffb3088680 R12: ffff8af232307f80
36 R13: 0000000000000003 R14: ffff8af1ed9ec000 R15: 0000000000000000
37 FS: 00007fe9c6d2f740(0000) GS:ffff8af23da80000(0000) knlGS:0000000000000000
38 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
39 CR2: 00007fff6772f000 CR3: 00000000746a2004 CR4: 00000000001606e0
40 Call Trace:
41 tcf_action_exec+0x7c/0x1c0
42 tcf_classify+0x57/0x160
43 __dev_queue_xmit+0x3dc/0xd10
44 ip_finish_output2+0x257/0x6d0
45 ip_output+0x75/0x280
46 ip_send_skb+0x15/0x40
47 raw_sendmsg+0xae3/0x1410
48 sock_sendmsg+0x36/0x40
49 __sys_sendto+0x10e/0x140
50 __x64_sys_sendto+0x24/0x30
51 do_syscall_64+0x60/0x210
52 entry_SYSCALL_64_after_hwframe+0x49/0xbe
53 [...]
54 Kernel panic - not syncing: Fatal exception in interrupt
55
56 Add a TDC selftest to document that 'rate' is now being validated.
57
58 Reported-by: Matteo Croce <mcroce@redhat.com>
59 Fixes: 5c5670fae430 ("net/sched: Introduce sample tc action")
60 Signed-off-by: Davide Caratti <dcaratti@redhat.com>
61 Acked-by: Yotam Gigi <yotam.gi@gmail.com>
62 Signed-off-by: David S. Miller <davem@davemloft.net>
63 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
64 ---
65 net/sched/act_sample.c | 10 +++++++++-
66 1 file changed, 9 insertions(+), 1 deletion(-)
67
68 --- a/net/sched/act_sample.c
69 +++ b/net/sched/act_sample.c
70 @@ -45,6 +45,7 @@ static int tcf_sample_init(struct net *n
71 struct tc_sample *parm;
72 struct tcf_sample *s;
73 bool exists = false;
74 + u32 rate;
75 int ret;
76
77 if (!nla)
78 @@ -73,10 +74,17 @@ static int tcf_sample_init(struct net *n
79 if (!ovr)
80 return -EEXIST;
81 }
82 - s = to_sample(*a);
83
84 + rate = nla_get_u32(tb[TCA_SAMPLE_RATE]);
85 + if (!rate) {
86 + tcf_idr_release(*a, bind);
87 + return -EINVAL;
88 + }
89 +
90 + s = to_sample(*a);
91 s->tcf_action = parm->action;
92 s->rate = nla_get_u32(tb[TCA_SAMPLE_RATE]);
93 + s->rate = rate;
94 s->psample_group_num = nla_get_u32(tb[TCA_SAMPLE_PSAMPLE_GROUP]);
95 psample_group = psample_group_get(net, s->psample_group_num);
96 if (!psample_group) {