Re: [RFC PATCH] net/smc: Consider using kfree_sensitive() to free cpu_addr
From: Andrew Lunn
Date: Fri Apr 11 2025 - 08:27:22 EST
On Fri, Apr 11, 2025 at 04:44:56AM +0000, Zilin Guan wrote:
> Hello,
>
> In smcr_buf_unuse() and smc_buf_unuse(), memzero_explicit() is used to
> clear cpu_addr when it is no longer in use, suggesting that cpu_addr
> may contain sensitive information.
>
> To ensure proper handling of this sensitive memory, I propose using
> kfree_sensitive()/kvfree_sensitive instead of kfree()/vfree() to free
> cpu_addr in both smcd_buf_free() and smc_buf_free(). This change aims
> to prevent potential sensitive data leaks.
There is another possible meaning:
memzero_explicit(conn->sndbuf_desc->cpu_addr, bufsize);
WRITE_ONCE(conn->sndbuf_desc->used, 0);
The WRITE_ONCE() probably tells the hardware the buffer is ready for
it. In order to ensure they memzero has completed and that the
compiler does not reorder the instructions you need a memory barrier:
static inline void memzero_explicit(void *s, size_t count)
{
memset(s, 0, count);
barrier_data(s);
}
So it could be using memzero_explicit() just for the barrier_data().
Please spend some time to analyze this code, look at the git history
etc, see if there are any clues as to why memzero_explicit is used, or
if there is any indication of sensitive information.
Andrew