From: Eric Dumazet <edumazet@google.com>
To: Alexander Potapenko <glider@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>,
Kostya Serebryany <kcc@google.com>,
Kees Cook <keescook@chromium.org>,
Paul Moore <paul@paul-moore.com>,
sds@tycho.nsa.gov, LKML <linux-kernel@vger.kernel.org>,
netdev <netdev@vger.kernel.org>,
selinux@tycho.nsa.gov
Subject: Re: [PATCH] selinux: check for address length in selinux_socket_bind()
Date: Fri, 3 Mar 2017 09:35:49 -0800 [thread overview]
Message-ID: <CANn89i+RB0o98-uVPTMfx919T8M+X0AGt7U636O6ERK=685gsQ@mail.gmail.com> (raw)
In-Reply-To: <20170303172330.83421-1-glider@google.com>
On Fri, Mar 3, 2017 at 9:23 AM, Alexander Potapenko <glider@google.com> wrote:
> This happens because bind() unconditionally copies |size| bytes of
> |addr| to the kernel, leaving the rest uninitialized. Then
> security_socket_bind() reads the IP address bytes, including the
> uninitialized ones, to determine the port, or e.g. pass them further to
> sel_netnode_find(), which uses them to calculate a hash.
>
> Signed-off-by: Alexander Potapenko <glider@google.com>
> ---
> security/selinux/hooks.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index 0a4b4b040e0a..eba54489b11b 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -4351,10 +4351,19 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
> u32 sid, node_perm;
>
> if (family == PF_INET) {
> + if (addrlen != sizeof(struct sockaddr_in)) {
Please take a look at inet_bind()
The correct test would be :
if (addrlen < sizeof(struct sockaddr_in))
err = -EINVAL;
...
> + err = -EINVAL;
> + goto out;
> + }
> addr4 = (struct sockaddr_in *)address;
> snum = ntohs(addr4->sin_port);
> addrp = (char *)&addr4->sin_addr.s_addr;
> +
> } else {
> + if (addrlen != sizeof(struct sockaddr_in6)) {
Look at inet6_bind()
if (addrlen < SIN6_LEN_RFC2133)
> + err = -EINVAL;
> + goto out;
> + }
> addr6 = (struct sockaddr_in6 *)address;
> snum = ntohs(addr6->sin6_port);
> addrp = (char *)&addr6->sin6_addr.s6_addr;
> --
> 2.12.0.rc1.440.g5b76565f74-goog
>
prev parent reply other threads:[~2017-03-03 18:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-03 17:23 [PATCH] selinux: check for address length in selinux_socket_bind() Alexander Potapenko
2017-03-03 17:26 ` Alexander Potapenko
2017-03-03 17:35 ` Eric Dumazet [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CANn89i+RB0o98-uVPTMfx919T8M+X0AGt7U636O6ERK=685gsQ@mail.gmail.com' \
--to=edumazet@google.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=kcc@google.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=sds@tycho.nsa.gov \
--cc=selinux@tycho.nsa.gov \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).