Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751367AbdFGOkk (ORCPT ); Wed, 7 Jun 2017 10:40:40 -0400 Received: from emsm-gh1-uea11.nsa.gov ([8.44.101.9]:52296 "EHLO emsm-gh1-uea11.nsa.gov" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750975AbdFGOkO (ORCPT ); Wed, 7 Jun 2017 10:40:14 -0400 X-IronPort-AV: E=Sophos;i="5.39,311,1493683200"; d="scan'208";a="6438502" IronPort-PHdr: =?us-ascii?q?9a23=3A2xv5qhxAbFCV13DXCy+O+j09IxM/srCxBDY+r6Qd?= =?us-ascii?q?0ugSKPad9pjvdHbS+e9qxAeQG96KtLQa0qGJ7ujJYi8p2d65qncMcZhBBVcuqP?= =?us-ascii?q?49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6?= =?us-ascii?q?JvjvGo7Vks+7y/2+94fdbghMhjexe7J/IAi5oQjTtsQdnJdvJLs2xhbVuHVDZv?= =?us-ascii?q?5YxXlvJVKdnhb84tm/8Zt++ClOuPwv6tBNX7zic6s3UbJXAjImM3so5MLwrhnM?= =?us-ascii?q?URGP5noHXWoIlBdDHhXI4wv7Xpf1tSv6q/Z91SyHNsD4Ubw4RTKv5LpwRRT2lC?= =?us-ascii?q?kIKSI28GDPisxxkq1bpg6hpwdiyILQeY2ZKeZycr/Ycd4cS2VBRMJRXDFfDI26?= =?us-ascii?q?YYUEEu4NMf9Go4XholcDqwa1CwuxC+P10jJGhWL4060k3eovEw7G0gsgEM4Jvn?= =?us-ascii?q?vbo9v4L7sSXOOvwaXU1zjPc/Fb1DHg44bIaBAhpvSMUKptf8rN10YvDwPFgUuW?= =?us-ascii?q?qYf4Ij2V0/4Cs2yf7+V+VeOklmkqqxpsrTi03coslonIiZ4VylDD7yl5xp01Ks?= =?us-ascii?q?eiRE50Zt6kDoJduieHPIV1WsMvW3xktSk1x7EcuZO3YTIG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ascii?q?Tkl89B2Xa1Fzn+63/R4Tw+eAVvcPzJoAuSEosTIyG0yyiZaeM9Odo0JEe6JGbJ?= =?us-ascii?q?tp+F5a0UrBvhF5e5mnKLpvwFUZdlIkkVnp0kBMFohYkcUs5EgvxQ52JLPQhEhN?= =?us-ascii?q?bBuEzJvwPfvRMWC08xexPf2FkmrC2cqbr/9coM8zrE/u6UTwTBIv?= X-IPAS-Result: =?us-ascii?q?A2G3AgA1DzhZ/wHyM5BeGgEBAQECAQEBAQgBAQEBFQEBAQE?= =?us-ascii?q?CAQEBAQgBAQEBgwACK4Vimk0BAQEBAQEGgSeYEIYkAoJ0VwEBAQEBAQEBAgECa?= =?us-ascii?q?CiCMyQBgkEBBSMPAUYQCQINCwICHwcCAlcGAYgdghMNkHydYIImJgKLVwEBAQE?= =?us-ascii?q?BAQQBAQEBAQEigQuFEIImgyCHfIJhBZZxh0iTOIsmgSyFLpRnWIEKJwkCHwghD?= =?us-ascii?q?4VNHBmBaCSHSyuCEgEBAQ?= Message-ID: <1496846667.15470.6.camel@tycho.nsa.gov> Subject: Re: "selinux: support distinctions among all network address families" causing existing bluetooth sepolicies to not work properly with Android? From: Stephen Smalley To: John Stultz , Paul Moore Cc: Jeffrey Vander Stoep , Android Kernel Team , Nick Kralevich , lkml , Satish Patel , Rob Herring Date: Wed, 07 Jun 2017 10:44:27 -0400 In-Reply-To: <1496839230.15470.1.camel@tycho.nsa.gov> References: <1496839230.15470.1.camel@tycho.nsa.gov> Organization: National Security Agency Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6 (3.22.6-2.fc25) Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4048 Lines: 81 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.