diff mbox series

[RFC] net/smc: Consider using kfree_sensitive() to free cpu_addr

Message ID 20250411044456.1661380-1-zilin@seu.edu.cn (mailing list archive)
State Not Applicable
Headers show
Series [RFC] net/smc: Consider using kfree_sensitive() to free cpu_addr | expand

Commit Message

Zilin Guan April 11, 2025, 4:44 a.m. UTC
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.

I am submitting this as an RFC to seek feedback on whether this change
is appropriate and aligns with the subsystem's expectations. If confirmed
to be useful, I will send a formal patch.

Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
 net/smc/smc_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andrew Lunn April 11, 2025, 12:22 p.m. UTC | #1
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
diff mbox series

Patch

diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index ac07b963aede..1b5eb0149b89 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -1388,7 +1388,7 @@  static void smcr_buf_free(struct smc_link_group *lgr, bool is_rmb,
 	if (!buf_desc->is_vm && buf_desc->pages)
 		__free_pages(buf_desc->pages, buf_desc->order);
 	else if (buf_desc->is_vm && buf_desc->cpu_addr)
-		vfree(buf_desc->cpu_addr);
+		kvfree_sensitive(buf_desc->cpu_addr, buf_desc->len);
 	kfree(buf_desc);
 }
 
@@ -1400,7 +1400,7 @@  static void smcd_buf_free(struct smc_link_group *lgr, bool is_dmb,
 		buf_desc->len += sizeof(struct smcd_cdc_msg);
 		smc_ism_unregister_dmb(lgr->smcd, buf_desc);
 	} else {
-		kfree(buf_desc->cpu_addr);
+		kfree_sensitive(buf_desc->cpu_addr);
 	}
 	kfree(buf_desc);
 }