public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] groups: integer underflow in groups_alloc()
@ 2015-02-23 15:44 Dan Carpenter
  2015-02-23 17:10 ` Eric W. Biederman
  0 siblings, 1 reply; 8+ messages in thread
From: Dan Carpenter @ 2015-02-23 15:44 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Andrew Morton, Andy Lutomirski, Wang YanQing, linux-kernel,
	linux-nfs, kernel-janitors

This is called from rsc_parse() with a use controlled value.  Say for
example that "gidsetsize" is negative, then we could end up allocating
less than sizeof(struct group_info) leading to memory corruption.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
I copied the NGROUPS_MAX limit from the surrounding code, I'm not
absolutely that it's the correct limit to use.

diff --git a/kernel/groups.c b/kernel/groups.c
index 664411f..e9341b3 100644
--- a/kernel/groups.c
+++ b/kernel/groups.c
@@ -18,6 +18,9 @@ struct group_info *groups_alloc(int gidsetsize)
 	int nblocks;
 	int i;
 
+	if ((unsigned)gidsetsize > NGROUPS_MAX)
+		return NULL;
+
 	nblocks = (gidsetsize + NGROUPS_PER_BLOCK - 1) / NGROUPS_PER_BLOCK;
 	/* Make sure we always allocate at least one indirect block pointer */
 	nblocks = nblocks ? : 1;

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

end of thread, other threads:[~2015-02-26 20:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-23 15:44 [patch] groups: integer underflow in groups_alloc() Dan Carpenter
2015-02-23 17:10 ` Eric W. Biederman
2015-02-23 18:03   ` Dan Carpenter
2015-02-23 18:46     ` Eric W. Biederman
2015-02-23 21:16     ` J. Bruce Fields
2015-02-24 15:34       ` [patch v2] sunrpc: integer underflow in rsc_parse() Dan Carpenter
2015-02-25  3:54         ` Simo Sorce
2015-02-26 20:40           ` J. Bruce Fields

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox