2012-08-08 10:34:28

by Alexey Khoroshilov

[permalink] [raw]
Subject: [PATCH] net/core: Fix potential memory leak in dev_set_alias()

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 <[email protected]>
---
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


2012-08-08 23:07:08

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] net/core: Fix potential memory leak in dev_set_alias()

From: Alexey Khoroshilov <[email protected]>
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 <[email protected]>

Applied, thanks.