mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 18:51:56 -04:00
mm: add kvfree_sensitive() for freeing sensitive data objects
[ Upstream commit d4eaa2837851db2bfed572898bfc17f9a9f9151e ]
For kvmalloc'ed data object that contains sensitive information like
cryptographic keys, we need to make sure that the buffer is always cleared
before freeing it. Using memset() alone for buffer clearing may not
provide certainty as the compiler may compile it away. To be sure, the
special memzero_explicit() has to be used.
This patch introduces a new kvfree_sensitive() for freeing those sensitive
data objects allocated by kvmalloc(). The relevant places where
kvfree_sensitive() can be used are modified to use it.
Fixes: 4f0882491a14 ("KEYS: Avoid false positive ENOMEM error on key read")
Suggested-by: Linus Torvalds <[email protected]>
Signed-off-by: Waiman Long <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reviewed-by: Eric Biggers <[email protected]>
Acked-by: David Howells <[email protected]>
Cc: Jarkko Sakkinen <[email protected]>
Cc: James Morris <[email protected]>
Cc: "Serge E. Hallyn" <[email protected]>
Cc: Joe Perches <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Uladzislau Rezki <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
This commit is contained in:
parent
7c41d8c1bc
commit
0b11ec4ae5
4 changed files with 24 additions and 22 deletions
18
mm/util.c
18
mm/util.c
|
|
@ -594,6 +594,24 @@ void kvfree(const void *addr)
|
|||
}
|
||||
EXPORT_SYMBOL(kvfree);
|
||||
|
||||
/**
|
||||
* kvfree_sensitive - Free a data object containing sensitive information.
|
||||
* @addr: address of the data object to be freed.
|
||||
* @len: length of the data object.
|
||||
*
|
||||
* Use the special memzero_explicit() function to clear the content of a
|
||||
* kvmalloc'ed object containing sensitive data to make sure that the
|
||||
* compiler won't optimize out the data clearing.
|
||||
*/
|
||||
void kvfree_sensitive(const void *addr, size_t len)
|
||||
{
|
||||
if (likely(!ZERO_OR_NULL_PTR(addr))) {
|
||||
memzero_explicit((void *)addr, len);
|
||||
kvfree(addr);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(kvfree_sensitive);
|
||||
|
||||
static inline void *__page_rmapping(struct page *page)
|
||||
{
|
||||
unsigned long mapping;
|
||||
|
|
|
|||
Loading…
Reference in a new issue