From patchwork Wed Oct 19 08:24:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5125 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp251425wrs; Wed, 19 Oct 2022 03:51:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7rZdESfkQ4BCVCTQqL+xYqHbd6/55JUsWAZLEIVkwkLlhgpob7hosHr848qeI9gQxMu432 X-Received: by 2002:a17:907:2710:b0:78d:9be4:492a with SMTP id w16-20020a170907271000b0078d9be4492amr6015335ejk.151.1666176700998; Wed, 19 Oct 2022 03:51:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666176700; cv=none; d=google.com; s=arc-20160816; b=RuVXB5qbscTEjgDZhBvFF5MApHNddKIBwnuB6ie0bqL0uY3bYMeRVooJyLn4Pdiimm fT8uXyYr3K20pJs3Nq6zhF/FlpDLIbqhTZuCzmNxpa542EHEH+DF5o2eOB2e11Vo52iG 648gvO1PQimChpUB9a/kzZcAadoyAoAykRfR6prNFMzJz5tTAK8A/L6h0h8g1M10SLRj VA66nfxN6gvL0htshpu9rmyKlqp9t/6rVZUURU2H1eoUNCpi3INzGB01vRAy4hDMrcwv /38hzFMUHSCWHP9iBOFbmQSmQhc9be8qijn1YOJziNpmup2z6b2UdSs1RG2HviuvHAmc slbA== 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=KK85ApFBCpM/C2rHr8ROARWaJXCtJnLvktDFtx2x9EIjWSNuv70/nzcoVrfXVcyNKt r3e2/W8FBGm4rsjGkshhag25UUzVp5V2MOFaIzadQqxOOAvy744S3Gi05pzSGtZ9Q0Pu +FE6y7PMBZ8odqRDeVv49Wz/7K47HOocYZ44TrBSCHaJNnLUimUYmyBs92ozwHfLZt9v hIXHVuyJwwFxAHh3uXwQ6LBCb7D1dACTYd0HMDh8wUjFX2GwMuGp99QlVLdgTYJ7l93x M8+k2K+L/gb/m5uQiqUfIwoXsRqXGwqhPUoxRjmRZWPDGmUFrP7xmk1ak/fmtm1qEn3k vttw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WEpHNCbr; 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 bo12-20020a170906d04c00b007828ae31468si10874682ejb.698.2022.10.19.03.51.15; Wed, 19 Oct 2022 03:51:40 -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=WEpHNCbr; 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 S233586AbiJSKuI (ORCPT + 99 others); Wed, 19 Oct 2022 06:50:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233848AbiJSKrq (ORCPT ); Wed, 19 Oct 2022 06:47:46 -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 4E92B15B117; Wed, 19 Oct 2022 03:21:52 -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 1D205B8231B; Wed, 19 Oct 2022 08:47:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71B85C433D7; Wed, 19 Oct 2022 08:47:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169230; bh=7Q6MPwhmrr5duWhaJn7LPUnD03iMIW/ggf8M3L2Dfm0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WEpHNCbrn8SRy9cOEnx0tMEWYXafRSgNlA0Q7obZqmiXk08i1G1EUTiqC49gNWwii pZ7oPzhP8VVQPf+DBJGs/Ri9c16c7CJnniNsqnPJpcIT5zIxBWzxfIzN83Y7Vbnuav 51ZtjzZETTi1OU6quNOyYhKi2B2v9GOkQLz49/mU= 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 6.0 203/862] ima: fix blocking of security.ima xattrs of unsupported algorithms Date: Wed, 19 Oct 2022 10:24:50 +0200 Message-Id: <20221019083258.973461857@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747112900811508818?= X-GMAIL-MSGID: =?utf-8?q?1747112900811508818?= 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; }