Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2822825pxv; Mon, 12 Jul 2021 02:48:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+cjQZxvccw7acQPfV1rHHMgVWg0W8Eks7BlmTC4tMi5jKYxyBWO/HMngJ6H1ZWit8arK+ X-Received: by 2002:a02:6f1c:: with SMTP id x28mr127315jab.95.1626083290937; Mon, 12 Jul 2021 02:48:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626083290; cv=none; d=google.com; s=arc-20160816; b=rvydt1pIKoJBNgljEZR6kZbD5WttPNGaJ6iRHb4r9RwUQjCkNPJ+3nZnGueFogUd9H x7VNSgTkY9K0ZiMD11YaDg1yydKegxnNDy47ajfAn+oh/itJJtSbJqxvtNc45JQBv+PU nhY5aFpxhcBiGeNN40U/Co6n6jS11N83wE0x8w7wlbKzj11yH2Yk5VT/uJaKx+Nw65h/ cuOXni1s7l00n+4pvI6yhM+aVSfnzY9V2wDg8w8aMSTeRkTquAJcDTq31ObeGvT8bP3o UWBnXjnOlMUTfvoFQRGxM3ah3TKMG7LO1fi3oBPfY9vunM7evET3OccYm6RNYWzjPUs6 HTIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mQBZ45gZinOjrdaV9Z1K2PIHKu1XW3QRuMJdnRztZH8=; b=pM6K+jyZD1jCaC3gppciLiQmHPYaEu7VAnt82k/PUihM1kWGroN0PDvIbdqIZrOznp Pz61ahR3RG0b17Jja+jmBkEtJXgMEXn5DhIIH2NHWD9cqQsOA5HYFX/YO9fT51IhNHHf EqzSfhi1kPJVRt0OZnw/Nbbj8q1jcXyepBfK5QBy9kSFmJhdOcqjHif+SbLf/svEdfBD fG9t4WpC7PPbxl1HwNKBRwgVK24lNvtv7c0YgBYS/2uv1i1MZa3af+DQula6EPbne3E6 OafV5bx6m35cyM+PPBLgCPx4LbQiU5Y3X9z0GW6rVkEUJqK2975ecRpiZnmJm1pEIIrz w5Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="c47dz/dA"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c4si4658694jal.120.2021.07.12.02.47.58; Mon, 12 Jul 2021 02:48:10 -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=@linuxfoundation.org header.s=korg header.b="c47dz/dA"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238409AbhGLGoA (ORCPT + 99 others); Mon, 12 Jul 2021 02:44:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:55076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237786AbhGLGew (ORCPT ); Mon, 12 Jul 2021 02:34:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AB804610D0; Mon, 12 Jul 2021 06:31:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071492; bh=jOF2+mVU5Zoyesc5FztQrLVVkG6ddrANPmsqaU+DgXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c47dz/dARBfE7FDJQdjtZGs3ukcePwTPJqgbmyQBF2Lth6QMvDGuxSM46tfg1lTiA Oz3ObJ1b4nGWHrTmPJoSr/vthEpE45e1FywZv8cV22EFMeaP87D3fXl9/PU/IXkhec EO3/FEQ0oXGSuqE9jI6iVhWDNL+k2p0i22EbwSyE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Roberto Sassu , Mimi Zohar Subject: [PATCH 5.10 092/593] evm: Refuse EVM_ALLOW_METADATA_WRITES only if an HMAC key is loaded Date: Mon, 12 Jul 2021 08:04:12 +0200 Message-Id: <20210712060853.320147055@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Roberto Sassu commit 9acc89d31f0c94c8e573ed61f3e4340bbd526d0c upstream. EVM_ALLOW_METADATA_WRITES is an EVM initialization flag that can be set to temporarily disable metadata verification until all xattrs/attrs necessary to verify an EVM portable signature are copied to the file. This flag is cleared when EVM is initialized with an HMAC key, to avoid that the HMAC is calculated on unverified xattrs/attrs. Currently EVM unnecessarily denies setting this flag if EVM is initialized with a public key, which is not a concern as it cannot be used to trust xattrs/attrs updates. This patch removes this limitation. Fixes: ae1ba1676b88e ("EVM: Allow userland to permit modification of EVM-protected metadata") Signed-off-by: Roberto Sassu Cc: stable@vger.kernel.org # 4.16.x Signed-off-by: Mimi Zohar Signed-off-by: Greg Kroah-Hartman --- Documentation/ABI/testing/evm | 26 ++++++++++++++++++++++++-- security/integrity/evm/evm_secfs.c | 8 ++++---- 2 files changed, 28 insertions(+), 6 deletions(-) --- a/Documentation/ABI/testing/evm +++ b/Documentation/ABI/testing/evm @@ -49,8 +49,30 @@ Description: modification of EVM-protected metadata and disable all further modification of policy - Note that once a key has been loaded, it will no longer be - possible to enable metadata modification. + Echoing a value is additive, the new value is added to the + existing initialization flags. + + For example, after:: + + echo 2 >/evm + + another echo can be performed:: + + echo 1 >/evm + + and the resulting value will be 3. + + Note that once an HMAC key has been loaded, it will no longer + be possible to enable metadata modification. Signaling that an + HMAC key has been loaded will clear the corresponding flag. + For example, if the current value is 6 (2 and 4 set):: + + echo 1 >/evm + + will set the new value to 3 (4 cleared). + + Loading an HMAC key is the only way to disable metadata + modification. Until key loading has been signaled EVM can not create or validate the 'security.evm' xattr, but returns --- a/security/integrity/evm/evm_secfs.c +++ b/security/integrity/evm/evm_secfs.c @@ -80,12 +80,12 @@ static ssize_t evm_write_key(struct file if (!i || (i & ~EVM_INIT_MASK) != 0) return -EINVAL; - /* Don't allow a request to freshly enable metadata writes if - * keys are loaded. + /* + * Don't allow a request to enable metadata writes if + * an HMAC key is loaded. */ if ((i & EVM_ALLOW_METADATA_WRITES) && - ((evm_initialized & EVM_KEY_MASK) != 0) && - !(evm_initialized & EVM_ALLOW_METADATA_WRITES)) + (evm_initialized & EVM_INIT_HMAC) != 0) return -EPERM; if (i & EVM_INIT_HMAC) {