From: bluhm Date: Wed, 19 Apr 2023 17:42:47 +0000 (+0000) Subject: Protect rtable_setsource() and rtable_getsource() with exclusive X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=eed9a6174bd8c0627663a27bbcec46d5d49ddbb3;p=openbsd Protect rtable_setsource() and rtable_getsource() with exclusive and shared netlock respectively. OK kn@ mvs@ --- diff --git a/sys/net/art.h b/sys/net/art.h index 98b8a60299a..33462c465de 100644 --- a/sys/net/art.h +++ b/sys/net/art.h @@ -1,4 +1,4 @@ -/* $OpenBSD: art.h,v 1.22 2023/04/18 10:19:16 mvs Exp $ */ +/* $OpenBSD: art.h,v 1.23 2023/04/19 17:42:47 bluhm Exp $ */ /* * Copyright (c) 2015 Martin Pieuchot @@ -41,7 +41,7 @@ struct art_root { uint8_t ar_nlvl; /* [I] Number of levels */ uint8_t ar_alen; /* [I] Address length in bits */ uint8_t ar_off; /* [I] Offset of key in bytes */ - struct sockaddr *ar_source; /* [K] optional src addr to use */ + struct sockaddr *ar_source; /* [N] use optional src addr */ }; #define ISLEAF(e) (((unsigned long)(e) & 1) == 0) diff --git a/sys/net/rtable.c b/sys/net/rtable.c index 56c7789935e..6f7b96f9f50 100644 --- a/sys/net/rtable.c +++ b/sys/net/rtable.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtable.c,v 1.81 2023/04/18 10:19:16 mvs Exp $ */ +/* $OpenBSD: rtable.c,v 1.82 2023/04/19 17:42:47 bluhm Exp $ */ /* * Copyright (c) 2014-2016 Martin Pieuchot @@ -376,6 +376,8 @@ rtable_setsource(unsigned int rtableid, int af, struct sockaddr *src) { struct art_root *ar; + NET_ASSERT_LOCKED_EXCLUSIVE(); + if ((ar = rtable_get(rtableid, af)) == NULL) return (EAFNOSUPPORT); @@ -389,6 +391,8 @@ rtable_getsource(unsigned int rtableid, int af) { struct art_root *ar; + NET_ASSERT_LOCKED(); + ar = rtable_get(rtableid, af); if (ar == NULL) return (NULL); diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index d3cc836db49..58afbba9182 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.363 2023/04/18 22:01:24 mvs Exp $ */ +/* $OpenBSD: rtsock.c,v 1.364 2023/04/19 17:42:47 bluhm Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -864,7 +864,9 @@ route_output(struct mbuf *m, struct socket *so) type = rtm->rtm_type; seq = rtm->rtm_seq; free(rtm, M_RTABLE, len); + NET_LOCK_SHARED(); rtm = rtm_report(rt, type, seq, tableid); + NET_UNLOCK_SHARED(); len = rtm->rtm_msglen; } }