Index | Thread | Search

From:
Martin Pieuchot <mpi@grenadille.net>
Subject:
Unlock stat(2) & co
To:
tech@openbsd.org
Date:
Mon, 6 Jan 2025 10:10:36 +0100

Download raw body.

Thread
Diff below pushes the kernel lock around namei() and vn_stat().

ok?

Index: kern/syscalls.master
===================================================================
RCS file: /cvs/src/sys/kern/syscalls.master,v
diff -u -p -r1.266 syscalls.master
--- kern/syscalls.master	6 Jan 2025 08:57:23 -0000	1.266
+++ kern/syscalls.master	6 Jan 2025 09:06:01 -0000
@@ -104,11 +104,11 @@
 35	STD		{ int sys_fchflags(int fd, u_int flags); }
 36	STD		{ void sys_sync(void); }
 37	OBSOL		msyscall
-38	STD		{ int sys_stat(const char *path, struct stat *ub); }
+38	STD NOLOCK	{ int sys_stat(const char *path, struct stat *ub); }
 39	STD NOLOCK	{ pid_t sys_getppid(void); }
-40	STD		{ int sys_lstat(const char *path, struct stat *ub); }
+40	STD NOLOCK	{ int sys_lstat(const char *path, struct stat *ub); }
 41	STD NOLOCK	{ int sys_dup(int fd); }
-42	STD		{ int sys_fstatat(int fd, const char *path, \
+42	STD NOLOCK	{ int sys_fstatat(int fd, const char *path, \
 			    struct stat *buf, int flag); }
 43	STD NOLOCK	{ gid_t sys_getegid(void); }
 44	STD		{ int sys_profil(caddr_t samples, size_t size, \
Index: kern/vfs_syscalls.c
===================================================================
RCS file: /cvs/src/sys/kern/vfs_syscalls.c,v
diff -u -p -r1.370 vfs_syscalls.c
--- kern/vfs_syscalls.c	5 Nov 2024 06:03:19 -0000	1.370
+++ kern/vfs_syscalls.c	6 Jan 2025 09:06:02 -0000
@@ -2066,10 +2066,14 @@ dofstatat(struct proc *p, int fd, const 
 	NDINITAT(&nd, LOOKUP, follow | LOCKLEAF, UIO_USERSPACE, fd, path, p);
 	nd.ni_pledge = PLEDGE_RPATH;
 	nd.ni_unveil = UNVEIL_READ;
-	if ((error = namei(&nd)) != 0)
+	KERNEL_LOCK();
+	if ((error = namei(&nd)) != 0) {
+		KERNEL_UNLOCK();
 		return (error);
+	}
 	error = vn_stat(nd.ni_vp, &sb, p);
 	vput(nd.ni_vp);
+	KERNEL_UNLOCK();
 	if (error)
 		return (error);
 	/* Don't let non-root see generation numbers (for NFS security) */