linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH-next] fs/cifs: Fix resource leak
@ 2021-05-04 12:43 Khaled ROMDHANI
  2021-05-04 13:44 ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Khaled ROMDHANI @ 2021-05-04 12:43 UTC (permalink / raw)
  To: sfrench
  Cc: Khaled ROMDHANI, linux-cifs, samba-technical, linux-kernel,
	kernel-janitors

The -EIO error return path is leaking memory allocated
to page. Fix this by invoking the free_dentry_path before
the return.

Addresses-Coverity: ("Resource leak")
Signed-off-by: Khaled ROMDHANI <khaledromdhani216@gmail.com>
---
 fs/cifs/link.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/cifs/link.c b/fs/cifs/link.c
index 1cbe7ec73728..1485c6095ba1 100644
--- a/fs/cifs/link.c
+++ b/fs/cifs/link.c
@@ -686,8 +686,10 @@ cifs_symlink(struct user_namespace *mnt_userns, struct inode *inode,
 	void *page = alloc_dentry_path();
 	struct inode *newinode = NULL;
 
-	if (unlikely(cifs_forced_shutdown(cifs_sb)))
+	if (unlikely(cifs_forced_shutdown(cifs_sb))) {
+		free_dentry_path(page);
 		return -EIO;
+	}
 
 	xid = get_xid();
 
-- 
2.17.1


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

* Re: [PATCH-next] fs/cifs: Fix resource leak
  2021-05-04 12:43 [PATCH-next] fs/cifs: Fix resource leak Khaled ROMDHANI
@ 2021-05-04 13:44 ` Dan Carpenter
  2021-05-04 14:14   ` Khaled Romdhani
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2021-05-04 13:44 UTC (permalink / raw)
  To: Khaled ROMDHANI
  Cc: sfrench, linux-cifs, samba-technical, linux-kernel, kernel-janitors

On Tue, May 04, 2021 at 01:43:43PM +0100, Khaled ROMDHANI wrote:
> The -EIO error return path is leaking memory allocated
> to page. Fix this by invoking the free_dentry_path before
> the return.
> 
> Addresses-Coverity: ("Resource leak")
> Signed-off-by: Khaled ROMDHANI <khaledromdhani216@gmail.com>

Add a Fixes tag.

Fixes: 583248493f78 ("cifs: add shutdown support")

> ---
>  fs/cifs/link.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/cifs/link.c b/fs/cifs/link.c
> index 1cbe7ec73728..1485c6095ba1 100644
> --- a/fs/cifs/link.c
> +++ b/fs/cifs/link.c
> @@ -686,8 +686,10 @@ cifs_symlink(struct user_namespace *mnt_userns, struct inode *inode,
>  	void *page = alloc_dentry_path();
>  	struct inode *newinode = NULL;
>  
> -	if (unlikely(cifs_forced_shutdown(cifs_sb)))
> +	if (unlikely(cifs_forced_shutdown(cifs_sb))) {
> +		free_dentry_path(page);
>  		return -EIO;
> +	}

Better to move the allocation here.  Avoid calling functions which can
fail in the declaration block.  Better to test for NULL directly instead
of hiding the test inside the build_path_from_dentry() function.

	page = alloc_dentry_path();
	if (!page)
		return -ENOMEM;

The error handling in this function is slightly unweildy...

regards,
dan carpenter


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

* Re: [PATCH-next] fs/cifs: Fix resource leak
  2021-05-04 13:44 ` Dan Carpenter
@ 2021-05-04 14:14   ` Khaled Romdhani
  0 siblings, 0 replies; 4+ messages in thread
From: Khaled Romdhani @ 2021-05-04 14:14 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: sfrench, linux-cifs, samba-technical, linux-kernel, kernel-janitors

On Tue, May 04, 2021 at 04:44:45PM +0300, Dan Carpenter wrote:
> On Tue, May 04, 2021 at 01:43:43PM +0100, Khaled ROMDHANI wrote:
> > The -EIO error return path is leaking memory allocated
> > to page. Fix this by invoking the free_dentry_path before
> > the return.
> > 
> > Addresses-Coverity: ("Resource leak")
> > Signed-off-by: Khaled ROMDHANI <khaledromdhani216@gmail.com>
> 
> Add a Fixes tag.
> 
> Fixes: 583248493f78 ("cifs: add shutdown support")
>

Yes, I will add a Fixes tag.

> > ---
> >  fs/cifs/link.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/cifs/link.c b/fs/cifs/link.c
> > index 1cbe7ec73728..1485c6095ba1 100644
> > --- a/fs/cifs/link.c
> > +++ b/fs/cifs/link.c
> > @@ -686,8 +686,10 @@ cifs_symlink(struct user_namespace *mnt_userns, struct inode *inode,
> >  	void *page = alloc_dentry_path();
> >  	struct inode *newinode = NULL;
> >  
> > -	if (unlikely(cifs_forced_shutdown(cifs_sb)))
> > +	if (unlikely(cifs_forced_shutdown(cifs_sb))) {
> > +		free_dentry_path(page);
> >  		return -EIO;
> > +	}
> 
> Better to move the allocation here.  Avoid calling functions which can
> fail in the declaration block.  Better to test for NULL directly instead
> of hiding the test inside the build_path_from_dentry() function.
> 
> 	page = alloc_dentry_path();
> 	if (!page)
> 		return -ENOMEM;
> 
> The error handling in this function is slightly unweildy...
> 
> regards,
> dan carpenter
>

Yes, it would be better to move the allocation...
I will send a V2.

Thanks.

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

* [PATCH-next] fs/cifs: Fix resource leak
@ 2021-05-04 13:22 Khaled ROMDHANI
  0 siblings, 0 replies; 4+ messages in thread
From: Khaled ROMDHANI @ 2021-05-04 13:22 UTC (permalink / raw)
  To: sfrench
  Cc: Khaled ROMDHANI, linux-cifs, samba-technical, linux-kernel,
	kernel-janitors

The -EIO error return path is leaking memory allocated
to page. Fix this by invoking the free_dentry_path before
the return.

Addresses-Coverity: ("Resource leak")
Signed-off-by: Khaled ROMDHANI <khaledromdhani216@gmail.com>
---
 fs/cifs/link.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/cifs/link.c b/fs/cifs/link.c
index 1cbe7ec73728..1485c6095ba1 100644
--- a/fs/cifs/link.c
+++ b/fs/cifs/link.c
@@ -686,8 +686,10 @@ cifs_symlink(struct user_namespace *mnt_userns, struct inode *inode,
 	void *page = alloc_dentry_path();
 	struct inode *newinode = NULL;
 
-	if (unlikely(cifs_forced_shutdown(cifs_sb)))
+	if (unlikely(cifs_forced_shutdown(cifs_sb))) {
+		free_dentry_path(page);
 		return -EIO;
+	}
 
 	xid = get_xid();
 
-- 
2.17.1


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

end of thread, other threads:[~2021-05-04 14:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-04 12:43 [PATCH-next] fs/cifs: Fix resource leak Khaled ROMDHANI
2021-05-04 13:44 ` Dan Carpenter
2021-05-04 14:14   ` Khaled Romdhani
2021-05-04 13:22 Khaled ROMDHANI

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).