netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: sched: Fix hw_stats_type setting in pedit loop
@ 2020-03-18 17:42 Petr Machata
  2020-03-18 23:52 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Petr Machata @ 2020-03-18 17:42 UTC (permalink / raw)
  To: netdev; +Cc: Petr Machata, Jiri Pirko, David Miller

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")
Signed-off-by: Petr Machata <petrm@mellanox.com>
---
 net/sched/cls_api.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 259a2e51ef3e..ca46290c5809 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -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;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] net: sched: Fix hw_stats_type setting in pedit loop
  2020-03-18 17:42 [PATCH net-next] net: sched: Fix hw_stats_type setting in pedit loop Petr Machata
@ 2020-03-18 23:52 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2020-03-18 23:52 UTC (permalink / raw)
  To: petrm; +Cc: netdev, jiri

From: Petr Machata <petrm@mellanox.com>
Date: Wed, 18 Mar 2020 19:42:29 +0200

> 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")
> Signed-off-by: Petr Machata <petrm@mellanox.com>

Good catch, applied, thank you.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-18 23:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-18 17:42 [PATCH net-next] net: sched: Fix hw_stats_type setting in pedit loop Petr Machata
2020-03-18 23:52 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).