SELinux Archive on lore.kernel.org
 help / color / Atom feed
From: Dmitry Vyukov <dvyukov@google.com>
To: Paul Moore <paul@paul-moore.com>,
	David Miller <davem@davemloft.net>,
	kuba@kernel.org, netdev <netdev@vger.kernel.org>
Cc: Stephen Smalley <stephen.smalley.work@gmail.com>,
	Eric Paris <eparis@parisplace.org>,
	selinux@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
	syzkaller <syzkaller@googlegroups.com>,
	Willem de Bruijn <willemb@google.com>
Subject: Re: selinux_netlink_send changes program behavior
Date: Sat, 25 Apr 2020 07:14:52 +0200
Message-ID: <CACT4Y+b8HiV6KFuAPysZD=5hmyO4QisgxCKi4DHU3CfMPSP=yg@mail.gmail.com> (raw)
In-Reply-To: <CAHC9VhQs6eJpX4oMrhBiDap-HhEsBBgmYWEou=ZH60YiA__T7w@mail.gmail.com>

On Fri, Apr 24, 2020 at 11:51 PM Paul Moore <paul@paul-moore.com> wrote:
>
> On Fri, Apr 24, 2020 at 4:27 AM Dmitry Vyukov <dvyukov@google.com> wrote:
> > Hi SELinux maintainers,
> >
> > We've hit a case where a developer wasn't able to reproduce a kernel
> > bug, it turned out to be a difference in behavior between SELinux and
> > non-SELinux kernels.
> > Condensed version: a program does sendmmsg on netlink socket with 2
> > mmsghdr's, first is completely empty/zeros, second contains some
> > actual payload. Without SELinux the first mmsghdr is treated as no-op
> > and the kernel processes the second one (triggers bug). However the
> > SELinux hook does:
> >
> > static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb)
> > {
> >     if (skb->len < NLMSG_HDRLEN) {
> >         err = -EINVAL;
> >         goto out;
> >     }
> >
> > and fails processing on the first empty mmsghdr (does not happen
> > without SELinux).
> >
> > Is this difference in behavior intentional/acceptable/should be fixed?
>
> From a practical perspective, SELinux is always going to need to do a
> length check as it needs to peek into the netlink message header for
> the message type so it can map that to the associated SELinux
> permissions.  So in that sense, the behavior is intentional and
> desired; however from a bug-for-bug compatibility perspective ... not
> so much.
>
> Ultimately, my it's-Friday-and-it's-been-a-long-week-ending-in-a-long-day
> thought is that this was a buggy operation to begin with and the bug
> was just caught in different parts of the kernel, depending on how it
> was configured.  It may not be ideal, but I can think of worse things
> (and arguably SELinux is doing the Right Thing).

+netlink maintainers for intended semantics of empty netlink messages

If it's a bug, or intended behavior depends on the intended
behavior... which I assume is not documented anywhere officially.
However, most of the netlink families use netlink_rcv_skb, which does:

int netlink_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *,
                           struct nlmsghdr *,
                           struct netlink_ext_ack *))
{
    ...
    while (skb->len >= nlmsg_total_size(0)) {
    ...
       skb_pull(skb, msglen);
    }
    return 0;
}

1. How intentional is this while loop logic vs sloppy error checking?
2. netlink_rcv_skb seems to be able to handle 2+ messages in the same
skb, while selinux_netlink_send only checks the first one... so can I
skip SELinux checks by putting a malicious message after a permitted
one?..

  reply index

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-24  8:27 Dmitry Vyukov
2020-04-24 21:51 ` Paul Moore
2020-04-25  5:14   ` Dmitry Vyukov [this message]
2020-04-25 11:42     ` Paul Moore
2020-04-25 12:00       ` Dmitry Vyukov
2020-04-28  1:53         ` Paul Moore

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='CACT4Y+b8HiV6KFuAPysZD=5hmyO4QisgxCKi4DHU3CfMPSP=yg@mail.gmail.com' \
    --to=dvyukov@google.com \
    --cc=davem@davemloft.net \
    --cc=eparis@parisplace.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=selinux@vger.kernel.org \
    --cc=stephen.smalley.work@gmail.com \
    --cc=syzkaller@googlegroups.com \
    --cc=willemb@google.com \
    /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

SELinux Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/selinux/0 selinux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 selinux selinux/ https://lore.kernel.org/selinux \
		selinux@vger.kernel.org
	public-inbox-index selinux

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.selinux


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git