netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] net/sched: cls_u32: Fix reference counter leak leading to overflow
@ 2023-05-31 14:15 Lee Jones
  2023-05-31 15:03 ` Eric Dumazet
  2023-05-31 15:05 ` Jamal Hadi Salim
  0 siblings, 2 replies; 8+ messages in thread
From: Lee Jones @ 2023-05-31 14:15 UTC (permalink / raw)
  To: lee, jhs, xiyou.wangcong, jiri, davem, edumazet, kuba, pabeni
  Cc: linux-kernel, netdev, stable

In the event of a failure in tcf_change_indev(), u32_set_parms() will
immediately return without decrementing the recently incremented
reference counter.  If this happens enough times, the counter will
rollover and the reference freed, leading to a double free which can be
used to do 'bad things'.

Cc: stable@kernel.org # v4.14+
Signed-off-by: Lee Jones <lee@kernel.org>
---
 net/sched/cls_u32.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
index 4e2e269f121f8..fad61ca5e90bf 100644
--- a/net/sched/cls_u32.c
+++ b/net/sched/cls_u32.c
@@ -762,8 +762,11 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp,
 	if (tb[TCA_U32_INDEV]) {
 		int ret;
 		ret = tcf_change_indev(net, tb[TCA_U32_INDEV], extack);
-		if (ret < 0)
+		if (ret < 0) {
+			if (tb[TCA_U32_LINK])
+				n->ht_down->refcnt--;
 			return -EINVAL;
+		}
 		n->ifindex = ret;
 	}
 	return 0;
-- 
2.41.0.rc0.172.g3f132b7071-goog


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

end of thread, other threads:[~2023-06-03 12:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-31 14:15 [PATCH 1/1] net/sched: cls_u32: Fix reference counter leak leading to overflow Lee Jones
2023-05-31 15:03 ` Eric Dumazet
2023-05-31 15:07   ` Jamal Hadi Salim
2023-06-01 14:06     ` Lee Jones
2023-06-01 15:10       ` Eric Dumazet
2023-06-01 16:48         ` Lee Jones
2023-06-03 12:35       ` Jamal Hadi Salim
2023-05-31 15:05 ` Jamal Hadi Salim

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).