Module Name: src Committed By: christos Date: Tue Mar 12 21:54:36 UTC 2013
Modified Files: src/sys/netinet: in4_cksum.c Log Message: - 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... To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sys/netinet/in4_cksum.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/netinet/in4_cksum.c diff -u src/sys/netinet/in4_cksum.c:1.18 src/sys/netinet/in4_cksum.c:1.19 --- src/sys/netinet/in4_cksum.c:1.18 Mon Apr 25 18:04:32 2011 +++ src/sys/netinet/in4_cksum.c Tue Mar 12 17:54:36 2013 @@ -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 <jo...@netbsd.org>. @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: in4_cksum.c, * * 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,13 +58,15 @@ in4_cksum(struct mbuf *m, u_int8_t nxt, uint32_t sum; uint16_t *w; - 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"); + 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("in4_cksum: mbuf too short for IP header"); + 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); /* * Compute the equivalent of: