Skip to content

Commit 627cae9

Browse files
committed
Merge branch 'for-6.18/io_uring' into for-next
* for-6.18/io_uring: io_uring: add request poisoning
2 parents 0b02de8 + eb7d5ca commit 627cae9

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

include/linux/poison.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,7 @@
9090
/********** lib/stackdepot.c **********/
9191
#define STACK_DEPOT_POISON ((void *)(0xD390 + POISON_POINTER_DELTA))
9292

93+
/********** io_uring/ **********/
94+
#define IO_URING_PTR_POISON ((void *)(0x1091UL + POISON_POINTER_DELTA))
95+
9396
#endif

io_uring/io_uring.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,26 @@ static const struct ctl_table kernel_io_uring_disabled_table[] = {
179179
};
180180
#endif
181181

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+
182202
static inline unsigned int __io_cqring_events(struct io_ring_ctx *ctx)
183203
{
184204
return ctx->cached_cq_tail - READ_ONCE(ctx->rings->cq.head);
@@ -235,6 +255,8 @@ static inline void req_fail_link_node(struct io_kiocb *req, int res)
235255

236256
static inline void io_req_add_to_cache(struct io_kiocb *req, struct io_ring_ctx *ctx)
237257
{
258+
if (IS_ENABLED(CONFIG_KASAN))
259+
io_poison_cached_req(req);
238260
wq_stack_add_head(&req->comp_list, &ctx->submit_state.free_list);
239261
}
240262

@@ -2766,6 +2788,7 @@ static __cold void __io_req_caches_free(struct io_ring_ctx *ctx)
27662788

27672789
while (!io_req_cache_empty(ctx)) {
27682790
req = io_extract_req(ctx);
2791+
io_poison_req(req);
27692792
kmem_cache_free(req_cachep, req);
27702793
nr++;
27712794
}

0 commit comments

Comments
 (0)