diff mbox series

[net-next,02/11] net: sched: cls_u32: make sure that divisor is a power of 2

Message ID 20181007163811.18453-3-jhs@emojatatu.com
State Changes Requested, archived
Delegated to: David Miller
Headers show
Series net: sched: cls_u32 Various improvements | expand

Commit Message

Jamal Hadi Salim Oct. 7, 2018, 4:38 p.m. UTC
From: Al Viro <viro@zeniv.linux.org.uk>

Tested by modifying iproute2 to to allow
sending a divisor > 255 

Tested-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
---
 net/sched/cls_u32.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Sergei Shtylyov Oct. 8, 2018, 8:46 a.m. UTC | #1
Hello!

On 07.10.2018 19:38, Jamal Hadi Salim wrote:

> From: Al Viro <viro@zeniv.linux.org.uk>
>
> Tested by modifying iproute2 to to allow

    One "to" is enough, no? :-)

> sending a divisor > 255
>
> Tested-by: Jamal Hadi Salim <jhs@mojatatu.com>
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
[...]

MBR, Sergei
Jamal Hadi Salim Oct. 8, 2018, 9:49 a.m. UTC | #2
On 2018-10-08 4:46 a.m., Sergei Shtylyov wrote:
> Hello!
> 
> On 07.10.2018 19:38, Jamal Hadi Salim wrote:
> 
>> From: Al Viro <viro@zeniv.linux.org.uk>
>>
>> Tested by modifying iproute2 to to allow
> 
>     One "to" is enough, no? :-)
> 

Will fix in updated version.

cheers,
jamal
diff mbox series

Patch

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;
 		}