linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mateusz Guzik <mguzik@redhat.com>
To: "Lukáš Czerner" <lczerner@redhat.com>
Cc: Benjamin LaHaise <bcrl@kvack.org>,
	torvalds@linux-foundation.org, linux-aio@kvack.org,
	linux-fsdevel@vger.kernel.org, stable@vger.kernel.org,
	Leon Yu <chianglungyu@gmail.com>
Subject: Re: [PATCH 2/2] aio: fix potential leak in aio_run_iocb().
Date: Fri, 2 May 2014 13:53:11 +0200	[thread overview]
Message-ID: <20140502115310.GA13207@mguzik.redhat.com> (raw)
In-Reply-To: <alpine.LFD.2.00.1405021051050.7522@localhost.localdomain>

On Fri, May 02, 2014 at 10:56:32AM +0200, Lukáš Czerner wrote:
> On Thu, 1 May 2014, Benjamin LaHaise wrote:
> 
> > Date: Thu, 1 May 2014 09:07:09 -0400
> > From: Benjamin LaHaise <bcrl@kvack.org>
> > To: torvalds@linux-foundation.org
> > Cc: linux-aio@kvack.org, linux-fsdevel@vger.kernel.org,
> >     stable@vger.kernel.org, Leon Yu <chianglungyu@gmail.com>
> > Subject: [PATCH 2/2] aio: fix potential leak in aio_run_iocb().
> > 
> > iovec should be reclaimed whenever caller of rw_copy_check_uvector() returns,
> > but it doesn't hold when failure happens right after aio_setup_vectored_rw().
> > 
> > Fix that in a such way to avoid hairy goto.
> 
> As I already replied to Leon,
> 
> this does not seem right.
> 
> > 
> > Signed-off-by: Leon Yu <chianglungyu@gmail.com>
> > Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>
> > Cc: stable@vger.kernel.org
> > ---
> >  fs/aio.c | 6 ++----
> >  1 file changed, 2 insertions(+), 4 deletions(-)
> > 
> > diff --git a/fs/aio.c b/fs/aio.c
> > index 2adbb03..a0ed6c7 100644
> > --- a/fs/aio.c
> > +++ b/fs/aio.c
> > @@ -1327,10 +1327,8 @@ rw_common:
> >  						&iovec, compat)
> >  			: aio_setup_single_vector(req, rw, buf, &nr_segs,
> >  						  iovec);
> > -		if (ret)
> > -			return ret;
> > -
> > -		ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
> 
> here ret could be possibly set to a positive number.
> 

How?

                ret = (opcode == IOCB_CMD_PREADV ||
                       opcode == IOCB_CMD_PWRITEV)
                        ? aio_setup_vectored_rw(req, rw, buf, &nr_segs,
                                                &iovec, compat)
                        : aio_setup_single_vector(req, rw, buf, &nr_segs,
                                                  iovec);

Where aio_setup_vectored_rw:
        if (ret < 0)
                return ret;
[..]
	return 0;


and aio_setup_single_vector:
        if (unlikely(!access_ok(!rw, buf, kiocb->ki_nbytes)))
                return -EFAULT;
[..]
	        return 0;

Both functions are returning ssize_t, thus it's either 0 on success or
negative on failure.

"if (ret)" replaced by "if (ret < 0)" should indeed set off alarm bells,
but turns it turns out to be fine here.

> > +		if (!ret)
> > +			ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
> >  		if (ret < 0) {
> 

So this check is fine and cleanup will be called.

However, there is a yet to be merged patch which fixes actual problem
which is weird rw_copy_check_uvector semantics:
https://lkml.org/lkml/2014/4/25/778

rendering this patch unnecessary

-- 
Mateusz Guzik

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to majordomo@kvack.org.  For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

  reply	other threads:[~2014-05-02 11:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1398948681.git.bcrl@kvack.org>
2014-05-01 13:06 ` [PATCH 1/2] aio: block io_destroy() until all context requests are completed Benjamin LaHaise
2014-05-01 13:07 ` [PATCH 2/2] aio: fix potential leak in aio_run_iocb() Benjamin LaHaise
2014-05-02  8:56   ` Lukáš Czerner
2014-05-02 11:53     ` Mateusz Guzik [this message]
2014-05-02 12:16       ` Lukáš Czerner

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=20140502115310.GA13207@mguzik.redhat.com \
    --to=mguzik@redhat.com \
    --cc=bcrl@kvack.org \
    --cc=chianglungyu@gmail.com \
    --cc=lczerner@redhat.com \
    --cc=linux-aio@kvack.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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).