Skip to content

Commit

Permalink
Enable vn_io_fault() deadlock avoidance for msdosfs.
Browse files Browse the repository at this point in the history
Reported and tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
  • Loading branch information
kostikbel committed Oct 28, 2016
1 parent b05088a commit 2aa3944
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sys/fs/msdosfs/msdosfs_vfsops.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ mountmsdosfs(struct vnode *devvp, struct mount *mp)
mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
MNT_ILOCK(mp);
mp->mnt_flag |= MNT_LOCAL;
mp->mnt_kern_flag |= MNTK_USES_BCACHE;
mp->mnt_kern_flag |= MNTK_USES_BCACHE | MNTK_NO_IOPF;
MNT_IUNLOCK(mp);

if (pmp->pm_flags & MSDOSFS_LARGEFS)
Expand Down
10 changes: 8 additions & 2 deletions sys/fs/msdosfs/msdosfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ msdosfs_read(struct vop_read_args *ap)
diff = blsize - bp->b_resid;
if (diff < n)
n = diff;
error = uiomove(bp->b_data + on, (int) n, uio);
error = vn_io_fault_uiomove(bp->b_data + on, (int) n, uio);
brelse(bp);
} while (error == 0 && uio->uio_resid > 0 && n != 0);
if (!isadir && (error == 0 || uio->uio_resid != orig_resid) &&
Expand Down Expand Up @@ -723,6 +723,12 @@ msdosfs_write(struct vop_write_args *ap)
* then no need to read data from disk.
*/
bp = getblk(thisvp, bn, pmp->pm_bpcluster, 0, 0, 0);
/*
* This call to vfs_bio_clrbuf() ensures that
* even if vn_io_fault_uiomove() below faults,
* garbage from the newly instantiated buffer
* is not exposed to the userspace via mmap().
*/
vfs_bio_clrbuf(bp);
/*
* Do the bmap now, since pcbmap needs buffers
Expand Down Expand Up @@ -760,7 +766,7 @@ msdosfs_write(struct vop_write_args *ap)
/*
* Copy the data from user space into the buf header.
*/
error = uiomove(bp->b_data + croffset, n, uio);
error = vn_io_fault_uiomove(bp->b_data + croffset, n, uio);
if (error) {
brelse(bp);
break;
Expand Down

0 comments on commit 2aa3944

Please sign in to comment.