From: mpi Date: Tue, 4 Jul 2017 12:51:18 +0000 (+0000) Subject: Assert that the socket lock is held when `so_qlen' is modified. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=24fc5127499d135791cc40b148096d463d664acf;p=openbsd Assert that the socket lock is held when `so_qlen' is modified. ok bluhm@, visa@ --- diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index 9619cbd3dc4..d8fc578817d 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket2.c,v 1.80 2017/06/27 12:02:43 mpi Exp $ */ +/* $OpenBSD: uipc_socket2.c,v 1.81 2017/07/04 12:51:18 mpi Exp $ */ /* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */ /* @@ -208,6 +208,7 @@ sonewconn(struct socket *head, int connstatus) void soqinsque(struct socket *head, struct socket *so, int q) { + soassertlocked(head); #ifdef DIAGNOSTIC if (so->so_onq != NULL) @@ -228,9 +229,10 @@ soqinsque(struct socket *head, struct socket *so, int q) int soqremque(struct socket *so, int q) { - struct socket *head; + struct socket *head = so->so_head; + + soassertlocked(head); - head = so->so_head; if (q == 0) { if (so->so_onq != &head->so_q0) return (0); diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 857e23621f1..514156e9a9e 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: socketvar.h,v 1.70 2017/06/26 09:32:32 mpi Exp $ */ +/* $OpenBSD: socketvar.h,v 1.71 2017/07/04 12:51:18 mpi Exp $ */ /* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */ /*- @@ -199,11 +199,15 @@ sbspace(struct socket *so, struct sockbuf *sb) ((so)->so_state & SS_ISSENDING) /* can we read something from so? */ -#define soreadable(so) \ - (!isspliced(so) && \ - ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \ - ((so)->so_state & SS_CANTRCVMORE) || \ - (so)->so_qlen || (so)->so_error)) +static inline int +soreadable(struct socket *so) +{ + soassertlocked(so); + if (isspliced(so)) + return 0; + return (so->so_state & SS_CANTRCVMORE) || so->so_qlen || so->so_error || + so->so_rcv.sb_cc >= so->so_rcv.sb_lowat; +} /* can we write something to so? */ #define sowriteable(so) \