[PATCH] net: sched: cls: fix a potential missing-check bug

From: Wenwen Wang
Date: Fri May 04 2018 - 03:05:22 EST


In rsvp_change(), the value of f->res.classid is checked to be no more
than 255. Otherwise, the execution will goto errout. This is enforced by a
if-statement check. However, in the following execution, f->res.classid is
assigned with a new value returned from gen_tunnel(), and the new value
is only checked against 0. Given that gen_tunnel() may return a value
larger than 255 based on data, the new value of f->res.classid should
be re-checked.

This patch adds a re-check to ensure the new value of f->res.classid is not
great than 255; otherwise, an error code will be returned.

Signed-off-by: Wenwen Wang <wang6495@xxxxxxx>
---
net/sched/cls_rsvp.h | 3 +++
1 file changed, 3 insertions(+)

diff --git a/net/sched/cls_rsvp.h b/net/sched/cls_rsvp.h
index 4f12976..7ced8fc 100644
--- a/net/sched/cls_rsvp.h
+++ b/net/sched/cls_rsvp.h
@@ -590,6 +590,9 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,
if (f->res.classid == 0 &&
(f->res.classid = gen_tunnel(data)) == 0)
goto errout;
+
+ if (f->res.classid > 255)
+ goto errout;
}

for (sp = &data->ht[h1];
--
2.7.4