From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jamal Hadi Salim Subject: [PATCH net-next 02/11] net: sched: cls_u32: make sure that divisor is a power of 2 Date: Sun, 7 Oct 2018 12:38:02 -0400 Message-ID: <20181007163811.18453-3-jhs@emojatatu.com> References: <20181007163811.18453-1-jhs@emojatatu.com> Cc: jiri@resnulli.us, xiyou.wangcong@gmail.com, viro@zeniv.linux.org.uk, netdev@vger.kernel.org, Jamal Hadi Salim To: davem@davemloft.net Return-path: Received: from mail-it1-f196.google.com ([209.85.166.196]:33664 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726803AbeJGXqR (ORCPT ); Sun, 7 Oct 2018 19:46:17 -0400 Received: by mail-it1-f196.google.com with SMTP id h6-v6so8605621ith.0 for ; Sun, 07 Oct 2018 09:38:28 -0700 (PDT) In-Reply-To: <20181007163811.18453-1-jhs@emojatatu.com> Sender: netdev-owner@vger.kernel.org List-ID: From: Al Viro Tested by modifying iproute2 to to allow sending a divisor > 255 Tested-by: Jamal Hadi Salim Signed-off-by: Al Viro Signed-off-by: Jamal Hadi Salim --- 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 3357331a80a2..ce55eea448a0 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -994,7 +994,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