From: Paul Moore <paul@paul-moore.com>
To: Nazarov Sergey <s-nazarov@yandex.ru>
Cc: linux-security-module@vger.kernel.org, selinux@vger.kernel.org,
netdev@vger.kernel.org, Casey Schaufler <casey@schaufler-ca.com>
Subject: Re: Kernel memory corruption in CIPSO labeled TCP packets processing.
Date: Fri, 18 Jan 2019 09:53:31 -0500 [thread overview]
Message-ID: <CAHC9VhTEUzjd=Wk1y0Jjq8y0-xUf-8nVY727KRBD3z6APuQKfw@mail.gmail.com> (raw)
In-Reply-To: <CAHC9VhTNnEpOito2b6ARFseCXcSw+kSE0erKhikd6FfwwBYppA@mail.gmail.com>
On Tue, Jan 15, 2019 at 2:52 PM Paul Moore <paul@paul-moore.com> wrote:
> On Tue, Jan 15, 2019 at 12:55 PM Casey Schaufler <casey@schaufler-ca.com> wrote:
> > On 1/15/2019 9:06 AM, Nazarov Sergey wrote:
> > > Hello!
> > > Security modules (selinux, smack) use icmp_send for discarded incorrectly labeled network packets.
> > > This could be on TCP level too (security_sock_rcv_skb -> cipso_v4_error for INET stream connection, for example).
> > > icmp_send calls ip_option_echo, which uses IPCB to take compiled IP options.
> > > After moving IP header data to the end of the struct tcp_skb_cb (since 3.18 kernel), this could lead to
> > > kernel memory corruption when IP options copying.
> >
> > Can you explain how that corruption might occur?
> > Do you have a test case?
>
> Thanks for pointing this out Nazarov.
>
> Presumably we are going to hit a problem whenever icmp_send is called
> from outside the IP layer in the stack. We fixed a similar problem a
> few years back with 04f81f0154e4 ("cipso: don't use IPCB() to locate
> the CIPSO IP option").
>
> I've CC'd netdev, as I'm guessing they will have some thoughts on
> this, but my initial reaction is that your proposed patch isn't as
> generic as it should be for code that lives in icmp_send(). I suspect
> the safe thing to do would be to call ip_options_compile() again on
> skb_in and build a local copy of the ip_options struct that could then
> be used in the call to __ip_options_echo(); the code could either live
> in icmp_send() or some new ip_options_echo() variant
> (ip_options_echo_safe()? I dunno). Unfortunately, calling
> ip_options_compile() is going to add some overhead, and may be a
> non-starter for the netdev folks, but this is error path code, so it
> might be acceptable. Hopefully the netdev folks will have some
> better, more clever suggestions.
It's been a few days now with no comments from the netdev folks, so I
think it's probably best to start putting together a RFC patch for
review/comment. Nazarov, would you like to do that? If not, that's
okay, just let me know.
I'm still concerned about calling ip_options_compile() in icmp_send()
and I'm thinking we might be better off to add a new ip_options
parameter to icmp_send(); if the parameter is NULL we behave as we do
today, but if it is non-NULL we use the given ip_options parameter in
place of calling ip_options_echo(). With that change in place, we
would need to update cipso_v4_error() to do the extra work of calling
ip_options_compile() and __ip_options_echo(). There looks to be maybe
a dozen (or two?) existing icmp_send() callers, but it should be
pretty trivial to update them to pass NULL for the new parameter.
What do you think?
> > > This patch fix a bug, but I'm not sure, that this is a best solution. Perhaps someone more familiar with the
> > > linux TCP/IP stack will offer a better one.
> > > Thanks.
> > >
> > > --- a/net/ipv4/icmp.c
> > > +++ b/net/ipv4/icmp.c
> > > @@ -679,7 +679,8 @@ void icmp_send(struct sk_buff *skb_in, i
> > > iph->tos;
> > > mark = IP4_REPLY_MARK(net, skb_in->mark);
> > >
> > > - if (ip_options_echo(&icmp_param->replyopts.opt.opt, skb_in))
> > > + if (__ip_options_echo(&icmp_param->replyopts.opt.opt, skb_in,
> > > + ip_hdr(skb_in)->protocol == IPPROTO_TCP ? &TCP_SKB_CB(skb_in)->header.h4.opt : &IPCB(skb_in)->opt))
> > > goto out_unlock;
> > >
> > >
--
paul moore
www.paul-moore.com
next prev parent reply other threads:[~2019-01-18 14:53 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <16659801547571984@sas1-890ba5c2334a.qloud-c.yandex.net>
[not found] ` <1378e106-1826-2ab4-a3b1-88b57cee8497@schaufler-ca.com>
2019-01-15 19:52 ` Kernel memory corruption in CIPSO labeled TCP packets processing Paul Moore
2019-01-18 14:53 ` Paul Moore [this message]
2019-01-18 16:34 ` Nazarov Sergey
2019-01-18 17:17 ` Paul Moore
2019-01-21 17:11 ` Nazarov Sergey
2019-01-22 16:49 ` Paul Moore
2019-01-22 17:35 ` Nazarov Sergey
2019-01-22 17:48 ` Paul Moore
2019-01-24 14:46 ` Nazarov Sergey
2019-01-25 16:45 ` Paul Moore
2019-01-28 13:10 ` Nazarov Sergey
2019-01-28 22:18 ` Paul Moore
2019-01-29 7:23 ` Nazarov Sergey
2019-01-29 22:42 ` Paul Moore
2019-01-30 13:11 ` Nazarov Sergey
2019-01-31 2:10 ` Paul Moore
2019-01-31 13:20 ` Nazarov Sergey
2019-02-11 20:37 ` Paul Moore
2019-02-11 21:21 ` Nazarov Sergey
2019-02-11 23:43 ` Paul Moore
2019-02-12 15:10 ` [PATCH] NETWORKING: avoid use IPCB in cipso_v4_error Nazarov Sergey
2019-02-13 21:41 ` Paul Moore
2019-02-14 18:00 ` Nazarov Sergey
2019-02-14 18:59 ` Stephen Smalley
2019-02-14 16:43 ` David Miller
2019-02-14 18:14 ` Nazarov Sergey
2019-02-15 19:02 ` Paul Moore
2019-02-15 20:00 ` David Miller
2019-02-15 20:04 ` Paul Moore
2019-02-18 13:39 ` Nazarov Sergey
2019-02-19 1:25 ` David Miller
2019-02-22 16:35 ` Nazarov Sergey
2019-02-22 17:39 ` [PATCH v2 0/2] " Nazarov Sergey
2019-02-25 1:33 ` David Miller
2019-02-25 16:24 ` [PATCH v2 1/2] " Nazarov Sergey
2019-02-25 22:07 ` Paul Moore
2019-02-25 22:33 ` David Miller
2019-02-25 23:30 ` Paul Moore
2019-02-25 16:27 ` [PATCH v2 2/2] " Nazarov Sergey
2019-02-25 22:06 ` Paul Moore
2019-02-25 22:34 ` David Miller
2019-02-22 17:43 ` [PATCH v2 1/2] " Nazarov Sergey
2019-02-22 17:50 ` [PATCH v2 2/2] " Nazarov Sergey
2019-02-25 1:33 ` [PATCH] " David Miller
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='CAHC9VhTEUzjd=Wk1y0Jjq8y0-xUf-8nVY727KRBD3z6APuQKfw@mail.gmail.com' \
--to=paul@paul-moore.com \
--cc=casey@schaufler-ca.com \
--cc=linux-security-module@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=s-nazarov@yandex.ru \
--cc=selinux@vger.kernel.org \
/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).