Skip to content

Commit 0279957

Browse files
jhsmtdavem330
authored andcommitted
net_sched: cls_route: disallow handle of 0
Follows up on: https://lore.kernel.org/all/[email protected]/ handle of 0 implies from/to of universe realm which is not very sensible. Lets see what this patch will do: $sudo tc qdisc add dev $DEV root handle 1:0 prio //lets manufacture a way to insert handle of 0 $sudo tc filter add dev $DEV parent 1:0 protocol ip prio 100 \ route to 0 from 0 classid 1:10 action ok //gets rejected... Error: handle of 0 is not valid. We have an error talking to the kernel, -1 //lets create a legit entry.. sudo tc filter add dev $DEV parent 1:0 protocol ip prio 100 route from 10 \ classid 1:10 action ok //what did the kernel insert? $sudo tc filter ls dev $DEV parent 1:0 filter protocol ip pref 100 route chain 0 filter protocol ip pref 100 route chain 0 fh 0x000a8000 flowid 1:10 from 10 action order 1: gact action pass random type none pass val 0 index 1 ref 1 bind 1 //Lets try to replace that legit entry with a handle of 0 $ sudo tc filter replace dev $DEV parent 1:0 protocol ip prio 100 \ handle 0x000a8000 route to 0 from 0 classid 1:10 action drop Error: Replacing with handle of 0 is invalid. We have an error talking to the kernel, -1 And last, lets run Cascardo's POC: $ ./poc 0 0 -22 -22 -22 Signed-off-by: Jamal Hadi Salim <[email protected]> Acked-by: Stephen Hemminger <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7396ba8 commit 0279957

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

net/sched/cls_route.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,11 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,
424424
return -EINVAL;
425425
}
426426

427+
if (!nhandle) {
428+
NL_SET_ERR_MSG(extack, "Replacing with handle of 0 is invalid");
429+
return -EINVAL;
430+
}
431+
427432
h1 = to_hash(nhandle);
428433
b = rtnl_dereference(head->table[h1]);
429434
if (!b) {
@@ -477,6 +482,11 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,
477482
int err;
478483
bool new = true;
479484

485+
if (!handle) {
486+
NL_SET_ERR_MSG(extack, "Creating with handle of 0 is invalid");
487+
return -EINVAL;
488+
}
489+
480490
if (opt == NULL)
481491
return handle ? -EINVAL : 0;
482492

0 commit comments

Comments
 (0)