Index | Thread | Search

From:
Alexander Bluhm <bluhm@openbsd.org>
Subject:
solock assert in in_pcbrtentry()
To:
tech@openbsd.org
Date:
Tue, 24 Dec 2024 14:00:12 +0100

Download raw body.

Thread
Hi,

I would like to assert that socket lock is taken when modifying the
route cached at the inpcb.  This is better than just documenting
inp_route with [s].

ok?

bluhm

Index: netinet/in_pcb.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_pcb.c,v
diff -u -p -r1.306 in_pcb.c
--- netinet/in_pcb.c	21 Dec 2024 00:10:04 -0000	1.306
+++ netinet/in_pcb.c	23 Dec 2024 17:44:33 -0000
@@ -923,6 +923,8 @@ in_pcblookup_local_lock(struct inpcbtabl
 struct rtentry *
 in_pcbrtentry(struct inpcb *inp)
 {
+	soassertlocked(inp->inp_socket);
+
 #ifdef INET6
 	if (ISSET(inp->inp_flags, INP_IPV6))
 		return in6_pcbrtentry(inp);
Index: netinet/in_pcb.h
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_pcb.h,v
diff -u -p -r1.160 in_pcb.h
--- netinet/in_pcb.h	21 Dec 2024 00:10:04 -0000	1.160
+++ netinet/in_pcb.h	23 Dec 2024 19:01:37 -0000
@@ -138,7 +138,7 @@ struct inpcb {
 	u_int16_t inp_lport;		/* [t] local port */
 	struct	  socket *inp_socket;	/* [I] back pointer to socket */
 	caddr_t	  inp_ppcb;		/* pointer to per-protocol pcb */
-	struct    route inp_route;	/* cached route */
+	struct    route inp_route;	/* [s] cached route */
 	struct    refcnt inp_refcnt;	/* refcount PCB, delay memory free */
 	int	  inp_flags;		/* generic IP/datagram flags */
 	union {				/* Header prototype. */