diff mbox series

[v2] char: tpm: Fix possible memory leak in tpm_bios_measurements_open()

Message ID 20240627063109.1239467-1-joe@pf.is.s.u-tokyo.ac.jp (mailing list archive)
State New
Headers show
Series [v2] char: tpm: Fix possible memory leak in tpm_bios_measurements_open() | expand

Commit Message

Joe Hattori June 27, 2024, 6:31 a.m. UTC
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 results in a reference count leak, which prevents the
device from being properly released. This commit makes sure to call
put_device() when the seq_open() call fails.

Fixes: 9b01b5356629 ("tpm: Move shared eventlog functions to common.c")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
Changes since v1:
- Keep the code diff minimal.
- Fix the commit message.
- Add a Fixes tag.
---
 drivers/char/tpm/eventlog/common.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Jarkko Sakkinen July 1, 2024, 3:18 p.m. UTC | #1
On Thu, 2024-06-27 at 15:31 +0900, 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 results in a reference count leak, which prevents the
> device from being properly released. This commit makes sure to call
> put_device() when the seq_open() call fails.
> 
> Fixes: 9b01b5356629 ("tpm: Move shared eventlog functions to common.c")
> Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
> ---
> Changes since v1:
> - Keep the code diff minimal.
> - Fix the commit message.
> - Add a Fixes tag.
> ---
>  drivers/char/tpm/eventlog/common.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/char/tpm/eventlog/common.c b/drivers/char/tpm/eventlog/common.c
> index 639c3f395a5a..4c0bbba64ee5 100644
> --- a/drivers/char/tpm/eventlog/common.c
> +++ b/drivers/char/tpm/eventlog/common.c
> @@ -47,6 +47,8 @@ static int tpm_bios_measurements_open(struct inode *inode,
>  	if (!err) {
>  		seq = file->private_data;
>  		seq->private = chip;
> +	} else {
> +		put_device(&chip->dev);
>  	}
>  
>  	return err;

Thank you. I applied this.

BR, Jarkko
diff mbox series

Patch

diff --git a/drivers/char/tpm/eventlog/common.c b/drivers/char/tpm/eventlog/common.c
index 639c3f395a5a..4c0bbba64ee5 100644
--- a/drivers/char/tpm/eventlog/common.c
+++ b/drivers/char/tpm/eventlog/common.c
@@ -47,6 +47,8 @@  static int tpm_bios_measurements_open(struct inode *inode,
 	if (!err) {
 		seq = file->private_data;
 		seq->private = chip;
+	} else {
+		put_device(&chip->dev);
 	}
 
 	return err;