* [PATCH] net: geneve: Fix a possible null-pointer dereference in geneve_link_config()
@ 2019-07-29 10:26 Jia-Ju Bai
2019-07-29 10:30 ` Jiri Benc
0 siblings, 1 reply; 3+ messages in thread
From: Jia-Ju Bai @ 2019-07-29 10:26 UTC (permalink / raw)
To: davem, sbrivio, sd, liuhangbin, jbenc, dsahern, natechancellor, tglx
Cc: netdev, linux-kernel, Jia-Ju Bai
In geneve_link_config(), there is an if statement on line 1524 to check
whether rt is NULL:
if (rt && rt->dst.dev)
When rt is NULL, it is used on line 1526:
ip6_rt_put(rt)
dst_release(&rt->dst);
Thus, a possible null-pointer dereference may occur.
To fix this bug, ip6_rt_put(rt) is called when rt is not NULL.
This bug is found by a static analysis tool STCheck written by us.
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
drivers/net/geneve.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
index cb2ea8facd8d..a47a1b31b166 100644
--- a/drivers/net/geneve.c
+++ b/drivers/net/geneve.c
@@ -1521,9 +1521,10 @@ static void geneve_link_config(struct net_device *dev,
rt = rt6_lookup(geneve->net, &info->key.u.ipv6.dst, NULL, 0,
NULL, 0);
- if (rt && rt->dst.dev)
+ if (rt && rt->dst.dev) {
ldev_mtu = rt->dst.dev->mtu - GENEVE_IPV6_HLEN;
- ip6_rt_put(rt);
+ ip6_rt_put(rt);
+ }
break;
}
#endif
--
2.17.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: geneve: Fix a possible null-pointer dereference in geneve_link_config()
2019-07-29 10:26 [PATCH] net: geneve: Fix a possible null-pointer dereference in geneve_link_config() Jia-Ju Bai
@ 2019-07-29 10:30 ` Jiri Benc
2019-07-29 10:52 ` Jiri Benc
0 siblings, 1 reply; 3+ messages in thread
From: Jiri Benc @ 2019-07-29 10:30 UTC (permalink / raw)
To: Jia-Ju Bai
Cc: davem, sbrivio, sd, liuhangbin, dsahern, natechancellor, tglx,
netdev, linux-kernel
On Mon, 29 Jul 2019 18:26:11 +0800, Jia-Ju Bai wrote:
> --- a/drivers/net/geneve.c
> +++ b/drivers/net/geneve.c
> @@ -1521,9 +1521,10 @@ static void geneve_link_config(struct net_device *dev,
> rt = rt6_lookup(geneve->net, &info->key.u.ipv6.dst, NULL, 0,
> NULL, 0);
>
> - if (rt && rt->dst.dev)
> + if (rt && rt->dst.dev) {
> ldev_mtu = rt->dst.dev->mtu - GENEVE_IPV6_HLEN;
> - ip6_rt_put(rt);
> + ip6_rt_put(rt);
> + }
> break;
> }
> #endif
Are you sure rt6_lookup can never return a non-NULL rt with rt->dst.dev
being NULL? You'd leak the reference in such case.
Jiri
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: geneve: Fix a possible null-pointer dereference in geneve_link_config()
2019-07-29 10:30 ` Jiri Benc
@ 2019-07-29 10:52 ` Jiri Benc
0 siblings, 0 replies; 3+ messages in thread
From: Jiri Benc @ 2019-07-29 10:52 UTC (permalink / raw)
To: Jia-Ju Bai
Cc: davem, sbrivio, sd, liuhangbin, dsahern, natechancellor, tglx,
netdev, linux-kernel
On Mon, 29 Jul 2019 12:30:55 +0200, Jiri Benc wrote:
> Are you sure rt6_lookup can never return a non-NULL rt with rt->dst.dev
> being NULL? You'd leak the reference in such case.
In fact, you're introducing a bug, not fixing one. ip6_rt_put does
accept NULL parameter. And it seems you already have been told that?
Nacked-by: Jiri Benc <jbenc@redhat.com>
Jiri
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-07-29 10:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-29 10:26 [PATCH] net: geneve: Fix a possible null-pointer dereference in geneve_link_config() Jia-Ju Bai
2019-07-29 10:30 ` Jiri Benc
2019-07-29 10:52 ` Jiri Benc
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).