* [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
* Re: [PATCH] char: tpm: Fix possible memory leak in tpm_bios_measurements_open()
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
0 siblings, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2024-06-20 0:53 UTC (permalink / raw)
To: Joe Hattori, peterhuewe; +Cc: jgg, linux-integrity
On Sun Jun 9, 2024 at 12:29 PM EEST, Joe Hattori wrote:
> 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
When it does not then?
> prevent the device from being properly released. This commit makes sure
> to call put_device() when the tpm_bios_measurements_open() fails.
s/could//g
Either *is* or *is not*.
>
> 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;
So this does two things:
1. It restructures code.
2. Possibly fixes a leak (with quick skimo does).
So it breaks "Separate your changes" section of [1].
Instead:
if (!err) {
seq = file->private_data;
seq->private = chip;
} else {
put_device(&chip->dev);
}
I.e. least likelyhood of merge conflicts, when backporting.
Also, add a fixes tag (also [1]).
[1] https://docs.kernel.org/process/submitting-patches.html
BR, Jarkko
^ permalink raw reply [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).