Date: Fri, 21 Jun 2019 23:29:29 +0000 (UTC) From: Alan Somers <asomers@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r349282 - projects/fuse2/sys/fs/fuse Message-ID: <201906212329.x5LNTT4Q074639@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: asomers Date: Fri Jun 21 23:29:29 2019 New Revision: 349282 URL: https://svnweb.freebsd.org/changeset/base/349282 Log: fusefs: fix corruption on short reads caused by r349279 Even if a short read is caused by EOF, it's still necessary to bzero the remaining buffer, because that buffer could become valid as a result of a future ftruncate or pwrite operation. Reported by: fsx Sponsored by: The FreeBSD Foundation Modified: projects/fuse2/sys/fs/fuse/fuse_io.c Modified: projects/fuse2/sys/fs/fuse/fuse_io.c ============================================================================== --- projects/fuse2/sys/fs/fuse/fuse_io.c Fri Jun 21 23:29:16 2019 (r349281) +++ projects/fuse2/sys/fs/fuse/fuse_io.c Fri Jun 21 23:29:29 2019 (r349282) @@ -899,33 +899,37 @@ fuse_io_strategy(struct vnode *vp, struct buf *bp) error = fuse_read_directbackend(vp, uiop, cred, fufh); if (!error && uiop->uio_resid) { - /* - * A short read with no error, when not using direct io, - * and when no writes are cached, indicates EOF. - * Update the file size accordingly. - */ + int nread = bp->b_bcount - uiop->uio_resid; + int left = uiop->uio_resid; + bzero((char *)bp->b_data + nread, left); + if (fuse_data_cache_mode != FUSE_CACHE_WB || (fvdat->flag & FN_SIZECHANGE) == 0) { - SDT_PROBE2(fusefs, , io, trace, 1, - "Short read of a clean file"); - /* + /* + * A short read with no error, when not using + * direct io, and when no writes are cached, + * indicates EOF. Update the file size + * accordingly. We must still bzero the + * remaining buffer so uninitialized data + * doesn't get exposed by a future truncate + * that extends the file. + * * XXX To prevent lock order problems, we must * truncate the file upstack */ + SDT_PROBE2(fusefs, , io, trace, 1, + "Short read of a clean file"); } else { /* * If dirty writes _are_ cached beyond EOF, * that indicates a newly created hole that the - * server doesn't know about. Fill it in. + * server doesn't know about. * XXX: we don't currently track whether dirty * writes are cached beyond EOF, before EOF, or * both. */ SDT_PROBE2(fusefs, , io, trace, 1, "Short read of a dirty file"); - int nread = bp->b_bcount - uiop->uio_resid; - int left = uiop->uio_resid; - bzero((char *)bp->b_data + nread, left); uiop->uio_resid = 0; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201906212329.x5LNTT4Q074639>