From mboxrd@z Thu Jan 1 00:00:00 1970 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 53EF21D04B6; Wed, 2 Oct 2024 13:33:21 +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=1727876001; cv=none; b=piF1le1vcW1sPbXNyRbES9JuBMPWK9V7kZdc09gRTTGIbTv06npd8+Y1Om25pmsULP2QlY34GMLwe+J3mCfQZ2dbFGZkeyQO3BbEsse4vUhiCDuURQM9D3ftW8C6cWGDB0zjpKgB7AOouSzJKaJSxE1M65kGZDk8r4/7EQDb7QE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727876001; c=relaxed/simple; bh=IUTvbI02bD0h3uKCoQpBDEai3wkUvodo/b20fLhzvhM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qcOe9kvbXE+9+NGVTomglAVzRtYph477tdAgr27zeJCIaKzRAwrSssUhhwLcFzJPrDgAZG5rzr/5noPeYYuOXLEM+ihm9hREPTKsBo1mIonNV/2l4eVxxm1bTvZ1vgalKlzAVdEMbHDqdmxZW+lL867sz9tdmVwOmvEAmr0FrRA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=F2dKb5Ju; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="F2dKb5Ju" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5C90C4CEC5; Wed, 2 Oct 2024 13:33:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1727876001; bh=IUTvbI02bD0h3uKCoQpBDEai3wkUvodo/b20fLhzvhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F2dKb5Ju4GBxtS1ZJ132jsll/t71o5LKXwj8z36UvWyL8zBnSpgwGp3CFJYHLEvS9 V7TzO5vc94P9PuUkEcFhWhJ3MbyHZJC5vfEEkCNvezN7wameYxQjKaxKhZQhLG+FlR tOYNtMp1HWoNb8aWJygodN3S1X4tsujIFJt7VBVY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jonathan McDowell , Jarkko Sakkinen , Sasha Levin Subject: [PATCH 6.11 253/695] tpm: Clean up TPM space after command failure Date: Wed, 2 Oct 2024 14:54:11 +0200 Message-ID: <20241002125832.547289036@linuxfoundation.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241002125822.467776898@linuxfoundation.org> References: <20241002125822.467776898@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.11-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jonathan McDowell [ Upstream commit e3aaebcbb7c6b403416f442d1de70d437ce313a7 ] tpm_dev_transmit prepares the TPM space before attempting command transmission. However if the command fails no rollback of this preparation is done. This can result in transient handles being leaked if the device is subsequently closed with no further commands performed. Fix this by flushing the space in the event of command transmission failure. Fixes: 745b361e989a ("tpm: infrastructure for TPM spaces") Signed-off-by: Jonathan McDowell Reviewed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: Sasha Levin --- drivers/char/tpm/tpm-dev-common.c | 2 ++ drivers/char/tpm/tpm2-space.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/drivers/char/tpm/tpm-dev-common.c b/drivers/char/tpm/tpm-dev-common.c index 30b4c288c1bbc..c3fbbf4d3db79 100644 --- a/drivers/char/tpm/tpm-dev-common.c +++ b/drivers/char/tpm/tpm-dev-common.c @@ -47,6 +47,8 @@ static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space, if (!ret) ret = tpm2_commit_space(chip, space, buf, &len); + else + tpm2_flush_space(chip); out_rc: return ret ? ret : len; diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c index 4892d491da8da..25a66870c165c 100644 --- a/drivers/char/tpm/tpm2-space.c +++ b/drivers/char/tpm/tpm2-space.c @@ -169,6 +169,9 @@ void tpm2_flush_space(struct tpm_chip *chip) struct tpm_space *space = &chip->work_space; int i; + if (!space) + return; + for (i = 0; i < ARRAY_SIZE(space->context_tbl); i++) if (space->context_tbl[i] && ~space->context_tbl[i]) tpm2_flush_context(chip, space->context_tbl[i]); -- 2.43.0