Re: [PATCH v3] mm: Add kvfree_sensitive() for freeing sensitive data objects
From: Waiman Long
Date: Tue May 05 2020 - 21:30:12 EST
On 5/5/20 4:35 PM, Andrew Morton wrote:
On Tue, 07 Apr 2020 21:21:57 +0100 David Howells <dhowells@xxxxxxxxxx> wrote:
David Howells <dhowells@xxxxxxxxxx> wrote:
if (unlikely(key_data))
- __kvzfree(key_data, key_data_len);
+ kvfree_sensitive(key_data, key_data_len);
I think the if-statement is redundant.
Ah - I see that you explicitly wanted to keep it.
Why's that?
There is a comment above it:
/*
* The key may change (unlikely) in between 2 consecutive
* __keyctl_read_key() calls. In this case, we reallocate
* a larger buffer and redo the key read when
* key_data_len < ret <= buflen.
*/
if (ret > key_data_len) {
if (unlikely(key_data))
__kvzfree(key_data, key_data_len);
key_data will be defined only if the unlikely case that the key increase
in length between the 2 consecutive __keyctl_read_key() call and we have
to enlarge the buffer and read the key again. I want to keep the
unlikely() macro to emphasize the fact that this condition should not
happen.
There's a good chance it'll get janitored at some point.
Indeed. Perhaps add a few little comments to explain the reasoning and
to keep the janitorial fingers away?
I can reword the comment to make it more explicit and send a v4 if you
think the current comment is not clear enough.
Cheers,
Longman