Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1172854lqb; Sat, 25 May 2024 08:44:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWa/hDbwyjeQryM4Q8P0PjwnaHWwnIBNCsOZsypXmsKdPbqfDiitqUxP6BSvU96J37w8nyS1i9/AkD0X5dLUe5m8J713wwgoMxJ0IFmhA== X-Google-Smtp-Source: AGHT+IEvxS4xXNc55YPg7mmpFeKTV1N/p3kF3da+L0EFVmAg/CXZkplWklvlqyKtmMFDDKh4ekDM X-Received: by 2002:a05:6358:80a1:b0:192:b048:2942 with SMTP id e5c5f4694b2df-197e5666013mr609232955d.30.1716651885269; Sat, 25 May 2024 08:44:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716651885; cv=pass; d=google.com; s=arc-20160816; b=bdYjM76Ctk7tPtzizNC+77lqaOpiOfDRgrsuAD6mFHdz1lrJkFyEgHh9+fxWCRRzk5 IvXsfpLqAbmIoXS5v51VVfPtyeN15IyzYGxP9HuGRcQNa11bCHVbGzyhjO3fwBijvp6E 1Q8naR4YOWEc0Mi9J2FkJAh9YbU9+3afutDeQ0RlVJF/uuANm3rezHQ2VZMkatCE91J8 h2VY4EjerLW9imXp/zK1bVJePiEtNOmGF+8UNZNMEYdaw27o98c0W8IWUh9nB1XPdOd4 iwgSD25Jcyap0uEqgwuXlF+0IqaORjvjAeijEbF23lrT7tOoiEE44kIaFERtu6FZDahD 7Hdw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=R6xiYo/dllYn1dYD4IX5Y25N/YI8l4jHWWGBL9Tk7+s=; fh=A2IKz+AX+3QZmxlbm/zEbftJPmplgwUxo7EEP+DIM88=; b=mizY6RBeNbDTOSt2Y99Q8Ga/troN+1c7/eLnZoO2409ZTd6kOqZVd3gObzUkBMcS0O vDst5+634xmEIeQfiouWZ9ykvzpx1+TY72MpbX4b8N4c2Js9Q/xDpqMociVF8asBLB9Y jN80NPT3a5q4otL9JS0HviC3LYw3/XucnR4ntj3dOYK8FHA6Urro9rW7Sur+gpHws5Jp cWdaqEjVRE/EJuP0Lb03y/RGXyMMzsdWlylPkF5NJ1CJ2iNN29NHqIuXckU/d4xI9rMc R9Eb99o09/VZBnME35/RW69bPVvalEHaae9epPeADpOUHLiuo+EhdeExOOmSGJEITfNG I2Jg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bhTAFEAH; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-189429-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189429-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6822ae582ccsi3295486a12.842.2024.05.25.08.44.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 May 2024 08:44:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189429-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bhTAFEAH; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-189429-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189429-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 43E8AB212E7 for ; Sat, 25 May 2024 15:44:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 834F985C7D; Sat, 25 May 2024 15:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bhTAFEAH" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D8368565D; Sat, 25 May 2024 15:44:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716651856; cv=none; b=oNPJ7UFmk1ha4ujt6gY3URIQkaLxPwMIUDVtZ6X+6IkX+loQEhYM0QvRLh6SV4BgpH4CrfEYaIFt8mV+TYIjoOwFgWTkehzzIb0VXZzC4Wsniouub3IqA+jVRqLQtaaUj6JmCzUMa5UUldGBd2ng6Xf3ej7TAHVMAqaVHqcjiFU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716651856; c=relaxed/simple; bh=fx96WQ3CA4fuu9xuV7Rhy8dNDsj3dwwERPeQsBhGeRM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=TxAsrSCVUz5UltUMXjx/PpRSI1lTOfQQmcOaKuUDoApoAeX6HyEv3pmIBtYeD8vsE04ii32j5rnQMCtD7iSH/ZXu1AECBnMVPOvsza63aDyNqYemkMJbuEhGp++vMMPuqZuDmHm0m4SJXoHCoGESmviDLFqsSKof0SXWus/EyFY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bhTAFEAH; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8063C2BD11; Sat, 25 May 2024 15:44:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716651856; bh=fx96WQ3CA4fuu9xuV7Rhy8dNDsj3dwwERPeQsBhGeRM=; h=From:To:Cc:Subject:Date:From; b=bhTAFEAHw0HlX86mVI0bdn8jf47V7qQ4dKQj2qSwTpS1TMoUP3/FfAcTOA9Ye4prr n3Z0Dgo4HvmlwaIG2wdYxD6Jb/R3tLh6iZ2gMLtJBEjsKrN+JyFUJQgayGhZO6qv29 rtDStv9+/PvPpUsyokXLDPqm1iHzvNSdOOPfllA2+IcOAfhKxT+YPi6QngYOd90ddt ITywiGgPHyfIqDO21byZmrnp5WeTyBRVzUw5B8RELVmnoCyp5Qk+agL0pRev2MJNgV VfBWQxW3MLDj0X6l9AMq9s3XIBuwGNw7xNHhkRolbX9Ocm0oQnEbTTRYrTqODJ2efi XXazKmB5sraHQ== From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: keyrings@vger.kernel.org, James.Bottomley@HansenPartnership.com, Jarkko Sakkinen , Peter Huewe , Jason Gunthorpe , Mimi Zohar , David Howells , Paul Moore , James Morris , "Serge E. Hallyn" , Stefan Berger , Ard Biesheuvel , Mario Limonciello , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH] tpm: Open code tpm_buf_parameters() Date: Sat, 25 May 2024 18:44:01 +0300 Message-ID: <20240525154406.4811-1-jarkko@kernel.org> X-Mailer: git-send-email 2.45.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit With only single call site, this no sense, and it actually slipped out of the radar during the review. Open code and document the action directly to the site, to make it more readable. Fixes: 1b6d7f9eb150 ("tpm: add session encryption protection to tpm2_get_random()") Signed-off-by: Jarkko Sakkinen --- Just a glitch but would be better land to v6.10 so that we don't have to deal with this post-release. drivers/char/tpm/tpm-buf.c | 26 -------------------------- drivers/char/tpm/tpm2-cmd.c | 10 +++++++++- include/linux/tpm.h | 2 -- 3 files changed, 9 insertions(+), 29 deletions(-) diff --git a/drivers/char/tpm/tpm-buf.c b/drivers/char/tpm/tpm-buf.c index 647c6ca92ac3..cad0048bcc3c 100644 --- a/drivers/char/tpm/tpm-buf.c +++ b/drivers/char/tpm/tpm-buf.c @@ -223,30 +223,4 @@ u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset) } EXPORT_SYMBOL_GPL(tpm_buf_read_u32); -static u16 tpm_buf_tag(struct tpm_buf *buf) -{ - struct tpm_header *head = (struct tpm_header *)buf->data; - - return be16_to_cpu(head->tag); -} - -/** - * tpm_buf_parameters - return the TPM response parameters area of the tpm_buf - * @buf: tpm_buf to use - * - * Where the parameters are located depends on the tag of a TPM - * command (it's immediately after the header for TPM_ST_NO_SESSIONS - * or 4 bytes after for TPM_ST_SESSIONS). Evaluate this and return a - * pointer to the first byte of the parameters area. - * - * @return: pointer to parameters area - */ -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/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index 0cdf892ec2a7..1e856259219e 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -281,6 +281,7 @@ struct tpm2_get_random_out { int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max) { struct tpm2_get_random_out *out; + struct tpm_header *head; struct tpm_buf buf; u32 recd; u32 num_bytes = max; @@ -288,6 +289,7 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max) int total = 0; int retries = 5; u8 *dest_ptr = dest; + off_t offset; if (!num_bytes || max > TPM_MAX_RNG_DATA) return -EINVAL; @@ -320,7 +322,13 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max) goto out; } - out = (struct tpm2_get_random_out *)tpm_buf_parameters(&buf); + head = (struct tpm_header *)buf.data; + offset = TPM_HEADER_SIZE; + /* Skip the parameter size field: */ + if (be16_to_cpu(head->tag) == TPM2_ST_SESSIONS) + offset += 4; + + out = (struct tpm2_get_random_out *)&buf.data[offset]; recd = min_t(u32, be16_to_cpu(out->size), num_bytes); if (tpm_buf_length(&buf) < TPM_HEADER_SIZE + diff --git a/include/linux/tpm.h b/include/linux/tpm.h index c17e4efbb2e5..b3217200df28 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -437,8 +437,6 @@ u8 tpm_buf_read_u8(struct tpm_buf *buf, off_t *offset); u16 tpm_buf_read_u16(struct tpm_buf *buf, off_t *offset); u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset); -u8 *tpm_buf_parameters(struct tpm_buf *buf); - /* * Check if TPM device is in the firmware upgrade mode. */ -- 2.45.1