lkml.org 
[lkml]   [2014]   [Apr]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH] decnet: fix possible NULL deref in dnet_select_source()
From
Date
From: Eric Dumazet <edumazet@google.com>

dnet_select_source() should make sure dn_ptr is not NULL.

While looking at this decnet code, I believe I found a device
reference leak, lets fix it as well.

Reported-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
It seems this bug is very old, no recent change is involved.

net/decnet/dn_route.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index ce0cbbfe0f43..4d1608dfb0bd 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -923,6 +923,8 @@ static __le16 dnet_select_source(const struct net_device *dev, __le16 daddr, int

rcu_read_lock();
dn_db = rcu_dereference(dev->dn_ptr);
+ if (!dn_db)
+ goto out;
for (ifa = rcu_dereference(dn_db->ifa_list);
ifa != NULL;
ifa = rcu_dereference(ifa->ifa_next)) {
@@ -938,6 +940,7 @@ static __le16 dnet_select_source(const struct net_device *dev, __le16 daddr, int
if (best_match == 0)
saddr = ifa->ifa_local;
}
+out:
rcu_read_unlock();

return saddr;
@@ -1034,7 +1037,6 @@ source_ok:
if (dev_out)
dev_put(dev_out);
dev_out = init_net.loopback_dev;
- dev_hold(dev_out);
if (!fld.daddr) {
fld.daddr =
fld.saddr = dnet_select_source(dev_out, 0,
@@ -1042,6 +1044,7 @@ source_ok:
if (!fld.daddr)
goto out;
}
+ dev_hold(dev_out);
fld.flowidn_oif = LOOPBACK_IFINDEX;
res.type = RTN_LOCAL;
goto make_route;



\
 
 \ /
  Last update: 2014-04-07 00:41    [W:0.042 / U:6.608 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site