seq_file: disallow extremely large seq buffer allocations
authorEric Sandeen <sandeen@redhat.com>
Tue, 13 Jul 2021 15:49:23 +0000 (17:49 +0200)
committerPDO SCM Team <hudsoncm@motorola.com>
Mon, 6 Dec 2021 08:55:36 +0000 (03:55 -0500)
commit 8cae8cd89f05f6de223d63e6d15e31c8ba9cf53b upstream.

There is no reasonable need for a buffer larger than this, and it avoids
int overflow pitfalls.

Mot-CRs-fixed: (CR)
CVE-Fixed: CVE-2021-33909
Bug: 195082750

Change-Id: I862f73cb7ec270b2d17ff61d405b5c5fd60d7353
Fixes: 058504edd026 ("fs/seq_file: fallback to vmalloc allocation")
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Reported-by: Qualys Security Advisory <qsa@qualys.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Gajjala Chakradhar <gajjalac@motorola.com>
Reviewed-on: https://gerrit.mot.com/2123620
SME-Granted: SME Approvals Granted
SLTApproved: Slta Waiver
Tested-by: Jira Key
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Submit-Approved: Jira Key
(cherry picked from commit 55b17c68973feef965d30a323651f4f340d3302b)

fs/seq_file.c

index eea09f6d883056b8e6fcc0aad857ab1a76fdb3f1..6cb1144421bbd32dc6572126388c3d1fd57d4b11 100644 (file)
@@ -26,6 +26,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);
 }