Source-Changes-HG archive

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

[src/trunk]: src/sys/netipsec Reinforce and clarify.



details:   https://anonhg.NetBSD.org/src/rev/0db14ecdeab5
branches:  trunk
changeset: 829276:0db14ecdeab5
user:      maxv <maxv%NetBSD.org@localhost>
date:      Wed Jan 24 13:49:23 2018 +0000

description:
Reinforce and clarify.

diffstat:

 sys/netipsec/xform_ah.c |  61 +++++++++++++++++++++---------------------------
 1 files changed, 27 insertions(+), 34 deletions(-)

diffs (110 lines):

diff -r f70b99ac437d -r 0db14ecdeab5 sys/netipsec/xform_ah.c
--- a/sys/netipsec/xform_ah.c   Wed Jan 24 13:30:47 2018 +0000
+++ b/sys/netipsec/xform_ah.c   Wed Jan 24 13:49:23 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xform_ah.c,v 1.76 2018/01/24 13:30:47 maxv Exp $       */
+/*     $NetBSD: xform_ah.c,v 1.77 2018/01/24 13:49:23 maxv Exp $       */
 /*     $FreeBSD: src/sys/netipsec/xform_ah.c,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $   */
 /*     $OpenBSD: ip_ah.c,v 1.63 2001/06/26 06:18:58 angelos Exp $ */
 /*
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xform_ah.c,v 1.76 2018/01/24 13:30:47 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xform_ah.c,v 1.77 2018/01/24 13:49:23 maxv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -494,54 +494,45 @@
 
                nxt = ip6.ip6_nxt & 0xff; /* Next header type. */
 
-               for (off = 0; off < skip - sizeof(struct ip6_hdr);)
+               for (off = 0; off < skip - sizeof(struct ip6_hdr);) {
+                       int noff;
+
                        switch (nxt) {
                        case IPPROTO_HOPOPTS:
                        case IPPROTO_DSTOPTS:
-                               ip6e = (struct ip6_ext *) (ptr + off);
+                               ip6e = (struct ip6_ext *)(ptr + off);
+                               noff = off + ((ip6e->ip6e_len + 1) << 3);
+
+                               /* Sanity check. */
+                               if (noff > skip - sizeof(struct ip6_hdr)) {
+                                       goto error6;
+                               }
 
                                /*
-                                * Process the mutable/immutable
-                                * options -- borrows heavily from the
-                                * KAME code.
+                                * Zero out mutable options.
                                 */
                                for (count = off + sizeof(struct ip6_ext);
-                                    count < off + ((ip6e->ip6e_len + 1) << 3);) {
+                                    count < noff;) {
                                        if (ptr[count] == IP6OPT_PAD1) {
                                                count++;
-                                               continue; /* Skip padding. */
-                                       }
-
-                                       /* Sanity check. */
-                                       if (count > off +
-                                           ((ip6e->ip6e_len + 1) << 3)) {
-                                               m_freem(m);
-
-                                               /* Free, if we allocated. */
-                                               if (alloc)
-                                                       free(ptr, M_XDATA);
-                                               return EINVAL;
+                                               continue;
                                        }
 
                                        ad = ptr[count + 1] + 2;
 
-                                       /* If mutable option, zeroize. */
-                                       if (ptr[count] & IP6OPT_MUTABLE)
-                                               memcpy(ptr + count, ipseczeroes,
-                                                   ad);
+                                       if (count + ad > noff) {
+                                               goto error6;
+                                       }
+
+                                       if (ptr[count] & IP6OPT_MUTABLE) {
+                                               memset(ptr + count, 0, ad);
+                                       }
 
                                        count += ad;
-
-                                       /* Sanity check. */
-                                       if (count >
-                                           skip - sizeof(struct ip6_hdr)) {
-                                               m_freem(m);
+                               }
 
-                                               /* Free, if we allocated. */
-                                               if (alloc)
-                                                       free(ptr, M_XDATA);
-                                               return EINVAL;
-                                       }
+                               if (count != noff) {
+                                       goto error6;
                                }
 
                                /* Advance. */
@@ -595,11 +586,13 @@
                        default:
                                DPRINTF(("%s: unexpected IPv6 header type %d\n",
                                    __func__, off));
+error6:
                                if (alloc)
                                        free(ptr, M_XDATA);
                                m_freem(m);
                                return EINVAL;
                        }
+               }
 
                /* Copyback and free, if we allocated. */
                if (alloc) {



Home | Main Index | Thread Index | Old Index