[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANn89iL5F=zN2t-LfBPtR6xzCQjVr8XB+bHu=LLYCvaao3Fx0Q@mail.gmail.com>
Date: Wed, 11 Feb 2026 20:07:12 +0100
From: Eric Dumazet <edumazet@...gle.com>
To: Ruitong Liu <cnitlrt@...il.com>
Cc: netdev@...r.kernel.org, jhs@...atatu.com, xiyou.wangcong@...il.com,
jiri@...nulli.us, davem@...emloft.net, kuba@...nel.org, pabeni@...hat.com,
horms@...nel.org, linux-kernel@...r.kernel.org, stable@...r.kernel.org,
Shuyuan Liu <L0x1c3r@...il.com>
Subject: Re: [PATCH] net/sched: act_skbedit: fix divide-by-zero in tcf_skbedit_hash()
On Wed, Feb 11, 2026 at 7:48 PM Ruitong Liu <cnitlrt@...il.com> wrote:
>
> mapping_mod is computed as:
>
> mapping_mod = queue_mapping_max - queue_mapping + 1;
>
> mapping_mod is stored as u16, so the calculation can overflow when
> queue_mapping=0 and queue_mapping_max=0xffff. In this case the value
> wraps to 0, leading to a divide-by-zero in tcf_skbedit_hash():
>
> queue_mapping += skb_get_hash(skb) % params->mapping_mod;
>
> Fix it by using a wider type for mapping_mod and performing the
> calculation in u32, preventing overflow to zero.
>
> Fixes: 38a6f0865796 ("net: sched: support hash selecting tx queue")
> Cc: stable@...r.kernel.org # 6.12+
> Reported-by: Ruitong Liu <cnitlrt@...il.com>
> Reported-by: Shuyuan Liu <L0x1c3r@...il.com>
> Signed-off-by: Ruitong Liu <cnitlrt@...il.com>
> ---
I do not think we want to support very large mapping_mod values, this
makes no sense.
Please reject wrong configuration instead.
diff --git a/net/sched/act_skbedit.c b/net/sched/act_skbedit.c
index 8c1d1554f657..0ab83dc776d1 100644
--- a/net/sched/act_skbedit.c
+++ b/net/sched/act_skbedit.c
@@ -126,7 +126,7 @@ static int tcf_skbedit_init(struct net *net,
struct nlattr *nla,
struct tcf_skbedit *d;
u32 flags = 0, *priority = NULL, *mark = NULL, *mask = NULL;
u16 *queue_mapping = NULL, *ptype = NULL;
- u16 mapping_mod = 1;
+ u32 mapping_mod = 1;
bool exists = false;
int ret = 0, err;
u32 index;
@@ -194,6 +194,10 @@ static int tcf_skbedit_init(struct net *net,
struct nlattr *nla,
}
mapping_mod = *queue_mapping_max - *queue_mapping + 1;
+ if (mapping_mod > 0xFFFF) {
+ NL_SET_ERR_MSG_MOD(extack, "The range
of queue_mapping is invalid.");
+ return -EINVAL;
+ }
flags |= SKBEDIT_F_TXQ_SKBHASH;
}
if (*pure_flags & SKBEDIT_F_INHERITDSFIELD)
Powered by blists - more mailing lists