From patchwork Thu Oct 19 22:57:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 10018433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D37F7602C8 for ; Thu, 19 Oct 2017 22:57:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3E3C28E5E for ; Thu, 19 Oct 2017 22:57:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6DD128E69; Thu, 19 Oct 2017 22:57:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37D3228E5E for ; Thu, 19 Oct 2017 22:57:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750968AbdJSW5z (ORCPT ); Thu, 19 Oct 2017 18:57:55 -0400 Received: from mail-oi0-f74.google.com ([209.85.218.74]:41551 "EHLO mail-oi0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752656AbdJSW5y (ORCPT ); Thu, 19 Oct 2017 18:57:54 -0400 Received: by mail-oi0-f74.google.com with SMTP id l5so9470531oib.0 for ; Thu, 19 Oct 2017 15:57:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:message-id:subject:from:to:cc; bh=t0VuZVlMEBehQukNVNJgiqLiyr/mIHA9o+WYLv1Le+U=; b=DyuilPLTPMkyV0+9PMBOLsYa7vXtJBF6mWyVBIyPwlhaHJ1pM4+ko96KQxE9CXaaD7 JFrP5EKElxgc/NZCV5HWu6Tb+0B7hfvVXslY0AEW4uhqmTL62Jecm+fkOiaz2Jc9fODR H0Nn8I+hViyMUCfCKxl/U3NS4qGSglr41B6Cf5sIPsLScuKLexsGt5e9cyRLGVgYDEww M36e6jUV4InY/3+/oS5BMg1zxxFSBH3xKnz25TC5V6nXtOwZZNSfO5aCvdOtQrDd0qhq Ca5vqPmZX3yNVZd3uMq+HVHOodgte78IH0JgJp3x7lMqqtHjwohdl24qOtaMumLCygvj HKFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc; bh=t0VuZVlMEBehQukNVNJgiqLiyr/mIHA9o+WYLv1Le+U=; b=KFETPU+fs0YvmQ3SAvKW94ISDcCqAOPsdt3xjNHllDzTwFtunZ853OKJANimRX3myN HeJbVWvLa+rnobQYBGxmFf48jZP35kLo1hUKQ8WQCiL6Y87QPjJrec88O1qjZ5fbslp/ /9VwNbZJghxblrch6OiTHiyndKQZ0HUKd8Rlpy4DeDlODfQgnc7Tr45Yv8k6btNpZmr4 uMQhdUFeWl2D215iMxwbQ5MRPPiDMFoQZNqvcjMmNUVJK74szLCjRl4vRGAk54SAAvpT VwygmPjLhdXhGdtKPGLnRj9b90QTEHztALtESbOKIhCJ0aXeH9Jq361DrNv3H+POgGE6 4dhA== X-Gm-Message-State: AMCzsaUqg7uVuO3BhmcSySkUmFkQ8LPm1+0sW5JWolCD25wSyLcZiopi i78uA2dKUeGjPDQUaP6498k0r2SYs28jX761NO142g3zyNCiBrVaYWoA7DD8kF7MwUhndNuYYZt RMdmHQm+Sd3oBfwojounGW0M9Mcicnzoox9s= X-Google-Smtp-Source: ABhQp+SIYwyZcHUKA/2rtS52R/gNa7AIlugtDFtUAln3NMtgZH4UYEl+zXP/3a4hSjLmDyDrH5CQfugyrQm6XNVaTE5t5g== MIME-Version: 1.0 X-Received: by 10.157.33.99 with SMTP id l32mr1679089otd.54.1508453873280; Thu, 19 Oct 2017 15:57:53 -0700 (PDT) Date: Thu, 19 Oct 2017 15:57:39 -0700 Message-Id: <20171019225739.4196-1-mjg59@google.com> X-Mailer: git-send-email 2.15.0.rc0.271.g36b669edcc-goog Subject: [PATCH] EVM: Allow userland to permit modification of EVM-protected xattrs From: Matthew Garrett To: linux-integrity@vger.kernel.org Cc: zohar@linux.vnet.ibm.com, Matthew Garrett Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When EVM is enabled it forbids modification of extended attributes that are protected by EVM unless there is already a valid EVM signature. If any modification is made, the kernel will then generate a new EVM HMAC. However, this does not map well on use cases which use only asymmetric EVM signatures, as in this scenario the kernel is unable to generate new signatures. This patch extends the /sys/kernel/security/evm interface to allow userland to request that modification of these xattrs be permitted. This is only permitted if there is no symmetric key loaded. In this configuration, modifying the extended attributes will increase the i_version on the file in question, invalidating any existing validation state. This allows packaging systems to write out new files, set the relevant extended attributes and then move them into place. Signed-off-by: Matthew Garrett --- Documentation/ABI/testing/evm | 33 +++++++++++++++++++++++---------- security/integrity/evm/evm.h | 4 +++- security/integrity/evm/evm_main.c | 5 +++++ security/integrity/evm/evm_secfs.c | 4 ++++ 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/Documentation/ABI/testing/evm b/Documentation/ABI/testing/evm index d2782afb0d96..3de362fd1278 100644 --- a/Documentation/ABI/testing/evm +++ b/Documentation/ABI/testing/evm @@ -14,20 +14,33 @@ Description: generated either locally or remotely using an asymmetric key. These keys are loaded onto root's keyring using keyctl, and EVM is then enabled by - echoing a value to /evm: + echoing a value to /evm made up of the + following bits: - 1: enable HMAC validation and creation - 2: enable digital signature validation - 3: enable HMAC and digital signature validation and HMAC - creation + Bit Effect + 0 Enable HMAC validation and creation + 1 Enable digital signature validation + 2 Permit modification of EVM-protected xattrs at + runtime. Not supported if HMAC validation and + creation is enabled. + 31 Disable further runtime modification of EVM policy - Further writes will be blocked if HMAC support is enabled or - if bit 32 is set: + For example: - echo 0x80000002 >/evm + echo 1 >/evm - will enable digital signature validation and block - further writes to /evm. + will enable HMAC validation and creation + + echo 0x80000003 >/evm + + will enable HMAC and digital signature validation and + HMAC creation and disable all further modification of policy. + + echo 0x80000006 >/evm + + will enable digital signature validation, permit + modification of EVM-protected extended attributes and + disable all further modification of policy Until this is done, EVM can not create or validate the 'security.evm' xattr, but returns INTEGRITY_UNKNOWN. diff --git a/security/integrity/evm/evm.h b/security/integrity/evm/evm.h index 946efffcc389..81ec6c74b178 100644 --- a/security/integrity/evm/evm.h +++ b/security/integrity/evm/evm.h @@ -23,9 +23,11 @@ #define EVM_INIT_HMAC 0x0001 #define EVM_INIT_X509 0x0002 +#define EVM_PERMIT_XATTR_WRITES 0x0004 #define EVM_SETUP 0x80000000 /* userland has signaled key load */ -#define EVM_INIT_MASK (EVM_INIT_HMAC | EVM_INIT_X509 | EVM_SETUP) +#define EVM_INIT_MASK (EVM_INIT_HMAC | EVM_INIT_X509 | EVM_SETUP | \ + EVM_PERMIT_XATTR_WRITES) extern int evm_initialized; extern char *evm_hmac; diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c index f29ac3384b2a..1d895226af29 100644 --- a/security/integrity/evm/evm_main.c +++ b/security/integrity/evm/evm_main.c @@ -303,6 +303,11 @@ static int evm_protect_xattr(struct dentry *dentry, const char *xattr_name, return 0; goto out; } + + /* Policy permits modification of the protected xattrs */ + if (evm_initialized & EVM_PERMIT_XATTR_WRITES) + return 0; + evm_status = evm_verify_current_integrity(dentry); if (evm_status == INTEGRITY_NOXATTRS) { struct integrity_iint_cache *iint; diff --git a/security/integrity/evm/evm_secfs.c b/security/integrity/evm/evm_secfs.c index 319cf16d6603..0ce5134d3de5 100644 --- a/security/integrity/evm/evm_secfs.c +++ b/security/integrity/evm/evm_secfs.c @@ -81,6 +81,10 @@ static ssize_t evm_write_key(struct file *file, const char __user *buf, return ret; /* Forbid further writes after the symmetric key is loaded */ i |= EVM_SETUP; + /* Don't allow protected xattr modification if a + * symmetric key is loaded + */ + i &= ~(EVM_PERMIT_XATTR_WRITES); } evm_initialized |= i;