Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2156789lqo; Sun, 19 May 2024 16:52:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVoV5zfM9dmM40mSyFoexwztEy8p+zX3CB5+3kYChbgLhdAj/bPlXEjHz1usRj0LLg/yUOqEunVt89N0Ob8CMMoKOOTAe3D6iLXL3J9+g== X-Google-Smtp-Source: AGHT+IHBmrWg8Es66nXAUnavWt93dqJCOcKoHmDVj/lIZl2JsrEjonlu/fSvbUIlTwvWoLWC0E0t X-Received: by 2002:a05:6a20:431a:b0:1af:6911:ddf3 with SMTP id adf61e73a8af0-1afde0af0bbmr30995415637.7.1716162737262; Sun, 19 May 2024 16:52:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716162737; cv=pass; d=google.com; s=arc-20160816; b=W6OyiuLsld9MQA41eF6qiJCIryOH9nmC/cd4ar+N/3QCwz68yk0ZbDDxVDWmWnB+ur jO6IJPx1wadP5SFCSV4UvwKwgI8Hs36RQwQLFVZzYiQnsR6ct2sHI5sU0t/gVK2j31Cq M78bYnIuZ6Qd3MrdgY5bWBPb92wimfaKkItla+MGd7GDMnDHZzqfPTCtcV/Fd1J0RZvg JcEk9hiTd6d/HyyItgXRfZ0D7MvFf7HGR0yFleYQNq13lN1o52TnODxT2bhD0W1PBsk6 ww8MR+Ck6Tw0KSZIlU4aONDXWNtlUZhC2tKX2eMZ/ru15bT4eXTP9XzScKUi6ex54+FL IezA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=8ItXH7ww45b4C7cKTXpA9ZCp1neT4t/nWWbv2HCHy/I=; fh=hVg4LrrhFSDzbriqHJpcMiUtLePPU0VRrh7QdWe4jXM=; b=eemRmYZrmc96JfCC+Mx5OJTpbTbX15nhGsScJpppvtDK/xL4//VIpZegJ644sucH7Q DB4+y0hj7BM6BYwFITIIPEgTzkyM15lHPddREywO8lKXDyNZMq+2DIKPeerQdWqriU6X /Nd8LDu3aQqf8tEUQcaSsQQaxMdGMTfZJ4EVAnFwpiOgVAq5NtOYhCIl6ndb4ukX03kI xDLOcdHKDgvJdhbiBY+98Div9tOBH/FUJH69dt/CO3TfNv8KDwbqzSxpipf8ZdyeoBWN 2AkuwdbLWD1eLK10r+1rNxGu7PkCUT3fQMY0nbW4fmxoDbjHg0xbRy2Ccpi27rF3ipd3 j+rg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=l3Lb2162; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-183310-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6341171922bsi7178252a12.533.2024.05.19.16.52.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 16:52:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183310-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=l3Lb2162; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-183310-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E04C1281014 for ; Sun, 19 May 2024 23:52:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B2BB77580E; Sun, 19 May 2024 23:51:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="l3Lb2162" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBC327319C; Sun, 19 May 2024 23:51:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716162700; cv=none; b=rXaSUy07TWHam0tr6IUN+EmA4/qsLcPeKbIcX8Wlla3IR1G5yiTg/3JOixhbx+8dYo0vhG52KCmeMhRgifRbj3LFNr1ovqnwk4b70pVvPLGUSahLUAAlEtttxFfBWKclHV6sNSmISgJ0PbdXp9keKUWTeffUPtulAkuXUVhzJw4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716162700; c=relaxed/simple; bh=zjmdVHD9xhS/1n4Rw9BcJgcMBhyRpG01mLSj2X8CQ7M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AfkvPHxlCk0ASx4yH5WlbhBbvG0mRmuNyVKUWj+kYfj397+xuxcf4usYAuFhdL8duhSOZPU8g4bbpJNCXTr/fG4Hc+E19ZQIurtpZcZhLTdlESO9RBiAqT6IZQIxAjRCGBQcFJDExksnDqAQKocPztbLpZIshdnwaBLm60GUfb0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l3Lb2162; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E683C32781; Sun, 19 May 2024 23:51:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716162700; bh=zjmdVHD9xhS/1n4Rw9BcJgcMBhyRpG01mLSj2X8CQ7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l3Lb2162/JhmAcr52fdxBYIVFT0E0WJqupbELbdF7J/L+4DQ1f/B9o3012H8g6c9w wmzLSzMjwFDWWSduTDLjbgXWQPATveMALp4SZS9CoGD5KKynYXO/5RZjc+oUw0tcJM +qGBxmFCEoN0bV8fdKxLceFd634RgcK8cxUhrZsNjLUp75m+NkuCJ0FLQQfT++0Rqd owCILHuxNo0OQIyE+FPI+Rp7j5sW2ox4LFyHkMopYAkFIfvMCHQ4WyuJD5/pVsYROf xOSU455i/+We96q/x+a2PtLZdZC98DgKk+zaqCjCZ/abHOJQLVG7XVHGGFs3FABQHe Y9tJ0LMP5TeCw== From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: keyrings@vger.kernel.org, James.Bottomley@HansenPartnership.com, Jarkko Sakkinen , stable@vger.kernel.org, Mimi Zohar , David Howells , Paul Moore , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] KEYS: trusted: Do not use WARN when encode fails Date: Mon, 20 May 2024 02:51:21 +0300 Message-ID: <20240519235122.3380-4-jarkko@kernel.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240519235122.3380-1-jarkko@kernel.org> References: <20240519235122.3380-1-jarkko@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When asn1_encode_sequence() fails, WARN is not the correct solution. 1. asn1_encode_sequence() is not an internal function (located in lib/asn1_encode.c). 2. Location is known, which makes the stack trace useless. 3. Results a crash if panic_on_warn is set. It is also noteworthy that the use of WARN is undocumented, and it should be avoided unless there is a carefully considered rationale to use it. Replace WARN with pr_err, and print the return value instead, which is only useful piece of information. Cc: stable@vger.kernel.org # v5.13+ Fixes: f2219745250f ("security: keys: trusted: use ASN.1 TPM2 key format for the blobs") Signed-off-by: Jarkko Sakkinen --- security/keys/trusted-keys/trusted_tpm2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trusted-keys/trusted_tpm2.c index c6882f5d094f..8b7dd73d94c1 100644 --- a/security/keys/trusted-keys/trusted_tpm2.c +++ b/security/keys/trusted-keys/trusted_tpm2.c @@ -84,8 +84,9 @@ static int tpm2_key_encode(struct trusted_key_payload *payload, work1 = payload->blob; work1 = asn1_encode_sequence(work1, work1 + sizeof(payload->blob), scratch, work - scratch); - if (WARN(IS_ERR(work1), "BUG: ASN.1 encoder failed")) { + if (IS_ERR(work1)) { ret = PTR_ERR(work1); + pr_err("BUG: ASN.1 encoder failed with %d\n", ret); goto err; } -- 2.45.1