Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8839860imu; Tue, 4 Dec 2018 15:20:05 -0800 (PST) X-Google-Smtp-Source: AFSGD/U2Rj48XbX7QxrNUI3ZRxR59HpQPZxOLhQzqU4efc2JnBPb4pA8/uxfSOP1i6B8wPqY7k59 X-Received: by 2002:a62:e044:: with SMTP id f65mr21860771pfh.208.1543965605245; Tue, 04 Dec 2018 15:20:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543965605; cv=none; d=google.com; s=arc-20160816; b=bjXZz0XGq4qvo02OwqecblxN4D+wwN7a0maEAsAb18pkPxAT5ia5m5UlnaiW0y78ct AvHjvHKWhD4Pac2PMBYLBWtzfODM0StkhJ7rzM0+1Vjj+fmOmyH+DYTGnCsVj9pKjGsw 2sxsl5WwHLaG4WmzjN6dp8hVfgLndd7e2MAH1GoDHDxodukfToQ+cSmXbR0pxiHtCMo+ nDpUQdAShBFPlrYpko3TvtwOIE9sbkRa1cqAT9MDdEcr48SUO6igA48oCCtm3mOWbOMq eq7cG7U5Bf8Jo6zHqCLhlVGvmilu63VjFaOljjuqAkjGp8y1S2WV+naNLPz41OoHblYU MGCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=zev7oGPl36t5Z8FD6qvPXy52Siz3UyZIg24/bgGEY70=; b=w1HsbjPWfofb3wjcXO4QAldc/v8Ip4Cbt7XFHZJ2xNyjapkFGQ0ub4tDmH+wc5w1Hi qurzpT26WwyU3yN49iqz4hwNJlj2bYeU8hqYB3w4D5gi4P9htPaFjqziYkzk4tDYZ4Pe BYmeTA5ayJ4ItqkuB1Q2SRKYNHbZgz7xggdQveZHsJGoPThJX2+EdBtAeTAsYjKLO89F q5LoylXIIqFa6nqJNiM3Swilx61eNtcEp3Z84liQR0mdRuqgrKT6ZDEdpnaqKblTbAXK Rmca1CbjF67uw57uQ+9vJ8Ztt5lVsldWjTQJrnPnaLg19IEV1e1RulqBG+EHS8VA9xCH QWMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v25si15750401pgk.341.2018.12.04.15.19.49; Tue, 04 Dec 2018 15:20:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726391AbeLDXSv (ORCPT + 99 others); Tue, 4 Dec 2018 18:18:51 -0500 Received: from mga09.intel.com ([134.134.136.24]:14341 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725875AbeLDXSu (ORCPT ); Tue, 4 Dec 2018 18:18:50 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Dec 2018 15:18:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,316,1539673200"; d="scan'208";a="116067975" Received: from jsakkine-mobl1.jf.intel.com (HELO localhost) ([10.24.8.183]) by FMSMGA003.fm.intel.com with ESMTP; 04 Dec 2018 15:18:48 -0800 Date: Tue, 4 Dec 2018 15:18:48 -0800 From: Jarkko Sakkinen To: Roberto Sassu Cc: zohar@linux.ibm.com, david.safford@ge.com, monty.wiseman@ge.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, silviu.vlasceanu@huawei.com Subject: Re: [PATCH v6 1/7] tpm: dynamically allocate the allocated_banks array Message-ID: <20181204231848.GA1233@linux.intel.com> References: <20181204082138.24600-1-roberto.sassu@huawei.com> <20181204082138.24600-2-roberto.sassu@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181204082138.24600-2-roberto.sassu@huawei.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 04, 2018 at 09:21:32AM +0100, Roberto Sassu wrote: > tpm2_get_pcr_allocation() determines if a PCR bank is allocated by checking > the mask in the TPML_PCR_SELECTION structure returned by the TPM for > TPM2_Get_Capability(). One PCR bank with algorithm set to SHA1 is always > allocated for TPM 1.x. ... > + for (j = 0; j < pcr_selection.size_of_select; j++) > + if (pcr_selection.pcr_select[j]) > + break; > + > + if (j < pcr_selection.size_of_select) { > + chip->allocated_banks[nr_alloc_banks] = hash_alg; > + nr_alloc_banks++; > + } > + Why was this needed? Can CAP_PCRS return completely unallocated banks? Kind of out-of-context for the rest of the changes. Should this be a bug fix of its own because it looks like as this is a bug fix for existing code, and not a new feature? Just asking because I don't yet fully understand this change. Anyway, I believe that you can streamline this by: /* Check that at least some of the PCRs have been allocated. This is * required because CAP_PCRS ... */ if (memchr_inv(pcr_selection.pcr_select, 0, pcr_selection.size_of_select)) nr_allocated_banks++; [yeah, comment would be awesome about CAP_PCRS. Did not finish up the comment because I don't know the answer] In addition, it would be consistent to call the local variable also nr_allocated_banks (not nr_alloc_banks). /Jarkko