@@ -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+
182202static 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
236256static 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