Skip to contentSkip to conversation

io_uring: ensure open/openat2 name is cleaned on cancelation

PATCH In review Jens Axboe 2 participants 3 messages Sep 24, 2020 – Sep 25, 2020

Subsystems (2)
lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 io_uring: ensure open/openat2 name is cleaned on cancelation

io_uring: ensure open/openat2 name is cleaned on cancelation

If we cancel these requests, we'll leak the memory associated with the filename. Add them to the table of ops that need cleaning, if REQ_F_NEED_CLEANUP is set.

--

fs/io_uring.c +5 -0
index e6004b92e553..0ab16df31288 100644
@@ -5671,6 +5671,11 @@ static void __io_clean_op(struct io_kiocb *req)
 			io_put_file(req, req->splice.file_in,
 				    (req->splice.flags & SPLICE_F_FD_IN_FIXED));
 			break;
+		case IORING_OP_OPENAT:
+		case IORING_OP_OPENAT2:
+			if (req->open.filename)
+				putname(req->open.filename);
+			break;
 		}
 		req->flags &= ~REQ_F_NEED_CLEANUP;
 	}
Signature · 1 line
Jens Axboe
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jens Axboe

io_uring: ensure open/openat2 name is cleaned on cancelation

If we cancel these requests, we'll leak the memory associated with the filename. Add them to the table of ops that need cleaning, if REQ_F_NEED_CLEANUP is set.

IIUC we inadvertently removed 'putname(req->open.filename)' from the cleanup function in commit e62753e4e292 ("io_uring: call statx directly").

Should we add the Fixes tag?

    Fixes: e62753e4e292 ("io_uring: call statx directly")

I'm not sure since the code is changed a bit.

Anyway the patch LGTM:

Thanks,
Stefano

Quoted 25 lines

--

fs/io_uring.c +5 -0
index e6004b92e553..0ab16df31288 100644
@@ -5671,6 +5671,11 @@ static void __io_clean_op(struct io_kiocb *req)
 			io_put_file(req, req->splice.file_in,
 				    (req->splice.flags & SPLICE_F_FD_IN_FIXED));
 			break;
+		case IORING_OP_OPENAT:
+		case IORING_OP_OPENAT2:
+			if (req->open.filename)
+				putname(req->open.filename);
+			break;
 		}
 		req->flags &= ~REQ_F_NEED_CLEANUP;
 	}
Signature · 2 lines
-- 
Jens Axboe
author maintainer
#2 lore raw
Quoted 8 lines · Stefano Garzarella
Quoted 6 lines · Jens Axboe

io_uring: ensure open/openat2 name is cleaned on cancelation

If we cancel these requests, we'll leak the memory associated with the filename. Add them to the table of ops that need cleaning, if REQ_F_NEED_CLEANUP is set.

Quoted 6 lines

IIUC we inadvertently removed 'putname(req->open.filename)' from the cleanup function in commit e62753e4e292 ("io_uring: call statx directly").

Should we add the Fixes tag?

    Fixes: e62753e4e292 ("io_uring: call statx directly")

You are right, I got a bit tricked by it since that commit removed the putname(), and then later on we got rid of the (now) empty openat/openat2 entries.

I'll add the fixes, which means it's 5.8 only.

Quoted 1 line

Added, thanks for reviewing!

Signature · 1 line
Jens Axboe