Skip to contentSkip to conversation

net_sched: fix datalen for ematch

PATCH In review Cong Wang 3 participants 3 messages Jan 22, 2020 – Jan 23, 2020

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 net_sched: fix datalen for ematch

syzbot reported an out-of-bound access in em_nbyte. As initially analyzed by Eric, this is because em_nbyte sets its own em->datalen in em_nbyte_change() other than the one specified by user, but this value gets overwritten later by its caller tcf_em_validate(). We should leave em->datalen untouched to respect their choices.

I audit all the in-tree ematch users, all of those implement ->change() set em->datalen, so we can just avoid setting it twice in this case.

Reported-and-tested-by [email protected]
Reported-by [email protected]
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc Eric Dumazet <[email protected]>
---
 net/sched/ematch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/ematch.c +1 -1
index 8f2ad706784d..d0140a92694a 100644
@@ -263,12 +263,12 @@ static int tcf_em_validate(struct tcf_proto *tp,
 				}
 				em->data = (unsigned long) v;
 			}
+			em->datalen = data_len;
 		}
 	}
 
 	em->matchid = em_hdr->matchid;
 	em->flags = em_hdr->flags;
-	em->datalen = data_len;
 	em->net = net;
 
 	err = 0;
Signature · 1 line
2.21.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Cong Wang

syzbot reported an out-of-bound access in em_nbyte. As initially analyzed by Eric, this is because em_nbyte sets its own em->datalen in em_nbyte_change() other than the one specified by user, but this value gets overwritten later by its caller tcf_em_validate(). We should leave em->datalen untouched to respect their choices.

I audit all the in-tree ematch users, all of those implement ->change() set em->datalen, so we can just avoid setting it twice in this case.

Quoted 7 lines
Reported-and-tested-by [email protected]
Reported-by [email protected]
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc Eric Dumazet <[email protected]>

---

SGTM, thanks.

maintainer
#2 lore raw
In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Wed, 22 Jan 2020 15:42:02 -0800

Quoted 10 lines

syzbot reported an out-of-bound access in em_nbyte. As initially analyzed by Eric, this is because em_nbyte sets its own em->datalen in em_nbyte_change() other than the one specified by user, but this value gets overwritten later by its caller tcf_em_validate(). We should leave em->datalen untouched to respect their choices.

I audit all the in-tree ematch users, all of those implement ->change() set em->datalen, so we can just avoid setting it twice in this case.

Quoted 5 lines
Reported-and-tested-by [email protected]
Reported-by [email protected]
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc Eric Dumazet <[email protected]>

Applied and queued up for -stable, thanks.