Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp561498yba; Mon, 1 Apr 2019 11:53:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqwLGbEUZl1UbsEzELKOl+qZGsQNv2iEu2APH+zNY/CFFYk0r9tRvBKUc9yS3YCxxOs2KcsJ X-Received: by 2002:a65:5343:: with SMTP id w3mr43479920pgr.232.1554144813114; Mon, 01 Apr 2019 11:53:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554144813; cv=none; d=google.com; s=arc-20160816; b=xDM/lWHv/BG2cbAuupyT0ybjjSOxH/GrcgVykt3AGa6bs0Sinm4JJjRzbyDUe4bfEO W89MuXN71NBx7K8ErBF3NQz6MVHOSW8HXoLFwuWHsgHbk7VYnkj3C6Qg+fPYg74LGO8W rD37dU14XPuMXtoLev5cHVAE44HAc4qAj90NOCLlP8vf+Y9qfdlIvnTz5VBLKRd3Z4zL JEp+L/FUbSjtcWbQDY/mVvIgS4VSSeyf/eIupnUOVbsYSYFfrw9ZbRZ7F5gzFuvO3AhH xQ0EHcOIPUDlbQ6MJpjYifg78iGhbqmVIyN1wC6xMHVT15d6zy1FpH/Iw0Ev32lqlcIM Xg/w== 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; bh=0MSeNMB9pGPcF5DSSBDNczu0N++pMl9RCrhB490TauI=; b=xXJ1jdxCQWxxMGZ2lwO+jiQIioVVXPYucLXfbPhfGsHAKdyucEefUe44vfWdSFz7Yu hfJOyUu2LbVZlQwbwla3Id4X6D+FKliSWVtcHNYW432nJ0vh7gVebefIBgEHc65i0paQ 7adCh1fID4ymPmpdOlFnF6sRBCZDSQ9I5T3hCfDonYdfoliR7u48kIGZyeWxtaE8oo+q kWiVU7dsHQwyuVTjyjyy6dg9/9zP3NgBK7Hkml1YC8fiLNNSmEQuone92M1VMTLB+6Eg Te92CaUJq3meHV4KNDQKmoxjSXmpwdUWioPTx2cW6tDHqalqLmB7euYYJDrbhZ/G9L0x TYGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=JxNudvRu; 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=hansenpartnership.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e68si9608813pgc.552.2019.04.01.11.53.14; Mon, 01 Apr 2019 11:53:33 -0700 (PDT) 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; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=JxNudvRu; 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=hansenpartnership.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729107AbfDASwY (ORCPT + 99 others); Mon, 1 Apr 2019 14:52:24 -0400 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:34776 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729056AbfDASwX (ORCPT ); Mon, 1 Apr 2019 14:52:23 -0400 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id 624F68EE12C; Mon, 1 Apr 2019 11:52:22 -0700 (PDT) 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 m_V6JpWY5juF; Mon, 1 Apr 2019 11:52:22 -0700 (PDT) Received: from [153.66.254.194] (unknown [50.35.68.20]) (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 B35718EE0CD; Mon, 1 Apr 2019 11:52:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1554144742; bh=T/NKeFg77h83qXnntr52YuorgzIRcsJNlC20Q0OwuB4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=JxNudvRuhN9MpiERgjXF3DNZdFqEv+P9IFczRyxbltqdBZBUp/atAvGPnzhdW8OTG Kx2CGq5BaAYUUTNJI+bR4jwHEWUtnlPLCLojBMdqdtkZNspzE0wQYfJS+RcAso7gdM dv3MOe0YHDYE5M//ObLwaBGc9ys7UmM730FuuWco= Message-ID: <1554144741.3029.18.camel@HansenPartnership.com> Subject: Re: [PATCH] tpm: Actually fail on TPM errors during "get random" From: James Bottomley To: Kees Cook , Jarkko Sakkinen , Tomas Winkler Cc: Phil Baker , Craig Robson , Laura Abbott , linux-kernel@vger.kernel.org, Peter Huewe , Jason Gunthorpe , Arnd Bergmann , linux-integrity@vger.kernel.org Date: Mon, 01 Apr 2019 11:52:21 -0700 In-Reply-To: <20190401183211.GA21228@beast> References: <20190401183211.GA21228@beast> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.6 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2019-04-01 at 11:32 -0700, Kees Cook wrote: [...] > --- a/drivers/char/tpm/tpm1-cmd.c > +++ b/drivers/char/tpm/tpm1-cmd.c > @@ -510,7 +510,7 @@ struct tpm1_get_random_out { > * > * Return: > * * number of bytes read > - * * -errno or a TPM return code otherwise > + * * -errno (positive TPM return codes are masked to -EIO) > */ > int tpm1_get_random(struct tpm_chip *chip, u8 *dest, size_t max) > { > @@ -524,7 +524,7 @@ int tpm1_get_random(struct tpm_chip *chip, u8 > *dest, size_t max) > > rc = tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, > TPM_ORD_GET_RANDOM); > if (rc) > - return rc; > + goto fail; > > do { > tpm_buf_append_u32(&buf, num_bytes); > @@ -559,7 +559,10 @@ int tpm1_get_random(struct tpm_chip *chip, u8 > *dest, size_t max) > rc = total ? (int)total : -EIO; > out: > tpm_buf_destroy(&buf); > - return rc; You can't remove this otherwise the only return will ever be a failure. I think what you're trying to catch is tpm_transmit_cmd returning a positive failure, So you need to check the output of tpm_transmit_cmd as well and goto failure leaving the above return in place. James > +fail: > + if (rc < 0) > + return rc; > + return -EIO; > } > > #define TPM_ORD_PCRREAD 21 > -- > 2.17.1 > >