Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern vnodeops(9): Take exclusive lock in read/seek for f...
details: https://anonhg.NetBSD.org/src/rev/9299ff011227
branches: trunk
changeset: 368810:9299ff011227
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sat Aug 06 21:21:10 2022 +0000
description:
vnodeops(9): Take exclusive lock in read/seek for f_offset update.
Otherwise concurrent readers/seekers might clobber it.
diffstat:
sys/kern/vfs_vnops.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diffs (42 lines):
diff -r 09d3f1537bac -r 9299ff011227 sys/kern/vfs_vnops.c
--- a/sys/kern/vfs_vnops.c Sat Aug 06 20:16:42 2022 +0000
+++ b/sys/kern/vfs_vnops.c Sat Aug 06 21:21:10 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_vnops.c,v 1.234 2022/07/18 04:30:30 thorpej Exp $ */
+/* $NetBSD: vfs_vnops.c,v 1.235 2022/08/06 21:21:10 riastradh Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.234 2022/07/18 04:30:30 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.235 2022/08/06 21:21:10 riastradh Exp $");
#include "veriexec.h"
@@ -647,7 +647,10 @@
ioflag |= IO_ALTSEMANTICS;
if (fflag & FDIRECT)
ioflag |= IO_DIRECT;
- vn_lock(vp, LK_SHARED | LK_RETRY);
+ if (offset == &fp->f_offset && (flags & FOF_UPDATE_OFFSET) != 0)
+ vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+ else
+ vn_lock(vp, LK_SHARED | LK_RETRY);
uio->uio_offset = *offset;
count = uio->uio_resid;
error = VOP_READ(vp, uio, ioflag, cred);
@@ -1135,7 +1138,10 @@
if (vp->v_type == VFIFO)
return ESPIPE;
- vn_lock(vp, LK_SHARED | LK_RETRY);
+ if (flags & FOF_UPDATE_OFFSET)
+ vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+ else
+ vn_lock(vp, LK_SHARED | LK_RETRY);
/* Compute the old and new offsets. */
oldoff = fp->f_offset;
Home |
Main Index |
Thread Index |
Old Index