Skip to content

Commit

Permalink
Use domain name for socket lock.
Browse files Browse the repository at this point in the history
Syzkaller with witness complains about lock ordering of pf lock
with socket lock.  Socket lock for inet is taken before pf lock.
Pf lock is taken before socket lock for route.  This is a false
positive as route and inet socket locks are distinct.  Witness does
not know this.  Name the socket lock like the domain of the socket,
then rwlock name is used in witness lo_name subtype.  Make domain
names more consistent for locking, they were not used anyway.
Regardless of witness problem, unique lock name for each socket
type make sense.

Reported-by: syzbot+34d22dcbf20d76629c5a@syzkaller.appspotmail.com
Reported-by: syzbot+fde8d07ba74b69d0adfe@syzkaller.appspotmail.com
OK mvs@
  • Loading branch information
bluhm committed Jan 11, 2024
1 parent 41ac090 commit 66bd633
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
3 changes: 1 addition & 2 deletions sys/kern/uipc_domain.c
@@ -1,4 +1,4 @@
/* $OpenBSD: uipc_domain.c,v 1.64 2023/05/18 10:23:19 mvs Exp $ */
/* $OpenBSD: uipc_domain.c,v 1.65 2024/01/11 14:15:11 bluhm Exp $ */
/* $NetBSD: uipc_domain.c,v 1.14 1996/02/09 19:00:44 christos Exp $ */

/*
Expand Down Expand Up @@ -62,7 +62,6 @@ const struct domain *const domains[] = {

void pffasttimo(void *);
void pfslowtimo(void *);
const struct domain * pffinddomain(int);

void
domaininit(void)
Expand Down
8 changes: 4 additions & 4 deletions sys/kern/uipc_socket.c
@@ -1,4 +1,4 @@
/* $OpenBSD: uipc_socket.c,v 1.312 2023/12/19 21:34:22 bluhm Exp $ */
/* $OpenBSD: uipc_socket.c,v 1.313 2024/01/11 14:15:11 bluhm Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */

/*
Expand Down Expand Up @@ -148,15 +148,15 @@ soinit(void)
}

struct socket *
soalloc(int wait)
soalloc(const struct domain *dp, int wait)
{
struct socket *so;

so = pool_get(&socket_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) |
PR_ZERO);
if (so == NULL)
return (NULL);
rw_init_flags(&so->so_lock, "solock", RWL_DUPOK);
rw_init_flags(&so->so_lock, dp->dom_name, RWL_DUPOK);
refcnt_init(&so->so_refcnt);
klist_init(&so->so_rcv.sb_klist, &socket_klistops, so);
klist_init(&so->so_snd.sb_klist, &socket_klistops, so);
Expand Down Expand Up @@ -190,7 +190,7 @@ socreate(int dom, struct socket **aso, int type, int proto)
return (EPROTONOSUPPORT);
if (prp->pr_type != type)
return (EPROTOTYPE);
so = soalloc(M_WAIT);
so = soalloc(pffinddomain(dom), M_WAIT);
so->so_type = type;
if (suser(p) == 0)
so->so_state = SS_PRIV;
Expand Down
4 changes: 2 additions & 2 deletions sys/kern/uipc_socket2.c
@@ -1,4 +1,4 @@
/* $OpenBSD: uipc_socket2.c,v 1.139 2023/12/18 13:11:20 bluhm Exp $ */
/* $OpenBSD: uipc_socket2.c,v 1.140 2024/01/11 14:15:11 bluhm Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */

/*
Expand Down Expand Up @@ -188,7 +188,7 @@ sonewconn(struct socket *head, int connstatus, int wait)
return (NULL);
if (head->so_qlen + head->so_q0len > head->so_qlimit * 3)
return (NULL);
so = soalloc(wait);
so = soalloc(head->so_proto->pr_domain, wait);
if (so == NULL)
return (NULL);
so->so_type = head->so_type;
Expand Down
4 changes: 2 additions & 2 deletions sys/net/pfkeyv2.c
@@ -1,4 +1,4 @@
/* $OpenBSD: pfkeyv2.c,v 1.259 2023/10/11 22:13:16 tobhe Exp $ */
/* $OpenBSD: pfkeyv2.c,v 1.260 2024/01/11 14:15:11 bluhm Exp $ */

/*
* @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
Expand Down Expand Up @@ -225,7 +225,7 @@ const struct protosw pfkeysw[] = {

const struct domain pfkeydomain = {
.dom_family = PF_KEY,
.dom_name = "PF_KEY",
.dom_name = "pfkey",
.dom_init = pfkey_init,
.dom_protosw = pfkeysw,
.dom_protoswNPROTOSW = &pfkeysw[nitems(pfkeysw)],
Expand Down
4 changes: 2 additions & 2 deletions sys/netinet/in_proto.c
@@ -1,4 +1,4 @@
/* $OpenBSD: in_proto.c,v 1.102 2023/07/06 04:55:05 dlg Exp $ */
/* $OpenBSD: in_proto.c,v 1.103 2024/01/11 14:15:12 bluhm Exp $ */
/* $NetBSD: in_proto.c,v 1.14 1996/02/18 18:58:32 christos Exp $ */

/*
Expand Down Expand Up @@ -387,7 +387,7 @@ const struct protosw inetsw[] = {

const struct domain inetdomain = {
.dom_family = AF_INET,
.dom_name = "internet",
.dom_name = "inet",
.dom_init = in_init,
.dom_protosw = inetsw,
.dom_protoswNPROTOSW = &inetsw[nitems(inetsw)],
Expand Down
4 changes: 2 additions & 2 deletions sys/netinet6/in6_proto.c
@@ -1,4 +1,4 @@
/* $OpenBSD: in6_proto.c,v 1.112 2022/11/23 14:48:28 kn Exp $ */
/* $OpenBSD: in6_proto.c,v 1.113 2024/01/11 14:15:12 bluhm Exp $ */
/* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */

/*
Expand Down Expand Up @@ -332,7 +332,7 @@ const struct protosw inet6sw[] = {

const struct domain inet6domain = {
.dom_family = AF_INET6,
.dom_name = "internet6",
.dom_name = "inet6",
.dom_protosw = inet6sw,
.dom_protoswNPROTOSW = &inet6sw[nitems(inet6sw)],
.dom_sasize = sizeof(struct sockaddr_in6),
Expand Down
4 changes: 2 additions & 2 deletions sys/sys/domain.h
@@ -1,4 +1,4 @@
/* $OpenBSD: domain.h,v 1.23 2022/11/23 14:50:59 kn Exp $ */
/* $OpenBSD: domain.h,v 1.24 2024/01/11 14:15:12 bluhm Exp $ */
/* $NetBSD: domain.h,v 1.10 1996/02/09 18:25:07 christos Exp $ */

/*
Expand Down Expand Up @@ -49,7 +49,7 @@ struct ifnet;

struct domain {
int dom_family; /* AF_xxx */
char *dom_name;
const char *dom_name;
void (*dom_init)(void); /* initialize domain data structures */
/* externalize access rights */
int (*dom_externalize)(struct mbuf *, socklen_t, int);
Expand Down
3 changes: 2 additions & 1 deletion sys/sys/protosw.h
@@ -1,4 +1,4 @@
/* $OpenBSD: protosw.h,v 1.63 2023/12/18 13:11:20 bluhm Exp $ */
/* $OpenBSD: protosw.h,v 1.64 2024/01/11 14:15:12 bluhm Exp $ */
/* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */

/*-
Expand Down Expand Up @@ -259,6 +259,7 @@ struct ifnet;
struct sockaddr;
const struct protosw *pffindproto(int, int, int);
const struct protosw *pffindtype(int, int);
const struct domain *pffinddomain(int);
void pfctlinput(int, struct sockaddr *);

extern u_char ip_protox[];
Expand Down
4 changes: 2 additions & 2 deletions sys/sys/socketvar.h
@@ -1,4 +1,4 @@
/* $OpenBSD: socketvar.h,v 1.120 2023/07/04 22:28:24 mvs Exp $ */
/* $OpenBSD: socketvar.h,v 1.121 2024/01/11 14:15:12 bluhm Exp $ */
/* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */

/*-
Expand Down Expand Up @@ -346,7 +346,7 @@ int soconnect(struct socket *, struct mbuf *);
int soconnect2(struct socket *, struct socket *);
int socreate(int, struct socket **, int, int);
int sodisconnect(struct socket *);
struct socket *soalloc(int);
struct socket *soalloc(const struct domain *, int);
void sofree(struct socket *, int);
int sogetopt(struct socket *, int, int, struct mbuf *);
void sohasoutofband(struct socket *);
Expand Down

0 comments on commit 66bd633

Please sign in to comment.