Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50F51C433F5 for ; Tue, 16 Nov 2021 00:12:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3815B6325E for ; Tue, 16 Nov 2021 00:12:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242315AbhKPAPW (ORCPT ); Mon, 15 Nov 2021 19:15:22 -0500 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:36983 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242616AbhKOVpz (ORCPT ); Mon, 15 Nov 2021 16:45:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1637012578; bh=JLM+dQYuxLqsARbffxhy9CCQHdkq0qFjOtXJ8aRN2hc=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=kezj0zhEqdCNSddi1oM7xnc5vDVDln4nIlyRU3xPHfaytHTIN4R5KsnAfLkPdY4BUVkLk3b4g9rvzmn50P70Y9QjxUvxta4kluK0g3HOsvGHO7KvLNuOx5MmOxuBxQdk3JcHBhmYyssLW9O5dsfWDEV5Ie9v91XlOLThFEDYnfDjVN4u4xmjIhErqVobLVifcuSO+UxkT2QlS8cx6tsN6McG+SPk6d5OM06rw3r4qvP39MJGOvVllHVWVXTXDCNsvZ+UjDIeKsgCuN+DHSsAzhkyahJ7NkhypTea4au7dvO1rJG4Xcds5q4v/zeCHNoeAJlrV4mfXfziCQFhZVA3lQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1637012578; bh=W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msOnPoTAo0pv3CGXJv_ i_4Zm7LIohbgHVaURxLqBcz6mR_HEQEEgfaDunRpgmrGpIgVRiW3I7I3pZ2Qs7r0RgHcKOrNtdsW BCB9oPl6O6Vbuc7HsOz6FEWeRa4OnwmBiPJlfwNq8Tdb5AT2MrMTRHNhh.3KatOetvYXanf2wWP. XNsrk68DcsmfOGfmcYG8nUjPMm6TNdrYE63fFLkJjZUI1xMV44zT21NgrBTy705xNPaZJnDMbljT nd4kivKeUAv9HNly_phyT0g7SOWSZH4vnT5qfVlcgOX2FpoNOKh8ToAK0C5Lwo45833OZ5c_8MJP MjXE8moLhh7nqEDMOfZzRqd_Qi7FoAP7dm4iv.LR47Llh89zxehLMFZ9wHCkcIUiRafIcRBDiuxd Gy2Y5F5ke.wdsrUkFjWa244IeXiFk4ZGdzK7YSMsvcrVaQTPHizJg7hhfZZn6JYIknONSGutDFla ERNhwnbF5lBnzI0f5o3rYzOPxA9UDYf6jfTlmkgCDEdOT_Cm1GYIp4WtIWAg9v2sbnX1p.aANm7_ USpgM2L3WJeGk2YvGq6RVSg.LKWjEdimhrSyDSRLCy.N9naFFxOlhGHuLTU3kF5lk0afCtqejt0C hFkfbWToqYw-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Mon, 15 Nov 2021 21:42:58 +0000 Received: by kubenode516.mail-prod1.omega.bf1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID f245e8adb4dd8224e2af8148652e2228; Mon, 15 Nov 2021 21:42:57 +0000 (UTC) Message-ID: Date: Mon, 15 Nov 2021 13:42:54 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: [PATCH] block: Check ADMIN before NICE for IOPRIO_CLASS_RT Content-Language: en-US To: Alistair Delva , Ondrej Mosnacek Cc: Linux kernel mailing list , Khazhismel Kumykov , Bart Van Assche , Serge Hallyn , Jens Axboe , Greg Kroah-Hartman , Paul Moore , SElinux list , Linux Security Module list , "Cc: Android Kernel" , Linux Stable maillist , Casey Schaufler References: <20211115173850.3598768-1-adelva@google.com> From: Casey Schaufler In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.19306 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/15/2021 11:08 AM, Alistair Delva wrote: > On Mon, Nov 15, 2021 at 11:04 AM Ondrej Mosnacek wrote: >> On Mon, Nov 15, 2021 at 7:14 PM Alistair Delva wrote: >>> Booting to Android userspace on 5.14 or newer triggers the following >>> SELinux denial: >>> >>> avc: denied { sys_nice } for comm="init" capability=23 >>> scontext=u:r:init:s0 tcontext=u:r:init:s0 tclass=capability >>> permissive=0 >>> >>> Init is PID 0 running as root, so it already has CAP_SYS_ADMIN. For >>> better compatibility with older SEPolicy, check ADMIN before NICE. >> But with this patch you in turn punish the new/better policies that >> try to avoid giving domains CAP_SYS_ADMIN unless necessary (using only >> the more granular capabilities wherever possible), which may now get a >> bogus sys_admin denial. IMHO the order is better as it is, as it >> motivates the "good" policy writing behavior - i.e. spelling out the >> capability permissions more explicitly and avoiding CAP_SYS_ADMIN. >> >> IOW, if you domain does CAP_SYS_NICE things, and you didn't explicitly >> grant it that (and instead rely on the CAP_SYS_ADMIN fallback), then >> the denial correctly flags it as an issue in your policy and >> encourages you to add that sys_nice permission to the domain. Then >> when one beautiful hypothetical day the CAP_SYS_ADMIN fallback is >> removed, your policy will be ready for that and things will keep >> working. >> >> Feel free to carry that patch downstream if patching the kernel is >> easier for you than fixing the policy, but for the upstream kernel >> this is just a step in the wrong direction. > I'm personally fine with this position, but I am curious why "never > break userspace" doesn't apply to SELinux policies. Because SELinux policy is configuration data, not system code. One is free to modify SELinux policy to suit one's whims without making any change to the Linux kernel or its APIs. > At the end of the > day, booting 5.13 or older, we don't get a denial, and there's nothing > for the sysadmin to do. On 5.14 and newer, we get denials. This is a > common pattern we see each year: some new capability or permission is > required where it wasn't required before, and there's no compatibility > mechanism to grandfather in old policies. This is an artifact of separating policy from mechanism. The capability mechanism does not suffer from this issue because it embodies its policy. SELinux, Smack, AppArmor and "containers" are vulnerable to it because they explicitly deny the kernel and kernel developers permission to make assumptions about how they define "policy". > So, we have to touch > userspace. If this is just how things are, I can certainly update our > init.te definitions. If SELinux was a required kernel mechanism and the policy was included in the kernel tree you might be able to argue that kernel developers are responsible for changes to SELinux policy. But it ain't, and it isn't. By design. > >>> Fixes: 9d3a39a5f1e4 ("block: grant IOPRIO_CLASS_RT to CAP_SYS_NICE") >>> Signed-off-by: Alistair Delva >>> Cc: Khazhismel Kumykov >>> Cc: Bart Van Assche >>> Cc: Serge Hallyn >>> Cc: Jens Axboe >>> Cc: Greg Kroah-Hartman >>> Cc: Paul Moore >>> Cc: selinux@vger.kernel.org >>> Cc: linux-security-module@vger.kernel.org >>> Cc: kernel-team@android.com >>> Cc: stable@vger.kernel.org # v5.14+ >>> --- >>> block/ioprio.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/block/ioprio.c b/block/ioprio.c >>> index 0e4ff245f2bf..4d59c559e057 100644 >>> --- a/block/ioprio.c >>> +++ b/block/ioprio.c >>> @@ -69,7 +69,7 @@ int ioprio_check_cap(int ioprio) >>> >>> switch (class) { >>> case IOPRIO_CLASS_RT: >>> - if (!capable(CAP_SYS_NICE) && !capable(CAP_SYS_ADMIN)) >>> + if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_NICE)) >>> return -EPERM; >>> fallthrough; >>> /* rt has prio field too */ >>> -- >>> 2.34.0.rc1.387.gb447b232ab-goog >>> >> -- >> Ondrej Mosnacek >> Software Engineer, Linux Security - SELinux kernel >> Red Hat, Inc. >>