linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Smalley <sds@tycho.nsa.gov>
To: John Stultz <john.stultz@linaro.org>, Paul Moore <paul@paul-moore.com>
Cc: Jeffrey Vander Stoep <jeffv@google.com>,
	Android Kernel Team <kernel-team@android.com>,
	Nick Kralevich <nnk@google.com>,
	lkml <linux-kernel@vger.kernel.org>,
	Satish Patel <satish.patel@linaro.org>,
	Rob Herring <rob.herring@linaro.org>
Subject: Re: "selinux: support distinctions among all network address families" causing existing bluetooth sepolicies to not work properly with Android?
Date: Wed, 07 Jun 2017 10:44:27 -0400	[thread overview]
Message-ID: <1496846667.15470.6.camel@tycho.nsa.gov> (raw)
In-Reply-To: <1496839230.15470.1.camel@tycho.nsa.gov>

On Wed, 2017-06-07 at 08:40 -0400, Stephen Smalley wrote:
> On Tue, 2017-06-06 at 17:45 -0700, John Stultz wrote:
> > Hey folks,
> > 
> > Recently I was working to validate/enable a new bluetooth HAL on
> > HiKey
> > with Android, and after getting it working properly with a 4.9
> > based
> > kernel, I found that I was seeing failures trying to run with an
> > upstream (4.12-rc3 based) kernel.
> > 
> > It seemed a call to:
> >    socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
> > 
> > was suddenly failing, and running "setenforce 0" would allow it to
> > continue properly.
> > 
> > I chased the issue down to  da69a5306ab9 ("selinux: support
> > distinctions among all network address families"). And work around
> > it
> > with the following (whitespace corrupted, sorry) hack:
> > 
> > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > index e67a526..42dfd0f 100644
> > --- a/security/selinux/hooks.c
> > +++ b/security/selinux/hooks.c
> > @@ -1379,8 +1379,8 @@ static inline u16
> > socket_type_to_security_class(int family, int type, int protoc
> >                         return SECCLASS_CAN_SOCKET;
> >                 case PF_TIPC:
> >                         return SECCLASS_TIPC_SOCKET;
> > -               case PF_BLUETOOTH:
> > -                       return SECCLASS_BLUETOOTH_SOCKET;
> > +//             case PF_BLUETOOTH:
> > +//                     return SECCLASS_BLUETOOTH_SOCKET;
> >                 case PF_IUCV:
> >                         return SECCLASS_IUCV_SOCKET;
> >                 case PF_RXRPC:
> > 
> > Obviously this isn't ideal. The commit message claims that "
> > Backward
> > compatibility is provided by only enabling the finer-grained socket
> > classes if a new policy capability is set in the policy; older
> > policies will behave as before."
> > 
> > Which makes it seem like the older sepolicy should be fine with
> > newer
> > kernels, but this doesn't seem to be the case here? Am I missing
> > something? Is Android doing something odd with their POLICYDB that
> > is
> > causing the kernel to think the sepolicy is newer?
> 
> The code above is only enabled if the policy enables the
> extended_socket_class policy capability.  I added that to AOSP policy
> in 431bdd9f2f344ecde4cd3fe0109bd70eab0a394c.  The correct fix is not
> to
> change the kernel but rather to add allow rules to policy for the
> finer-grained socket classes.  Your dmesg or logcat output will show
> you the denials, and audit2allow can help with an initial cut at
> rules,
> although you should refine them to use the macros and, where
> appropriate, attributes.

To elaborate a bit further: the backward compatibility provision is for
policies that predate the introduction of the extended_socket_class
policy capability or that do not opt into it.  Thus, for example,
Android N and earlier had policies that did not define this capability
and therefore will fall back to the old behavior and remain compatible.
 Android O appears to have included the aforementioned sepolicy commit
from AOSP master and therefore has opted into this functionality and
must provide appropriate allow rules for it when using a kernel that
includes this functionality. To do so, one needs to review all allow
rules on 'socket' and duplicate them with allow rules on the more
specific per-address-family security classes that are required (which
can be determined either through testing or code examination). 
Eventually, the original rules on the generic 'socket' class can be
removed from sepolicy entirely, but not until support for older kernels
that predate this capability is no longer needed.  One also needs to
review all allow rules on rawip_socket and determine whether they
should be duplicated for sctp_socket and/or icmp_socket if the program
was in fact using a SCTP or an unprivileged ICMP (ping) socket.

  reply	other threads:[~2017-06-07 14:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-07  0:45 "selinux: support distinctions among all network address families" causing existing bluetooth sepolicies to not work properly with Android? John Stultz
2017-06-07 12:40 ` Stephen Smalley
2017-06-07 14:44   ` Stephen Smalley [this message]
2017-06-07 19:40     ` John Stultz

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=1496846667.15470.6.camel@tycho.nsa.gov \
    --to=sds@tycho.nsa.gov \
    --cc=jeffv@google.com \
    --cc=john.stultz@linaro.org \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nnk@google.com \
    --cc=paul@paul-moore.com \
    --cc=rob.herring@linaro.org \
    --cc=satish.patel@linaro.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).