Skip to contentSkip to conversation

net/rds: reset op_nents when zerocopy page pin fails

PATCH Applied Allison Henderson 3 participants 3 messages May 5 – May 12

Subsystems (4)
lore
Share & tools
lore

Allison Henderson

author maintainer
#0 lore raw

PATCH 1/1 net/rds: reset op_nents when zerocopy page pin fails

When iov_iter_get_pages2() fails in rds_message_zcopy_from_user(), the pinned pages are released with put_page(), and rm->data.op_mmp_znotifier is cleared. But we fail to properly clear rm->data.op_nents.

Later when rds_message_purge() is called from rds_sendmsg() the cleanup loop iterates over the incorrectly non zero number of op_nents and frees them again.

Fix this by properly resetting op_nents when it should be in rds_message_zcopy_from_user().

Fixes 0cebaccef3ac ("rds: zerocopy Tx support.")
---
 net/rds/message.c | 1 +
 1 file changed, 1 insertion(+)
net/rds/message.c +1 -0
index 25fedcb3cd00..7feb0eb6537d 100644
@@ -448,6 +448,7 @@ static int rds_message_zcopy_from_user(struct rds_message *rm, struct iov_iter *
 
 			for (i = 0; i < rm->data.op_nents; i++)
 				put_page(sg_page(&rm->data.op_sg[i]));
+			rm->data.op_nents = 0;
 			mmp = &rm->data.op_mmp_znotifier->z_mmp;
 			mm_unaccount_pinned_pages(mmp);
 			ret = -EFAULT;
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Allison Henderson

When iov_iter_get_pages2() fails in rds_message_zcopy_from_user(), the pinned pages are released with put_page(), and rm->data.op_mmp_znotifier is cleared. But we fail to properly clear rm->data.op_nents.

Later when rds_message_purge() is called from rds_sendmsg() the cleanup loop iterates over the incorrectly non zero number of op_nents and frees them again.

Quoted 5 lines

Fix this by properly resetting op_nents when it should be in rds_message_zcopy_from_user().

Fixes 0cebaccef3ac ("rds: zerocopy Tx support.")
#2 lore raw
In reply to Allison Henderson
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Tue, 5 May 2026 16:43:36 -0700 you wrote:

When iov_iter_get_pages2() fails in rds_message_zcopy_from_user(), the pinned pages are released with put_page(), and rm->data.op_mmp_znotifier is cleared. But we fail to properly clear rm->data.op_nents.

Later when rds_message_purge() is called from rds_sendmsg() the cleanup loop iterates over the incorrectly non zero number of op_nents and frees them again.

[...]

Here is the summary with links:
- [net,v1] net/rds: reset op_nents when zerocopy page pin fails

    https://git.kernel.org/netdev/net/c/e17492979319

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html