From 60965b7606bcb194c87043d83ad62589b7e72d7f Mon Sep 17 00:00:00 2001 From: Conrad Meyer Date: Mon, 20 Nov 2017 21:38:24 +0000 Subject: [PATCH] msdosfs(5): Reflect READONLY attribute in file mode Msdosfs allows setting READONLY by clearing the owner write bit of the file mode. (While here, correct the misspelling of S_IWUSR as VWRITE. No functional change.) In msdosfs_getattr, intuitively reflect that READONLY attribute to userspace in the file mode. Reported by: Karl Denninger Sponsored by: Dell EMC Isilon --- sys/fs/msdosfs/msdosfs_vnops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c index 1a3b8bbc10dc..cbe24abf89db 100644 --- a/sys/fs/msdosfs/msdosfs_vnops.c +++ b/sys/fs/msdosfs/msdosfs_vnops.c @@ -287,6 +287,8 @@ msdosfs_getattr(struct vop_getattr_args *ap) vap->va_fileid = fileid; mode = S_IRWXU|S_IRWXG|S_IRWXO; + if (dep->de_Attributes & ATTR_READONLY) + mode &= ~(S_IWUSR|S_IWGRP|S_IWOTH); vap->va_mode = mode & (ap->a_vp->v_type == VDIR ? pmp->pm_dirmask : pmp->pm_mask); vap->va_uid = pmp->pm_uid; @@ -502,7 +504,7 @@ msdosfs_setattr(struct vop_setattr_args *ap) } if (vp->v_type != VDIR) { /* We ignore the read and execute bits. */ - if (vap->va_mode & VWRITE) + if (vap->va_mode & S_IWUSR) dep->de_Attributes &= ~ATTR_READONLY; else dep->de_Attributes |= ATTR_READONLY;