Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp793621pxa; Wed, 5 Aug 2020 12:56:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWeGh7duhSNuMlyap3QXviCgGAs0uwONiJDYwZ6TNPEgbmie+QPe1Wqh08+4Y7qahGXYBB X-Received: by 2002:aa7:c64e:: with SMTP id z14mr946015edr.368.1596657389492; Wed, 05 Aug 2020 12:56:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596657389; cv=none; d=google.com; s=arc-20160816; b=OrjN1obICosr7Hs/jcbR24v0gwIlSu/LERFcgEhiaX2EDwRZtzlkDMvmp4xW4KzVdl FaB/Xy6rBwDtcMWQvXswGERAXSBq29w9LxWtK3/Bu4FwcOoDVzb0vnA7mAJV9NOo2BeJ M57zFCRVqtyd3b+up9SoFQi3IEpHsPPxEDcGGwnC2ceI9x+S/qHtAKC2phyQcXvTryJs 1zPZXeRrjM3EJvhTxEjQizLDbhsrWmJBwwdis2SsLi0dgZRp4HfrNrtHDzViUBRdg/51 OWMwm9Ni8rTk93RdKAlYsoxlqNqCHc8wqxOyYheRYTVlIrntVaZ3NePqy3Wt61QASmkr XURw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:autocrypt:from:references:cc:to:subject; bh=WpOR4PZK5pni9pYv9hyexC9/f1bW4vCMfRg9D39y2SM=; b=XhcIlRA8XBv7OLBOIkrx5+jtQpBE4l301qhrhi7/rlTVWm5Ksc7XB0Y1cKAMK2CY4t te/3/JmhR47pyltoB6uHojMuoITLWV9tE/2R5hyMtYXjjRGhzLG1NPw9K1XvFQwQHFHg sF1Yy+Qyq7wEnMaOB90EPde6V0cwJ2Viz7dHMIjznSmXDfD8CpJSDsW7oGxgUrTA2zeW pjEbrwJaETDHRy8NrRUAeDdy95l9hOyHLCQAcGyfl+ca2qbcywcz1J5EOD8xznRqFK2F vzHw6nCyHB730IDMCcWyUGAn51stAiOjgeVcWmDH7nsoA2TgKeq7wlccllECOqfdDW+0 JOhQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bd8si1773678edb.477.2020.08.05.12.56.06; Wed, 05 Aug 2020 12:56:29 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727979AbgHEQsG (ORCPT + 99 others); Wed, 5 Aug 2020 12:48:06 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:37526 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728014AbgHEQpn (ORCPT ); Wed, 5 Aug 2020 12:45:43 -0400 Received: from static-50-53-58-29.bvtn.or.frontiernet.net ([50.53.58.29] helo=[192.168.192.153]) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1k3MXp-0000Xu-4e; Wed, 05 Aug 2020 16:45:37 +0000 Subject: Re: [PATCH v6 1/4] IMA: Add func to measure LSM state and policy To: Stephen Smalley , Tyler Hicks Cc: Mimi Zohar , Lakshmi Ramasubramanian , Casey Schaufler , sashal@kernel.org, James Morris , linux-integrity@vger.kernel.org, SElinux list , LSM List , linux-kernel References: <20200805004331.20652-1-nramas@linux.microsoft.com> <20200805004331.20652-2-nramas@linux.microsoft.com> <4b9d2715d3ef3c8f915ef03867cfb1a39c0abc54.camel@linux.ibm.com> <31d00876438d2652890ab8bf6ba2e80f554ca7a4.camel@linux.ibm.com> <20200805150732.GA4365@sequoia> <39390a53-51df-12f0-5451-e677ccca581a@gmail.com> From: John Johansen Autocrypt: addr=john.johansen@canonical.com; prefer-encrypt=mutual; keydata= LS0tLS1CRUdJTiBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tCgptUUlOQkU1bXJQb0JFQURB azE5UHNnVmdCS2tJbW1SMmlzUFE2bzdLSmhUVEtqSmR3VmJrV1NuTm4rbzZVcDVrCm5LUDFm NDlFQlFsY2VXZzF5cC9Od2JSOGFkK2VTRU8vdW1hL0srUHFXdkJwdEtDOVNXRDk3Rkc0dUI0 L2Nhb20KTEVVOTdzTFFNdG52R1dkeHJ4VlJHTTRhbnpXWU1neno1VFptSWlWVFo0M091NVZw YVMxVnoxWlN4UDNoL3hLTgpaci9UY1c1V1FhaTh1M1BXVm5ia2poU1pQSHYxQmdoTjY5cXhF UG9tckpCbTFnbXR4M1ppVm1GWGx1d1RtVGdKCk9rcEZvbDduYkowaWxuWUhyQTdTWDNDdFIx dXBlVXBNYS9XSWFuVk85NldkVGpISElhNDNmYmhtUXViZTR0eFMKM0ZjUUxPSlZxUXN4NmxF OUI3cUFwcG05aFExMHFQV3dkZlB5LyswVzZBV3ROdTVBU2lHVkNJbld6bDJIQnFZZAovWmxs OTN6VXErTklvQ244c0RBTTlpSCt3dGFHRGNKeXdJR0luK2VkS050SzcyQU1nQ2hUZy9qMVpv V0g2WmVXClBqdVVmdWJWelp0bzFGTW9HSi9TRjRNbWRRRzFpUU50ZjRzRlpiRWdYdXk5Y0dp MmJvbUYwenZ5QkpTQU5weGwKS05CRFlLek42S3owOUhVQWtqbEZNTmdvbUwvY2pxZ0FCdEF4 NTlMK2RWSVpmYUYyODFwSWNVWnp3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YOVBrUEpZdnhmUmxD NmRLOFBLS2ZYOUtkZm1BSWNnSGZuVjFqU24rCjh5SDJkakJQdEtpcVcwSjY5YUlzeXg3aVYv MDNwYVBDakpoN1hxOXZBenlkTjVVL1VBPT0KPTZQL2IKLS0tLS1FTkQgUEdQIFBVQkxJQyBL RVkgQkxPQ0stLS0tLQo= Organization: Canonical Message-ID: Date: Wed, 5 Aug 2020 09:45:33 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <39390a53-51df-12f0-5451-e677ccca581a@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/5/20 8:43 AM, Stephen Smalley wrote: > On 8/5/20 11:07 AM, Tyler Hicks wrote: > >> On 2020-08-05 10:27:43, Stephen Smalley wrote: >>> On Wed, Aug 5, 2020 at 9:20 AM Mimi Zohar wrote: >>>> On Wed, 2020-08-05 at 09:03 -0400, Stephen Smalley wrote: >>>>> On Wed, Aug 5, 2020 at 8:57 AM Mimi Zohar wrote: >>>>>> On Wed, 2020-08-05 at 08:46 -0400, Stephen Smalley wrote: >>>>>>> On 8/4/20 11:25 PM, Mimi Zohar wrote: >>>>>>> >>>>>>>> Hi Lakshmi, >>>>>>>> >>>>>>>> There's still  a number of other patch sets needing to be reviewed >>>>>>>> before my getting to this one.  The comment below is from a high level. >>>>>>>> >>>>>>>> On Tue, 2020-08-04 at 17:43 -0700, Lakshmi Ramasubramanian wrote: >>>>>>>>> Critical data structures of security modules need to be measured to >>>>>>>>> enable an attestation service to verify if the configuration and >>>>>>>>> policies for the security modules have been setup correctly and >>>>>>>>> that they haven't been tampered with at runtime. A new IMA policy is >>>>>>>>> required for handling this measurement. >>>>>>>>> >>>>>>>>> Define two new IMA policy func namely LSM_STATE and LSM_POLICY to >>>>>>>>> measure the state and the policy provided by the security modules. >>>>>>>>> Update ima_match_rules() and ima_validate_rule() to check for >>>>>>>>> the new func and ima_parse_rule() to handle the new func. >>>>>>>> I can understand wanting to measure the in kernel LSM memory state to >>>>>>>> make sure it hasn't changed, but policies are stored as files.  Buffer >>>>>>>> measurements should be limited  to those things that are not files. >>>>>>>> >>>>>>>> Changing how data is passed to the kernel has been happening for a >>>>>>>> while.  For example, instead of passing the kernel module or kernel >>>>>>>> image in a buffer, the new syscalls - finit_module, kexec_file_load - >>>>>>>> pass an open file descriptor.  Similarly, instead of loading the IMA >>>>>>>> policy data, a pathname may be provided. >>>>>>>> >>>>>>>> Pre and post security hooks already exist for reading files.   Instead >>>>>>>> of adding IMA support for measuring the policy file data, update the >>>>>>>> mechanism for loading the LSM policy.  Then not only will you be able >>>>>>>> to measure the policy, you'll also be able to require the policy be >>>>>>>> signed. >>>>>>> To clarify, the policy being measured by this patch series is a >>>>>>> serialized representation of the in-memory policy data structures being >>>>>>> enforced by SELinux.  Not the file that was loaded.  Hence, this >>>>>>> measurement would detect tampering with the in-memory policy data >>>>>>> structures after the policy has been loaded.  In the case of SELinux, >>>>>>> one can read this serialized representation via /sys/fs/selinux/policy. >>>>>>> The result is not byte-for-byte identical to the policy file that was >>>>>>> loaded but can be semantically compared via sediff and other tools to >>>>>>> determine whether it is equivalent. >>>>>> Thank you for the clarification.   Could the policy hash be included >>>>>> with the other critical data?  Does it really need to be measured >>>>>> independently? >>>>> They were split into two separate functions because we wanted to be >>>>> able to support using different templates for them (ima-buf for the >>>>> state variables so that the measurement includes the original buffer, >>>>> which is small and relatively fixed-size, and ima-ng for the policy >>>>> because it is large and we just want to capture the hash for later >>>>> comparison against known-good).  Also, the state variables are >>>>> available for measurement always from early initialization, whereas >>>>> the policy is only available for measurement once we have loaded an >>>>> initial policy. >>>> Ok, measuring the policy separately from other critical data makes >>>> sense.  Instead of measuring the policy, which is large, measure the >>>> policy hash. >>> I think that was the original approach.  However, I had concerns with >>> adding code to SELinux to compute a hash over the policy versus >>> leaving that to IMA's existing policy and mechanism.  If that's >>> preferred I guess we can do it that way but seems less flexible and >>> duplicative. >> In AppArmor, we store the sha1 of the raw policy as the policy is >> loaded. The hash is exposed to userspace in apparmorfs. See commit >> 5ac8c355ae00 ("apparmor: allow introspecting the loaded policy pre >> internal transform"). >> >> It has proved useful as a mechanism for debugging as sometimes the >> on-disk policy doesn't match the loaded policy and this can be a good >> way to check that while providing support to users. John also mentions >> checkpoint/restore in the commit message and I could certainly see how >> the policy hashes would be useful in that scenario. >> >> When thinking through how Lakshmi's series could be extended for >> AppArmor support, I was thinking that the AppArmor policy measurement >> would be a measurement of these hashes that we already have in place. >> >> Perhaps there's some general usefulness in storing/exposing an SELinux >> policy hash rather than only seeing it as duplicative property required >> this measurement series? > > That would be a hash of the policy file that was last loaded via the selinuxfs interface for loading policy, not a hash of the in-memory policy data structures at the time of measurement (which is what this patch series is implementing).  The duplicative part is with respect to selecting a hash algorithm and hashing the in-memory policy as part of the SELinux code rather than just passing the policy buffer to IMA for measurement like any other buffer.  Userspace can already hash the in-memory policy data itself by running sha256sum or whatever on /sys/fs/selinux/policy, so we don't need to save or expose that separately. > > yeah apparmor exposes full loaded policy data that userspace could hash independently too, the hashing done by the kernel just reduces the amount of data that userspace has to suck down if they trust the kernel to do the hash. Those hashes are also used by apparmor internally for the first part of a dedup check so exposing them cost very little. The hashing of the in-memory data structures and variables is something we are not currently doing. If we were to do it hashing in-memory apparmor policy would be quite involved and that would be something I would rather have LSMs export an interface for rather than having IMA poke directly at the data structures (ie. apparmor specific code in apparmor). As for computing a measurement based on the hash instead of the in-memory policy, while quicker that would not detect memory corruption/attacks that manage to modify policy via writing kernel memory. Whether that type of measurement is sufficient depends on what you are trying to achieve.