Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1418040pxj; Fri, 21 May 2021 13:51:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsvkl/nxYqjyBu6nR2YC/a5sAGnMnmxrH1D+21pHrTeCMlRPQNnNdyYHp23RIyfj3GospE X-Received: by 2002:a5d:8b09:: with SMTP id k9mr689245ion.185.1621630286895; Fri, 21 May 2021 13:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621630286; cv=none; d=google.com; s=arc-20160816; b=JRvStpPbAF52likWiFXmGOAQ0HJDujctomJQxohwBoRIlTRKwKKef9PvIykorCvdGN fr25+W3+KUIfcMKYMraX18G9uAmIYdClDIKV1f22GOkuW9B4wRhXvWmzglLPMRrP5Ci5 A00lPvcSAYrUD47so2mi69eAWOPiJ4GHWfYo85nP788J/87HodXsfa7UNFBrLvWWKkYp idKG8aoNqFH99poj2INSVDfi5dDjNHy0p3+UtdQXt4F7JlypruNbiW+rcQyPVoZJuPKp lfeWSzo3O+yiEZ58wXdeN5Og9VIZmDhJdWUNSVkCyi5RruAiblXfngg80gfEegWfYs/P VYmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=aVEzTQ8I4J/3yp3MgA3FQPj62TME7oEjwi3UB54+9j4=; b=So0wRjt8QZUL5O7WWmZDepwblv/05mTHbJEF32haV5RY+t/loIUoW08hFJ4eSIow35 toNLXfbnjazYfE6bbsxfC4y8xYcNJ3ewfF7F7OZ04Jk2B8bX7fQioSQeHYtBEhocN7pH BsiFHvtTkMY53ZbIYCwh4YScFm6/HDE9acBgvagOr0lMYCVZwongZRt3l80khGQIaZ34 8l9LVIanyBn7BvkZ1kxB9reExW0vBh0hHJNSUgA2U5VLsUiuUN7XyemgLJXdC1nJWHbw KKO82Y3jH0366ZWKMPxgOi5e8hW8zgug4ZTnrrSo6UEiUDHu5GX8NbDbDshFNORkRV5Q OOLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=y5acabY0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si6647181iov.75.2021.05.21.13.51.13; Fri, 21 May 2021 13:51:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=y5acabY0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230253AbhEUUUu (ORCPT + 99 others); Fri, 21 May 2021 16:20:50 -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-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