2020-02-07 21:02:11

by Pavel Begunkov

[permalink] [raw]
Subject: [PATCH v2] io_uring: add cleanup for openat()/statx()

openat() and statx() may have allocated ->open.filename, which should be
be put. Add cleanup handlers for them.

Signed-off-by: Pavel Begunkov <[email protected]>
---

v2: add handler for statx (Jens)

fs/io_uring.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index b0e6b3bc1aec..1698b4950366 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2547,6 +2547,7 @@ static int io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
return ret;
}

+ req->flags |= REQ_F_NEED_CLEANUP;
return 0;
}

@@ -2585,6 +2586,7 @@ static int io_openat2_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
return ret;
}

+ req->flags |= REQ_F_NEED_CLEANUP;
return 0;
}

@@ -2616,6 +2618,7 @@ static int io_openat2(struct io_kiocb *req, struct io_kiocb **nxt,
}
err:
putname(req->open.filename);
+ req->flags &= ~REQ_F_NEED_CLEANUP;
if (ret < 0)
req_set_fail_links(req);
io_cqring_add_event(req, ret);
@@ -2775,6 +2778,7 @@ static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
return ret;
}

+ req->flags |= REQ_F_NEED_CLEANUP;
return 0;
}

@@ -2812,6 +2816,7 @@ static int io_statx(struct io_kiocb *req, struct io_kiocb **nxt,
ret = cp_statx(&stat, ctx->buffer);
err:
putname(ctx->filename);
+ req->flags &= ~REQ_F_NEED_CLEANUP;
if (ret < 0)
req_set_fail_links(req);
io_cqring_add_event(req, ret);
@@ -2857,7 +2862,6 @@ static void io_close_finish(struct io_wq_work **workptr)
}

fput(req->close.put_file);
-
io_put_req_find_next(req, &nxt);
if (nxt)
io_wq_assign_next(workptr, nxt);
@@ -4233,6 +4237,11 @@ static void io_cleanup_req(struct io_kiocb *req)
if (io->msg.iov != io->msg.fast_iov)
kfree(io->msg.iov);
break;
+ case IORING_OP_OPENAT:
+ case IORING_OP_OPENAT2:
+ case IORING_OP_STATX:
+ putname(req->open.filename);
+ break;
}

req->flags &= ~REQ_F_NEED_CLEANUP;
--
2.24.0


2020-02-07 21:14:28

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH v2] io_uring: add cleanup for openat()/statx()

On 2/7/20 1:59 PM, Pavel Begunkov wrote:
> openat() and statx() may have allocated ->open.filename, which should be
> be put. Add cleanup handlers for them.

Thanks, applied - but I dropped this hunk:

> @@ -2857,7 +2862,6 @@ static void io_close_finish(struct io_wq_work **workptr)
> }
>
> fput(req->close.put_file);
> -
> io_put_req_find_next(req, &nxt);
> if (nxt)
> io_wq_assign_next(workptr, nxt);

--
Jens Axboe

2020-02-07 21:21:36

by Pavel Begunkov

[permalink] [raw]
Subject: Re: [PATCH v2] io_uring: add cleanup for openat()/statx()

On 08/02/2020 00:13, Jens Axboe wrote:
> On 2/7/20 1:59 PM, Pavel Begunkov wrote:
>> openat() and statx() may have allocated ->open.filename, which should be
>> be put. Add cleanup handlers for them.
>
> Thanks, applied - but I dropped this hunk:

That's the second time it slipped, I need to read patches more attentively.
Thanks

>
>> @@ -2857,7 +2862,6 @@ static void io_close_finish(struct io_wq_work **workptr)
>> }
>>
>> fput(req->close.put_file);
>> -
>> io_put_req_find_next(req, &nxt);
>> if (nxt)
>> io_wq_assign_next(workptr, nxt);
>

--
Pavel Begunkov


Attachments:
signature.asc (849.00 B)
OpenPGP digital signature