Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Jul 2019 01:52:34 +0000 (UTC)
From:      Rick Macklem <rmacklem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r350367 - head/sys/ufs/ufs
Message-ID:  <201907270152.x6R1qYo4020082@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rmacklem
Date: Sat Jul 27 01:52:34 2019
New Revision: 350367
URL: https://svnweb.freebsd.org/changeset/base/350367

Log:
  Lock the vnode before calling ufs_bmap_seekdata().
  
  r346932 replaced a call to vn_bmap_seekhole() with a call to
  ufs_bmap_seekdata(). Although vn_bmap_seekhole() locks the vnode,
  ufs_bmap_seekdata() assumes it is already locked.
  This patch adds locking of the vnode before the ufs_bmap_seekdata() call.
  If the vn_lock() call fails, it returns EBADF since that is the normal
  error returned when a file system is forced dismounted and is already
  listed as an error return in the lseek(2) man page.
  
  Discussed with:	markj
  Reviewed by:	kib

Modified:
  head/sys/ufs/ufs/ufs_vnops.c

Modified: head/sys/ufs/ufs/ufs_vnops.c
==============================================================================
--- head/sys/ufs/ufs/ufs_vnops.c	Fri Jul 26 21:08:01 2019	(r350366)
+++ head/sys/ufs/ufs/ufs_vnops.c	Sat Jul 27 01:52:34 2019	(r350367)
@@ -2702,11 +2702,18 @@ static int
 ufs_ioctl(struct vop_ioctl_args *ap)
 {
 	struct vnode *vp;
+	int error;
 
 	vp = ap->a_vp;
 	switch (ap->a_command) {
 	case FIOSEEKDATA:
-		return (ufs_bmap_seekdata(vp, (off_t *)ap->a_data));
+		error = vn_lock(vp, LK_SHARED);
+		if (error == 0) {
+			error = ufs_bmap_seekdata(vp, (off_t *)ap->a_data);
+			VOP_UNLOCK(vp, 0);
+		} else
+			error = EBADF;
+		return (error);
 	case FIOSEEKHOLE:
 		return (vn_bmap_seekhole(vp, ap->a_command, (off_t *)ap->a_data,
 		    ap->a_cred));



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201907270152.x6R1qYo4020082>