From: Vitaliy Makkoveev Subject: sysctl(2): unlock `gre_vars' To: Alexander Bluhm , tech@openbsd.org Date: Wed, 4 Dec 2024 20:32:53 +0300 Both `gre_allow' and `gre_wccp' are atomically accessed integers. They could have only '0' and '1' values, so no extra dances around atomic_load_int(9) required. Index: sys/net/if_gre.c =================================================================== RCS file: /cvs/src/sys/net/if_gre.c,v diff -u -p -r1.178 if_gre.c --- sys/net/if_gre.c 23 Dec 2023 10:52:54 -0000 1.178 +++ sys/net/if_gre.c 4 Dec 2024 17:29:28 -0000 @@ -101,6 +101,11 @@ #include /* + * Locks used to protect data: + * a atomic + */ + +/* * packet formats */ struct gre_header { @@ -545,8 +550,8 @@ struct eoip_tree eoip_tree = RBT_INITIAL * allowed as well. * */ -int gre_allow = 0; -int gre_wccp = 0; +int gre_allow = 0; /* [a] */ +int gre_wccp = 0; /* [a] */ void greattach(int n) @@ -1009,7 +1014,7 @@ gre_input_key(struct mbuf **mp, int *off int mcast = 0; uint8_t itos; - if (!gre_allow) + if (!atomic_load_int(&gre_allow)) goto decline; key->t_rtableid = m->m_pkthdr.ph_rtableid; @@ -1092,7 +1097,8 @@ gre_input_key(struct mbuf **mp, int *off * draft-wilson-wrec-wccp-v2-01.txt */ - if (!gre_wccp && !ISSET(ifp->if_flags, IFF_LINK0)) + if (!atomic_load_int(&gre_wccp) && + !ISSET(ifp->if_flags, IFF_LINK0)) goto decline; /* @@ -1494,7 +1500,7 @@ gre_output(struct ifnet *ifp, struct mbu struct m_tag *mtag; int error = 0; - if (!gre_allow) { + if (!atomic_load_int(&gre_allow)) { error = EACCES; goto drop; } @@ -1633,7 +1639,7 @@ mgre_output(struct ifnet *ifp, struct mb sa_family_t af; const void *addr; - if (!gre_allow) { + if (!atomic_load_int(&gre_allow)) { error = EACCES; goto drop; } @@ -1785,7 +1791,7 @@ egre_start(struct ifnet *ifp) caddr_t if_bpf; #endif - if (!gre_allow) { + if (!atomic_load_int(&gre_allow)) { ifq_purge(&ifp->if_snd); return; } @@ -3642,7 +3648,7 @@ nvgre_start(struct ifnet *ifp) caddr_t if_bpf; #endif - if (!gre_allow) { + if (!atomic_load_int(&gre_allow)) { ifq_purge(&ifp->if_snd); return; } @@ -3833,7 +3839,7 @@ eoip_start(struct ifnet *ifp) caddr_t if_bpf; #endif - if (!gre_allow) { + if (!atomic_load_int(&gre_allow)) { ifq_purge(&ifp->if_snd); return; } @@ -4047,13 +4053,8 @@ int gre_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen) { - int error; - - NET_LOCK(); - error = sysctl_bounded_arr(gre_vars, nitems(gre_vars), name, + return sysctl_bounded_arr(gre_vars, nitems(gre_vars), name, namelen, oldp, oldlenp, newp, newlen); - NET_UNLOCK(); - return error; } static inline int Index: sys/netinet/in_proto.c =================================================================== RCS file: /cvs/src/sys/netinet/in_proto.c,v diff -u -p -r1.113 in_proto.c --- sys/netinet/in_proto.c 22 Aug 2024 10:58:31 -0000 1.113 +++ sys/netinet/in_proto.c 4 Dec 2024 17:29:28 -0000 @@ -318,7 +318,7 @@ const struct protosw inetsw[] = { .pr_type = SOCK_RAW, .pr_domain = &inetdomain, .pr_protocol = IPPROTO_GRE, - .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET, + .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET|PR_MPSYSCTL, .pr_input = gre_input, .pr_ctloutput = rip_ctloutput, .pr_usrreqs = &gre_usrreqs,