Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3022183imj; Mon, 11 Feb 2019 12:27:16 -0800 (PST) X-Google-Smtp-Source: AHgI3IaJSmzt0ylc+2SaVDVJGQnKhgdtesjxVY5zramO42v39494emSRA673G/dQ33JJt0hgsKEW X-Received: by 2002:a62:20d1:: with SMTP id m78mr53738pfj.250.1549916836037; Mon, 11 Feb 2019 12:27:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549916836; cv=none; d=google.com; s=arc-20160816; b=DgikgHTt0laAlXLhlThzbkcfA0FSu9bT+RS4yMr4jBZVFAk8zd3YhTJfYmJ0npdQdX apMfDssrxD27rB8yiLewky1h+eCYXDliGbovwydR6Qj2oySnvC92yw9Af6tyz+Z8CFbx PqQRIgxTbzfFxqcvg7J0ZsBokVSDgPDpLMaGRCumVy9hmxSqOwIakliqbBvTcR+giXYt OZUwAAEsodPUmt9tvASSg35IcILyu9GfPJOnCsae9YPueXesg6fcBb66YWKxA9wBTF0P zvIL+Ewpf3UUuKLSNwF6MvAALYFs7EJQHRXunCi3ooWj8WM41a7tc/JuyV0edF32gS+j tCCQ== 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=q36xuN0xhiQX5luWmY+liINRnpDdrp0vG5VbWxxwPPY=; b=VLMVXz8xR9Ny270FeKXZEwFk6Wv0KiOTisZGR5G0fY2YQKbWvSZrxSvqjJwMk/hrT2 dNFaCqaWmy376rlqK18kLKs76hY/d87j1wllrnF1wegvxKOzt9+/e7fEoq3c7jpDhUrh bS5lcwh4slNruyey5UY5NALbQdzcygkKH/Rdd93iq0niz9groprsk69YWlCaH1Fq2tzh ki0Z3wFxgJEqC2ZL8ldnm+QCwcGCvQIT1ky+4xkvN5w0mHHsnW4hxbegcJHgPKUIHEPG lsD9F/s+Naw1Dh1caCkM9AGLwSL4krd6ViTvata7yBTjFJy7BwHz1NNkxNfxdixbtNg5 eCUw== 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 128si567795pgb.373.2019.02.11.12.26.22; Mon, 11 Feb 2019 12:27:16 -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 S1729466AbfBKQsK (ORCPT + 99 others); Mon, 11 Feb 2019 11:48:10 -0500 Received: from mga05.intel.com ([192.55.52.43]:47093 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728968AbfBKQsI (ORCPT ); Mon, 11 Feb 2019 11:48:08 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Feb 2019 08:48:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,359,1544515200"; d="scan'208";a="114050317" Received: from jsakkine-mobl1.tm.intel.com (HELO localhost) ([10.237.50.142]) by orsmga007.jf.intel.com with ESMTP; 11 Feb 2019 08:48:04 -0800 Date: Mon, 11 Feb 2019 18:48:03 +0200 From: Jarkko Sakkinen To: Tadeusz Struk Cc: linux-kselftest@vger.kernel.org, shuah@kernel.org, linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, PeterHuewe@gmx.de, jgg@ziepe.ca Subject: Re: [PATCH 2/2] selftests: tpm2: Extend tests to cover partial reads Message-ID: <20190211164803.GG8431@linux.intel.com> References: <154939851385.18477.481518864800562919.stgit@tstruk-mobl1.jf.intel.com> <154939851969.18477.13778157467131576825.stgit@tstruk-mobl1.jf.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <154939851969.18477.13778157467131576825.stgit@tstruk-mobl1.jf.intel.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 You are missing a cover letter from this patch set. Please have it in v2. Also use tag "selftests/tpm2" instead of having two tags in the short summaries. Now they look a bit weird. On Tue, Feb 05, 2019 at 12:28:39PM -0800, Tadeusz Struk wrote: > Three new tests added: > 1. Send get random cmd, read header in 1st read, read the rest in second > read - expect success > 2. Send get random cmd, read only part of the response, send another > get random command, read the response - expect success > 3. Send get random cmd followed by another get random cmd, without > reading the first response - expect the second cmd to fail with -EBUSY > > Signed-off-by: Tadeusz Struk > --- > tools/testing/selftests/tpm2/tpm2.py | 1 > tools/testing/selftests/tpm2/tpm2_tests.py | 82 ++++++++++++++++++++++++++++ > 2 files changed, 83 insertions(+) > > diff --git a/tools/testing/selftests/tpm2/tpm2.py b/tools/testing/selftests/tpm2/tpm2.py > index c2b9f2b1a0ac..828c18584624 100644 > --- a/tools/testing/selftests/tpm2/tpm2.py > +++ b/tools/testing/selftests/tpm2/tpm2.py > @@ -22,6 +22,7 @@ TPM2_CC_UNSEAL = 0x015E > TPM2_CC_FLUSH_CONTEXT = 0x0165 > TPM2_CC_START_AUTH_SESSION = 0x0176 > TPM2_CC_GET_CAPABILITY = 0x017A > +TPM2_CC_GET_RANDOM = 0x017B > TPM2_CC_PCR_READ = 0x017E > TPM2_CC_POLICY_PCR = 0x017F > TPM2_CC_PCR_EXTEND = 0x0182 > diff --git a/tools/testing/selftests/tpm2/tpm2_tests.py b/tools/testing/selftests/tpm2/tpm2_tests.py > index 3bb066fea4a0..3f6a65cbdd39 100644 > --- a/tools/testing/selftests/tpm2/tpm2_tests.py > +++ b/tools/testing/selftests/tpm2/tpm2_tests.py > @@ -158,6 +158,88 @@ class SmokeTest(unittest.TestCase): > pass > self.assertEqual(rejected, True) > > + def test_read_partial_resp(self): > + """Reads random in two subsequent reads""" > + log = logging.getLogger(__name__) > + try: > + fmt = '>HIIH' > + cmd = struct.pack(fmt, > + tpm2.TPM2_ST_NO_SESSIONS, > + struct.calcsize(fmt), > + tpm2.TPM2_CC_GET_RANDOM, > + 0x20) > + self.client.tpm.write(cmd) > + hdr = self.client.tpm.read(10) > + sz = struct.unpack('>I', hdr[2:6])[0] > + rsp = self.client.tpm.read() 8< > + log.debug("header:") > + log.debug(tpm2.hex_dump(hdr)) > + log.debug("resp:") > + log.debug(tpm2.hex_dump(rsp)) Remove. > + except: 8< > + log.debug("Error:", sys.exc_info()[0]) Remove. > + raise > + > + self.assertEqual(sz, 10 + 2 + 32) > + self.assertEqual(len(rsp), 2 + 32) > + > + def test_read_partial_overwrite(self): > + """Reads only part of the response and issue a new cmd""" > + log = logging.getLogger(__name__) > + try: > + fmt = '>HIIH' > + cmd = struct.pack(fmt, > + tpm2.TPM2_ST_NO_SESSIONS, > + struct.calcsize(fmt), > + tpm2.TPM2_CC_GET_RANDOM, > + 0x20) > + self.client.tpm.write(cmd) > + # Read part of the respone > + rsp1 = self.client.tpm.read(15) 8< > + log.debug("rsp 1:") > + log.debug(tpm2.hex_dump(rsp1)) Remove. > + > + # Send a new cmd > + self.client.tpm.write(cmd) > + > + # Read the whole respone > + rsp2 = self.client.tpm.read() 8< > + log.debug("rsp 2:") > + log.debug(tpm2.hex_dump(rsp2)) Remove. > + > + except: 8< > + log.debug("Error:", sys.exc_info()[0]) Remove. > + raise > + > + self.assertEqual(len(rsp1), 15) > + self.assertEqual(len(rsp2), 10 + 2 + 32) > + > + def test_send_two_cmds(self): > + """Send two cmds without reading a response""" > + rejected = False > + try: > + fmt = '>HIIH' > + cmd = struct.pack(fmt, > + tpm2.TPM2_ST_NO_SESSIONS, > + struct.calcsize(fmt), > + tpm2.TPM2_CC_GET_RANDOM, > + 0x20) > + self.client.tpm.write(cmd) > + > + # expect the second one to raise -EBUSY error > + self.client.tpm.write(cmd) > + rsp = self.client.tpm.read() > + > + except IOError, e: > + # read the response > + rsp = self.client.tpm.read() > + rejected = True > + pass > + except: > + raise > + > + self.assertEqual(rejected, True) > + > class SpaceTest(unittest.TestCase): > def setUp(self): > logging.basicConfig(filename='SpaceTest.log', level=logging.DEBUG) > /Jarkko