* [PATCH 8/9] bpf: Check address length before reading address family
@ 2019-04-12 10:55 Tetsuo Handa
2019-04-12 16:19 ` Alexei Starovoitov
2019-04-12 17:26 ` David Miller
0 siblings, 2 replies; 4+ messages in thread
From: Tetsuo Handa @ 2019-04-12 10:55 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann; +Cc: David S. Miller, netdev, Tetsuo Handa
KMSAN will complain if valid address length passed to bpf_bind() is
shorter than sizeof("struct sockaddr"->sa_family) bytes.
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
net/core/filter.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/core/filter.c b/net/core/filter.c
index 41f633cf4fc1..b9089fda4367 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4458,6 +4458,8 @@ BPF_CALL_3(bpf_bind, struct bpf_sock_addr_kern *, ctx, struct sockaddr *, addr,
* Only binding to IP is supported.
*/
err = -EINVAL;
+ if (addr_len < offsetofend(struct sockaddr, sa_family))
+ return err;
if (addr->sa_family == AF_INET) {
if (addr_len < sizeof(struct sockaddr_in))
return err;
--
2.16.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 8/9] bpf: Check address length before reading address family
2019-04-12 10:55 [PATCH 8/9] bpf: Check address length before reading address family Tetsuo Handa
@ 2019-04-12 16:19 ` Alexei Starovoitov
2019-04-12 16:51 ` Andrey Ignatov
2019-04-12 17:26 ` David Miller
1 sibling, 1 reply; 4+ messages in thread
From: Alexei Starovoitov @ 2019-04-12 16:19 UTC (permalink / raw)
To: Tetsuo Handa
Cc: Alexei Starovoitov, Daniel Borkmann, David S. Miller,
Network Development, Andrey Ignatov
On Fri, Apr 12, 2019 at 3:56 AM Tetsuo Handa
<penguin-kernel@i-love.sakura.ne.jp> wrote:
>
> KMSAN will complain if valid address length passed to bpf_bind() is
> shorter than sizeof("struct sockaddr"->sa_family) bytes.
>
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> ---
> net/core/filter.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 41f633cf4fc1..b9089fda4367 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -4458,6 +4458,8 @@ BPF_CALL_3(bpf_bind, struct bpf_sock_addr_kern *, ctx, struct sockaddr *, addr,
> * Only binding to IP is supported.
> */
> err = -EINVAL;
> + if (addr_len < offsetofend(struct sockaddr, sa_family))
> + return err;
the verifier will check that addr_len is not zero,
but it can be one byte, so it's a good check.
Thanks!
> if (addr->sa_family == AF_INET) {
> if (addr_len < sizeof(struct sockaddr_in))
> return err;
> --
> 2.16.5
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 8/9] bpf: Check address length before reading address family
2019-04-12 16:19 ` Alexei Starovoitov
@ 2019-04-12 16:51 ` Andrey Ignatov
0 siblings, 0 replies; 4+ messages in thread
From: Andrey Ignatov @ 2019-04-12 16:51 UTC (permalink / raw)
To: Tetsuo Handa, Alexei Starovoitov
Cc: Alexei Starovoitov, Daniel Borkmann, David S. Miller,
Network Development
Alexei Starovoitov <alexei.starovoitov@gmail.com> [Fri, 2019-04-12 09:20 -0700]:
> On Fri, Apr 12, 2019 at 3:56 AM Tetsuo Handa
> <penguin-kernel@i-love.sakura.ne.jp> wrote:
> >
> > KMSAN will complain if valid address length passed to bpf_bind() is
> > shorter than sizeof("struct sockaddr"->sa_family) bytes.
> >
> > Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> > ---
> > net/core/filter.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/net/core/filter.c b/net/core/filter.c
> > index 41f633cf4fc1..b9089fda4367 100644
> > --- a/net/core/filter.c
> > +++ b/net/core/filter.c
> > @@ -4458,6 +4458,8 @@ BPF_CALL_3(bpf_bind, struct bpf_sock_addr_kern *, ctx, struct sockaddr *, addr,
> > * Only binding to IP is supported.
> > */
> > err = -EINVAL;
> > + if (addr_len < offsetofend(struct sockaddr, sa_family))
> > + return err;
>
> the verifier will check that addr_len is not zero,
> but it can be one byte, so it's a good check.
> Thanks!
True, I missed this corner-case. Thanks for fixing.
Acked-by: Andrey Ignatov <rdna@fb.com>
> > if (addr->sa_family == AF_INET) {
> > if (addr_len < sizeof(struct sockaddr_in))
> > return err;
> > --
> > 2.16.5
> >
--
Andrey Ignatov
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 8/9] bpf: Check address length before reading address family
2019-04-12 10:55 [PATCH 8/9] bpf: Check address length before reading address family Tetsuo Handa
2019-04-12 16:19 ` Alexei Starovoitov
@ 2019-04-12 17:26 ` David Miller
1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2019-04-12 17:26 UTC (permalink / raw)
To: penguin-kernel; +Cc: ast, daniel, netdev
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Date: Fri, 12 Apr 2019 19:55:47 +0900
> KMSAN will complain if valid address length passed to bpf_bind() is
> shorter than sizeof("struct sockaddr"->sa_family) bytes.
>
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Applied.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-04-12 17:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-12 10:55 [PATCH 8/9] bpf: Check address length before reading address family Tetsuo Handa
2019-04-12 16:19 ` Alexei Starovoitov
2019-04-12 16:51 ` Andrey Ignatov
2019-04-12 17:26 ` David Miller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.