[PATCH] seq_file: Disallow extremely large seq buffer allocations
authorEric Sandeen <sandeen@redhat.com>
Tue, 6 Jul 2021 17:56:03 +0000 (19:56 +0200)
committerSalvatore Bonaccorso <carnil@debian.org>
Thu, 23 Sep 2021 20:35:21 +0000 (21:35 +0100)
There is no reasonable need for a buffer larger than this,
and it avoids int overflow pitfalls.

Fixes: 058504edd026 ("fs/seq_file: fallback to vmalloc allocation")
Reported-by: Qualys Security Advisory <qsa@qualys.com>
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Gbp-Pq: Topic bugfix/all
Gbp-Pq: Name seq_file-Disallow-extremely-large-seq-buffer-allocat.patch

fs/seq_file.c

index 03a369ccd28c342dad3e2bf815642aa8ade08f9e..472714716be69a984a327fb00ebb3f93abdf9cf0 100644 (file)
@@ -32,6 +32,9 @@ static void seq_set_overflow(struct seq_file *m)
 
 static void *seq_buf_alloc(unsigned long size)
 {
+       if (unlikely(size > MAX_RW_COUNT))
+               return NULL;
+
        return kvmalloc(size, GFP_KERNEL_ACCOUNT);
 }