Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2706073pxv; Sun, 11 Jul 2021 23:19:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJCpFI4M4qn9KwOFcOH9Mj3cT/eMJRu69b6YVNXKk+MbUcneqcDVzIueFvUb5LJ1fZ2b1v X-Received: by 2002:a02:93a3:: with SMTP id z32mr12057140jah.33.1626070741242; Sun, 11 Jul 2021 23:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626070741; cv=none; d=google.com; s=arc-20160816; b=yJuW/EfZUcgCNnn1xsbV9C4Q0sFn1c58jAb1YxrV7wVyoCtBGdp2Q5huUmtS0bR+Nr A8gIdO+MwZmDj2kuiERLBsOn3Lqts45cm3ymJP17rFBVYUzzNdiTs+vpGWCTGdyXXJoS fyq//tudDea5GPjkIvzw99toBHxusjHq4TZGT6aOlFZFe65Ci5CUvSvCdiILmOoxXE4D G1zki4F++Td6ixpChLUnsfkpOr9JRxmD0QeAmSRuyUOmT6u5C/maa/7aS07OfGR9GzSQ jpA8+EIAdeucsZscSug46F38wJ5Tyog3SFWCUpEfzwlLKAZWYTKWJh1OU/lTV6/yRb45 8U6w== 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=fu1kAIhhOPLUKq7jvOUiSzHjtwsU1s5gZfG6+68kpCg=; b=sjC/unRjUINzM+Rjx5/h200a8Dpi9tE4ma/a4pu23pIVY8fdxM+uuaDPQ5m9xib3Cx Sr/5XzYmY5RmzK4JDy9bQE3znZNwpZoogeze2TZkkT5YszJR6B81BrNI6TRmeLAsxFte 6TuMgpEa9SflNI6iTYFPIkDekxLZINso+faq1F/Cw5nlWJME1ZRmKDrXoEAH0mRdJa+f vMzruTnQptL9zIf6BkJDx+OhctaPtgE3T2NBLxjswSuN93U5hIGvSznyd1esCL7inacw d/SAOUi4roid0dsjbgUdEqtMai4Xm7IhlXNz46iKau8TYRZjUCPs/E7YLYl5Z2rnr0nh rQXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=N+BvebYR; 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 h5si18846902iol.44.2021.07.11.23.18.49; Sun, 11 Jul 2021 23:19:01 -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=N+BvebYR; 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 S233964AbhGLGUH (ORCPT + 99 others); Mon, 12 Jul 2021 02:20:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:38404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233331AbhGLGTc (ORCPT ); Mon, 12 Jul 2021 02:19:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C10596101E; Mon, 12 Jul 2021 06:16:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626070604; bh=P8fxVXUHAz59Ij1yhWEmEHViTB8eiZdPGvDhLrL+hJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N+BvebYRckR7c7iFPia0nl+jaPog1k32OaQp0kjiwQIiua48NDCm3fy28GlVd8vyV qgHl4HIcr8SA+T6afyvLG1oN+tYCBpwSAXQVusfeTICf5Voxv5LfZS5z9nSbOfhzGW gv5d39PRTxC4CCSiwZus8eUJfl9ahCiJXfqTZwwY= 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.4 060/348] evm: Refuse EVM_ALLOW_METADATA_WRITES only if an HMAC key is loaded Date: Mon, 12 Jul 2021 08:07:24 +0200 Message-Id: <20210712060709.837872157@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@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 @@ -42,8 +42,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 @@ -82,12 +82,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) {