Skip to content

Commit adef2ae

Browse files
cmzxotehcaster
authored andcommitted
slab: don't put freepointer outside of object if only orig_size
The commit 946fa0d ("mm/slub: extend redzone check to extra allocated kmalloc space than requested") will extend right redzone when allocating for orig_size < object_size. So we can't overlay the freepointer in the object space in this case. But the code looks like it forgot to check SLAB_RED_ZONE, since there won't be extended right redzone if only orig_size enabled. As we are here, make this complex conditional expressions a little prettier and add some comments about extending right redzone when slub_debug_orig_size() enabled. Reviewed-by: Feng Tang <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Signed-off-by: Chengming Zhou <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 47d911b commit adef2ae

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

mm/slub.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5167,18 +5167,19 @@ static int calculate_sizes(struct kmem_cache *s)
51675167
*/
51685168
s->inuse = size;
51695169

5170-
if (slub_debug_orig_size(s) ||
5171-
(flags & (SLAB_TYPESAFE_BY_RCU | SLAB_POISON)) ||
5172-
((flags & SLAB_RED_ZONE) && s->object_size < sizeof(void *)) ||
5173-
s->ctor) {
5170+
if ((flags & (SLAB_TYPESAFE_BY_RCU | SLAB_POISON)) || s->ctor ||
5171+
((flags & SLAB_RED_ZONE) &&
5172+
(s->object_size < sizeof(void *) || slub_debug_orig_size(s)))) {
51745173
/*
51755174
* Relocate free pointer after the object if it is not
51765175
* permitted to overwrite the first word of the object on
51775176
* kmem_cache_free.
51785177
*
51795178
* This is the case if we do RCU, have a constructor or
51805179
* destructor, are poisoning the objects, or are
5181-
* redzoning an object smaller than sizeof(void *).
5180+
* redzoning an object smaller than sizeof(void *) or are
5181+
* redzoning an object with slub_debug_orig_size() enabled,
5182+
* in which case the right redzone may be extended.
51825183
*
51835184
* The assumption that s->offset >= s->inuse means free
51845185
* pointer is outside of the object is used in the

0 commit comments

Comments
 (0)