From: Benjamin LaHaise <bcrl@kvack.org>
To: Robert Baldyga <r.baldyga@samsung.com>
Cc: viro@zeniv.linux.org.uk, kmo@daterainc.com,
linux-fsdevel@vger.kernel.org, linux-aio@kvack.org,
linux-kernel@vger.kernel.org, m.szyprowski@samsung.com
Subject: Re: [PATCH] aio: fix kiocb_cancel() funcition
Date: Mon, 27 Jan 2014 12:36:08 -0500 [thread overview]
Message-ID: <20140127173608.GI19273@kvack.org> (raw)
In-Reply-To: <1390812301-4102-1-git-send-email-r.baldyga@samsung.com>
Hello Robert,
On Mon, Jan 27, 2014 at 09:45:01AM +0100, Robert Baldyga wrote:
> This patch solves problem related with lack of possibility to call
> aio_complete() from cancel callback. It was because it needs to lock
> ctx->ctx_lock which is always locked before kiocb_cancel() call. So there
> was no way to complete request properly.
>
> Now spinlock is unlocked before cancel callback function call, so spinlock
> recursion will not occur in case of aio_complete() call. After cancel function
> call spinlock is locked back.
You can't just do that -- it introduces a possible use-after-free issue with
the kiocb when cancellation occurs. Like I said in my previous email: you
have to deal with object lifetime expecatations in order to do that. If you
could post the code that you're trying to fix this bug for, there might be
other solutions to the problem we can suggest.
-ben
> There is also __must_hold() macro added for kiocb_cancel() function, to allow
> sparse spin lock checking.
>
> Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Nack. Do not apply.
> ---
>
> This patch was created according to suggestions of Benjamin LaHaise
> (https://lkml.org/lkml/2014/1/23/336).
>
> fs/aio.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/fs/aio.c b/fs/aio.c
> index 062a5f6..6d5cd9e 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -472,8 +472,10 @@ void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel)
> EXPORT_SYMBOL(kiocb_set_cancel_fn);
>
> static int kiocb_cancel(struct kioctx *ctx, struct kiocb *kiocb)
> + __must_hold(&ctx->ctx_lock)
> {
> kiocb_cancel_fn *old, *cancel;
> + int ret;
>
> /*
> * Don't want to set kiocb->ki_cancel = KIOCB_CANCELLED unless it
> @@ -489,7 +491,15 @@ static int kiocb_cancel(struct kioctx *ctx, struct kiocb *kiocb)
> cancel = cmpxchg(&kiocb->ki_cancel, old, KIOCB_CANCELLED);
> } while (cancel != old);
>
> - return cancel(kiocb);
> + /*
> + * cancel() function may call aio_complete function, which needs to
> + * lock ctx->ctx_lock, so we call cancel() with spinlock unlocked
> + */
> + spin_unlock(&ctx->ctx_lock);
> + ret = cancel(kiocb);
> + spin_lock(&ctx->ctx_lock);
> +
> + return ret;
> }
>
> static void free_ioctx(struct work_struct *work)
> --
> 1.7.9.5
--
"Thought is the essence of where you are now."
--
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>
prev parent reply other threads:[~2014-01-27 17:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-27 8:45 [PATCH] aio: fix kiocb_cancel() funcition Robert Baldyga
2014-01-27 17:36 ` Benjamin LaHaise [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=20140127173608.GI19273@kvack.org \
--to=bcrl@kvack.org \
--cc=kmo@daterainc.com \
--cc=linux-aio@kvack.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=r.baldyga@samsung.com \
--cc=viro@zeniv.linux.org.uk \
/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).