Jesse Keating 2f82dda
From: Ben Hutchings <bhutchings@solarflare.com>
Jesse Keating 2f82dda
Date: Mon, 28 Jun 2010 08:44:07 +0000 (+0000)
Jesse Keating 2f82dda
Subject: ethtool: Fix potential kernel buffer overflow in ETHTOOL_GRXCLSRLALL
Jesse Keating 2f82dda
X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Fdavem%2Fnet-2.6.git;a=commitdiff_plain;h=db048b69037e7fa6a7d9e95a1271a50dc08ae233
Jesse Keating 2f82dda
Jesse Keating 2f82dda
ethtool: Fix potential kernel buffer overflow in ETHTOOL_GRXCLSRLALL
Jesse Keating 2f82dda
Jesse Keating 2f82dda
On a 32-bit machine, info.rule_cnt >= 0x40000000 leads to integer
Jesse Keating 2f82dda
overflow and the buffer may be smaller than needed.  Since
Jesse Keating 2f82dda
ETHTOOL_GRXCLSRLALL is unprivileged, this can presumably be used for at
Jesse Keating 2f82dda
least denial of service.
Jesse Keating 2f82dda
Jesse Keating 2f82dda
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Jesse Keating 2f82dda
Cc: stable@kernel.org
Jesse Keating 2f82dda
Signed-off-by: David S. Miller <davem@davemloft.net>
Jesse Keating 2f82dda
---
Jesse Keating 2f82dda
Jesse Keating 2f82dda
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
Jesse Keating 2f82dda
index a0f4964..a3a7e9a 100644
Jesse Keating 2f82dda
--- a/net/core/ethtool.c
Jesse Keating 2f82dda
+++ b/net/core/ethtool.c
Jesse Keating 2f82dda
@@ -347,8 +347,9 @@ static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
Jesse Keating 2f82dda
 
Jesse Keating 2f82dda
 	if (info.cmd == ETHTOOL_GRXCLSRLALL) {
Jesse Keating 2f82dda
 		if (info.rule_cnt > 0) {
Jesse Keating 2f82dda
-			rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
Jesse Keating 2f82dda
-					   GFP_USER);
Jesse Keating 2f82dda
+			if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
Jesse Keating 2f82dda
+				rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
Jesse Keating 2f82dda
+						   GFP_USER);
Jesse Keating 2f82dda
 			if (!rule_buf)
Jesse Keating 2f82dda
 				return -ENOMEM;
Jesse Keating 2f82dda
 		}