Skip to content

Commit

Permalink
mm/slub.c: fix wrong address during slab padding restoration
Browse files Browse the repository at this point in the history
Start address calculated for slab padding restoration was wrong.  Wrong
address would point to some section before padding and could cause
corruption

Link: http://lkml.kernel.org/r/1516604578-4577-1-git-send-email-balasubramani_vivekanandan@mentor.com
Signed-off-by: Balasubramani Vivekanandan <balasubramani_vivekanandan@mentor.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Balasubramani Vivekanandan authored and Linus Torvalds committed Feb 1, 2018
1 parent 84ebb58 commit 5d68268
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ static int slab_pad_check(struct kmem_cache *s, struct page *page)
u8 *start;
u8 *fault;
u8 *end;
u8 *pad;
int length;
int remainder;

Expand All @@ -851,18 +852,19 @@ static int slab_pad_check(struct kmem_cache *s, struct page *page)
if (!remainder)
return 1;

pad = end - remainder;
metadata_access_enable();
fault = memchr_inv(end - remainder, POISON_INUSE, remainder);
fault = memchr_inv(pad, POISON_INUSE, remainder);
metadata_access_disable();
if (!fault)
return 1;
while (end > fault && end[-1] == POISON_INUSE)
end--;

slab_err(s, page, "Padding overwritten. 0x%p-0x%p", fault, end - 1);
print_section(KERN_ERR, "Padding ", end - remainder, remainder);
print_section(KERN_ERR, "Padding ", pad, remainder);

restore_bytes(s, "slab padding", POISON_INUSE, end - remainder, end);
restore_bytes(s, "slab padding", POISON_INUSE, fault, end);
return 0;
}

Expand Down

0 comments on commit 5d68268

Please sign in to comment.