Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5244709ybe; Tue, 10 Sep 2019 00:15:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwnzaIY3AVjVirYl7Y6p1VpHtCVDo0beifuAoQyDSoG61fehk3uyHKlyrf6bzU4ZXbWOrY X-Received: by 2002:a05:6402:1426:: with SMTP id c6mr12370717edx.53.1568099753298; Tue, 10 Sep 2019 00:15:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568099753; cv=none; d=google.com; s=arc-20160816; b=AMm2nRQH04bAl582KACGQ5EEW2pDoCSHYOl7Os3ZD16vV6iB2m8ZcxIt0bQ3qRji+y fFpEhN5ChDm0hhBKmlq9CTMDHkCk7UylxW1L2QKw6vEs2nEFo6gj0r7FvwaxRTTQcVbD pihA9JmlrfUVe4RCGWm2B7vQqXR4h6RcHrBVjeNbmxIVncHlK7PXml7kKu8kNUVGC6wu JbdKmsVcfzfVrHHZ8RVloMBYcAbx+5ABQ4bmfvJmc3c28LI1d6A43YRFYNBBnTidrCvZ KRMp/Sa4+5eZEsBh5rCks0MzyjdInEuPMPpa/cxAkyYol55TiivulcVg3g9+4+DI+f0l 69jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature:dkim-signature; bh=tRYNmXB+OTSQdbtYI2RzgenOfLLoSRPlp2Un5N6ue8s=; b=B1ing6oWpzOWt1w3yZZz8lpLgh51plpkTIzHBracu/flYYLCTSYIiXOMdq0p3pYoYk p+/NvG4ABX8j+hyBUyA6NSRenzrUnQRHllsa+mCMCD2rs5vrEReA/DTyDGGpq8oh+uMn 7vgKwv0qSnRPem5JY7MdbJu1jj3KuWsX461/bIUizO4IygmU4uVpoOVN4iM1/Gk76vVZ PQbsGlGpr3yk3RNLC6oO8QXyWqvFbKeFg/aRktRggb2mfcqLXv83IKDZIcMTC2shdy77 pCtcSybbHvjGs0cllRxvRdN5MOIqB+L047sFx7tUwCE0CdSD6Ft3iABJ3QBWhRr2vGTC cDdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=vGz2DLk7; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=vGz2DLk7; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hansenpartnership.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l21si8778557ejg.365.2019.09.10.00.15.19; Tue, 10 Sep 2019 00:15:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=vGz2DLk7; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=vGz2DLk7; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hansenpartnership.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731303AbfIIMVr (ORCPT + 99 others); Mon, 9 Sep 2019 08:21:47 -0400 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:48268 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726008AbfIIMVr (ORCPT ); Mon, 9 Sep 2019 08:21:47 -0400 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id ECDC48EE180; Mon, 9 Sep 2019 05:21:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1568031706; bh=gqf6WgGq84ztgJ7EfhZXjh7m/VKvK9/wTfvOmBw2jeU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=vGz2DLk7e1YbwHo12r8IJxFdbiuxfknWweuwVOantB4NQWifustgUAlpSr+H7VUn7 pXYyiJO6IEQLRjy9YUBmN/WZNNScYGCebKnvCQPuf+yJSzm6Q96L6/b67QEPFfbW0S aPFkXAKJWxm3CW72MdbwNXedOy9Nd22hg6UqOEGk= 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 fVOnH2bKexWG; Mon, 9 Sep 2019 05:21:46 -0700 (PDT) Received: from [192.168.6.117] (unknown [148.69.85.38]) (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 BC7B68EE105; Mon, 9 Sep 2019 05:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1568031706; bh=gqf6WgGq84ztgJ7EfhZXjh7m/VKvK9/wTfvOmBw2jeU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=vGz2DLk7e1YbwHo12r8IJxFdbiuxfknWweuwVOantB4NQWifustgUAlpSr+H7VUn7 pXYyiJO6IEQLRjy9YUBmN/WZNNScYGCebKnvCQPuf+yJSzm6Q96L6/b67QEPFfbW0S aPFkXAKJWxm3CW72MdbwNXedOy9Nd22hg6UqOEGk= Message-ID: <1568031703.6613.35.camel@HansenPartnership.com> Subject: [PATCH v6 06/12] tpm-buf: add tpm_buf_parameters() From: James Bottomley To: linux-integrity@vger.kernel.org Cc: linux-crypto@vger.kernel.org, linux-security-module@vger.kernel.org, Jarkko Sakkinen Date: Mon, 09 Sep 2019 13:21:43 +0100 In-Reply-To: <1568031408.6613.29.camel@HansenPartnership.com> References: <1568031408.6613.29.camel@HansenPartnership.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.6 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Introducing encryption sessions changes where the return parameters are located in the buffer because if a return session is present they're 4 bytes beyond the header with those 4 bytes showing the parameter length. If there is no return session, then they're in the usual place immediately after the header. The tpm_buf_parameters() encapsulates this calculation and should be used everywhere &buf.data[TPM_HEADER_SIZE] is used now Signed-off-by: James Bottomley --- drivers/char/tpm/tpm-buf.c | 10 ++++++++++ drivers/char/tpm/tpm.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/drivers/char/tpm/tpm-buf.c b/drivers/char/tpm/tpm-buf.c index f56350123a08..a5d793d8180d 100644 --- a/drivers/char/tpm/tpm-buf.c +++ b/drivers/char/tpm/tpm-buf.c @@ -190,3 +190,13 @@ u32 tpm_get_inc_u32(const u8 **ptr) return val; } EXPORT_SYMBOL_GPL(tpm_get_inc_u32); + +u8 *tpm_buf_parameters(struct tpm_buf *buf) +{ + int offset = TPM_HEADER_SIZE; + + if (tpm_buf_tag(buf) == TPM2_ST_SESSIONS) + offset += 4; + + return &buf->data[offset]; +} diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index ebead8e4c3fe..c88eee6376e4 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -311,6 +311,8 @@ u8 tpm_get_inc_u8(const u8 **ptr); u16 tpm_get_inc_u16(const u8 **ptr); u32 tpm_get_inc_u32(const u8 **ptr); +u8 *tpm_buf_parameters(struct tpm_buf *buf); + /* opaque structure, holds auth session parameters like the session key */ struct tpm2_auth; -- 2.16.4