Skip to contentSkip to conversation

net: sched: Fix hw_stats_type setting in pedit loop

PATCH In review Petr Machata 2 participants 2 messages Mar 18, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: sched: Fix hw_stats_type setting in pedit loop

In the commit referenced below, hw_stats_type of an entry is set for every entry that corresponds to a pedit action. However, the assignment is only done after the entry pointer is bumped, and therefore could overwrite memory outside of the entries array.

The reason for this positioning may have been that the current entry's hw_stats_type is already set above, before the action-type dispatch. However, if there are no more actions, the assignment is wrong. And if there are, the next round of the for_each_action loop will make the assignment before the action-type dispatch anyway.

Therefore fix this issue by simply reordering the two lines.

Fixes 74522e7baae2 ("net: sched: set the hw_stats_type in pedit loop")
---
 net/sched/cls_api.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/cls_api.c +1 -1
index 259a2e51ef3e..ca46290c5809 100644
@@ -3613,8 +3613,8 @@ int tc_setup_flow_action(struct flow_action *flow_action,
 				entry->mangle.mask = tcf_pedit_mask(act, k);
 				entry->mangle.val = tcf_pedit_val(act, k);
 				entry->mangle.offset = tcf_pedit_offset(act, k);
-				entry = &flow_action->entries[++j];
 				entry->hw_stats_type = act->hw_stats_type;
+				entry = &flow_action->entries[++j];
 			}
 		} else if (is_tcf_csum(act)) {
 			entry->id = FLOW_ACTION_CSUM;
Signature · 1 line
2.20.1
maintainer
#1 lore raw

From: Petr Machata <[email protected]>
Date: Wed, 18 Mar 2020 19:42:29 +0200

Quoted 11 lines

In the commit referenced below, hw_stats_type of an entry is set for every entry that corresponds to a pedit action. However, the assignment is only done after the entry pointer is bumped, and therefore could overwrite memory outside of the entries array.

The reason for this positioning may have been that the current entry's hw_stats_type is already set above, before the action-type dispatch. However, if there are no more actions, the assignment is wrong. And if there are, the next round of the for_each_action loop will make the assignment before the action-type dispatch anyway.

Quoted 4 lines

Therefore fix this issue by simply reordering the two lines.

Fixes 74522e7baae2 ("net: sched: set the hw_stats_type in pedit loop")

Good catch, applied, thank you.