Allow listen(2) only on sockets of type SOCK_STREAM or SOCK_SEQPACKET.
authormvs <mvs@openbsd.org>
Sun, 31 Mar 2024 14:01:28 +0000 (14:01 +0000)
committermvs <mvs@openbsd.org>
Sun, 31 Mar 2024 14:01:28 +0000 (14:01 +0000)
listen(2) man(1) page clearly prohibits sockets of other types.

Reported-by: syzbot+00450333592fcd38c6fe@syzkaller.appspotmail.com
ok bluhm

sys/kern/uipc_socket.c

index a904ac0..35f75a0 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uipc_socket.c,v 1.324 2024/03/31 13:50:00 mvs Exp $   */
+/*     $OpenBSD: uipc_socket.c,v 1.325 2024/03/31 14:01:28 mvs Exp $   */
 /*     $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $        */
 
 /*
@@ -233,6 +233,14 @@ solisten(struct socket *so, int backlog)
        int sominconn_local = READ_ONCE(sominconn);
        int error;
 
+       switch (so->so_type) {
+       case SOCK_STREAM:
+       case SOCK_SEQPACKET:
+               break;
+       default:
+               return (EOPNOTSUPP);
+       }
+
        soassertlocked(so);
 
        if (so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING|SS_ISDISCONNECTING))