From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_2 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC4F6C433E0 for ; Wed, 22 Jul 2020 00:39:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B49372077D for ; Wed, 22 Jul 2020 00:39:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=hansenpartnership.com header.i=@hansenpartnership.com header.b="tfoIqvoT"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=hansenpartnership.com header.i=@hansenpartnership.com header.b="tfoIqvoT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727045AbgGVAjr (ORCPT ); Tue, 21 Jul 2020 20:39:47 -0400 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:41586 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726468AbgGVAjr (ORCPT ); Tue, 21 Jul 2020 20:39:47 -0400 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id CD2898EE269; Tue, 21 Jul 2020 17:39:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1595378386; bh=HemS2Wx1CbQ5r0AN07L/O+M5UepaijzVbSxf8O2v4qE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=tfoIqvoTKrU8jpC0fFI4bV92tsGpQVC/Hs3KphAx4K/ShYjalN0PV1pzh4FjBDlCm lPvyx81mQMr+xeTgOvBqNI0jvuxCR8Viwt3ksE+UCxkThDSejOptqIJF5Rr8adU3rh XE43rccxmmaFy/wQ+trV+i/cOOzwx8hHbxOTtaek= Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MCIGWM6Wk-SZ; Tue, 21 Jul 2020 17:39:46 -0700 (PDT) Received: from [153.66.254.194] (unknown [50.35.76.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id 674208EE207; Tue, 21 Jul 2020 17:39:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1595378386; bh=HemS2Wx1CbQ5r0AN07L/O+M5UepaijzVbSxf8O2v4qE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=tfoIqvoTKrU8jpC0fFI4bV92tsGpQVC/Hs3KphAx4K/ShYjalN0PV1pzh4FjBDlCm lPvyx81mQMr+xeTgOvBqNI0jvuxCR8Viwt3ksE+UCxkThDSejOptqIJF5Rr8adU3rh XE43rccxmmaFy/wQ+trV+i/cOOzwx8hHbxOTtaek= Message-ID: <1595378385.3575.31.camel@HansenPartnership.com> Subject: Re: [PATCH v2 1/1] tpm: add sysfs exports for all banks of PCR registers From: James Bottomley To: Jerry Snitselaar Cc: linux-integrity@vger.kernel.org, Mimi Zohar , Jarkko Sakkinen Date: Tue, 21 Jul 2020 17:39:45 -0700 In-Reply-To: <877duwl8n9.fsf@redhat.com> References: <20200721155615.12625-1-James.Bottomley@HansenPartnership.com> <20200721155615.12625-2-James.Bottomley@HansenPartnership.com> <87a6zslar5.fsf@redhat.com> <1595374674.3575.28.camel@HansenPartnership.com> <877duwl8n9.fsf@redhat.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.6 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org On Tue, 2020-07-21 at 17:02 -0700, Jerry Snitselaar wrote: > James Bottomley @ 2020-07-21 16:37 MST: > > > On Tue, 2020-07-21 at 16:16 -0700, Jerry Snitselaar wrote: > > > James Bottomley @ 2020-07-21 08:56 MST: > > > > [...] > > > > + /* > > > > + * This will only trigger if someone has added an > > > > additional > > > > + * hash to the tpm_algorithms enum without > > > > incrementing > > > > + * TPM_MAX_HASHES. This has to be a BUG_ON because > > > > under > > > > this > > > > + * condition, the chip->groups array will overflow > > > > corrupting > > > > + * the chips structure. > > > > + */ > > > > + BUG_ON(chip->groups_cnt > TPM_MAX_HASHES); > > > > > > Should this check be 3 + TPM_MAX_HASHES like below? > > > > No, because at this point only a single additional group has been > > addedin addition to the hashes groups. The first line of > > tpm_sysfs_add_device is > > > > WARN_ON(chip->groups_cnt != 0); > > > > And then we add the unnamed group. This loop over the banks > > follows it, so chip->groups_cnt should be nr_banks_allocated by the > > end (it's the index, which is one fewer than the number of entries > > in chip->groups[]). We have a problem if nr_banks_allocated > > > TPM_MAX_HASHES > > > > which is what the BUG_ON checks. > > > > James > > If the chip supported all 5 listed cases wouldn't groups_cnt be 6 at > this point? Actually, yes, I think it would be because it's pointing at the next free index not the current one. So it should be BUG_ON (chip- >groups_cnt > TPM_MAX_HASHES + 1) James