net/rds: Do not unpin a page after a failed atomic pin
Subsystems (4)
PATCH v2 1/1 net/rds: Do not unpin a page after a failed atomic pin
rds_cmsg_atomic() assumes that a non-NULL output from rds_pin_pages() represents a pin that it owns. However, pin_user_pages_fast() can roll back a fast-GUP pin after racing fork() and then fail in the slow path, for example after a concurrent mprotect(PROT_NONE). The output slot can still contain the already-unpinned page.
The common error path calls unpin_user_page() on that stale pointer. This can consume another subsystem's pin and allow the page to be freed while it is still in use. A local unprivileged reproducer triggers a KASAN use-after-free write through an io_uring registered buffer.
Clear page when rds_pin_pages() does not return one. The error path continues to release the page on errors after a successful pin, and successful requests retain their existing ownership and behavior. All four RDS atomic ancillary operations share this path.
The issue was found by an LLM.
---
v2: Use the net subject prefix, add Fixes and stable Cc tags, and
include the validation results.
v1: https://lore.kernel.org/r/[email protected]
I have a reproducer for this issue and can share via DM
net/rds/rdma.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/rds/rdma.c +4 -1
@@ -957,8 +957,11 @@ int rds_cmsg_atomic(struct rds_sock *rs, struct rds_message *rm, } ret =rds_pin_pages (args->local_addr,1 , &page,1 ); -if (ret !=1 ) +if (ret !=1 ) { +/* A failed pin can leave a stale page pointer. */ + page =NULL ; goto err; + } ret =0 ;sg_set_page (rm->atomic.op_sg, page,8 ,offset_in_page (args->local_addr));
base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d
Signature · 1 line
2.55.0.openai.911.g06873a30d2f3
Quoted 16 lines · Kyle Zeng
rds_cmsg_atomic()assumes that a non-NULL output fromrds_pin_pages()represents a pin that it owns. However,pin_user_pages_fast()can roll back a fast-GUP pin after racingfork()and then fail in the slow path, for example after a concurrentmprotect(PROT_NONE). The output slot can still contain the already-unpinned page.The common error path calls
unpin_user_page()on that stale pointer. This can consume another subsystem's pin and allow the page to be freed while it is still in use. A local unprivileged reproducer triggers a KASAN use-after-free write through anio_uringregistered buffer.Clear page when
rds_pin_pages()does not return one. The error path continues to release the page on errors after a successful pin, and successful requests retain their existing ownership and behavior. All four RDS atomic ancillary operations share this path.
Quoted 4 lines
The issue was found by an LLM.
Fixes 15133f6e67d8 ("RDS: Implement atomic operations")
Just for future reference, [email protected] is for unpublished security bugs and [email protected] is for known bugs. No need to resend, stable will still find it, but just an fyi for next time.
Quoted 1 line
Signed-off-by Kyle Zeng <[email protected]>
This version looks good to me, thanks Kyle!
Quoted 29 lines
---
v2: Use the net subject prefix, add Fixes and stable Cc tags, and
include the validation results.
v1: https://lore.kernel.org/r/[email protected]I have a reproducer for this issue and can share via DM
net/rds/rdma.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/rds/rdma.c +4
-1@@ -957,8 +957,11 @@ int rds_cmsg_atomic(struct rds_sock *rs, struct rds_message *rm, } ret =rds_pin_pages (args->local_addr,1 , &page,1 ); -if (ret !=1 ) +if (ret !=1 ) { +/* A failed pin can leave a stale page pointer. */ + page =NULL ; goto err; + } ret =0 ;sg_set_page (rm->atomic.op_sg, page,8 ,offset_in_page (args->local_addr));base-commit:
05441d697f7f9a927264f4058cbbc6a03dfcac9d
This patch was applied to netdev/net.git (main) by Dave Miller <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main) by Dave Miller <[email protected]>:
Quoted 6 lines · On Fri, 6 Nov 2026 20:18:04 -0800 you wrote:
rds_cmsg_atomic()assumes that a non-NULL output fromrds_pin_pages()represents a pin that it owns. However,pin_user_pages_fast()can roll back a fast-GUP pin after racingfork()and then fail in the slow path, for example after a concurrentmprotect(PROT_NONE). The output slot can still contain the already-unpinned page.
Quoted 6 lines
The common error path calls
unpin_user_page()on that stale pointer. This can consume another subsystem's pin and allow the page to be freed while it is still in use. A local unprivileged reproducer triggers a KASAN use-after-free write through anio_uringregistered buffer.[...]
Here is the summary with links:
- [net,v2] net/rds: Do not unpin a page after a failed atomic pin
https://git.kernel.org/netdev/net/c/8d5ce4751fad
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html