mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH] fs: Fix memory leak in mount()
Date: Fri, 26 Jan 2018 22:10:25 +0100	[thread overview]
Message-ID: <20180126211025.GB3317@ravnborg.org> (raw)
In-Reply-To: <20180126194227.32088-1-s.hauer@pengutronix.de>

Hi Sasha.

On Fri, Jan 26, 2018 at 08:42:27PM +0100, Sascha Hauer wrote:
> "path" is allocated by normalise_path() and thus must be
> freed. This was done in the error path, but not in the success
> path.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  fs/fs.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/fs/fs.c b/fs/fs.c
> index 6f15e93ba9..7d0d97906d 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -1392,6 +1392,8 @@ int mount(const char *device, const char *fsname, const char *_path,
>  		fsdev_set_linux_rootarg(fsdev, str);
>  	}
>  
> +	free(path);
> +
>  	return 0;
>  
>  err_no_driver:
An out: label so we only called free once was also an option.
Both patterns are used in this file - so either should be OK.


While browsing this file I think there is a few similar
cases involving normalise_path():

automount_remove()
path is assigned, but never freed.

automount_add()
am is allocated, but not freed if we return -ENOTDIR. And thus all of path, cmd, and am is leaked


I also noticed:
opendir()
No check for PTR_ERR after calling canonalize_path()

unlink()
No check for PTR_ERR after call to canonalize_dir()

readlink()
No check for PTR_ERR after call to canonalize_dir()

I can create patch for these - but I cannot do any thrustworthy testing.
And for the canonalize() I am uncertain if the check is requied.
Let me know your preference and I will take care.

	Sam

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2018-01-26 21:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-26 19:42 Sascha Hauer
2018-01-26 21:10 ` Sam Ravnborg [this message]
2018-01-29  7:24   ` Sascha Hauer
2018-01-29 19:05     ` Sam Ravnborg

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=20180126211025.GB3317@ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.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