Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp99287iof; Sun, 5 Jun 2022 22:20:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMGUCycoqJ/+S6qb9Q0BRedFzUk/cvXSBamggprBvrrva/zGOFTviuzYcbTHaIo85SBk/6 X-Received: by 2002:a05:6a00:2293:b0:51b:f02e:de32 with SMTP id f19-20020a056a00229300b0051bf02ede32mr11981331pfe.17.1654492815224; Sun, 05 Jun 2022 22:20:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654492815; cv=none; d=google.com; s=arc-20160816; b=P75Ygxb8/n6ZuTM9aZl6lDsns9tMEW1X569n14xybcu0oXWHQ7VJbUgYfUvPsP1qsH gWd1p2a9AyTl1hppGue0Pi5mLiNRxbXwwJMdN3g0xpVn4M9WAwjCzXX73x7rj4NAiNoX bn1lG9XcAam0YcWdIweKO4sJZgnlys9D/9yZU2O071+XfNOgxuTDnV9yJC5gOn12JeCk C6XXhjIXjf29llZiNlFrykPPtjzW2WCyZCBib3oBq4Q6OwuI6eiIU20FuK/Zly9F8l7r RrvXmCm/oFLa4keiIsYhFhMMhrJwvtdLh1Wc2S5atDPLYfOlLcHUTtDlNpUbOvf7ujA7 aFuA== 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=XeNR/SsWp//WN/uuhBeP9RHvmcyWGjv5dhySNkMXpl8=; b=O4x+GGcrXvx/ntWq5ZoOBdDw2QRLHuFkiwTbsGuAkaacn92ocPHhgRqLK2y25EbQWi q6AKPTsWgKUKtmahHa7KPzBnWSB2W63JSrO8X1v5xQ0RqDdepU87W0NnL7FVUw8AaPDD /C9HEqrkmp1EHR3FYACFTi3qCNXwsbj06+xDT7/qJ/QboqsumtrxTRTgshUhYqv95PZk Bp/sKxCMj+rnYy3PhqBvfXT9JBtHkARZPOJwkfGd/dfZsfv7zAG0xQzBB/gM38Xlz8RW lxjN/ekNQphVD9ntBdAstk3iv1yuCCxluJhFJ4VnFjN68KR7BkkpkJvL5jMmGSaSSZ2Z f9+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uO8bTDCu; 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 j189-20020a6380c6000000b003fce1c18cf9si14317215pgd.213.2022.06.05.22.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:20:15 -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=uO8bTDCu; 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 3AB561F5888; Sun, 5 Jun 2022 21:30:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344971AbiFCRq5 (ORCPT + 99 others); Fri, 3 Jun 2022 13:46:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345224AbiFCRo7 (ORCPT ); Fri, 3 Jun 2022 13:44:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A0ED541BC; Fri, 3 Jun 2022 10:42:54 -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 5BDE361B38; Fri, 3 Jun 2022 17:42:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 675E7C385A9; Fri, 3 Jun 2022 17:42:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654278172; bh=iivZnCsGxGWmQ0PjJ522aDyjFbkGafcMRljsvmTodfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uO8bTDCurb98G5eRF60FOnp3CXv+XMLDNbMyNQAydaBk4CMmYjgIH92Hwo5+aTL83 geVaHbJOZjJwFlGilh98giZaLrJVFn3bXF1E3zc/u3w2G8BW1IJJopd+Kw0xS7iVZ/ ydrEfkcKL/7rzwyNPAJwl5tcc9tURwlVJOqO1ibw= 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 4.19 26/30] tpm: Fix buffer access in tpm2_get_tpm_pt() Date: Fri, 3 Jun 2022 19:39:54 +0200 Message-Id: <20220603173815.860604563@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603173815.088143764@linuxfoundation.org> References: <20220603173815.088143764@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 @@ -717,7 +717,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;