Source-Changes-HG archive

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

[src/trunk]: src/sys sbappendaddr() is required any lock. Currently, softnet_...



details:   https://anonhg.NetBSD.org/src/rev/5f91d08c3ba3
branches:  trunk
changeset: 323570:5f91d08c3ba3
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Thu Jun 21 10:37:49 2018 +0000

description:
sbappendaddr() is required any lock. Currently, softnet_lock is appropriate.

When rip_input() is called as inetsw[].pr_input, rip_iput() is always called
with holding softnet_lock, that is, in case of !defined(NET_MPSAFE) it is
acquired in ipintr(), otherwise(defined(NET_MPSAFE)) it is acquire in
PR_WRAP_INPUT macro.
However, some function calls rip_input() directly without holding softnet_lock.
That causes assertion failure in sbappendaddr().
rip6_input() and icmp6_rip6_input() are also required softnet_lock for the same
reason.

diffstat:

 sys/net/if.h              |  10 +++++++++-
 sys/netinet/igmp.c        |   9 +++++++--
 sys/netinet/in_l2tp.c     |   7 +++++--
 sys/netinet/ip_encap.c    |  12 +++++++++---
 sys/netinet/ip_icmp.c     |   9 +++++++--
 sys/netinet/ip_mroute.c   |   9 +++++++--
 sys/netinet6/in6_l2tp.c   |  10 +++++++---
 sys/netinet6/ip6_mroute.c |   9 +++++++--
 8 files changed, 58 insertions(+), 17 deletions(-)

diffs (270 lines):

diff -r 6192f779cc95 -r 5f91d08c3ba3 sys/net/if.h
--- a/sys/net/if.h      Thu Jun 21 09:09:50 2018 +0000
+++ b/sys/net/if.h      Thu Jun 21 10:37:49 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.h,v 1.262 2018/06/12 07:12:35 ozaki-r Exp $ */
+/*     $NetBSD: if.h,v 1.263 2018/06/21 10:37:49 knakahara Exp $       */
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -535,6 +535,11 @@
 #define SOFTNET_LOCK_UNLESS_NET_MPSAFE()       do { } while (0)
 #define SOFTNET_UNLOCK_UNLESS_NET_MPSAFE()     do { } while (0)
 
+#define SOFTNET_LOCK_IF_NET_MPSAFE()                                   \
+       do { mutex_enter(softnet_lock); } while (0)
+#define SOFTNET_UNLOCK_IF_NET_MPSAFE()                                 \
+       do { mutex_exit(softnet_lock); } while (0)
+
 #else /* NET_MPSAFE */
 
 #define KERNEL_LOCK_UNLESS_NET_MPSAFE()                                        \
@@ -547,6 +552,9 @@
 #define SOFTNET_UNLOCK_UNLESS_NET_MPSAFE()                             \
        do { mutex_exit(softnet_lock); } while (0)
 
+#define SOFTNET_LOCK_IF_NET_MPSAFE()           do { } while (0)
+#define SOFTNET_UNLOCK_IF_NET_MPSAFE()         do { } while (0)
+
 #endif /* NET_MPSAFE */
 
 #define SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE()                                \
diff -r 6192f779cc95 -r 5f91d08c3ba3 sys/netinet/igmp.c
--- a/sys/netinet/igmp.c        Thu Jun 21 09:09:50 2018 +0000
+++ b/sys/netinet/igmp.c        Thu Jun 21 10:37:49 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: igmp.c,v 1.67 2018/04/10 08:22:35 maxv Exp $   */
+/*     $NetBSD: igmp.c,v 1.68 2018/06/21 10:37:50 knakahara Exp $      */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.67 2018/04/10 08:22:35 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.68 2018/06/21 10:37:50 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -474,6 +474,11 @@
         * Pass all valid IGMP packets up to any process(es) listening
         * on a raw IGMP socket.
         */
+       /*
+        * Currently, igmp_input() is always called holding softnet_lock
+        * by ipintr()(!NET_MPSAFE) or PR_INPUT_WRAP()(NET_MPSAFE).
+        */
+       KASSERT(mutex_owned(softnet_lock));
        rip_input(m, iphlen, proto);
        return;
 
diff -r 6192f779cc95 -r 5f91d08c3ba3 sys/netinet/in_l2tp.c
--- a/sys/netinet/in_l2tp.c     Thu Jun 21 09:09:50 2018 +0000
+++ b/sys/netinet/in_l2tp.c     Thu Jun 21 10:37:49 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_l2tp.c,v 1.14 2018/05/01 07:21:39 maxv Exp $        */
+/*     $NetBSD: in_l2tp.c,v 1.15 2018/06/21 10:37:50 knakahara Exp $   */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.14 2018/05/01 07:21:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.15 2018/06/21 10:37:50 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -42,6 +42,7 @@
 #include <sys/ioctl.h>
 #include <sys/syslog.h>
 #include <sys/kernel.h>
+#include <sys/socketvar.h> /* For softnet_lock */
 
 #include <net/if.h>
 #include <net/route.h>
@@ -275,7 +276,9 @@
                 * L2TPv3 control packet received.
                 * userland daemon(l2tpd?) should process.
                 */
+               SOFTNET_LOCK_IF_NET_MPSAFE();
                rip_input(m, off, proto);
+               SOFTNET_UNLOCK_IF_NET_MPSAFE();
                return;
        }
 
diff -r 6192f779cc95 -r 5f91d08c3ba3 sys/netinet/ip_encap.c
--- a/sys/netinet/ip_encap.c    Thu Jun 21 09:09:50 2018 +0000
+++ b/sys/netinet/ip_encap.c    Thu Jun 21 10:37:49 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_encap.c,v 1.68 2018/05/01 07:21:39 maxv Exp $       */
+/*     $NetBSD: ip_encap.c,v 1.69 2018/06/21 10:37:50 knakahara Exp $  */
 /*     $KAME: ip_encap.c,v 1.73 2001/10/02 08:30:58 itojun Exp $       */
 
 /*
@@ -68,7 +68,7 @@
 #define USE_RADIX
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.68 2018/05/01 07:21:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.69 2018/06/21 10:37:50 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -372,7 +372,9 @@
        }
 
        /* last resort: inject to raw socket */
+       SOFTNET_LOCK_IF_NET_MPSAFE();
        rip_input(m, off, proto);
+       SOFTNET_UNLOCK_IF_NET_MPSAFE();
 }
 #endif
 
@@ -494,6 +496,7 @@
        const struct encapsw *esw;
        struct encaptab *match;
        struct psref match_psref;
+       int rv;
 
        match = encap6_lookup(m, *offp, proto, INBOUND, &match_psref);
 
@@ -516,7 +519,10 @@
        }
 
        /* last resort: inject to raw socket */
-       return rip6_input(mp, offp, proto);
+       SOFTNET_LOCK_IF_NET_MPSAFE();
+       rv = rip6_input(mp, offp, proto);
+       SOFTNET_UNLOCK_IF_NET_MPSAFE();
+       return rv;
 }
 #endif
 
diff -r 6192f779cc95 -r 5f91d08c3ba3 sys/netinet/ip_icmp.c
--- a/sys/netinet/ip_icmp.c     Thu Jun 21 09:09:50 2018 +0000
+++ b/sys/netinet/ip_icmp.c     Thu Jun 21 10:37:49 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_icmp.c,v 1.171 2018/06/01 07:13:35 ozaki-r Exp $    */
+/*     $NetBSD: ip_icmp.c,v 1.172 2018/06/21 10:37:50 knakahara Exp $  */
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -94,7 +94,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.171 2018/06/01 07:13:35 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.172 2018/06/21 10:37:50 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -679,6 +679,11 @@
        }
 
 raw:
+       /*
+        * Currently, pim_input() is always called holding softnet_lock
+        * by ipintr()(!NET_MPSAFE) or PR_INPUT_WRAP()(NET_MPSAFE).
+        */
+       KASSERT(mutex_owned(softnet_lock));
        rip_input(m, hlen, proto);
        return;
 
diff -r 6192f779cc95 -r 5f91d08c3ba3 sys/netinet/ip_mroute.c
--- a/sys/netinet/ip_mroute.c   Thu Jun 21 09:09:50 2018 +0000
+++ b/sys/netinet/ip_mroute.c   Thu Jun 21 10:37:49 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_mroute.c,v 1.159 2018/05/14 17:26:16 maxv Exp $     */
+/*     $NetBSD: ip_mroute.c,v 1.160 2018/06/21 10:37:50 knakahara Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -93,7 +93,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.159 2018/05/14 17:26:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.160 2018/06/21 10:37:50 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -3165,6 +3165,11 @@
         * XXX: the outer IP header pkt size of a Register is not adjust to
         * reflect the fact that the inner multicast data is truncated.
         */
+       /*
+        * Currently, pim_input() is always called holding softnet_lock
+        * by ipintr()(!NET_MPSAFE) or PR_INPUT_WRAP()(NET_MPSAFE).
+        */
+       KASSERT(mutex_owned(softnet_lock));
        rip_input(m, iphlen, proto);
 
        return;
diff -r 6192f779cc95 -r 5f91d08c3ba3 sys/netinet6/in6_l2tp.c
--- a/sys/netinet6/in6_l2tp.c   Thu Jun 21 09:09:50 2018 +0000
+++ b/sys/netinet6/in6_l2tp.c   Thu Jun 21 10:37:49 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in6_l2tp.c,v 1.15 2018/04/27 09:55:28 knakahara Exp $  */
+/*     $NetBSD: in6_l2tp.c,v 1.16 2018/06/21 10:37:50 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.15 2018/04/27 09:55:28 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.16 2018/06/21 10:37:50 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -267,11 +267,15 @@
        log(LOG_DEBUG, "%s: sess_id = %" PRIu32 "\n", __func__, sess_id);
 #endif
        if (sess_id == 0) {
+               int rv;
                /*
                 * L2TPv3 control packet received.
                 * userland daemon(l2tpd?) should process.
                 */
-               return rip6_input(mp, offp, proto);
+               SOFTNET_LOCK_IF_NET_MPSAFE();
+               rv = rip6_input(mp, offp, proto);
+               SOFTNET_UNLOCK_IF_NET_MPSAFE();
+               return rv;
        }
 
        var = l2tp_lookup_session_ref(sess_id, &psref);
diff -r 6192f779cc95 -r 5f91d08c3ba3 sys/netinet6/ip6_mroute.c
--- a/sys/netinet6/ip6_mroute.c Thu Jun 21 09:09:50 2018 +0000
+++ b/sys/netinet6/ip6_mroute.c Thu Jun 21 10:37:49 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip6_mroute.c,v 1.128 2018/05/20 06:29:43 maxv Exp $    */
+/*     $NetBSD: ip6_mroute.c,v 1.129 2018/06/21 10:37:50 knakahara Exp $       */
 /*     $KAME: ip6_mroute.c,v 1.49 2001/07/25 09:21:18 jinmei Exp $     */
 
 /*
@@ -117,7 +117,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.128 2018/05/20 06:29:43 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.129 2018/06/21 10:37:50 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1931,6 +1931,11 @@
         * encapsulated ip6 header.
         */
 pim6_input_to_daemon:
+       /*
+        * Currently, rip6_input() is always called holding softnet_lock
+        * by ipintr()(!NET_MPSAFE) or PR_INPUT_WRAP()(NET_MPSAFE).
+        */
+       KASSERT(mutex_owned(softnet_lock));
        rip6_input(&m, offp, proto);
        return IPPROTO_DONE;
 }



Home | Main Index | Thread Index | Old Index