linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] char: tpm: Fix possible memory leak in tpm_bios_measurements_open()
@ 2024-06-09  9:29 Joe Hattori
  2024-06-20  0:53 ` Jarkko Sakkinen
  0 siblings, 1 reply; 2+ messages in thread
From: Joe Hattori @ 2024-06-09  9:29 UTC (permalink / raw)
  To: peterhuewe, jarkko; +Cc: jgg, linux-integrity, Joe Hattori

In tpm_bios_measurements_open(), get_device() is called on the device
embedded in struct tpm_chip. In the error path, however, put_device() is
not called. This could result in a reference count leak, which could
prevent the device from being properly released. This commit makes sure
to call put_device() when the tpm_bios_measurements_open() fails.

Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
 drivers/char/tpm/eventlog/common.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/char/tpm/eventlog/common.c b/drivers/char/tpm/eventlog/common.c
index 639c3f395a5a..df213ec428ca 100644
--- a/drivers/char/tpm/eventlog/common.c
+++ b/drivers/char/tpm/eventlog/common.c
@@ -44,11 +44,13 @@ static int tpm_bios_measurements_open(struct inode *inode,
 
 	/* now register seq file */
 	err = seq_open(file, seqops);
-	if (!err) {
-		seq = file->private_data;
-		seq->private = chip;
+	if (err) {
+		put_device(&chip->dev);
+		return err;
 	}
 
+	seq = file->private_data;
+	seq->private = chip;
 	return err;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-20  0:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-09  9:29 [PATCH] char: tpm: Fix possible memory leak in tpm_bios_measurements_open() Joe Hattori
2024-06-20  0:53 ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).