net: rds: check cmsg_len before reading rds_rdma_args in size pass
Subsystems (4)
PATCH v2 1/1 net: rds: check cmsg_len before reading rds_rdma_args in size pass
rds_rm_size() handles RDS_CMSG_RDMA_ARGS after only CMSG_OK() and then calls rds_rdma_extra_size(), which reads args->local_vec_addr and args->nr_local without first checking that cmsg_len covers struct rds_rdma_args. The other two RDS_CMSG_RDMA_ARGS consumers already guard
this: rds_rdma_bytes() in rds_sendmsg() and rds_cmsg_rdma_args() in rds_cmsg_send() both reject cmsg_len < CMSG_LEN(sizeof(struct rds_rdma_args)). Add the same check to rds_rm_size() so all three RDMA args passes are consistent.
This is a consistency and hardening change with no behavioral effect for well-formed senders and no reachable bug today: rds_rdma_bytes() runs before rds_rm_size() in rds_sendmsg() and already rejects a short RDS_CMSG_RDMA_ARGS, so the size pass is not reached with an undersized cmsg. But rds_rm_size() reads the args independently of that earlier pass, and nothing in rds_rm_size() itself records or enforces the precondition, so a reader or a future refactor of the size pass cannot tell the cmsg has already been length-checked. Applying the same cmsg_len guard in all three RDS_CMSG_RDMA_ARGS consumers keeps that invariant local to each and robust to reordering.
---
v2:
- Re-target net-next and drop the Fixes: tag and the stable Cc. This
is a consistency/hardening change, not a reachable bug: as Allison Henderson noted, rds_rdma_bytes() runs before rds_rm_size() in rds_sendmsg() and already rejects a short RDS_CMSG_RDMA_ARGS, so a
user cannot reach the rds_rm_size() read through sendmsg.
- Corrected the changelog: the two sibling guards are rds_rdma_bytes()
in rds_sendmsg() and rds_cmsg_rdma_args() in rds_cmsg_send(); the former runs before, not after, rds_rm_size().
- Dropped the KASAN/AF_RDS reachability framing. No code change from v1.
- v1: https://lore.kernel.org/all/[email protected]/
net/rds/send.c | 2 ++ 1 file changed, 2 insertions(+)
net/rds/send.c +2 -0
@@ -967,6 +967,8 @@ static int rds_rm_size(struct msghdr *msg, int num_sgs,switch (cmsg->cmsg_type) {case RDS_CMSG_RDMA_ARGS : +if (cmsg->cmsg_len <CMSG_LEN (sizeof (struct rds_rdma_args ))) +return -EINVAL ;if (vct->indx >= vct->len) { vct->len += vct->incr; tmp_iov =
base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8
Signature · 1 line
2.53.0
Quoted 20 lines · Michael Bommarito
rds_rm_size()handlesRDS_CMSG_RDMA_ARGSafter onlyCMSG_OK()and then callsrds_rdma_extra_size(), which readsargs->local_vec_addrandargs->nr_localwithout first checking thatcmsg_lencovers structrds_rdma_args. The other twoRDS_CMSG_RDMA_ARGSconsumers already guard
this:rds_rdma_bytes()inrds_sendmsg()andrds_cmsg_rdma_args()inrds_cmsg_send()both rejectcmsg_len<CMSG_LEN(sizeof(struct rds_rdma_args)). Add the same check tords_rm_size()so all three RDMA args passes are consistent.This is a consistency and hardening change with no behavioral effect for well-formed senders and no reachable bug today:
rds_rdma_bytes()runs beforerds_rm_size()inrds_sendmsg()and already rejects a shortRDS_CMSG_RDMA_ARGS, so the size pass is not reached with an undersized cmsg. Butrds_rm_size()reads the args independently of that earlier pass, and nothing inrds_rm_size()itself records or enforces the precondition, so a reader or a future refactor of the size pass cannot tell the cmsg has already been length-checked. Applying the samecmsg_lenguard in all threeRDS_CMSG_RDMA_ARGSconsumers keeps that invariant local to each and robust to reordering.
Quoted 2 lines
Assisted-by Claude:claude-opus-4-8Signed-off-by Michael Bommarito <[email protected]>
This looks good to me. Thanks for working on this.
Allison
Quoted 31 lines
---
v2:
- Re-target net-next and drop the Fixes: tag and the stable Cc. This
is a consistency/hardening change, not a reachable bug: as Allison Henderson noted,rds_rdma_bytes()runs beforerds_rm_size()inrds_sendmsg()and already rejects a shortRDS_CMSG_RDMA_ARGS, so a
user cannot reach therds_rm_size()read through sendmsg.
- Corrected the changelog: the two sibling guards arerds_rdma_bytes()
inrds_sendmsg()andrds_cmsg_rdma_args()inrds_cmsg_send(); the former runs before, not after,rds_rm_size().
- Dropped the KASAN/AF_RDS reachability framing. No code change from v1.
- v1: https://lore.kernel.org/all/[email protected]/net/rds/send.c | 2 ++ 1 file changed, 2 insertions(+)net/rds/send.c +2
-0@@ -967,6 +967,8 @@ static int rds_rm_size(struct msghdr *msg, int num_sgs,switch (cmsg->cmsg_type) {case RDS_CMSG_RDMA_ARGS : +if (cmsg->cmsg_len <CMSG_LEN (sizeof (struct rds_rdma_args ))) +return -EINVAL ;if (vct->indx >= vct->len) { vct->len += vct->incr; tmp_iov =base-commit:
5200f5f493f79f14bbdc349e402a40dfb32f23c8
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, 16 Jun 2026 22:31:46 -0400 you wrote:
rds_rm_size()handlesRDS_CMSG_RDMA_ARGSafter onlyCMSG_OK()and then callsrds_rdma_extra_size(), which readsargs->local_vec_addrandargs->nr_localwithout first checking thatcmsg_lencovers structrds_rdma_args. The other twoRDS_CMSG_RDMA_ARGSconsumers already guard
this:rds_rdma_bytes()inrds_sendmsg()andrds_cmsg_rdma_args()inrds_cmsg_send()both rejectcmsg_len<CMSG_LEN(sizeof(struct rds_rdma_args)). Add the same check tords_rm_size()so all three RDMA args passes are consistent.[...]
Here is the summary with links:
- [net-next,v2] net: rds: check cmsg_len before reading rds_rdma_args in size pass
https://git.kernel.org/netdev/net/c/e5c00023270e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html