NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: kern/60729: incosistent st_ino from the first stat(2) on a socket
The following reply was made to PR kern/60729; it has been noted by GNATS.
From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
To: uwe%NetBSD.org@localhost
Cc: gnats-bugs%NetBSD.org@localhost, netbsd-bugs%NetBSD.org@localhost
Subject: Re: kern/60729: incosistent st_ino from the first stat(2) on a socket
Date: Tue, 15 Sep 2026 16:49:49 +0000
This is a multi-part message in MIME format.
--=_yZfuFEUR5sBHB86OQy7idKn1uESPEWyt
Try attached?
--=_yZfuFEUR5sBHB86OQy7idKn1uESPEWyt
Content-Type: text/plain; charset="ISO-8859-1"; name="pr60729-unixsockino"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="pr60729-unixsockino.patch"
# HG changeset patch
# User Taylor R Campbell <riastradh%NetBSD.org@localhost>
# Date 1789490537 0
# Tue Sep 15 16:42:17 2026 +0000
# Branch trunk
# Node ID 3fe1ba99ddf50e054ee728621b78ed85d138cc5d
# Parent 4fbd288ac1da9e7d9592ddecf04f7513e244152f
# EXP-Topic riastradh-pr60729-unixsockino
uipc_usrreq: Fix unix-domain socket inode assignment.
1. `if (unp->unp_ino =3D=3D 0) unp->unp_ino =3D unp_ino++' would assign
zero the first time around by mistake, and then assign nonzero
after that. `if (unp->unp_ino =3D=3D 0) unp->unp_ino =3D ++unp_ino'
avoids this silliness.
2. Make the ++unp_ino part atomic.
PR kern/60729: incosistent st_ino from the first stat(2) on a socket
diff -r 4fbd288ac1da -r 3fe1ba99ddf5 sys/kern/uipc_usrreq.c
--- a/sys/kern/uipc_usrreq.c Mon Aug 10 13:36:10 2026 +0000
+++ b/sys/kern/uipc_usrreq.c Tue Sep 15 16:42:17 2026 +0000
@@ -179,7 +179,16 @@ const struct sockaddr_un sun_noname =3D {
.sun_len =3D offsetof(struct sockaddr_un, sun_path),
.sun_family =3D AF_LOCAL,
};
-ino_t unp_ino; /* prototype for fake inode numbers */
+
+/* prototype for fake inode numbers */
+#ifdef __HAVE_ATOMIC64_OPS
+volatile uint64_t unp_ino __cacheline_aligned;
+#else
+struct {
+ uint64_t num;
+ kmutex_t lock;
+} unp_ino __cacheline_aligned;
+#endif
=20
static struct mbuf * unp_addsockcred(struct lwp *, struct mbuf *);
static void unp_discard_later(file_t *);
@@ -233,6 +242,10 @@ uipc_init(void)
NULL, &unp_thread_lwp, "unpgc");
if (error !=3D 0)
panic("uipc_init %d", error);
+
+#ifndef __HAVE_ATOMIC64_OPS
+ mutex_init(&unp_ino.lock, MUTEX_DEFAULT, IPL_NONE);
+#endif
}
=20
static void
@@ -906,8 +919,15 @@ unp_stat(struct socket *so, struct stat=20
break;
}
ub->st_dev =3D NODEV;
- if (unp->unp_ino =3D=3D 0)
- unp->unp_ino =3D unp_ino++;
+ if (unp->unp_ino =3D=3D 0) {
+#ifdef __HAVE_ATOMIC64_OPS
+ unp->unp_ino =3D atomic_inc_64_nv(&unp_ino);
+#else
+ mutex_enter(&unp_ino.lock);
+ unp->unp_ino =3D ++unp_ino.num;
+ mutex_exit(&unp_ino.lock);
+#endif
+ }
ub->st_atimespec =3D ub->st_mtimespec =3D ub->st_ctimespec =3D unp->unp_c=
time;
ub->st_ino =3D unp->unp_ino;
ub->st_uid =3D so->so_uidinfo->ui_uid;
--=_yZfuFEUR5sBHB86OQy7idKn1uESPEWyt--
Home |
Main Index |
Thread Index |
Old Index