Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

io_uring: add request poisoning

Poison various request fields on free. __io_req_caches_free() is a slow
path, so can be done unconditionally, but gate it on kasan for
io_req_add_to_cache(). Note that some fields are logically retained
between cache allocations and can't be poisoned in
io_req_add_to_cache().

Ideally, it'd be replaced with KASAN'ed caches, but that can't be
enabled because of some synchronisation nuances.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/7a78e8a7f5be434313c400650b862e36c211b312.1755459452.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Pavel Begunkov and committed by
Jens Axboe
92a96b0a 1b237f19

+26
+3
include/linux/poison.h
··· 90 90 /********** lib/stackdepot.c **********/ 91 91 #define STACK_DEPOT_POISON ((void *)(0xD390 + POISON_POINTER_DELTA)) 92 92 93 + /********** io_uring/ **********/ 94 + #define IO_URING_PTR_POISON ((void *)(0x1091UL + POISON_POINTER_DELTA)) 95 + 93 96 #endif
+23
io_uring/io_uring.c
··· 179 179 }; 180 180 #endif 181 181 182 + static void io_poison_cached_req(struct io_kiocb *req) 183 + { 184 + req->ctx = IO_URING_PTR_POISON; 185 + req->tctx = IO_URING_PTR_POISON; 186 + req->file = IO_URING_PTR_POISON; 187 + req->creds = IO_URING_PTR_POISON; 188 + req->io_task_work.func = IO_URING_PTR_POISON; 189 + req->apoll = IO_URING_PTR_POISON; 190 + } 191 + 192 + static void io_poison_req(struct io_kiocb *req) 193 + { 194 + io_poison_cached_req(req); 195 + req->async_data = IO_URING_PTR_POISON; 196 + req->kbuf = IO_URING_PTR_POISON; 197 + req->comp_list.next = IO_URING_PTR_POISON; 198 + req->file_node = IO_URING_PTR_POISON; 199 + req->link = IO_URING_PTR_POISON; 200 + } 201 + 182 202 static inline unsigned int __io_cqring_events(struct io_ring_ctx *ctx) 183 203 { 184 204 return ctx->cached_cq_tail - READ_ONCE(ctx->rings->cq.head); ··· 255 235 256 236 static inline void io_req_add_to_cache(struct io_kiocb *req, struct io_ring_ctx *ctx) 257 237 { 238 + if (IS_ENABLED(CONFIG_KASAN)) 239 + io_poison_cached_req(req); 258 240 wq_stack_add_head(&req->comp_list, &ctx->submit_state.free_list); 259 241 } 260 242 ··· 2789 2767 2790 2768 while (!io_req_cache_empty(ctx)) { 2791 2769 req = io_extract_req(ctx); 2770 + io_poison_req(req); 2792 2771 kmem_cache_free(req_cachep, req); 2793 2772 nr++; 2794 2773 }