Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net Protect IFADDR_READER_FOREACH and obtained ifa with ...
details: https://anonhg.NetBSD.org/src/rev/7bb64d44ca46
branches: trunk
changeset: 357705:7bb64d44ca46
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Wed Nov 22 05:42:30 2017 +0000
description:
Protect IFADDR_READER_FOREACH and obtained ifa with psz/psref
diffstat:
sys/net/if_spppsubr.c | 26 +++++++++++++++++++++-----
1 files changed, 21 insertions(+), 5 deletions(-)
diffs (94 lines):
diff -r cba37b86f133 -r 7bb64d44ca46 sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c Wed Nov 22 05:17:32 2017 +0000
+++ b/sys/net/if_spppsubr.c Wed Nov 22 05:42:30 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_spppsubr.c,v 1.172 2017/11/15 07:52:58 knakahara Exp $ */
+/* $NetBSD: if_spppsubr.c,v 1.173 2017/11/22 05:42:30 ozaki-r Exp $ */
/*
* Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.172 2017/11/15 07:52:58 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.173 2017/11/22 05:42:30 ozaki-r Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@@ -5219,6 +5219,8 @@
struct ifaddr *ifa;
struct sockaddr_in *si, *sm;
uint32_t ssrc, ddst;
+ int s;
+ struct psref psref;
sm = NULL;
ssrc = ddst = 0;
@@ -5227,14 +5229,18 @@
* aliases don't make any sense on a p2p link anyway.
*/
si = 0;
+ s = pserialize_read_enter();
IFADDR_READER_FOREACH(ifa, ifp) {
if (ifa->ifa_addr->sa_family == AF_INET) {
si = (struct sockaddr_in *)ifa->ifa_addr;
sm = (struct sockaddr_in *)ifa->ifa_netmask;
- if (si)
+ if (si) {
+ ifa_acquire(ifa, &psref);
break;
+ }
}
}
+ pserialize_read_exit(s);
if (ifa) {
if (si && si->sin_addr.s_addr) {
ssrc = si->sin_addr.s_addr;
@@ -5245,6 +5251,7 @@
si = (struct sockaddr_in *)ifa->ifa_dstaddr;
if (si && si->sin_addr.s_addr)
ddst = si->sin_addr.s_addr;
+ ifa_release(ifa, &psref);
}
if (dst) *dst = ntohl(ddst);
@@ -5457,6 +5464,8 @@
struct ifaddr *ifa;
struct sockaddr_in6 *si, *sm;
struct in6_addr ssrc, ddst;
+ int s;
+ struct psref psref;
sm = NULL;
memset(&ssrc, 0, sizeof(ssrc));
@@ -5466,13 +5475,19 @@
* aliases don't make any sense on a p2p link anyway.
*/
si = 0;
- IFADDR_READER_FOREACH(ifa, ifp)
+ s = pserialize_read_enter();
+ IFADDR_READER_FOREACH(ifa, ifp) {
if (ifa->ifa_addr->sa_family == AF_INET6) {
si = (struct sockaddr_in6 *)ifa->ifa_addr;
sm = (struct sockaddr_in6 *)ifa->ifa_netmask;
- if (si && IN6_IS_ADDR_LINKLOCAL(&si->sin6_addr))
+ if (si && IN6_IS_ADDR_LINKLOCAL(&si->sin6_addr)) {
+ ifa_acquire(ifa, &psref);
break;
+ }
}
+ }
+ pserialize_read_exit(s);
+
if (ifa) {
if (si && !IN6_IS_ADDR_UNSPECIFIED(&si->sin6_addr)) {
memcpy(&ssrc, &si->sin6_addr, sizeof(ssrc));
@@ -5485,6 +5500,7 @@
si = (struct sockaddr_in6 *)ifa->ifa_dstaddr;
if (si && !IN6_IS_ADDR_UNSPECIFIED(&si->sin6_addr))
memcpy(&ddst, &si->sin6_addr, sizeof(ddst));
+ ifa_release(ifa, &psref);
}
if (dst)
Home |
Main Index |
Thread Index |
Old Index