Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet - Do the size checks before calling the cpu chec...



details:   https://anonhg.NetBSD.org/src/rev/a3a051259a6f
branches:  trunk
changeset: 785417:a3a051259a6f
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Mar 12 21:54:36 2013 +0000

description:
- Do the size checks before calling the cpu checksum code. Otherwise you'll
  crash there and not panic.
- Don't panic on short packets unless DIAGNOSTIC. In general we should try
  to make the kernel survive errors...

diffstat:

 sys/netinet/in4_cksum.c |  24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diffs (55 lines):

diff -r c1391b61130f -r a3a051259a6f sys/netinet/in4_cksum.c
--- a/sys/netinet/in4_cksum.c   Tue Mar 12 21:52:47 2013 +0000
+++ b/sys/netinet/in4_cksum.c   Tue Mar 12 21:54:36 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in4_cksum.c,v 1.18 2011/04/25 22:04:32 yamt Exp $      */
+/*     $NetBSD: in4_cksum.c,v 1.19 2013/03/12 21:54:36 christos Exp $  */
 
 /*-
  * Copyright (c) 2008 Joerg Sonnenberger <joerg%NetBSD.org@localhost>.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in4_cksum.c,v 1.18 2011/04/25 22:04:32 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in4_cksum.c,v 1.19 2013/03/12 21:54:36 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/mbuf.h>
@@ -43,6 +43,14 @@
  *
  * off is supposed to be the skipped IPv4 header, len is the payload size.
  */
+#ifdef DIAGNOSTIC
+#define PANIC(a,...)   panic(a, __VA_ARGS__)
+#else
+#define PANIC(a,...)   do { \
+       printf(a, __VA_ARGS__); \
+       return -1; \
+} while (/*CONSTCOND*/0)
+#endif
 
 int
 in4_cksum(struct mbuf *m, u_int8_t nxt, int off, int len)
@@ -50,14 +58,16 @@
        uint32_t sum;
        uint16_t *w;
 
+       if (__predict_false(off < sizeof(struct ip)))
+               PANIC("%s: offset %d too short for IP header %zu", __func__,
+                   off, sizeof(struct ip));
+       if (__predict_false(m->m_len < sizeof(struct ip)))
+               PANIC("%s: mbuf %d too short for IP header %zu", __func__,
+                   m->m_len, sizeof(struct ip));
+
        if (nxt == 0)
                return cpu_in_cksum(m, len, off, 0);
 
-       if (__predict_false(off < sizeof(struct ip)))
-               panic("in4_cksum: offset too short for IP header");
-       if (__predict_false(m->m_len < sizeof(struct ip)))
-               panic("in4_cksum: mbuf too short for IP header");
-
        /*
         * Compute the equivalent of:
         * struct ipovly ip;



Home | Main Index | Thread Index | Old Index