Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet Improve the check, we want to have len >= udphdr...



details:   https://anonhg.NetBSD.org/src/rev/281a3b9bd03d
branches:  trunk
changeset: 322007:281a3b9bd03d
user:      maxv <maxv%NetBSD.org@localhost>
date:      Fri Apr 13 09:29:04 2018 +0000

description:
Improve the check, we want to have len >= udphdr all the time, and not
just when the packet size doesn't match the mbuf size.

Normally that's not a huge problem, since IP6_EXTHDR_GET gets called
earlier, so we can't have

        (ip_len == iphlen + len) && (len < sizeof(struct udphdr))

diffstat:

 sys/netinet/udp_usrreq.c |  10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diffs (32 lines):

diff -r 68b1709d94f2 -r 281a3b9bd03d sys/netinet/udp_usrreq.c
--- a/sys/netinet/udp_usrreq.c  Fri Apr 13 09:21:16 2018 +0000
+++ b/sys/netinet/udp_usrreq.c  Fri Apr 13 09:29:04 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: udp_usrreq.c,v 1.247 2018/04/12 06:49:39 maxv Exp $    */
+/*     $NetBSD: udp_usrreq.c,v 1.248 2018/04/13 09:29:04 maxv Exp $    */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.247 2018/04/12 06:49:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.248 2018/04/13 09:29:04 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -374,8 +374,12 @@
         */
        ip_len = ntohs(ip->ip_len);
        len = ntohs((u_int16_t)uh->uh_ulen);
+       if (len < sizeof(struct udphdr)) {
+               UDP_STATINC(UDP_STAT_BADLEN);
+               goto bad;
+       }
        if (ip_len != iphlen + len) {
-               if (ip_len < iphlen + len || len < sizeof(struct udphdr)) {
+               if (ip_len < iphlen + len) {
                        UDP_STATINC(UDP_STAT_BADLEN);
                        goto bad;
                }



Home | Main Index | Thread Index | Old Index