Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp49755iof; Sun, 5 Jun 2022 20:45:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYtWYEtMIpHs7zFIVoqtLbnGW+3Wk7raPNK75zobBz/jqpc0IL4o3y5i80Qbmi7PvvzEph X-Received: by 2002:a17:902:b688:b0:162:3124:cde2 with SMTP id c8-20020a170902b68800b001623124cde2mr22495396pls.166.1654487148983; Sun, 05 Jun 2022 20:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654487148; cv=none; d=google.com; s=arc-20160816; b=qJyctZJrewjn9DwaHjfa/9rfhenPBXNJplDRIcx38dgyUUrwATog814WrsYhT5WRGS FWkOVcKyQRoHmxmVSo1Oz6aSkbp7ja8LsgPtWdqkEFcP2h5jJJO9S6r9Z2piNk/p7MW0 Ueq20QXElPBXdV5TrAih6AaM1EA72bO3GkcWzvSSe9tbjpqM5d5dTA2gpUnwjWCeLCxz wsVObW6ChZEkG7BsCdWMP4Os3FkzCcI5DoQV1/wYvCWh7xIOEq7WTRd+a7h3rrCDR9MP 5m2cTaYh4Im9rnlL0CNg5i5YganawSuAXyJ8/4FSZ4R4pZ/KVkUzcwDysyMeMgGX73cW uCXA== 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=ZDtbjXHkM9a70PO4HNS9xWC37Wv0NifH0Jwwwepc3JQ=; b=u4yTSjkbw21126HK0BkxusdE35v9rrwIALblmfQrERaNny759rkjnaV2CEh5AwanFD Lli6ZMH321hYfRpltlO4rrFQYMXY5h2U/393G/EsblnybErMf9TdrDRZwQBIoNcu3So8 M8PazTiN7GZRGFiwLZNJH4W+BQ+w5A112NtAaca4UkAPsTmwtAHWzj8DxMfevVtxhW3l w9Bt+zVz7gMZeQ9dBVSn0sGcWjySaUuq/b6iYMJW6ivtG1znQ0Qja/vwJdZwtZVhecFX G57lrQoeE6wG/P7c062nLAvgruhMo7e7DPkN7ICx9t69t5Zl29d6QFFH+5O6kyykM0Lc s3hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=faVpcDpd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b8-20020a170902e94800b001615b0c59f0si18465234pll.225.2022.06.05.20.45.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 20:45:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=faVpcDpd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 74F265A142; Sun, 5 Jun 2022 20:39:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345429AbiFCRtj (ORCPT + 99 others); Fri, 3 Jun 2022 13:49:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345004AbiFCRsU (ORCPT ); Fri, 3 Jun 2022 13:48:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF185541AA; Fri, 3 Jun 2022 10:45:24 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 7C25A60A6B; Fri, 3 Jun 2022 17:45:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CB3BC385B8; Fri, 3 Jun 2022 17:45:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654278323; bh=e1GvVuGQ+unzosyZcj6xC7FjpppfWqxA/blqXv1Kyd4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=faVpcDpdOgk7m2EIL3xxanoDyuwZWeSsd+calvMaG0P7GpQSTXgmEA4vBb199+EB/ ekf8C3fSsr/YIJooKRhHk8toGdZH4jV5r2bX2QWL0RKAIhBDsbsmoZj8yg8dnaSdwA AqAnloLn8Qh7vlqnizWLbkyC5cTVeY0CEuNFfv3Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stefan Mahnke-Hartmann , Jarkko Sakkinen Subject: [PATCH 5.4 29/34] tpm: Fix buffer access in tpm2_get_tpm_pt() Date: Fri, 3 Jun 2022 19:43:25 +0200 Message-Id: <20220603173817.028616126@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603173815.990072516@linuxfoundation.org> References: <20220603173815.990072516@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Stefan Mahnke-Hartmann commit e57b2523bd37e6434f4e64c7a685e3715ad21e9a upstream. Under certain conditions uninitialized memory will be accessed. As described by TCG Trusted Platform Module Library Specification, rev. 1.59 (Part 3: Commands), if a TPM2_GetCapability is received, requesting a capability, the TPM in field upgrade mode may return a zero length list. Check the property count in tpm2_get_tpm_pt(). Fixes: 2ab3241161b3 ("tpm: migrate tpm2_get_tpm_pt() to use struct tpm_buf") Cc: stable@vger.kernel.org Signed-off-by: Stefan Mahnke-Hartmann Reviewed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: Greg Kroah-Hartman --- drivers/char/tpm/tpm2-cmd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -706,7 +706,16 @@ ssize_t tpm2_get_tpm_pt(struct tpm_chip if (!rc) { out = (struct tpm2_get_cap_out *) &buf.data[TPM_HEADER_SIZE]; - *value = be32_to_cpu(out->value); + /* + * To prevent failing boot up of some systems, Infineon TPM2.0 + * returns SUCCESS on TPM2_Startup in field upgrade mode. Also + * the TPM2_Getcapability command returns a zero length list + * in field upgrade mode. + */ + if (be32_to_cpu(out->property_cnt) > 0) + *value = be32_to_cpu(out->value); + else + rc = -ENODATA; } tpm_buf_destroy(&buf); return rc;