linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jarkko Sakkinen" <jarkko@kernel.org>
To: "Joe Hattori" <joe@pf.is.s.u-tokyo.ac.jp>, <peterhuewe@gmx.de>
Cc: <jgg@ziepe.ca>, <linux-integrity@vger.kernel.org>
Subject: Re: [PATCH] char: tpm: Fix possible memory leak in tpm_bios_measurements_open()
Date: Thu, 20 Jun 2024 03:53:16 +0300	[thread overview]
Message-ID: <D24FMMS9HM8A.1EKLA59QSET6H@kernel.org> (raw)
In-Reply-To: <20240609092937.2874379-1-joe@pf.is.s.u-tokyo.ac.jp>

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

      reply	other threads:[~2024-06-20  0:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D24FMMS9HM8A.1EKLA59QSET6H@kernel.org \
    --to=jarkko@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=joe@pf.is.s.u-tokyo.ac.jp \
    --cc=linux-integrity@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).