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 AE394C433EF for ; Mon, 15 Nov 2021 23:12:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90F3761181 for ; Mon, 15 Nov 2021 23:12:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352306AbhKOXNh (ORCPT ); Mon, 15 Nov 2021 18:13:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:28908 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243960AbhKOTHR (ORCPT ); Mon, 15 Nov 2021 14:07:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637003060; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=v/SBXUx2gshVEpRR5lkDqOIRh1bD4WZmOak2pzCj75s=; b=CI+RBIVCNAGb7wL9M+nRNMMmRAezEua6e/g7R20OS0FeZQTCD2CC1A6rYMFkFJw3Lk5GFv e7sU5mUq5yW3DnnKwdkblnkjpJrelGP34BXl1Mw6pEaTLTfr7qrsvLetiklzFaJyzgVXlC a9aF434o1u198t13DZSymtSjfAgGT6I= Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-369-tISOsRmgOZOMo3SuQX9Y5g-1; Mon, 15 Nov 2021 14:04:19 -0500 X-MC-Unique: tISOsRmgOZOMo3SuQX9Y5g-1 Received: by mail-yb1-f197.google.com with SMTP id v20-20020a25fc14000000b005c2109e5ad1so27881306ybd.9 for ; Mon, 15 Nov 2021 11:04:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=v/SBXUx2gshVEpRR5lkDqOIRh1bD4WZmOak2pzCj75s=; b=IlWoZZuI3Flduq9NQfOdoXb4pCFPMypquwK8tt/34xr4/xMigTAjei78ZjEt5GRH3R L0ZA++70g+op7Zn+/upB31a8MEYXEwb8X/IpgsuXEaKrkJXioRYTpD5WnpwWHQWi7r3J 7IG3taRJun+JNCHUhaJLX5JJwATkQhFaU3AAH0GHbQ1afCbVLDVVhuo0nI93qscWksmJ 1epiPsWfTle06wjtjGJnyWL8ER9+WdSsXHyRIPvzGlzh61oRh3jM6O4Sff657lje7jKp XAnq+/Pu2ENaF2PszbMQ+8oftW1+XD4hK1UvPSNyUMCzxllGrglLTN7h0p14b6N8/Ish K6tg== X-Gm-Message-State: AOAM530SM9DplHVdJomz4Euq8sufY9pCgs64lh4Wbl/V58eU5ayAvhfG YivbNTOjKqFBoVcW5r6pGVIJ10/fmoAI3bI8mKk3yy2eiIdP8jPl3hwWPO0m4Y207GICJmlmnIz HrW24YqukSMUTTFfNHMCMkqrzyOJ8RudigGUEMJdf X-Received: by 2002:a25:3283:: with SMTP id y125mr1233686yby.479.1637003058347; Mon, 15 Nov 2021 11:04:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJzDg/2EKuxykc6+iQIz1Ve049nNfAryXwGXOETwxe8O1IwCanztgTBfr04ISJwL8oujwWmHkrKy78vI+kFMlCQ= X-Received: by 2002:a25:3283:: with SMTP id y125mr1233623yby.479.1637003057823; Mon, 15 Nov 2021 11:04:17 -0800 (PST) MIME-Version: 1.0 References: <20211115173850.3598768-1-adelva@google.com> In-Reply-To: <20211115173850.3598768-1-adelva@google.com> From: Ondrej Mosnacek Date: Mon, 15 Nov 2021 20:04:05 +0100 Message-ID: Subject: Re: [PATCH] block: Check ADMIN before NICE for IOPRIO_CLASS_RT To: Alistair Delva 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > 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.