From patchwork Mon Oct 24 11:28:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp554231wru; Mon, 24 Oct 2022 09:56:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7bwTdk/FkI16tOk0ilkQjwBaYChQjWBOF9c8/A8mbxS/UuRT7+FFueC3ienamD/th2//YI X-Received: by 2002:a17:902:8a88:b0:17f:8642:7c9a with SMTP id p8-20020a1709028a8800b0017f86427c9amr35397450plo.13.1666630595800; Mon, 24 Oct 2022 09:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666630595; cv=none; d=google.com; s=arc-20160816; b=ebmyf0gp32vhzGoxTYyf7hrW3QfLEDPYOsujQgYdvmZOyaMvAhvrpsLxMVidwUWJw7 y3dpxfulRyvqgdGRBuM4DylJwPEieN+t+J14Wvtz7UEDG+j1lrOHfT5LZIjTGjGRPhZN B/m8cDFLF/7kN9e+FDXaNF1vEx0WXnjttwgbU1goTAWCiIUCR0iuweOkrjfye3sjfqby cMm+yfUo26ymtkRCo/qshwH4/javNsKhIiTgMhbQHHXrbGm8nBnKGk1w047Mrf9mXcei 1ZkbX1aXaYSvKOVZ7+MD9mah376WPGhTI404kkros3X4jYHcrOE3Au3jFuF+axS78u4C EavQ== 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=wxep7Da0hCPN4H87Lg2pJLHOl90K8ToLf15iDTdTIXI=; b=NPLNyEToWWkKAuEOq6i0Bzw6OdXQTX5TrTnMyeY1E6ZCera9nwSQrBwPwZmerwhKcQ 8/tYCu+nGk6AnNfFcmERih3aoaxmvc9nLWl4b2oawxKw5kqaHnrtaIEYkjfjhnnya7a/ EARiV41ciQh3e/D61GaT053OkQ5nZA49iVTJtmnCSVsytY9GgdkK0bhTSvqrP72GheZV jcndKwpjNCPat0wIHHNjCuCsyY7+Fol+xaJNQnwwYwSwcy72vbywvXjEF38hZs2rohxb 8yaBG6LirHnaZKXwFIayBpVAofpN/aphp/UxBM6YL6hu/Z081u3BniDs7O0DHkWkZ2FA gwaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZNFgh4K+; 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 kb18-20020a17090ae7d200b002036f0a953esi529503pjb.88.2022.10.24.09.56.18; Mon, 24 Oct 2022 09:56:35 -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=ZNFgh4K+; 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 S230193AbiJXQuS (ORCPT + 99 others); Mon, 24 Oct 2022 12:50:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232997AbiJXQrN (ORCPT ); Mon, 24 Oct 2022 12:47:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 349B91BF228; Mon, 24 Oct 2022 08:31:34 -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 27311B8196F; Mon, 24 Oct 2022 12:40:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 734F3C433C1; Mon, 24 Oct 2022 12:40:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666615216; bh=A1DSbYE0CBk14ThL+CHiNgxGZfZvPhBFaGIk2PLlJqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZNFgh4K+WqC4uCH5LhGswvoKJ4rB5mq8CCJUuJY+UTut0IwCW5aBj/4Qydtydap81 /zR4irubC27F/Gv25PUiDg93HvLVyqgsPQedaofIb3NLn2CWLFgVrXWTslDlAd1ZMv EOSWIcFGi9QohItnMpPJUN77WVBFuNdF3GIV6a+M= 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.15 136/530] ima: fix blocking of security.ima xattrs of unsupported algorithms Date: Mon, 24 Oct 2022 13:28:00 +0200 Message-Id: <20221024113051.209158341@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747588843715940210?= X-GMAIL-MSGID: =?utf-8?q?1747588843715940210?= 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 ed04bb7c7512..08b49bd1e8ca 100644 --- a/security/integrity/ima/ima_appraise.c +++ b/security/integrity/ima/ima_appraise.c @@ -644,22 +644,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; }