netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/core: Fix potential memory leak in dev_set_alias()
@ 2012-08-08 10:33 Alexey Khoroshilov
  2012-08-08 23:07 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Khoroshilov @ 2012-08-08 10:33 UTC (permalink / raw)
  To: David S. Miller
  Cc: Alexey Khoroshilov, Eric Dumazet, netdev, linux-kernel,
	ldv-project

Do not leak memory by updating pointer with potentially NULL realloc return value.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 net/core/dev.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 0cb3fe8..3bcc5da 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1055,6 +1055,8 @@ rollback:
  */
 int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
 {
+	char *new_ifalias;
+
 	ASSERT_RTNL();
 
 	if (len >= IFALIASZ)
@@ -1068,9 +1070,10 @@ int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
 		return 0;
 	}
 
-	dev->ifalias = krealloc(dev->ifalias, len + 1, GFP_KERNEL);
-	if (!dev->ifalias)
+	new_ifalias = krealloc(dev->ifalias, len + 1, GFP_KERNEL);
+	if (!new_ifalias)
 		return -ENOMEM;
+	dev->ifalias = new_ifalias;
 
 	strlcpy(dev->ifalias, alias, len+1);
 	return len;
-- 
1.7.9.5

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

* Re: [PATCH] net/core: Fix potential memory leak in dev_set_alias()
  2012-08-08 10:33 [PATCH] net/core: Fix potential memory leak in dev_set_alias() Alexey Khoroshilov
@ 2012-08-08 23:07 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2012-08-08 23:07 UTC (permalink / raw)
  To: khoroshilov; +Cc: edumazet, netdev, linux-kernel, ldv-project

From: Alexey Khoroshilov <khoroshilov@ispras.ru>
Date: Wed,  8 Aug 2012 14:33:25 +0400

> Do not leak memory by updating pointer with potentially NULL realloc return value.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>

Applied, thanks.

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

end of thread, other threads:[~2012-08-08 23:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-08 10:33 [PATCH] net/core: Fix potential memory leak in dev_set_alias() Alexey Khoroshilov
2012-08-08 23:07 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).