From patchwork Sat Oct 22 07:20:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7220 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1090414wrr; Sat, 22 Oct 2022 00:46:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6zltsJR+luioOOgN7VwK656HpmY4KGjHlWRU7GjMUPAVzk1qjNTWFjR5NMilx22XQ5wpju X-Received: by 2002:a17:90b:4d90:b0:20d:9ded:4144 with SMTP id oj16-20020a17090b4d9000b0020d9ded4144mr26491821pjb.90.1666424817386; Sat, 22 Oct 2022 00:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666424817; cv=none; d=google.com; s=arc-20160816; b=ialEAXokzWnVN25xhhM6bYb5OtN7DGcxegONjYtIsMjYqTyXka8y07HJXZW7snU4Ko B/WEzUUnS1qU6EU1vs7dDBIIKJQe2Y/kgii6XByZtnb6mV7ZjxY/DESFu8vbL9BifF5Y SrZR0ime92CGU05JJswcqAecU18UZqDoVRTpz/nZU6FhFmTcuam1E/fHy/5XfHajnMaZ gJJNMCJq/2iBNMJAsnc1q5ODF2ygl8nK9yE9WPwFM+/nagVtPUcI+8ZKtR97PR5ZYQOF QLvG4gslKiU75GuRQ8DQyTeDoTYaf2YGSn7Hf0q6I404t1uEHfThr9EwTAWC8v2Iaodo XKdQ== 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=+O/+gog64ttEPELBpFAxYHgbWKBe4ovNezxJhgAKnCU=; b=mzDpRvN31PckybhUAxSpcxFtTnRVBiajCh/Lr1RjHnB+pDDe5ZlbZaFVKLgQXDnpyn com5+fARAtxlzPGF6CH2b5LSCY7N71YBe78xtk4L0m+BpynhqRImm87aBxoo9vewFcW0 gXL7VavZOiGvzd/eV+bxKlHz/hQMkfxtuirhOnjLSVzkf7X1iRV85dH0gnqnydZHXd1O BUucQ1ehCq3b025Ut0RBDWgo6/vibIXt9/xAxDn1kHpLznfi0hwcT7qNMejsT0Y2RcUu /vL8LJkrHt7o5Drwo7gyT+m47BMXBjsazWP2YvyCjAvbS/lLQH89lRI+nP/pe8rDDhDp ecBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Acyx54Ii; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o8-20020a170902bcc800b00182c510591asi25097248pls.246.2022.10.22.00.46.44; Sat, 22 Oct 2022 00:46:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Acyx54Ii; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231462AbiJVHq3 (ORCPT + 99 others); Sat, 22 Oct 2022 03:46:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231529AbiJVHoa (ORCPT ); Sat, 22 Oct 2022 03:44:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1928625B254; Sat, 22 Oct 2022 00:43:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CD78BB82E05; Sat, 22 Oct 2022 07:42:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C136C433C1; Sat, 22 Oct 2022 07:41:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424519; bh=7Q6MPwhmrr5duWhaJn7LPUnD03iMIW/ggf8M3L2Dfm0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Acyx54IiQQjNTIqUny4gXPQaOLMLf33wZt0uIz0RBzmhilTMV9wrlDC5xi93RTc9v Qa9jLjf3hGtTbbf0sHR7mqs3MeUW7qSqKtPFjoO1XQ/S0Ny+VmJv9j/VwgQQzurIHa FD/fnJdiLVlODzgDlOqbpFRE6qRjJhWGNHE1rmqw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christian Brauner , Mimi Zohar , Sasha Levin Subject: [PATCH 5.19 177/717] ima: fix blocking of security.ima xattrs of unsupported algorithms Date: Sat, 22 Oct 2022 09:20:56 +0200 Message-Id: <20221022072446.904520536@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747373069221397680?= X-GMAIL-MSGID: =?utf-8?q?1747373069221397680?= From: Mimi Zohar [ Upstream commit 5926586f291b53cb8a0c9631fc19489be1186e2d ] Limit validating the hash algorithm to just security.ima xattr, not the security.evm xattr or any of the protected EVM security xattrs, nor posix acls. Fixes: 50f742dd9147 ("IMA: block writes of the security.ima xattr with unsupported algorithms") Reported-by: Christian Brauner Acked-by: Christian Brauner (Microsoft) Signed-off-by: Mimi Zohar Signed-off-by: Sasha Levin --- security/integrity/ima/ima_appraise.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c index bde74fcecee3..3e0fbbd99534 100644 --- a/security/integrity/ima/ima_appraise.c +++ b/security/integrity/ima/ima_appraise.c @@ -750,22 +750,26 @@ int ima_inode_setxattr(struct dentry *dentry, const char *xattr_name, const struct evm_ima_xattr_data *xvalue = xattr_value; int digsig = 0; int result; + int err; result = ima_protect_xattr(dentry, xattr_name, xattr_value, xattr_value_len); if (result == 1) { if (!xattr_value_len || (xvalue->type >= IMA_XATTR_LAST)) return -EINVAL; + + err = validate_hash_algo(dentry, xvalue, xattr_value_len); + if (err) + return err; + digsig = (xvalue->type == EVM_IMA_XATTR_DIGSIG); } else if (!strcmp(xattr_name, XATTR_NAME_EVM) && xattr_value_len > 0) { digsig = (xvalue->type == EVM_XATTR_PORTABLE_DIGSIG); } if (result == 1 || evm_revalidate_status(xattr_name)) { - result = validate_hash_algo(dentry, xvalue, xattr_value_len); - if (result) - return result; - ima_reset_appraise_flags(d_backing_inode(dentry), digsig); + if (result == 1) + result = 0; } return result; }