From owner-svn-src-projects@freebsd.org Mon Jun 3 23:24:08 2019 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 59C9015C0F12 for ; Mon, 3 Jun 2019 23:24:08 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E8F37749E5; Mon, 3 Jun 2019 23:24:07 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BD3CDD2C2; Mon, 3 Jun 2019 23:24:07 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x53NO7jT028988; Mon, 3 Jun 2019 23:24:07 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x53NO70a028987; Mon, 3 Jun 2019 23:24:07 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201906032324.x53NO70a028987@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Mon, 3 Jun 2019 23:24:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r348593 - in projects/fuse2: sys/fs/fuse tests/sys/fs/fusefs X-SVN-Group: projects X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: in projects/fuse2: sys/fs/fuse tests/sys/fs/fusefs X-SVN-Commit-Revision: 348593 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: E8F37749E5 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.99 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.99)[-0.986,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Jun 2019 23:24:08 -0000 Author: asomers Date: Mon Jun 3 23:24:07 2019 New Revision: 348593 URL: https://svnweb.freebsd.org/changeset/base/348593 Log: fusefs: respect RLIMIT_FSIZE Sponsored by: The FreeBSD Foundation Modified: projects/fuse2/sys/fs/fuse/fuse_io.c projects/fuse2/tests/sys/fs/fusefs/write.cc Modified: projects/fuse2/sys/fs/fuse/fuse_io.c ============================================================================== --- projects/fuse2/sys/fs/fuse/fuse_io.c Mon Jun 3 23:17:35 2019 (r348592) +++ projects/fuse2/sys/fs/fuse/fuse_io.c Mon Jun 3 23:24:07 2019 (r348593) @@ -447,6 +447,9 @@ fuse_write_directbackend(struct vnode *vp, struct uio if (ioflag & IO_APPEND) uio_setoffset(uio, filesize); + if (vn_rlimit_fsize(vp, uio, uio->uio_td)) + return (EFBIG); + fdisp_init(&fdi, 0); while (uio->uio_resid > 0) { @@ -578,6 +581,9 @@ fuse_write_biobackend(struct vnode *vp, struct uio *ui if (ioflag & IO_APPEND) uio_setoffset(uio, filesize); + + if (vn_rlimit_fsize(vp, uio, uio->uio_td)) + return (EFBIG); /* * Find all of this file's B_NEEDCOMMIT buffers. If our writes Modified: projects/fuse2/tests/sys/fs/fusefs/write.cc ============================================================================== --- projects/fuse2/tests/sys/fs/fusefs/write.cc Mon Jun 3 23:17:35 2019 (r348592) +++ projects/fuse2/tests/sys/fs/fusefs/write.cc Mon Jun 3 23:24:07 2019 (r348593) @@ -31,12 +31,15 @@ extern "C" { #include #include +#include #include #include +#include #include #include #include +#include #include } @@ -48,7 +51,23 @@ using namespace testing; class Write: public FuseTest { public: +static sig_atomic_t s_sigxfsz; +void SetUp() { + s_sigxfsz = 0; + FuseTest::SetUp(); +} + +void TearDown() { + struct sigaction sa; + + bzero(&sa, sizeof(sa)); + sa.sa_handler = SIG_DFL; + sigaction(SIGXFSZ, &sa, NULL); + + FuseTest::TearDown(); +} + void expect_lookup(const char *relpath, uint64_t ino, uint64_t size) { FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, size, 1); @@ -73,6 +92,8 @@ void expect_write(uint64_t ino, uint64_t offset, uint6 }; +sig_atomic_t Write::s_sigxfsz = 0; + class Write_7_8: public FuseTest { public: @@ -158,6 +179,10 @@ void expect_write(uint64_t ino, uint64_t offset, uint6 } }; +void sigxfsz_handler(int __unused sig) { + Write::s_sigxfsz = 1; +} + /* AIO writes need to set the header's pid field correctly */ /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236379 */ TEST_F(AioWrite, DISABLED_aio_write) @@ -369,6 +394,36 @@ TEST_F(Write, direct_io_short_write_iov) iov[1].iov_base = (void*)CONTENTS1; iov[1].iov_len = strlen(CONTENTS1); ASSERT_EQ(size0, writev(fd, iov, 2)) << strerror(errno); + /* Deliberately leak fd. close(2) will be tested in release.cc */ +} + +/* fusefs should respect RLIMIT_FSIZE */ +TEST_F(Write, rlimit_fsize) +{ + const char FULLPATH[] = "mountpoint/some_file.txt"; + const char RELPATH[] = "some_file.txt"; + const char *CONTENTS = "abcdefgh"; + struct rlimit rl; + ssize_t bufsize = strlen(CONTENTS); + off_t offset = 1'000'000'000; + uint64_t ino = 42; + int fd; + + expect_lookup(RELPATH, ino, 0); + expect_open(ino, 0, 1); + + rl.rlim_cur = offset; + rl.rlim_max = 10 * offset; + ASSERT_EQ(0, setrlimit(RLIMIT_FSIZE, &rl)) << strerror(errno); + ASSERT_NE(SIG_ERR, signal(SIGXFSZ, sigxfsz_handler)) << strerror(errno); + + fd = open(FULLPATH, O_WRONLY); + + EXPECT_LE(0, fd) << strerror(errno); + + ASSERT_EQ(-1, pwrite(fd, CONTENTS, bufsize, offset)); + EXPECT_EQ(EFBIG, errno); + EXPECT_EQ(1, s_sigxfsz); /* Deliberately leak fd. close(2) will be tested in release.cc */ }