[PATCH 3.16.y-ckt 101/104] ethtool: Use kcalloc instead of kmalloc for ethtool_get_strings

Luis Henriques luis.henriques at canonical.com
Mon Oct 26 13:43:23 UTC 2015


3.16.7-ckt19 -stable review patch.  If anyone has any objections, please let me know.

------------------

From: Joe Perches <joe at perches.com>

commit 077cb37fcf6f00a45f375161200b5ee0cd4e937b upstream.

It seems that kernel memory can leak into userspace by a
kmalloc, ethtool_get_strings, then copy_to_user sequence.

Avoid this by using kcalloc to zero fill the copied buffer.

Signed-off-by: Joe Perches <joe at perches.com>
Acked-by: Ben Hutchings <ben at decadent.org.uk>
Signed-off-by: David S. Miller <davem at davemloft.net>
Signed-off-by: Luis Henriques <luis.henriques at canonical.com>
---
 net/core/ethtool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 17cb912793fa..e264527e41f8 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -1255,7 +1255,7 @@ static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
 
 	gstrings.len = ret;
 
-	data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
+	data = kcalloc(gstrings.len, ETH_GSTRING_LEN, GFP_USER);
 	if (!data)
 		return -ENOMEM;
 




More information about the kernel-team mailing list