Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Read the len before pushing the packet, otherwise po...



details:   https://anonhg.NetBSD.org/src/rev/261ed328947c
branches:  trunk
changeset: 847162:261ed328947c
user:      maxv <maxv%NetBSD.org@localhost>
date:      Fri Dec 13 14:13:55 2019 +0000

description:
Read the len before pushing the packet, otherwise possible use-after-free.
Found by a custom query on LGTM.

diffstat:

 sys/net/if_tun.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (34 lines):

diff -r baac5ebde319 -r 261ed328947c sys/net/if_tun.c
--- a/sys/net/if_tun.c  Fri Dec 13 14:10:32 2019 +0000
+++ b/sys/net/if_tun.c  Fri Dec 13 14:13:55 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_tun.c,v 1.156 2019/04/26 08:38:25 pgoyette Exp $    */
+/*     $NetBSD: if_tun.c,v 1.157 2019/12/13 14:13:55 maxv Exp $        */
 
 /*
  * Copyright (c) 1988, Julian Onions <jpo%cs.nott.ac.uk@localhost>
@@ -19,7 +19,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.156 2019/04/26 08:38:25 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.157 2019/12/13 14:13:55 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -609,6 +609,7 @@
                }
                /* FALLTHROUGH */
        case AF_UNSPEC:
+               mlen = m0->m_pkthdr.len;
                IFQ_ENQUEUE(&ifp->if_snd, m0, error);
                if (error) {
                        ifp->if_collisions++;
@@ -616,7 +617,6 @@
                        m0 = NULL;
                        goto out;
                }
-               mlen = m0->m_pkthdr.len;
                ifp->if_opackets++;
                ifp->if_obytes += mlen;
                break;



Home | Main Index | Thread Index | Old Index