From mboxrd@z Thu Jan 1 00:00:00 1970 From: Al Viro Subject: [PATCH 3/7] make sure that divisor is a power of 2 Date: Wed, 5 Sep 2018 20:04:10 +0100 Message-ID: <20180905190414.5477-3-viro@ZenIV.linux.org.uk> References: <20180905190134.GQ19965@ZenIV.linux.org.uk> <20180905190414.5477-1-viro@ZenIV.linux.org.uk> Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko To: netdev@vger.kernel.org Return-path: Received: from zeniv.linux.org.uk ([195.92.253.2]:56978 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727868AbeIEXfp (ORCPT ); Wed, 5 Sep 2018 19:35:45 -0400 In-Reply-To: <20180905190414.5477-1-viro@ZenIV.linux.org.uk> Sender: netdev-owner@vger.kernel.org List-ID: From: Al Viro Signed-off-by: Al Viro --- net/sched/cls_u32.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 9ea5f2be907b..5816288810cc 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -995,7 +995,11 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, if (tb[TCA_U32_DIVISOR]) { unsigned int divisor = nla_get_u32(tb[TCA_U32_DIVISOR]); - if (--divisor > 0x100) { + if (!is_power_of_2(divisor)) { + NL_SET_ERR_MSG_MOD(extack, "Divisor is not a power of 2"); + return -EINVAL; + } + if (divisor-- > 0x100) { NL_SET_ERR_MSG_MOD(extack, "Exceeded maximum 256 hash buckets"); return -EINVAL; } -- 2.11.0