Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp563213yba; Mon, 1 Apr 2019 11:56:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZlETNG1IAWiRAECkVZnaPC9691nrDjmAW/LwJ1wmTHll89Fj6jnOKRjsGWDldLoe7mc9f X-Received: by 2002:a62:12c9:: with SMTP id 70mr59783940pfs.156.1554144970731; Mon, 01 Apr 2019 11:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554144970; cv=none; d=google.com; s=arc-20160816; b=b50DFaOw3MebZvLR2bC/afN4OWtfsXwaUNY/KD32MOGDQh7pzJxhfd70ZvB/YEb45D /Whpj6n42Qyy5z+0bE8zF/KLflcEaHNxv5ufqtUXn4B8LEBMiglvpHCXRtTOh9q1p9np GE+QLWBd+iD3neTns+p2z3rVC9/TSKTU+M6atwReYcfy7Dnej9NR2r54zuzHWAvKrF4b u7xfoGVxmTgVWEqVYr+h5JWCVCZs/ZNgtqmCp3QllIhY9fqlzGdijc+AIs0PGNxVWejE TWwO36G6/eYUXxxy5hH6BBGw+qgA7BtF3JX/W5Qur1hOs/EcySQ4pjGV7tJ8Ce1NXQuB syng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=vThWi9g5/qJmdB4uS99oEI6x0u1DMV7y38c2bqYqBlY=; b=dQJl0e58L1/jpgQEFYWkX2nnHNMCIiudzI/qzrqpvF2Y8gSuOiUm6t+ahXlcsSPnBI MdBLWTS2SdwKYpR2L99uQbn35F0Z0Mg7TYBBhJ1d0S3ze81JyXpBZhcOfyP/NYgC+vqL TaX6Y5yyUFAr9nMdGGdEBOkY+fH5TpmCIpXx+7+7+o89udj0fuTOHon6TRcFBShpYSkk +PIKGx8yjLG5MEDGGCg9cR/tNHNXGK9iCuMVyBm4ATYNdeT3hiHx9Z4RmrQnbLKf2Paw ASEvGcZqj80WU3BKo+EWpwk8vSOEF5TUrx1Rs+JWWAhT4DPYAYyU1J2HqgCvOI8klHx6 iFtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jkX95TEs; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l127si9463205pfl.2.2019.04.01.11.55.55; Mon, 01 Apr 2019 11:56:10 -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=pass header.i=@chromium.org header.s=google header.b=jkX95TEs; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729275AbfDASy4 (ORCPT + 99 others); Mon, 1 Apr 2019 14:54:56 -0400 Received: from mail-vs1-f66.google.com ([209.85.217.66]:36673 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728690AbfDASyz (ORCPT ); Mon, 1 Apr 2019 14:54:55 -0400 Received: by mail-vs1-f66.google.com with SMTP id n4so6206586vsm.3 for ; Mon, 01 Apr 2019 11:54:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vThWi9g5/qJmdB4uS99oEI6x0u1DMV7y38c2bqYqBlY=; b=jkX95TEsaEzXy/QmyrssEXYhAVvQ7DMF+8pCwbBZOKrnLihi9zA+8wZSSLDp6px59B f3Z9GQPnIkNMJi4m8m6bLoc/LZ8STZbethSPuKYk4SYbxavQc8QBsBggPbubmBARnA9X yZS34AYj506J+NkPdzAiudLenVm0F7wl9Ki4Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vThWi9g5/qJmdB4uS99oEI6x0u1DMV7y38c2bqYqBlY=; b=q5Elt/zmucRjZj/seCEvW8z1wqNqJUhzEopaL5XrzDq4ZRoqgzFyXPNWNrTSJNqPjs F4WmTbMHTzGeVgu0I3pXB+8UE87hGw3a4r90TWVmrNwiq7MXCz2GKRp4NkTVAR83wKAI cHR1jRDkECxOkM9PwtKG0Ps1J04jus6PiVr6YmmPimI/8XcEoy4YDJr7dE7Cxt9akrK/ F6Iikpd78VLkWgjEv/5jPupAeM9o2hGMgppZ0wMdbugOgGLTaFUZa5VfF4r0T9ctrqT6 EEAncWqoUbAbeqMXpaAZZZiKt2vVkm6WdrEvMBEhje+m9qJ2OjAwBIWQyMR8tTycsRDY eTtw== X-Gm-Message-State: APjAAAWhB3nqUqoqFLzjoUNq4PuEQXx6eYhLeOb3JOnyDdtO/xqtlyaa bDSiinuaON9V0T//S8HP7Ie/8rIxlkY= X-Received: by 2002:a67:82c8:: with SMTP id e191mr39347818vsd.24.1554144893643; Mon, 01 Apr 2019 11:54:53 -0700 (PDT) Received: from mail-vk1-f178.google.com (mail-vk1-f178.google.com. [209.85.221.178]) by smtp.gmail.com with ESMTPSA id 190sm10533161vsz.0.2019.04.01.11.54.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Apr 2019 11:54:52 -0700 (PDT) Received: by mail-vk1-f178.google.com with SMTP id e131so2350555vkf.10 for ; Mon, 01 Apr 2019 11:54:52 -0700 (PDT) X-Received: by 2002:a1f:6bcb:: with SMTP id k72mr7359745vki.80.1554144891661; Mon, 01 Apr 2019 11:54:51 -0700 (PDT) MIME-Version: 1.0 References: <20190401183211.GA21228@beast> <1554144741.3029.18.camel@HansenPartnership.com> In-Reply-To: <1554144741.3029.18.camel@HansenPartnership.com> From: Kees Cook Date: Mon, 1 Apr 2019 11:54:40 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] tpm: Actually fail on TPM errors during "get random" To: James Bottomley Cc: Jarkko Sakkinen , Tomas Winkler , Phil Baker , Craig Robson , Laura Abbott , LKML , Peter Huewe , Jason Gunthorpe , Arnd Bergmann , linux-integrity Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 1, 2019 at 11:52 AM James Bottomley wrote: > > 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. eek, yes. I double-checked this in tpm2, but tpm1 is different... -- Kees Cook