linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs/iomap: fix memory leak on error condition
@ 2018-02-21 20:41 Garry McNulty
  2018-02-21 21:56 ` Dave Chinner
  0 siblings, 1 reply; 3+ messages in thread
From: Garry McNulty @ 2018-02-21 20:41 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: viro, hch, linux-kernel, Garry McNulty

If the call to is_sync_kiocb() fails an error is returned without
freeing dio. Set the return code and jump to out_free_dio.

Detected by CoverityScan, CID 1429424 ("Resource leak")

Signed-off-by: Garry McNulty <garrmcnu@gmail.com>
---
 fs/iomap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/iomap.c b/fs/iomap.c
index afd163586aa0..65c5db38c15a 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -1063,8 +1063,10 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
 		iomap_dio_set_error(dio, ret);
 
 	if (!atomic_dec_and_test(&dio->ref)) {
-		if (!is_sync_kiocb(iocb))
-			return -EIOCBQUEUED;
+		if (!is_sync_kiocb(iocb)) {
+			ret = -EIOCBQUEUED;
+			goto out_free_dio;
+		}
 
 		for (;;) {
 			set_current_state(TASK_UNINTERRUPTIBLE);
-- 
2.14.3

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

* Re: [PATCH] fs/iomap: fix memory leak on error condition
  2018-02-21 20:41 [PATCH] fs/iomap: fix memory leak on error condition Garry McNulty
@ 2018-02-21 21:56 ` Dave Chinner
  2018-02-21 23:12   ` Garry McNulty
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Chinner @ 2018-02-21 21:56 UTC (permalink / raw)
  To: Garry McNulty; +Cc: linux-fsdevel, viro, hch, linux-kernel

On Wed, Feb 21, 2018 at 08:41:28PM +0000, Garry McNulty wrote:
> If the call to is_sync_kiocb() fails an error is returned without
> freeing dio. Set the return code and jump to out_free_dio.
> 
> Detected by CoverityScan, CID 1429424 ("Resource leak")

Coverity is wrong.

> Signed-off-by: Garry McNulty <garrmcnu@gmail.com>
> ---
>  fs/iomap.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/iomap.c b/fs/iomap.c
> index afd163586aa0..65c5db38c15a 100644
> --- a/fs/iomap.c
> +++ b/fs/iomap.c
> @@ -1063,8 +1063,10 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>  		iomap_dio_set_error(dio, ret);
>  
>  	if (!atomic_dec_and_test(&dio->ref)) {
> -		if (!is_sync_kiocb(iocb))
> -			return -EIOCBQUEUED;
> +		if (!is_sync_kiocb(iocb)) {
> +			ret = -EIOCBQUEUED;
> +			goto out_free_dio;
> +		}

This is where we return after AIO submission. The struct dio has
already been attached to the bio we have submitted, and will be
freed on IO completion.  We are simply not waiting for IO completion
here, instead leaving it to the completion code to free the struct
dio and pass the completion status to the AIO code appropriately.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

* Re: [PATCH] fs/iomap: fix memory leak on error condition
  2018-02-21 21:56 ` Dave Chinner
@ 2018-02-21 23:12   ` Garry McNulty
  0 siblings, 0 replies; 3+ messages in thread
From: Garry McNulty @ 2018-02-21 23:12 UTC (permalink / raw)
  To: Dave Chinner; +Cc: linux-fsdevel, viro, hch, linux-kernel

On 21 February 2018 at 21:56, Dave Chinner <david@fromorbit.com> wrote:
>
> On Wed, Feb 21, 2018 at 08:41:28PM +0000, Garry McNulty wrote:
> > If the call to is_sync_kiocb() fails an error is returned without
> > freeing dio. Set the return code and jump to out_free_dio.
> >
> > Detected by CoverityScan, CID 1429424 ("Resource leak")
>
> Coverity is wrong.
>
> > Signed-off-by: Garry McNulty <garrmcnu@gmail.com>
> > ---
> >  fs/iomap.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/iomap.c b/fs/iomap.c
> > index afd163586aa0..65c5db38c15a 100644
> > --- a/fs/iomap.c
> > +++ b/fs/iomap.c
> > @@ -1063,8 +1063,10 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
> >               iomap_dio_set_error(dio, ret);
> >
> >       if (!atomic_dec_and_test(&dio->ref)) {
> > -             if (!is_sync_kiocb(iocb))
> > -                     return -EIOCBQUEUED;
> > +             if (!is_sync_kiocb(iocb)) {
> > +                     ret = -EIOCBQUEUED;
> > +                     goto out_free_dio;
> > +             }
>
> This is where we return after AIO submission. The struct dio has
> already been attached to the bio we have submitted, and will be
> freed on IO completion.  We are simply not waiting for IO completion
> here, instead leaving it to the completion code to free the struct
> dio and pass the completion status to the AIO code appropriately.
>
ah OK, thanks for reviewing and for the explanation.

Cheers

Garry

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

end of thread, other threads:[~2018-02-21 23:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-21 20:41 [PATCH] fs/iomap: fix memory leak on error condition Garry McNulty
2018-02-21 21:56 ` Dave Chinner
2018-02-21 23:12   ` Garry McNulty

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