From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 786DEC04FF3 for ; Fri, 21 May 2021 20:19:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B1DC613E1 for ; Fri, 21 May 2021 20:19:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230505AbhEUUUx (ORCPT ); Fri, 21 May 2021 16:20:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230409AbhEUUUp (ORCPT ); Fri, 21 May 2021 16:20:45 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CF17C061574 for ; Fri, 21 May 2021 13:19:21 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id gb17so14190689ejc.8 for ; Fri, 21 May 2021 13:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aVEzTQ8I4J/3yp3MgA3FQPj62TME7oEjwi3UB54+9j4=; b=y5acabY0hHaFulLVyRw96Upc3Tfg5b6Vkr2way0sktzbQKqkTD9yR07FT7pm2dbtK2 OmIX/Fgm2xBpq1gKrI2N3x9jMvF7NuA98vf/xJIjcCcJndHdWK2E02xm9dExvkQ5GvlT h0DXHodT+NB8JKTBfAsvxDtMdKm5KcxkiQcmBzjtyoKUWgK2oHjZtxvU8b6+lwdlDQjc D5hZyeGTTzmQ2/4wUyAApkMxFk9M65r/4JDnrXFYNPAeRoAD80OVIQWfeFAH/8N1BNVg qn061UVWCxSDmBHw6mCcH4UI/nRyNhP8vsZk5WokXPfE22Hielso21jzz8/mj0UnuA1U Ha5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aVEzTQ8I4J/3yp3MgA3FQPj62TME7oEjwi3UB54+9j4=; b=DBK5Pvo8Rpz/73Zj+X/MKyfgZRhh4bc1aMxNpdK8DcP/Ih2G4DtIfMvV7aFGPGib2P 43oyepKAscTIlBRl1jKQHv+ONdnPoqEr7yB+eJf6GeZCUO2/4PbfrR5cz4Or8KpCei5b oHSnfpRDkfLwnp/at7Eqfu8VQlSpZIqrja9Ho6jgSY8N90CyqK6ixTzNe/3NJoTJCSec gi3nrSlzny6L0INGEPhNGp7CPwRGHjucYYXXrg1GMOVfIIKVDmcD8uyuF///GzdxHboK mYiH7KHP4AJIkBXpiA/eTbb7NirgigW4+Rsk4ivyk7rzQY8qLKpcAs6cowShLgikgls8 VTnw== X-Gm-Message-State: AOAM531M3ON2Hp9tgpDhW3Z86PhedwCLILMKi5vO+fCBRXdlMBrwxJNa gOMW+pNwN5Fize9QA6X+2w9VPjWpbTiFjLF1ch8p X-Google-Smtp-Source: ABdhPJziKJYfK7MvqTrwnHeo+NPoz2FUDF+4sST5fBaH9Y8+nll4YIEPRA92LUzjYQjCfkAjrte8Kmy6TkEhHB1xuyQ= X-Received: by 2002:a17:906:7e0f:: with SMTP id e15mr11771196ejr.398.1621628359745; Fri, 21 May 2021 13:19:19 -0700 (PDT) MIME-Version: 1.0 References: <20210513200807.15910-1-casey@schaufler-ca.com> <20210513200807.15910-15-casey@schaufler-ca.com> <202105141218.21BDA22F@keescook> In-Reply-To: From: Paul Moore Date: Fri, 21 May 2021 16:19:08 -0400 Message-ID: Subject: Re: [PATCH v26 14/25] LSM: Specify which LSM to display To: Casey Schaufler Cc: Kees Cook , casey.schaufler@intel.com, James Morris , linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-audit@redhat.com, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, Stephen Smalley , linux-kernel@vger.kernel.org, Stephen Smalley , Greg Kroah-Hartman , linux-api@vger.kernel.org, linux-doc@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 17, 2021 at 3:53 PM Casey Schaufler wrote: > On 5/14/2021 12:23 PM, Kees Cook wrote: > > On Thu, May 13, 2021 at 01:07:56PM -0700, Casey Schaufler wrote: > >> Create a new entry "interface_lsm" in the procfs attr directory for > >> controlling which LSM security information is displayed for a > >> process. A process can only read or write its own display value. > >> > >> The name of an active LSM that supplies hooks for > >> human readable data may be written to "interface_lsm" to set the > >> value. The name of the LSM currently in use can be read from > >> "interface_lsm". At this point there can only be one LSM capable > >> of display active. A helper function lsm_task_ilsm() is > >> provided to get the interface lsm slot for a task_struct. > >> > >> Setting the "interface_lsm" requires that all security modules using > >> setprocattr hooks allow the action. Each security module is > >> responsible for defining its policy. > >> > >> AppArmor hook provided by John Johansen > >> SELinux hook provided by Stephen Smalley > >> > >> Signed-off-by: Casey Schaufler > >> Cc: Kees Cook > >> Cc: Stephen Smalley > >> Cc: Paul Moore > >> Cc: John Johansen > >> Cc: Greg Kroah-Hartman > >> Cc: linux-api@vger.kernel.org > >> Cc: linux-doc@vger.kernel.org > >> --- > >> .../ABI/testing/procfs-attr-lsm_display | 22 +++ > >> Documentation/security/lsm.rst | 14 ++ > >> fs/proc/base.c | 1 + > >> include/linux/lsm_hooks.h | 17 ++ > >> security/apparmor/include/apparmor.h | 3 +- > >> security/apparmor/lsm.c | 32 ++++ > >> security/security.c | 166 ++++++++++++++++-- > >> security/selinux/hooks.c | 11 ++ > >> security/selinux/include/classmap.h | 2 +- > >> security/smack/smack_lsm.c | 7 + > >> 10 files changed, 256 insertions(+), 19 deletions(-) > >> create mode 100644 Documentation/ABI/testing/procfs-attr-lsm_display ... > >> @@ -2171,23 +2203,110 @@ int security_getprocattr(struct task_struct *p, const char *lsm, char *name, > >> char **value) > >> { > >> struct security_hook_list *hp; > >> + int ilsm = lsm_task_ilsm(current); > >> + int slot = 0; > >> + > >> + if (!strcmp(name, "interface_lsm")) { > >> + /* > >> + * lsm_slot will be 0 if there are no displaying modules. > >> + */ > >> + if (lsm_slot == 0) > >> + return -EINVAL; > >> + > >> + /* > >> + * Only allow getting the current process' interface_lsm. > >> + * There are too few reasons to get another process' > >> + * interface_lsm and too many LSM policy issues. > >> + */ > >> + if (current != p) > >> + return -EINVAL; > > ... but context isn't established by just checking "current", as this > > file handle may have been given to another process. > > > > I suspect the security_get/setprocattr needs to gain a pointer to "file" > > so that the f_cred struct can be examined[1] (i.e. compare opener > > against reader/writer). > > > > [1] https://www.kernel.org/doc/html/latest/security/credentials.html#open-file-credentials > > It's not credentials being checked here. The check is whether the task that > would be affected is "current". Process A can't open /proc/B/attr/interface_lsm > with write access. The only process that can open it for write access is B. > If process B opens /proc/B/attr/interface_lsm for write access it could send > the file handle to process A, but process A can't write to the file because > (current != p) that is, (A != B). Agreed. Acked-by: Paul Moore -- paul moore www.paul-moore.com From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9141DC04FF3 for ; Fri, 21 May 2021 20:19:35 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 23D9761164 for ; Fri, 21 May 2021 20:19:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 23D9761164 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=paul-moore.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=linux-audit-bounces@redhat.com Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-394-G9VGr76-MXaQwi3ay3JONg-1; Fri, 21 May 2021 16:19:32 -0400 X-MC-Unique: G9VGr76-MXaQwi3ay3JONg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3DA151854E26; Fri, 21 May 2021 20:19:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1BB1236DE; Fri, 21 May 2021 20:19:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DE3091800BB4; Fri, 21 May 2021 20:19:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14LKJRvf012193 for ; Fri, 21 May 2021 16:19:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id AB1BF20BB90C; Fri, 21 May 2021 20:19:27 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A6F3F20BDB29 for ; Fri, 21 May 2021 20:19:24 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BD6A4857AA4 for ; Fri, 21 May 2021 20:19:24 +0000 (UTC) Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-316-dDZP9WhzM7W57XXxAeoQdg-1; Fri, 21 May 2021 16:19:21 -0400 X-MC-Unique: dDZP9WhzM7W57XXxAeoQdg-1 Received: by mail-ej1-f45.google.com with SMTP id gb17so14190690ejc.8 for ; Fri, 21 May 2021 13:19:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aVEzTQ8I4J/3yp3MgA3FQPj62TME7oEjwi3UB54+9j4=; b=SRqzZNTuctF/kr8IYMZx1/8RBKkmBHfXyeuJDmQ+vOS0iNW0VnZ8TVvrPSu1FxBzYO JpzqqFTrdyz7Cls/WAOUHPlPOmyyIGv0Cb+lQHeee3t1k9T6hWvbFyqApo3Y9FFf2QsN 8M0tBd+WPzn/kkqCN6dMZqLxlLS/QJFnojyQG7Tu3pyph/DbSw8Od213Y2XgLDXhBf2d 0zF7ZYZohOuGcIEDSEd9yfQu/BdphRLigMAaldzj/nBKA2KlwEWyST/XcXhcDcgkJLRi 52nSFjiGtjW5vBqGYLE9v9FfFZoUU5lgM45OpEvA71TMRUGLEsqJEo+xS/9GQ7TKz14T 9JIw== X-Gm-Message-State: AOAM532AWqM8hyO4WyOrvNa2edFletKcx5pxy+ELXkDXTXh2/lxer2Vm 30zhmcdyHotT0d85Gli1jc8PIGEKBlaN+0gZxgng X-Google-Smtp-Source: ABdhPJziKJYfK7MvqTrwnHeo+NPoz2FUDF+4sST5fBaH9Y8+nll4YIEPRA92LUzjYQjCfkAjrte8Kmy6TkEhHB1xuyQ= X-Received: by 2002:a17:906:7e0f:: with SMTP id e15mr11771196ejr.398.1621628359745; Fri, 21 May 2021 13:19:19 -0700 (PDT) MIME-Version: 1.0 References: <20210513200807.15910-1-casey@schaufler-ca.com> <20210513200807.15910-15-casey@schaufler-ca.com> <202105141218.21BDA22F@keescook> In-Reply-To: From: Paul Moore Date: Fri, 21 May 2021 16:19:08 -0400 Message-ID: Subject: Re: [PATCH v26 14/25] LSM: Specify which LSM to display To: Casey Schaufler X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: linux-audit@redhat.com Cc: john.johansen@canonical.com, linux-doc@vger.kernel.org, selinux@vger.kernel.org, Greg Kroah-Hartman , James Morris , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-audit@redhat.com, linux-api@vger.kernel.org, casey.schaufler@intel.com, Stephen Smalley X-BeenThere: linux-audit@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Linux Audit Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=linux-audit-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Mon, May 17, 2021 at 3:53 PM Casey Schaufler wrote: > On 5/14/2021 12:23 PM, Kees Cook wrote: > > On Thu, May 13, 2021 at 01:07:56PM -0700, Casey Schaufler wrote: > >> Create a new entry "interface_lsm" in the procfs attr directory for > >> controlling which LSM security information is displayed for a > >> process. A process can only read or write its own display value. > >> > >> The name of an active LSM that supplies hooks for > >> human readable data may be written to "interface_lsm" to set the > >> value. The name of the LSM currently in use can be read from > >> "interface_lsm". At this point there can only be one LSM capable > >> of display active. A helper function lsm_task_ilsm() is > >> provided to get the interface lsm slot for a task_struct. > >> > >> Setting the "interface_lsm" requires that all security modules using > >> setprocattr hooks allow the action. Each security module is > >> responsible for defining its policy. > >> > >> AppArmor hook provided by John Johansen > >> SELinux hook provided by Stephen Smalley > >> > >> Signed-off-by: Casey Schaufler > >> Cc: Kees Cook > >> Cc: Stephen Smalley > >> Cc: Paul Moore > >> Cc: John Johansen > >> Cc: Greg Kroah-Hartman > >> Cc: linux-api@vger.kernel.org > >> Cc: linux-doc@vger.kernel.org > >> --- > >> .../ABI/testing/procfs-attr-lsm_display | 22 +++ > >> Documentation/security/lsm.rst | 14 ++ > >> fs/proc/base.c | 1 + > >> include/linux/lsm_hooks.h | 17 ++ > >> security/apparmor/include/apparmor.h | 3 +- > >> security/apparmor/lsm.c | 32 ++++ > >> security/security.c | 166 ++++++++++++++++-- > >> security/selinux/hooks.c | 11 ++ > >> security/selinux/include/classmap.h | 2 +- > >> security/smack/smack_lsm.c | 7 + > >> 10 files changed, 256 insertions(+), 19 deletions(-) > >> create mode 100644 Documentation/ABI/testing/procfs-attr-lsm_display ... > >> @@ -2171,23 +2203,110 @@ int security_getprocattr(struct task_struct *p, const char *lsm, char *name, > >> char **value) > >> { > >> struct security_hook_list *hp; > >> + int ilsm = lsm_task_ilsm(current); > >> + int slot = 0; > >> + > >> + if (!strcmp(name, "interface_lsm")) { > >> + /* > >> + * lsm_slot will be 0 if there are no displaying modules. > >> + */ > >> + if (lsm_slot == 0) > >> + return -EINVAL; > >> + > >> + /* > >> + * Only allow getting the current process' interface_lsm. > >> + * There are too few reasons to get another process' > >> + * interface_lsm and too many LSM policy issues. > >> + */ > >> + if (current != p) > >> + return -EINVAL; > > ... but context isn't established by just checking "current", as this > > file handle may have been given to another process. > > > > I suspect the security_get/setprocattr needs to gain a pointer to "file" > > so that the f_cred struct can be examined[1] (i.e. compare opener > > against reader/writer). > > > > [1] https://www.kernel.org/doc/html/latest/security/credentials.html#open-file-credentials > > It's not credentials being checked here. The check is whether the task that > would be affected is "current". Process A can't open /proc/B/attr/interface_lsm > with write access. The only process that can open it for write access is B. > If process B opens /proc/B/attr/interface_lsm for write access it could send > the file handle to process A, but process A can't write to the file because > (current != p) that is, (A != B). Agreed. Acked-by: Paul Moore -- paul moore www.paul-moore.com -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit