Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Jun 2019 23:24:07 +0000 (UTC)
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r348593 - in projects/fuse2: sys/fs/fuse tests/sys/fs/fusefs
Message-ID:  <201906032324.x53NO70a028987@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <sys/types.h>
 #include <sys/mman.h>
+#include <sys/resource.h>
 #include <sys/stat.h>
 #include <sys/sysctl.h>
+#include <sys/time.h>
 #include <sys/uio.h>
 
 #include <aio.h>
 #include <fcntl.h>
+#include <signal.h>
 #include <unistd.h>
 }
 
@@ -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 */
 }
 



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