@@ -228,6 +228,9 @@ bool __kasan_mempool_poison_object(void *ptr, unsigned long ip);
228
228
* bugs and reports them. The caller can use the return value of this function
229
229
* to find out if the allocation is buggy.
230
230
*
231
+ * Before the poisoned allocation can be reused, it must be unpoisoned via
232
+ * kasan_mempool_unpoison_object().
233
+ *
231
234
* This function operates on all slab allocations including large kmalloc
232
235
* allocations (the ones returned by kmalloc_large() or by kmalloc() with the
233
236
* size > KMALLOC_MAX_SIZE).
@@ -241,6 +244,32 @@ static __always_inline bool kasan_mempool_poison_object(void *ptr)
241
244
return true;
242
245
}
243
246
247
+ void __kasan_mempool_unpoison_object (void * ptr , size_t size , unsigned long ip );
248
+ /**
249
+ * kasan_mempool_unpoison_object - Unpoison a mempool slab allocation.
250
+ * @ptr: Pointer to the slab allocation.
251
+ * @size: Size to be unpoisoned.
252
+ *
253
+ * This function is intended for kernel subsystems that cache slab allocations
254
+ * to reuse them instead of freeing them back to the slab allocator (e.g.
255
+ * mempool).
256
+ *
257
+ * This function unpoisons a slab allocation that was previously poisoned via
258
+ * kasan_mempool_poison_object() without initializing its memory. For the
259
+ * tag-based modes, this function does not assign a new tag to the allocation
260
+ * and instead restores the original tags based on the pointer value.
261
+ *
262
+ * This function operates on all slab allocations including large kmalloc
263
+ * allocations (the ones returned by kmalloc_large() or by kmalloc() with the
264
+ * size > KMALLOC_MAX_SIZE).
265
+ */
266
+ static __always_inline void kasan_mempool_unpoison_object (void * ptr ,
267
+ size_t size )
268
+ {
269
+ if (kasan_enabled ())
270
+ __kasan_mempool_unpoison_object (ptr , size , _RET_IP_ );
271
+ }
272
+
244
273
/*
245
274
* Unlike kasan_check_read/write(), kasan_check_byte() is performed even for
246
275
* the hardware tag-based mode that doesn't rely on compiler instrumentation.
@@ -301,6 +330,8 @@ static inline bool kasan_mempool_poison_object(void *ptr)
301
330
{
302
331
return true;
303
332
}
333
+ static inline void kasan_mempool_unpoison_object (void * ptr , size_t size ) {}
334
+
304
335
static inline bool kasan_check_byte (const void * address )
305
336
{
306
337
return true;
0 commit comments