Commit b60dbf12 authored by Waiman Long's avatar Waiman Long Committed by Sasha Levin
Browse files

mm/slab: use memzero_explicit() in kzfree()

commit 8982ae52 upstream.

The kzfree() function is normally used to clear some sensitive
information, like encryption keys, in the buffer before freeing it back to
the pool.  Memset() is currently used for buffer clearing.  However
unlikely, there is still a non-zero probability that the compiler may
choose to optimize away the memory clearing especially if LTO is being
used in the future.

To make sure that this optimization will never happen,
memzero_explicit(), which is introduced in v3.18, is now used in
kzfree() to future-proof it.

Fixes: 3ef0e5ba

 ("slab: introduce kzfree()")
Signed-off-by: default avatarWaiman Long <>
Acked-by: default avatarMichal Hocko <>
Cc: David Howells <>
Cc: Jarkko Sakkinen <>
Cc: James Morris <>
Cc: "Serge E. Hallyn" <>
Cc: Joe Perches <>
Cc: Matthew Wilcox <>
Cc: David Rientjes <>
Cc: Johannes Weiner <>
Cc: Dan Carpenter <>
Cc: "Jason A . Donenfeld" <>
Cc: <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent 768e7c02
...@@ -1726,7 +1726,7 @@ void kzfree(const void *p) ...@@ -1726,7 +1726,7 @@ void kzfree(const void *p)
if (unlikely(ZERO_OR_NULL_PTR(mem))) if (unlikely(ZERO_OR_NULL_PTR(mem)))
return; return;
ks = ksize(mem); ks = ksize(mem);
memset(mem, 0, ks); memzero_explicit(mem, ks);
kfree(mem); kfree(mem);
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment