Skip to content

Commit 8a8a9fa

Browse files
edumazetkuba-moo
authored andcommitted
net: do not pass flow_id to set_rps_cpu()
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>
1 parent 41e09ec commit 8a8a9fa

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

net/core/dev.c

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

49934993
static struct rps_dev_flow *
49944994
set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
4995-
struct rps_dev_flow *rflow, u16 next_cpu, u32 hash,
4996-
u32 flow_id)
4995+
struct rps_dev_flow *rflow, u16 next_cpu, u32 hash)
49974996
{
49984997
if (next_cpu < nr_cpu_ids) {
49994998
u32 head;
@@ -5004,6 +5003,7 @@ set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
50045003
struct rps_dev_flow *tmp_rflow;
50055004
unsigned int tmp_cpu;
50065005
u16 rxq_index;
5006+
u32 flow_id;
50075007
int rc;
50085008

50095009
/* Should we steer this flow to a different hardware queue? */
@@ -5019,6 +5019,7 @@ set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
50195019
if (!flow_table)
50205020
goto out;
50215021

5022+
flow_id = rfs_slot(hash, flow_table);
50225023
tmp_rflow = &flow_table->flows[flow_id];
50235024
tmp_cpu = READ_ONCE(tmp_rflow->cpu);
50245025

@@ -5066,7 +5067,6 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
50665067
struct rps_dev_flow_table *flow_table;
50675068
struct rps_map *map;
50685069
int cpu = -1;
5069-
u32 flow_id;
50705070
u32 tcpu;
50715071
u32 hash;
50725072

@@ -5113,8 +5113,7 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
51135113
/* OK, now we know there is a match,
51145114
* we can look at the local (per receive queue) flow table
51155115
*/
5116-
flow_id = rfs_slot(hash, flow_table);
5117-
rflow = &flow_table->flows[flow_id];
5116+
rflow = &flow_table->flows[rfs_slot(hash, flow_table)];
51185117
tcpu = rflow->cpu;
51195118

51205119
/*
@@ -5133,8 +5132,7 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
51335132
((int)(READ_ONCE(per_cpu(softnet_data, tcpu).input_queue_head) -
51345133
rflow->last_qtail)) >= 0)) {
51355134
tcpu = next_cpu;
5136-
rflow = set_rps_cpu(dev, skb, rflow, next_cpu, hash,
5137-
flow_id);
5135+
rflow = set_rps_cpu(dev, skb, rflow, next_cpu, hash);
51385136
}
51395137

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

0 commit comments

Comments
 (0)