linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vfs: Fix EOVERFLOW testing in put_compat_statfs64
@ 2019-10-02 21:17 Eric Sandeen
  2019-10-03 21:22 ` Linus Torvalds
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Sandeen @ 2019-10-02 21:17 UTC (permalink / raw)
  To: Linux Kernel Mailing List, fsdevel; +Cc: Al Viro, Linus Torvalds

Today, put_compat_statfs64() disallows nearly any field value over
2^32 if f_bsize is only 32 bits, but that makes no sense.
compat_statfs64 is there for the explicit purpose of providing 64-bit
fields for f_files, f_ffree, etc.  And f_bsize is always only 32 bits.

As a result, 32-bit userspace gets -EOVERFLOW for i.e. large file
counts even with -D_FILE_OFFSET_BITS=64 set.

In reality, only f_bsize and f_frsize can legitimately overflow
(fields like f_type and f_namelen should never be large), so test
only those fields.

This bug was discussed at length some time ago, and this is the proposal
Al suggested at https://lkml.org/lkml/2018/8/6/640.  It seemed to get
dropped amid the discussion of other related changes, but this
part seems obviously correct on its own, so I've picked it up and
sent it, for expediency.

Fixes: 64d2ab32efe3 ("vfs: fix put_compat_statfs64() does not handle errors")
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

Note, if it'd be better form to add:

From: Al Viro <viro@zeniv.linux.org.uk>

please do so.

Thanks,
-Eric

diff --git a/fs/statfs.c b/fs/statfs.c
index eea7af6f2f22..2616424012ea 100644
--- a/fs/statfs.c
+++ b/fs/statfs.c
@@ -318,19 +318,10 @@ COMPAT_SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct compat_statfs __user *,
 static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf)
 {
 	struct compat_statfs64 buf;
-	if (sizeof(ubuf->f_bsize) == 4) {
-		if ((kbuf->f_type | kbuf->f_bsize | kbuf->f_namelen |
-		     kbuf->f_frsize | kbuf->f_flags) & 0xffffffff00000000ULL)
-			return -EOVERFLOW;
-		/* f_files and f_ffree may be -1; it's okay
-		 * to stuff that into 32 bits */
-		if (kbuf->f_files != 0xffffffffffffffffULL
-		 && (kbuf->f_files & 0xffffffff00000000ULL))
-			return -EOVERFLOW;
-		if (kbuf->f_ffree != 0xffffffffffffffffULL
-		 && (kbuf->f_ffree & 0xffffffff00000000ULL))
-			return -EOVERFLOW;
-	}
+
+	if ((kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL)
+		return -EOVERFLOW;
+
 	memset(&buf, 0, sizeof(struct compat_statfs64));
 	buf.f_type = kbuf->f_type;
 	buf.f_bsize = kbuf->f_bsize;


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] vfs: Fix EOVERFLOW testing in put_compat_statfs64
  2019-10-02 21:17 [PATCH] vfs: Fix EOVERFLOW testing in put_compat_statfs64 Eric Sandeen
@ 2019-10-03 21:22 ` Linus Torvalds
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2019-10-03 21:22 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: Linux Kernel Mailing List, fsdevel, Al Viro

On Wed, Oct 2, 2019 at 2:17 PM Eric Sandeen <sandeen@redhat.com> wrote:
>
> As a result, 32-bit userspace gets -EOVERFLOW for i.e. large file
> counts even with -D_FILE_OFFSET_BITS=64 set.

Applied.

           Linus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-03 21:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-02 21:17 [PATCH] vfs: Fix EOVERFLOW testing in put_compat_statfs64 Eric Sandeen
2019-10-03 21:22 ` Linus Torvalds

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).