Thu Dec 14 05:49:00 2017 UTC ()
Fix a bug that tries to psref_acquire ifa with a psref used before

This fixes ATF tests that started to fail by a recent change to psref.


(ozaki-r)
diff -r1.233 -r1.234 src/sys/net/rtsock.c

cvs diff -r1.233 -r1.234 src/sys/net/rtsock.c (expand / switch to unified diff)

--- src/sys/net/rtsock.c 2017/12/14 05:47:45 1.233
+++ src/sys/net/rtsock.c 2017/12/14 05:48:59 1.234
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rtsock.c,v 1.233 2017/12/14 05:47:45 ozaki-r Exp $ */ 1/* $NetBSD: rtsock.c,v 1.234 2017/12/14 05:48:59 ozaki-r Exp $ */
2 2
3/* 3/*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -51,27 +51,27 @@ @@ -51,27 +51,27 @@
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE. 58 * SUCH DAMAGE.
59 * 59 *
60 * @(#)rtsock.c 8.7 (Berkeley) 10/12/95 60 * @(#)rtsock.c 8.7 (Berkeley) 10/12/95
61 */ 61 */
62 62
63#include <sys/cdefs.h> 63#include <sys/cdefs.h>
64__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.233 2017/12/14 05:47:45 ozaki-r Exp $"); 64__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.234 2017/12/14 05:48:59 ozaki-r Exp $");
65 65
66#ifdef _KERNEL_OPT 66#ifdef _KERNEL_OPT
67#include "opt_inet.h" 67#include "opt_inet.h"
68#include "opt_mpls.h" 68#include "opt_mpls.h"
69#include "opt_compat_netbsd.h" 69#include "opt_compat_netbsd.h"
70#include "opt_sctp.h" 70#include "opt_sctp.h"
71#include "opt_net_mpsafe.h" 71#include "opt_net_mpsafe.h"
72#endif 72#endif
73 73
74#include <sys/param.h> 74#include <sys/param.h>
75#include <sys/systm.h> 75#include <sys/systm.h>
76#include <sys/proc.h> 76#include <sys/proc.h>
77#include <sys/socket.h> 77#include <sys/socket.h>
@@ -612,26 +612,27 @@ route_output_get_ifa(const struct rt_add @@ -612,26 +612,27 @@ route_output_get_ifa(const struct rt_add
612{ 612{
613 struct ifaddr *ifa = NULL; 613 struct ifaddr *ifa = NULL;
614 614
615 *ifp = NULL; 615 *ifp = NULL;
616 if (info.rti_info[RTAX_IFP] != NULL) { 616 if (info.rti_info[RTAX_IFP] != NULL) {
617 ifa = ifa_ifwithnet_psref(info.rti_info[RTAX_IFP], psref); 617 ifa = ifa_ifwithnet_psref(info.rti_info[RTAX_IFP], psref);
618 if (ifa == NULL) 618 if (ifa == NULL)
619 goto next; 619 goto next;
620 *ifp = ifa->ifa_ifp; 620 *ifp = ifa->ifa_ifp;
621 if_acquire(*ifp, psref_ifp); 621 if_acquire(*ifp, psref_ifp);
622 if (info.rti_info[RTAX_IFA] == NULL && 622 if (info.rti_info[RTAX_IFA] == NULL &&
623 info.rti_info[RTAX_GATEWAY] == NULL) 623 info.rti_info[RTAX_GATEWAY] == NULL)
624 goto next; 624 goto next;
 625 ifa_release(ifa, psref);
625 if (info.rti_info[RTAX_IFA] == NULL) { 626 if (info.rti_info[RTAX_IFA] == NULL) {
626 /* route change <dst> <gw> -ifp <if> */ 627 /* route change <dst> <gw> -ifp <if> */
627 ifa = ifaof_ifpforaddr_psref(info.rti_info[RTAX_GATEWAY], 628 ifa = ifaof_ifpforaddr_psref(info.rti_info[RTAX_GATEWAY],
628 *ifp, psref); 629 *ifp, psref);
629 } else { 630 } else {
630 /* route change <dst> -ifp <if> -ifa <addr> */ 631 /* route change <dst> -ifp <if> -ifa <addr> */
631 ifa = ifa_ifwithaddr_psref(info.rti_info[RTAX_IFA], psref); 632 ifa = ifa_ifwithaddr_psref(info.rti_info[RTAX_IFA], psref);
632 if (ifa != NULL) 633 if (ifa != NULL)
633 goto out; 634 goto out;
634 ifa = ifaof_ifpforaddr_psref(info.rti_info[RTAX_IFA], 635 ifa = ifaof_ifpforaddr_psref(info.rti_info[RTAX_IFA],
635 *ifp, psref); 636 *ifp, psref);
636 } 637 }
637 goto out; 638 goto out;