* [PATCH] netlink: fix null pointer dereference on nlk->groups
@ 2016-01-08 5:46 Baozeng Ding
2016-01-08 19:43 ` Sergei Shtylyov
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Baozeng Ding @ 2016-01-08 5:46 UTC (permalink / raw)
To: davem, herbert, daniel, tgraf, pablo, chamaken, nicolas.dichtel,
fw
Cc: netdev, Baozeng Ding
If groups is not 0 and nlk->groups is NULL, it will not return
immediately and cause a null pointer dereference later.
Signed-off-by: Baozeng Ding <sploving1@gmail.com>
---
net/netlink/af_netlink.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 59651af..38efde0 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1524,6 +1524,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,
int err;
long unsigned int groups = nladdr->nl_groups;
bool bound;
+ unsigned long nlgroups;
if (addr_len < sizeof(struct sockaddr_nl))
return -EINVAL;
@@ -1576,14 +1577,17 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,
}
}
- if (!groups && (nlk->groups == NULL || !(u32)nlk->groups[0]))
+ if (nlk->groups == NULL)
+ return 0;
+ nlgroups = nlk->groups[0];
+ if (!groups && !(u32)nlgroups)
return 0;
netlink_table_grab();
netlink_update_subscriptions(sk, nlk->subscriptions +
hweight32(groups) -
- hweight32(nlk->groups[0]));
- nlk->groups[0] = (nlk->groups[0] & ~0xffffffffUL) | groups;
+ hweight32(nlgroups));
+ nlk->groups[0] = (nlgroups & ~0xffffffffUL) | groups;
netlink_update_listeners(sk);
netlink_table_ungrab();
--
1.9.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] netlink: fix null pointer dereference on nlk->groups
2016-01-08 5:46 [PATCH] netlink: fix null pointer dereference on nlk->groups Baozeng Ding
@ 2016-01-08 19:43 ` Sergei Shtylyov
2016-01-09 15:56 ` [PATCH v2] " Baozeng Ding
2016-01-12 11:10 ` [PATCH v3] " Baozeng Ding
2 siblings, 0 replies; 8+ messages in thread
From: Sergei Shtylyov @ 2016-01-08 19:43 UTC (permalink / raw)
To: Baozeng Ding, davem, herbert, daniel, tgraf, pablo, chamaken,
nicolas.dichtel, fw
Cc: netdev
Hello.
On 01/08/2016 08:46 AM, Baozeng Ding wrote:
> If groups is not 0 and nlk->groups is NULL, it will not return
> immediately and cause a null pointer dereference later.
>
> Signed-off-by: Baozeng Ding <sploving1@gmail.com>
> ---
> net/netlink/af_netlink.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
> index 59651af..38efde0 100644
> --- a/net/netlink/af_netlink.c
> +++ b/net/netlink/af_netlink.c
[...]
> @@ -1576,14 +1577,17 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,
> }
> }
>
> - if (!groups && (nlk->groups == NULL || !(u32)nlk->groups[0]))
> + if (nlk->groups == NULL)
'!nlk->groups' is preferred in the networking code.
[...]
MBR, Sergei
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2] netlink: fix null pointer dereference on nlk->groups
2016-01-08 5:46 [PATCH] netlink: fix null pointer dereference on nlk->groups Baozeng Ding
2016-01-08 19:43 ` Sergei Shtylyov
@ 2016-01-09 15:56 ` Baozeng Ding
2016-01-11 4:27 ` David Miller
2016-01-12 11:10 ` [PATCH v3] " Baozeng Ding
2 siblings, 1 reply; 8+ messages in thread
From: Baozeng Ding @ 2016-01-09 15:56 UTC (permalink / raw)
To: sergei.shtylyov; +Cc: netdev, Baozeng Ding
If groups is not 0 and nlk->groups is NULL, it will not return
immediately and cause a null pointer dereference later.
Signed-off-by: Baozeng Ding <sploving1@gmail.com>
---
This version uses the preferred networking coding style. Thanks
for Sergei's feedback. Also the patch keeps the original author's
coding style as much as possible.
---
net/netlink/af_netlink.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 59651af..eeff14a 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1576,7 +1576,10 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,
}
}
- if (!groups && (nlk->groups == NULL || !(u32)nlk->groups[0]))
+ if (!nlk->groups)
+ return 0;
+
+ if (!groups && !(u32)nlk->groups[0])
return 0;
netlink_table_grab();
--
1.9.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2] netlink: fix null pointer dereference on nlk->groups
2016-01-09 15:56 ` [PATCH v2] " Baozeng Ding
@ 2016-01-11 4:27 ` David Miller
0 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2016-01-11 4:27 UTC (permalink / raw)
To: sploving1; +Cc: sergei.shtylyov, netdev
From: Baozeng Ding <sploving1@gmail.com>
Date: Sat, 9 Jan 2016 23:56:41 +0800
> If groups is not 0 and nlk->groups is NULL, it will not return
> immediately and cause a null pointer dereference later.
>
> Signed-off-by: Baozeng Ding <sploving1@gmail.com>
> ---
> This version uses the preferred networking coding style. Thanks
> for Sergei's feedback. Also the patch keeps the original author's
> coding style as much as possible.
Is this an actual legal state? If not, add a WARN_ON() check.
Otherwise, provide a proper OOPS log and explain how the state
can be achieved.
Thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3] netlink: fix null pointer dereference on nlk->groups
2016-01-08 5:46 [PATCH] netlink: fix null pointer dereference on nlk->groups Baozeng Ding
2016-01-08 19:43 ` Sergei Shtylyov
2016-01-09 15:56 ` [PATCH v2] " Baozeng Ding
@ 2016-01-12 11:10 ` Baozeng Ding
2016-01-12 11:15 ` Denis Kirjanov
2016-01-12 19:40 ` David Miller
2 siblings, 2 replies; 8+ messages in thread
From: Baozeng Ding @ 2016-01-12 11:10 UTC (permalink / raw)
To: davem; +Cc: netdev, Baozeng Ding
If groups is not 0 and nlk->groups is NULL, it will not return
immediately and cause a null pointer dereference later.
Signed-off-by: Baozeng Ding <sploving1@gmail.com>
---
The v3 version adds WARN_ON, suggested by David Miller. Thanks for
David's feedback.
---
net/netlink/af_netlink.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 59651af..f93d579 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1576,7 +1576,10 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,
}
}
- if (!groups && (nlk->groups == NULL || !(u32)nlk->groups[0]))
+ if (WARN_ON(!nlk->groups))
+ return 0;
+
+ if (!groups && !(u32)nlk->groups[0])
return 0;
netlink_table_grab();
--
1.9.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3] netlink: fix null pointer dereference on nlk->groups
2016-01-12 11:10 ` [PATCH v3] " Baozeng Ding
@ 2016-01-12 11:15 ` Denis Kirjanov
2016-01-12 12:00 ` Herbert Xu
2016-01-12 19:40 ` David Miller
1 sibling, 1 reply; 8+ messages in thread
From: Denis Kirjanov @ 2016-01-12 11:15 UTC (permalink / raw)
To: Baozeng Ding; +Cc: davem, netdev
On 1/12/16, Baozeng Ding <sploving1@gmail.com> wrote:
> If groups is not 0 and nlk->groups is NULL, it will not return
> immediately and cause a null pointer dereference later.
>
> Signed-off-by: Baozeng Ding <sploving1@gmail.com>
> ---
> The v3 version adds WARN_ON, suggested by David Miller. Thanks for
> David's feedback.
But can you explain how can we get to this situation?
> ---
> net/netlink/af_netlink.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
> index 59651af..f93d579 100644
> --- a/net/netlink/af_netlink.c
> +++ b/net/netlink/af_netlink.c
> @@ -1576,7 +1576,10 @@ static int netlink_bind(struct socket *sock, struct
> sockaddr *addr,
> }
> }
>
> - if (!groups && (nlk->groups == NULL || !(u32)nlk->groups[0]))
> + if (WARN_ON(!nlk->groups))
> + return 0;
> +
> + if (!groups && !(u32)nlk->groups[0])
> return 0;
>
> netlink_table_grab();
> --
> 1.9.1
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] netlink: fix null pointer dereference on nlk->groups
2016-01-12 11:15 ` Denis Kirjanov
@ 2016-01-12 12:00 ` Herbert Xu
0 siblings, 0 replies; 8+ messages in thread
From: Herbert Xu @ 2016-01-12 12:00 UTC (permalink / raw)
To: Denis Kirjanov; +Cc: sploving1, davem, netdev
Denis Kirjanov <kda@linux-powerpc.org> wrote:
> On 1/12/16, Baozeng Ding <sploving1@gmail.com> wrote:
>> If groups is not 0 and nlk->groups is NULL, it will not return
>> immediately and cause a null pointer dereference later.
>>
>> Signed-off-by: Baozeng Ding <sploving1@gmail.com>
>> ---
>> The v3 version adds WARN_ON, suggested by David Miller. Thanks for
>> David's feedback.
>
> But can you explain how can we get to this situation?
Indeed, this patch makes no sense as it stands. If groups is
not NULL, then we should have allocated nlk->groups prior to
reaching this point. If that allocation failed, then we should
have already bailed out long ago. Perhaps we have a race condition
that needs to be closed with a lock?
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] netlink: fix null pointer dereference on nlk->groups
2016-01-12 11:10 ` [PATCH v3] " Baozeng Ding
2016-01-12 11:15 ` Denis Kirjanov
@ 2016-01-12 19:40 ` David Miller
1 sibling, 0 replies; 8+ messages in thread
From: David Miller @ 2016-01-12 19:40 UTC (permalink / raw)
To: sploving1; +Cc: netdev
From: Baozeng Ding <sploving1@gmail.com>
Date: Tue, 12 Jan 2016 19:10:43 +0800
> If groups is not 0 and nlk->groups is NULL, it will not return
> immediately and cause a null pointer dereference later.
>
> Signed-off-by: Baozeng Ding <sploving1@gmail.com>
> ---
> The v3 version adds WARN_ON, suggested by David Miller. Thanks for
> David's feedback.
My feedback was also that the situation is illegal, and therefore you
have to explain to us how this can actually occur.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-01-12 19:40 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-08 5:46 [PATCH] netlink: fix null pointer dereference on nlk->groups Baozeng Ding
2016-01-08 19:43 ` Sergei Shtylyov
2016-01-09 15:56 ` [PATCH v2] " Baozeng Ding
2016-01-11 4:27 ` David Miller
2016-01-12 11:10 ` [PATCH v3] " Baozeng Ding
2016-01-12 11:15 ` Denis Kirjanov
2016-01-12 12:00 ` Herbert Xu
2016-01-12 19:40 ` 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).