linux/io_uring
Peilin Ye f482aa9865 audit, io_uring, io-wq: Fix memory leak in io_sq_thread() and io_wqe_worker()
Currently @audit_context is allocated twice for io_uring workers:

  1. copy_process() calls audit_alloc();
  2. io_sq_thread() or io_wqe_worker() calls audit_alloc_kernel() (which
     is effectively audit_alloc()) and overwrites @audit_context,
     causing:

  BUG: memory leak
  unreferenced object 0xffff888144547400 (size 1024):
<...>
    hex dump (first 32 bytes):
      00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00  ................
      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    backtrace:
      [<ffffffff8135cfc3>] audit_alloc+0x133/0x210
      [<ffffffff81239e63>] copy_process+0xcd3/0x2340
      [<ffffffff8123b5f3>] create_io_thread+0x63/0x90
      [<ffffffff81686604>] create_io_worker+0xb4/0x230
      [<ffffffff81686f68>] io_wqe_enqueue+0x248/0x3b0
      [<ffffffff8167663a>] io_queue_iowq+0xba/0x200
      [<ffffffff816768b3>] io_queue_async+0x113/0x180
      [<ffffffff816840df>] io_req_task_submit+0x18f/0x1a0
      [<ffffffff816841cd>] io_apoll_task_func+0xdd/0x120
      [<ffffffff8167d49f>] tctx_task_work+0x11f/0x570
      [<ffffffff81272c4e>] task_work_run+0x7e/0xc0
      [<ffffffff8125a688>] get_signal+0xc18/0xf10
      [<ffffffff8111645b>] arch_do_signal_or_restart+0x2b/0x730
      [<ffffffff812ea44e>] exit_to_user_mode_prepare+0x5e/0x180
      [<ffffffff844ae1b2>] syscall_exit_to_user_mode+0x12/0x20
      [<ffffffff844a7e80>] do_syscall_64+0x40/0x80

Then,

  3. io_sq_thread() or io_wqe_worker() frees @audit_context using
     audit_free();
  4. do_exit() eventually calls audit_free() again, which is okay
     because audit_free() does a NULL check.

As suggested by Paul Moore, fix it by deleting audit_alloc_kernel() and
redundant audit_free() calls.

Fixes: 5bd2182d58 ("audit,io_uring,io-wq: add some basic audit support to io_uring")
Suggested-by: Paul Moore <paul@paul-moore.com>
Cc: stable@vger.kernel.org
Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>
Acked-by: Paul Moore <paul@paul-moore.com>
Link: https://lore.kernel.org/r/20220803222343.31673-1-yepeilin.cs@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2022-08-04 08:33:54 -06:00
..
advise.c io_uring: kill extra io_uring_types.h includes 2022-07-24 18:39:14 -06:00
advise.h io_uring: split out fadvise/madvise operations 2022-07-24 18:39:11 -06:00
alloc_cache.h io_uring: impose max limit on apoll cache 2022-07-24 18:39:17 -06:00
cancel.c io_uring: add sync cancelation API through io_uring_register() 2022-07-24 18:39:15 -06:00
cancel.h io_uring: add sync cancelation API through io_uring_register() 2022-07-24 18:39:15 -06:00
epoll.c io_uring: kill extra io_uring_types.h includes 2022-07-24 18:39:14 -06:00
epoll.h io_uring: move epoll handler to its own file 2022-07-24 18:39:11 -06:00
fdinfo.c io_uring: move a few private types to local headers 2022-07-24 18:39:14 -06:00
fdinfo.h io_uring: move fdinfo helpers to its own file 2022-07-24 18:39:12 -06:00
filetable.c io_uring: let to set a range for file slot allocation 2022-07-24 18:39:16 -06:00
filetable.h io_uring: let to set a range for file slot allocation 2022-07-24 18:39:16 -06:00
fs.c io_uring: kill extra io_uring_types.h includes 2022-07-24 18:39:14 -06:00
fs.h io_uring: split out filesystem related operations 2022-07-24 18:39:11 -06:00
io_uring.c io_uring: notification completion optimisation 2022-07-27 08:50:50 -06:00
io_uring.h io_uring: export req alloc from core 2022-07-27 08:50:50 -06:00
io-wq.c audit, io_uring, io-wq: Fix memory leak in io_sq_thread() and io_wqe_worker() 2022-08-04 08:33:54 -06:00
io-wq.h io_uring: move list helpers to a separate file 2022-07-24 18:39:15 -06:00
kbuf.c io_uring: allow 0 length for buffer select 2022-07-24 18:39:16 -06:00
kbuf.h io_uring: restore bgid in io_put_kbuf 2022-07-24 18:39:16 -06:00
Makefile io_uring: add zc notification infrastructure 2022-07-24 18:41:06 -06:00
msg_ring.c io_uring: add allow_overflow to io_post_aux_cqe 2022-07-24 18:39:17 -06:00
msg_ring.h io_uring: move msg_ring into its own file 2022-07-24 18:39:12 -06:00
net.c io_uring: notification completion optimisation 2022-07-27 08:50:50 -06:00
net.h io_uring: wire send zc request type 2022-07-24 18:41:07 -06:00
nop.c io_uring: kill extra io_uring_types.h includes 2022-07-24 18:39:14 -06:00
nop.h io_uring: move nop into its own file 2022-07-24 18:39:11 -06:00
notif.c io_uring: notification completion optimisation 2022-07-27 08:50:50 -06:00
notif.h io_uring: notification completion optimisation 2022-07-27 08:50:50 -06:00
opdef.c io_uring: rename IORING_OP_FILES_UPDATE 2022-07-24 18:41:07 -06:00
opdef.h io_uring: move opcode table to opdef.c 2022-07-24 18:39:12 -06:00
openclose.c io_uring: split out fixed file installation and removal 2022-07-24 18:39:16 -06:00
openclose.h io_uring: split out fixed file installation and removal 2022-07-24 18:39:16 -06:00
poll.c io_uring: add abstraction around apoll cache 2022-07-24 18:39:17 -06:00
poll.h io_uring: add abstraction around apoll cache 2022-07-24 18:39:17 -06:00
refs.h io_uring: make io_uring_types.h public 2022-07-24 18:39:14 -06:00
rsrc.c io_uring/net: make page accounting more consistent 2022-07-25 09:48:25 -06:00
rsrc.h io_uring/net: make page accounting more consistent 2022-07-25 09:48:25 -06:00
rw.c io_uring: Add tracepoint for short writes 2022-07-24 18:39:32 -06:00
rw.h io_uring: move read/write related opcodes to its own file 2022-07-24 18:39:12 -06:00
slist.h io_uring: move list helpers to a separate file 2022-07-24 18:39:15 -06:00
splice.c io_uring: kill extra io_uring_types.h includes 2022-07-24 18:39:14 -06:00
splice.h io_uring: split out splice related operations 2022-07-24 18:39:11 -06:00
sqpoll.c audit, io_uring, io-wq: Fix memory leak in io_sq_thread() and io_wqe_worker() 2022-08-04 08:33:54 -06:00
sqpoll.h io_uring: move SQPOLL related handling into its own file 2022-07-24 18:39:12 -06:00
statx.c io_uring: kill extra io_uring_types.h includes 2022-07-24 18:39:14 -06:00
statx.h io_uring: move statx handling to its own file 2022-07-24 18:39:11 -06:00
sync.c io_uring: kill extra io_uring_types.h includes 2022-07-24 18:39:14 -06:00
sync.h io_uring: split out fs related sync/fallocate functions 2022-07-24 18:39:11 -06:00
tctx.c io_uring: lockless task list 2022-07-24 18:39:15 -06:00
tctx.h io_uring: export io_put_task() 2022-07-24 18:41:06 -06:00
timeout.c io_uring: improve io_fail_links() 2022-07-24 18:39:16 -06:00
timeout.h io_uring: move a few private types to local headers 2022-07-24 18:39:14 -06:00
uring_cmd.c io_uring: pass correct parameters to io_req_set_res 2022-08-03 08:45:25 -06:00
uring_cmd.h io_uring: move uring_cmd handling to its own file 2022-07-24 18:39:11 -06:00
xattr.c io_uring: kill extra io_uring_types.h includes 2022-07-24 18:39:14 -06:00
xattr.h io_uring: move xattr related opcodes to its own file 2022-07-24 18:39:11 -06:00