Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1789712rdf; Sun, 5 Nov 2023 14:42:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+nnoHuJqg65YClyhcN+zUbjDsijQsbhOe6lZdCM5UpSY5HlJFxyptdO3nHw4sGjC03UgU X-Received: by 2002:a05:6e02:1a4f:b0:357:c844:4d51 with SMTP id u15-20020a056e021a4f00b00357c8444d51mr34588960ilv.12.1699224140788; Sun, 05 Nov 2023 14:42:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699224140; cv=none; d=google.com; s=arc-20160816; b=XKay+mktIzJNObo1anx5d7DYwGOyQi4mj1sOR6DzOrycH/zGpgh5Kn/DR3zw3yW15f MBFx6N+A2tLjnpy3soK/d8vCgVsZl0UB2W6PaHkq99zMg7XVohQQevb0quI+cxeU4JlZ 3DOu+sozYFmQ/NkaaFrrpcATkmLDMZOwmULR28YbB7XyO5/9pTVHzx+BoHJ1YacwWzcQ LeRoaHSk3mfReMDewY7ELBvl1c5bLONrArxT8VfZhDX7ijUTwMAD/LjzMz8A6IiAWsDh nRB8aOb4WEshaG732VJ5yQ3K9j3ySecWjx4xHkoi+3FtwQQX1tMRz2612jQqRjUhYY+y Iwzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature:dkim-signature; bh=0ORhJJDkbb5aSW2p68fxTUwKO1caFy0ILvEXKww+kvc=; fh=UQ/OBAP/r+xcpm8L6nCFFHGdQn5pam1sDT62rhW/rlo=; b=ljfXs+mEDc+yubs7DEjo7fXn0Cc55ISkJpOaHqTYWZBN4XgH01jetitkFJKMrFVVMp xPxBZexw9MhtnXdYbfTH0nuI/KLMMSgshrdiFItpzY8VKGfGAmVyCtZDO4ATBHEiYctC vsqR+AkKd6WLZLugrJKCLAG1e+7lUOei/6h32j+DqHCWBuwmdpHKpONcNJQOECxcknrH XS/0etXrPiSPiLGfLTWzkCLPhTN4k6aJeR1G01S6F4Uz9gfRjBTSHGalfou8sA3Cx51F IHAifhuimNpgy5nRaN5jBuL6dc0LRU3b6nFEkhU78kHAIJ1cpDKNRw2sC9ESODwVuIwk FTmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hansenpartnership.com header.s=20151216 header.b=OtRNMGZp; dkim=pass header.i=@hansenpartnership.com header.s=20151216 header.b=OtRNMGZp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=hansenpartnership.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id i191-20020a6387c8000000b00578b37ad24bsi6447629pge.619.2023.11.05.14.42.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 14:42:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@hansenpartnership.com header.s=20151216 header.b=OtRNMGZp; dkim=pass header.i=@hansenpartnership.com header.s=20151216 header.b=OtRNMGZp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=hansenpartnership.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 9D4BB805CDA9; Sun, 5 Nov 2023 14:42:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229690AbjKEWmL (ORCPT + 99 others); Sun, 5 Nov 2023 17:42:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbjKEWmL (ORCPT ); Sun, 5 Nov 2023 17:42:11 -0500 Received: from bedivere.hansenpartnership.com (bedivere.hansenpartnership.com [96.44.175.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14CF4DD for ; Sun, 5 Nov 2023 14:42:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hansenpartnership.com; s=20151216; t=1699224125; bh=8cXH1/Q4sHqWtgac+Sz4lIYk/+iiFfAcIe+nqos9YHE=; h=Message-ID:Subject:From:To:Date:In-Reply-To:References:From; b=OtRNMGZpt8C0C3EbyXo9vhekL8eMI49tLrSWoDb73wavLUk2npuysDqf4RjM7Z5Gx Ot3/3yi/Cu0FonYecScCfyvRR4PW7LgXKu8U+jL5cP1YVIUVvHNcyM0T37V726F1Sx Gv9xkTJ2QvEcivs1lgz+2ai0ceMt3WVpzZjdzRmU= Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id 9B48E12810B5; Sun, 5 Nov 2023 17:42:05 -0500 (EST) Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavis, port 10024) with ESMTP id LpbKEJnu54r0; Sun, 5 Nov 2023 17:42:05 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hansenpartnership.com; s=20151216; t=1699224125; bh=8cXH1/Q4sHqWtgac+Sz4lIYk/+iiFfAcIe+nqos9YHE=; h=Message-ID:Subject:From:To:Date:In-Reply-To:References:From; b=OtRNMGZpt8C0C3EbyXo9vhekL8eMI49tLrSWoDb73wavLUk2npuysDqf4RjM7Z5Gx Ot3/3yi/Cu0FonYecScCfyvRR4PW7LgXKu8U+jL5cP1YVIUVvHNcyM0T37V726F1Sx Gv9xkTJ2QvEcivs1lgz+2ai0ceMt3WVpzZjdzRmU= Received: from lingrow.int.hansenpartnership.com (unknown [IPv6:2601:5c4:4302:c21::a774]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id 417611280143; Sun, 5 Nov 2023 17:42:04 -0500 (EST) Message-ID: <2162ca751035b3ea8c5ce8409c17c1906951181d.camel@HansenPartnership.com> Subject: Re: [PATCH v3 1/6] tpm: Move buffer handling from static inlines to real functions From: James Bottomley To: Jarkko Sakkinen , Jerry Snitselaar Cc: linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, William Roberts , Stefan Berger , David Howells , Jason Gunthorpe , Mimi Zohar , Peter Huewe , Mario Limonciello , Julien Gomes , open list Date: Sun, 05 Nov 2023 17:42:02 -0500 In-Reply-To: References: <20231024011531.442587-1-jarkko@kernel.org> <20231024011531.442587-2-jarkko@kernel.org> <3e69c10c5d03ab2ccf7bda82b7ed9991dbced523.camel@kernel.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sun, 05 Nov 2023 14:42:17 -0800 (PST) On Mon, 2023-11-06 at 00:01 +0200, Jarkko Sakkinen wrote: > On Sun, 2023-11-05 at 23:59 +0200, Jarkko Sakkinen wrote: > > On Thu, 2023-10-26 at 13:55 -0400, James Bottomley wrote: > > > On Thu, 2023-10-26 at 10:10 -0700, Jerry Snitselaar wrote: > > > > On Wed, Oct 25, 2023 at 08:35:55PM +0300, Jarkko Sakkinen > > > > wrote: > > > > > On Wed Oct 25, 2023 at 12:03 PM EEST, Jerry Snitselaar wrote: > > > > > > Reviewed-by: Jerry Snitselaar > > > > > > > > > > On Wed, 2023-10-25 at 02:03 -0700, Jerry Snitselaar wrote: > > > > > > Reviewed-by: Jerry Snitselaar > > > > > > > > > > > > > > > > Thanks I'll add it to the next round. > > > > > > > > > > For the tpm_buf_read(), I was thinking along the lines of: > > > > > > > > > > /** > > > > >  * tpm_buf_read() - Read from a TPM buffer > > > > >  * @buf:        &tpm_buf instance > > > > >  * @pos:        position within the buffer > > > > >  * @count:      the number of bytes to read > > > > >  * @output:     the output buffer > > > > >  * > > > > >  * Read bytes from a TPM buffer, and update the position. > > > > > Returns > > > > > false when the > > > > >  * amount of bytes requested would overflow the buffer, which > > > > > is > > > > > expected to > > > > >  * only happen in the case of hardware failure. > > > > >  */ > > > > > static bool tpm_buf_read(const struct tpm_buf *buf, off_t > > > > > *pos, > > > > > size_t count, void *output) > > > > > { > > > > >         off_t next = *pos + count; > > > > > > > > > >         if (next >= buf->length) { > > > > >                 pr_warn("%s: %lu >= %lu\n", __func__, next, > > > > > *offset); > > > > >                 return false; > > > > >         } > > > > > > > > > >         memcpy(output, &buf->data[*pos], count); > > > > >         *offset = next; > > > > >         return true; > > > > > } > > > > > > > > > > BR, Jarkko > > > > > > > > > > > > > Then the callers will check, and return -EIO? > > > > > > Really, no, why would we do that? > > > > > > The initial buffer is a page and no TPM currently can have a > > > command that big, so if the buffer overflows, it's likely a > > > programming error (failure to terminate loop or something) rather > > > than a runtime one (a user actually induced a command that big > > > and wanted it to be sent to the TPM).  The only reason you might > > > need to check is the no-alloc case and you passed in a much > > > smaller buffer, but even there, I would guess it will come down > > > to a coding fault not a possible runtime error. > > > > > > Yeah, this was my thinking too. So in HMAC case you anyway would > > not need to check it because crypto is destined to fail anyway. > > > > Returning boolean here does no harm so I thought that this is > > overally good compromise. > > Or actually maybe we should go just with void, as it does have even > then "return value", as it emits to klog, right? Right, these functions are almost drop in replacements for the get_inc_XX ones. The latter were void returning because all the knowledge of what is being looked for is in the calling routine, because it knows at a macro level what structure the buffer should have. James