Re: "selinux: support distinctions among all network address families" causing existing bluetooth sepolicies to not work properly with Android?
From: Stephen Smalley
Date: Wed Jun 07 2017 - 08:36:17 EST
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.