Skip to content
/ linux Public

Commit 5455a23

Browse files
edumazetSasha Levin
authored andcommitted
net: do not pass flow_id to set_rps_cpu()
[ Upstream commit 8a8a9fa ] Blamed commit made the assumption that the RPS table for each receive queue would have the same size, and that it would not change. Compute flow_id in set_rps_cpu(), do not assume we can use the value computed by get_rps_cpu(). Otherwise we risk out-of-bound access and/or crashes. Fixes: 48aa304 ("net: Cache hash and flow_id to avoid recalculation") Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Krishna Kumar <krikku@gmail.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Link: https://patch.msgid.link/20260220222605.3468081-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9658174 commit 5455a23

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

net/core/dev.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4932,8 +4932,7 @@ static bool rps_flow_is_active(struct rps_dev_flow *rflow,
49324932

49334933
static struct rps_dev_flow *
49344934
set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
4935-
struct rps_dev_flow *rflow, u16 next_cpu, u32 hash,
4936-
u32 flow_id)
4935+
struct rps_dev_flow *rflow, u16 next_cpu, u32 hash)
49374936
{
49384937
if (next_cpu < nr_cpu_ids) {
49394938
u32 head;
@@ -4944,6 +4943,7 @@ set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
49444943
struct rps_dev_flow *tmp_rflow;
49454944
unsigned int tmp_cpu;
49464945
u16 rxq_index;
4946+
u32 flow_id;
49474947
int rc;
49484948

49494949
/* Should we steer this flow to a different hardware queue? */
@@ -4959,6 +4959,7 @@ set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
49594959
if (!flow_table)
49604960
goto out;
49614961

4962+
flow_id = rfs_slot(hash, flow_table);
49624963
tmp_rflow = &flow_table->flows[flow_id];
49634964
tmp_cpu = READ_ONCE(tmp_rflow->cpu);
49644965

@@ -5006,7 +5007,6 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
50065007
struct rps_dev_flow_table *flow_table;
50075008
struct rps_map *map;
50085009
int cpu = -1;
5009-
u32 flow_id;
50105010
u32 tcpu;
50115011
u32 hash;
50125012

@@ -5053,8 +5053,7 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
50535053
/* OK, now we know there is a match,
50545054
* we can look at the local (per receive queue) flow table
50555055
*/
5056-
flow_id = rfs_slot(hash, flow_table);
5057-
rflow = &flow_table->flows[flow_id];
5056+
rflow = &flow_table->flows[rfs_slot(hash, flow_table)];
50585057
tcpu = rflow->cpu;
50595058

50605059
/*
@@ -5073,8 +5072,7 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
50735072
((int)(READ_ONCE(per_cpu(softnet_data, tcpu).input_queue_head) -
50745073
rflow->last_qtail)) >= 0)) {
50755074
tcpu = next_cpu;
5076-
rflow = set_rps_cpu(dev, skb, rflow, next_cpu, hash,
5077-
flow_id);
5075+
rflow = set_rps_cpu(dev, skb, rflow, next_cpu, hash);
50785076
}
50795077

50805078
if (tcpu < nr_cpu_ids && cpu_online(tcpu)) {

0 commit comments

Comments
 (0)