* [PATCH] netlink: make sure nladdr has correct size in netlink_connect()
@ 2018-03-14 14:03 Alexander Potapenko
2018-03-14 14:11 ` Eric Dumazet
0 siblings, 1 reply; 6+ messages in thread
From: Alexander Potapenko @ 2018-03-14 14:03 UTC (permalink / raw)
To: dvyukov, edumazet, davem; +Cc: netdev, linux-kernel
KMSAN reports use of uninitialized memory in the case when |alen| is
smaller than sizeof(struct netlink_sock), and therefore |nladdr| isn't
fully copied from the userspace.
Signed-off-by: Alexander Potapenko <glider@google.com>
Fixes: 1da177e4c3f41524 ("Linux-2.6.12-rc2")
---
net/netlink/af_netlink.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 07e8478068f0..5d49b39e81c3 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1085,6 +1085,9 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr,
if (addr->sa_family != AF_NETLINK)
return -EINVAL;
+ if (alen < sizeof(struct netlink_sock))
+ return -EINVAL;
+
if ((nladdr->nl_groups || nladdr->nl_pid) &&
!netlink_allowed(sock, NL_CFG_F_NONROOT_SEND))
return -EPERM;
--
2.16.2.804.g6dcf76e118-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] netlink: make sure nladdr has correct size in netlink_connect()
2018-03-14 14:03 [PATCH] netlink: make sure nladdr has correct size in netlink_connect() Alexander Potapenko
@ 2018-03-14 14:11 ` Eric Dumazet
[not found] ` <CAG_fn=VMj0KDqr24Mx71QBZjHzJDdQi0OthA-E1YcB0q=Sk0BA@mail.gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2018-03-14 14:11 UTC (permalink / raw)
To: Alexander Potapenko; +Cc: Dmitry Vyukov, David Miller, netdev, LKML
On Wed, Mar 14, 2018 at 7:03 AM, Alexander Potapenko <glider@google.com> wrote:
> KMSAN reports use of uninitialized memory in the case when |alen| is
> smaller than sizeof(struct netlink_sock), and therefore |nladdr| isn't
> fully copied from the userspace.
>
> Signed-off-by: Alexander Potapenko <glider@google.com>
> Fixes: 1da177e4c3f41524 ("Linux-2.6.12-rc2")
> ---
> net/netlink/af_netlink.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
> index 07e8478068f0..5d49b39e81c3 100644
> --- a/net/netlink/af_netlink.c
> +++ b/net/netlink/af_netlink.c
> @@ -1085,6 +1085,9 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr,
> if (addr->sa_family != AF_NETLINK)
> return -EINVAL;
>
> + if (alen < sizeof(struct netlink_sock))
> + return -EINVAL;
> +
>
Hmmm. How was this patch tested exactly ?
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] netlink: make sure nladdr has correct size in netlink_connect()
[not found] ` <CAG_fn=VMj0KDqr24Mx71QBZjHzJDdQi0OthA-E1YcB0q=Sk0BA@mail.gmail.com>
@ 2018-03-14 14:40 ` Eric Dumazet
0 siblings, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2018-03-14 14:40 UTC (permalink / raw)
To: Alexander Potapenko; +Cc: Dmitriy Vyukov, David Miller, Networking, LKML
On Wed, Mar 14, 2018 at 7:16 AM, Alexander Potapenko <glider@google.com> wrote:
>
>
>
> On Wed, Mar 14, 2018 at 3:11 PM Eric Dumazet <edumazet@google.com> wrote:
>>
>> On Wed, Mar 14, 2018 at 7:03 AM, Alexander Potapenko <glider@google.com>
>> wrote:
>> > KMSAN reports use of uninitialized memory in the case when |alen| is
>> > smaller than sizeof(struct netlink_sock), and therefore |nladdr| isn't
>> > fully copied from the userspace.
>> >
>> > Signed-off-by: Alexander Potapenko <glider@google.com>
>> > Fixes: 1da177e4c3f41524 ("Linux-2.6.12-rc2")
>> > ---
>> > net/netlink/af_netlink.c | 3 +++
>> > 1 file changed, 3 insertions(+)
>> >
>> > diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
>> > index 07e8478068f0..5d49b39e81c3 100644
>> > --- a/net/netlink/af_netlink.c
>> > +++ b/net/netlink/af_netlink.c
>> > @@ -1085,6 +1085,9 @@ static int netlink_connect(struct socket *sock,
>> > struct sockaddr *addr,
>> > if (addr->sa_family != AF_NETLINK)
>> > return -EINVAL;
>> >
>> > + if (alen < sizeof(struct netlink_sock))
>> > + return -EINVAL;
>> > +
>> >
>>
>> Hmmm. How was this patch tested exactly ?
>
> You're absolutely right, I should have been using sizeof(sockaddr_nl).
> The reproducer that I used to trigger the bug was passing alen=2, so the
> patch still worked despite being incorrect.
> Is there any generic set of networking tests that I can use for such bugs?
There are upstream tests in tools/testing/selftests/
In your case, making sure tools like iproute2 ss are still working
would have done the job.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] netlink: make sure nladdr has correct size in netlink_connect()
2018-03-23 12:49 Alexander Potapenko
2018-03-23 12:57 ` Eric Dumazet
@ 2018-03-26 1:15 ` David Miller
1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2018-03-26 1:15 UTC (permalink / raw)
To: glider; +Cc: dvyukov, edumazet, netdev, linux-kernel
From: Alexander Potapenko <glider@google.com>
Date: Fri, 23 Mar 2018 13:49:02 +0100
> KMSAN reports use of uninitialized memory in the case when |alen| is
> smaller than sizeof(struct sockaddr_nl), and therefore |nladdr| isn't
> fully copied from the userspace.
>
> Signed-off-by: Alexander Potapenko <glider@google.com>
> Fixes: 1da177e4c3f41524 ("Linux-2.6.12-rc2")
> ---
> v2: fixed a typo spotted by Eric Dumazet
Applied and queued up for -stable, thank you.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] netlink: make sure nladdr has correct size in netlink_connect()
2018-03-23 12:49 Alexander Potapenko
@ 2018-03-23 12:57 ` Eric Dumazet
2018-03-26 1:15 ` David Miller
1 sibling, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2018-03-23 12:57 UTC (permalink / raw)
To: Alexander Potapenko, dvyukov, edumazet, davem; +Cc: netdev, linux-kernel
On 03/23/2018 05:49 AM, Alexander Potapenko wrote:
> KMSAN reports use of uninitialized memory in the case when |alen| is
> smaller than sizeof(struct sockaddr_nl), and therefore |nladdr| isn't
> fully copied from the userspace.
>
> Signed-off-by: Alexander Potapenko <glider@google.com>
> Fixes: 1da177e4c3f41524 ("Linux-2.6.12-rc2")
Reviewed-by: Eric Dumazet <edumazet@google.com>
Thanks Alexander.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] netlink: make sure nladdr has correct size in netlink_connect()
@ 2018-03-23 12:49 Alexander Potapenko
2018-03-23 12:57 ` Eric Dumazet
2018-03-26 1:15 ` David Miller
0 siblings, 2 replies; 6+ messages in thread
From: Alexander Potapenko @ 2018-03-23 12:49 UTC (permalink / raw)
To: dvyukov, edumazet, davem; +Cc: netdev, linux-kernel
KMSAN reports use of uninitialized memory in the case when |alen| is
smaller than sizeof(struct sockaddr_nl), and therefore |nladdr| isn't
fully copied from the userspace.
Signed-off-by: Alexander Potapenko <glider@google.com>
Fixes: 1da177e4c3f41524 ("Linux-2.6.12-rc2")
---
v2: fixed a typo spotted by Eric Dumazet
---
net/netlink/af_netlink.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 07e8478068f0..70c455341243 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1085,6 +1085,9 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr,
if (addr->sa_family != AF_NETLINK)
return -EINVAL;
+ if (alen < sizeof(struct sockaddr_nl))
+ return -EINVAL;
+
if ((nladdr->nl_groups || nladdr->nl_pid) &&
!netlink_allowed(sock, NL_CFG_F_NONROOT_SEND))
return -EPERM;
--
2.17.0.rc0.231.g781580f067-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-03-26 1:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-14 14:03 [PATCH] netlink: make sure nladdr has correct size in netlink_connect() Alexander Potapenko
2018-03-14 14:11 ` Eric Dumazet
[not found] ` <CAG_fn=VMj0KDqr24Mx71QBZjHzJDdQi0OthA-E1YcB0q=Sk0BA@mail.gmail.com>
2018-03-14 14:40 ` Eric Dumazet
2018-03-23 12:49 Alexander Potapenko
2018-03-23 12:57 ` Eric Dumazet
2018-03-26 1:15 ` 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).