diff -r 1c25535fd2c2 sys/netinet/in_pcb.c --- a/sys/netinet/in_pcb.c Mon Sep 29 17:01:48 2025 +0000 +++ b/sys/netinet/in_pcb.c Wed Oct 01 13:02:36 2025 +0000 @@ -142,14 +142,15 @@ struct in_addr zeroin_addr; #define INPCBHASH_PORT(table, lport) \ - &(table)->inpt_porthashtbl[ntohs(lport) & (table)->inpt_porthash] + (KASSERT(mutex_owned(softnet_lock)), \ + &(table)->inpt_porthashtbl[ntohs(lport) & (table)->inpt_porthash]) #define INPCBHASH_BIND(table, laddr, lport) \ - &(table)->inpt_bindhashtbl[ \ - ((ntohl((laddr).s_addr) + ntohs(lport))) & (table)->inpt_bindhash] + (KASSERT(mutex_owned(softnet_lock)), &(table)->inpt_bindhashtbl[ \ + ((ntohl((laddr).s_addr) + ntohs(lport))) & (table)->inpt_bindhash]) #define INPCBHASH_CONNECT(table, faddr, fport, laddr, lport) \ - &(table)->inpt_connecthashtbl[ \ + (KASSERT(mutex_owned(softnet_lock)), &(table)->inpt_connecthashtbl[ \ ((ntohl((faddr).s_addr) + ntohs(fport)) + \ - (ntohl((laddr).s_addr) + ntohs(lport))) & (table)->inpt_connecthash] + (ntohl((laddr).s_addr) + ntohs(lport))) & (table)->inpt_connecthash]) int anonportmin = IPPORT_ANONMIN; int anonportmax = IPPORT_ANONMAX; @@ -203,6 +204,8 @@ inpcb_create(struct socket *so, void *v) struct inpcb *inp; int s; + KASSERT(mutex_owned(softnet_lock)); + #ifdef INET6 KASSERT(soaf(so) == AF_INET || soaf(so) == AF_INET6); @@ -371,6 +374,8 @@ inpcb_bind_port(struct inpcb *inp, struc int reuseport = (so->so_options & SO_REUSEPORT); int wild = 0, error; + KASSERT(mutex_owned(softnet_lock)); + if (IN_MULTICAST(sin->sin_addr.s_addr)) { /* * Treat SO_REUSEADDR as SO_REUSEPORT for multicast; @@ -481,6 +486,8 @@ inpcb_bind(void *v, struct sockaddr_in * struct sockaddr_in lsin; int error; + KASSERT(mutex_owned(softnet_lock)); + if (inp->inp_af != AF_INET) return EINVAL; @@ -527,6 +534,8 @@ inpcb_connect(void *v, struct sockaddr_i int error; struct in_addr laddr; + KASSERT(mutex_owned(softnet_lock)); + if (inp->inp_af != AF_INET) return EINVAL; @@ -661,6 +670,8 @@ inpcb_disconnect(void *v) { struct inpcb *inp = v; + KASSERT(mutex_owned(softnet_lock)); + if (inp->inp_af != AF_INET) return; @@ -685,6 +696,8 @@ inpcb_destroy(void *v) struct socket *so = inp->inp_socket; int s; + KASSERT(mutex_owned(softnet_lock)); + KASSERT(inp->inp_af == AF_INET || inp->inp_af == AF_INET6); #if defined(IPSEC) @@ -775,6 +788,8 @@ inpcb_notify(struct inpcbtable *table, s in_port_t fport = fport_arg, lport = lport_arg; int nmatch; + KASSERT(mutex_owned(softnet_lock)); + if (in_nullhost(faddr) || notify == NULL) return 0; @@ -961,6 +976,8 @@ inpcb_lookup_local(struct inpcbtable *ta int wildcard; in_port_t lport = lport_arg; + KASSERT(mutex_owned(softnet_lock)); + if (vp) vp->valid = 0; @@ -1072,6 +1089,8 @@ inpcb_lookup(struct inpcbtable *table, struct inpcb *inp; in_port_t fport = fport_arg, lport = lport_arg; + KASSERT(mutex_owned(softnet_lock)); + if (vp) vp->valid = 0; @@ -1122,6 +1141,8 @@ inpcb_lookup_bound(struct inpcbtable *ta struct inpcb *inp; in_port_t lport = lport_arg; + KASSERT(mutex_owned(softnet_lock)); + head = INPCBHASH_BIND(table, laddr, lport); LIST_FOREACH(inp, head, inp_hash) { if (inp->inp_af != AF_INET) @@ -1161,6 +1182,8 @@ void inpcb_set_state(struct inpcb *inp, int state) { + KASSERT(mutex_owned(softnet_lock)); + #ifdef INET6 if (inp->inp_af == AF_INET6) { in6pcb_set_state(inp, state); diff -r 1c25535fd2c2 sys/netinet6/in6_pcb.c --- a/sys/netinet6/in6_pcb.c Mon Sep 29 17:01:48 2025 +0000 +++ b/sys/netinet6/in6_pcb.c Wed Oct 01 13:02:36 2025 +0000 @@ -110,19 +110,20 @@ const struct in6_addr zeroin6_addr; #define IN6PCBHASH_PORT(table, lport) \ - &(table)->inpt_porthashtbl[ntohs(lport) & (table)->inpt_porthash] + (KASSERT(mutex_owned(softnet_lock)), \ + &(table)->inpt_porthashtbl[ntohs(lport) & (table)->inpt_porthash]) #define IN6PCBHASH_BIND(table, laddr, lport) \ - &(table)->inpt_bindhashtbl[ \ + (KASSERT(mutex_owned(softnet_lock)), &(table)->inpt_bindhashtbl[ \ (((laddr)->s6_addr32[0] ^ (laddr)->s6_addr32[1] ^ \ (laddr)->s6_addr32[2] ^ (laddr)->s6_addr32[3]) + ntohs(lport)) & \ - (table)->inpt_bindhash] + (table)->inpt_bindhash]) #define IN6PCBHASH_CONNECT(table, faddr, fport, laddr, lport) \ - &(table)->inpt_bindhashtbl[ \ + (KASSERT(mutex_owned(softnet_lock)), &(table)->inpt_bindhashtbl[ \ ((((faddr)->s6_addr32[0] ^ (faddr)->s6_addr32[1] ^ \ (faddr)->s6_addr32[2] ^ (faddr)->s6_addr32[3]) + ntohs(fport)) + \ (((laddr)->s6_addr32[0] ^ (laddr)->s6_addr32[1] ^ \ (laddr)->s6_addr32[2] ^ (laddr)->s6_addr32[3]) + \ - ntohs(lport))) & (table)->inpt_bindhash] + ntohs(lport))) & (table)->inpt_bindhash]) int ip6_anonportmin = IPV6PORT_ANONMIN; int ip6_anonportmax = IPV6PORT_ANONMAX; @@ -237,6 +238,8 @@ in6pcb_bind_port(struct inpcb *inp, stru int wild = 0, reuseport = (so->so_options & SO_REUSEPORT); int error; + KASSERT(mutex_owned(softnet_lock)); + if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT)) == 0 && ((so->so_proto->pr_flags & PR_CONNREQUIRED) == 0 || (so->so_options & SO_ACCEPTCONN) == 0)) @@ -329,6 +332,8 @@ in6pcb_bind(void *v, struct sockaddr_in6 struct sockaddr_in6 lsin6; int error; + KASSERT(mutex_owned(softnet_lock)); + if (inp->inp_af != AF_INET6) return EINVAL; @@ -399,6 +404,8 @@ in6pcb_connect(void *v, struct sockaddr_ struct psref psref; int bound; + KASSERT(mutex_owned(softnet_lock)); + (void)&in6a; /* XXX fool gcc */ if (inp->inp_af != AF_INET6) @@ -550,6 +557,9 @@ in6pcb_connect(void *v, struct sockaddr_ void in6pcb_disconnect(struct inpcb *inp) { + + KASSERT(mutex_owned(softnet_lock)); + memset((void *)&in6p_faddr(inp), 0, sizeof(in6p_faddr(inp))); inp->inp_fport = 0; inpcb_set_state(inp, INP_BOUND); @@ -838,6 +848,8 @@ in6pcb_lookup_local(struct inpcbtable *t int matchwild = 3, wildcard; in_port_t lport = lport_arg; + KASSERT(mutex_owned(softnet_lock)); + if (vp) vp->valid = 0; @@ -1049,6 +1061,8 @@ in6pcb_lookup(struct inpcbtable *table, struct inpcb *inp; in_port_t fport = fport_arg, lport = lport_arg; + KASSERT(mutex_owned(softnet_lock)); + if (vp) vp->valid = 0; @@ -1096,6 +1110,8 @@ in6pcb_lookup_bound(struct inpcbtable *t struct in6_addr zero_mapped; #endif + KASSERT(mutex_owned(softnet_lock)); + head = IN6PCBHASH_BIND(table, laddr6, lport); LIST_FOREACH(inp, head, inp_hash) { if (inp->inp_af != AF_INET6) @@ -1166,6 +1182,8 @@ void in6pcb_set_state(struct inpcb *inp, int state) { + KASSERT(mutex_owned(softnet_lock)); + if (inp->inp_af != AF_INET6) return;