Skip to content

Commit aa0a4ef

Browse files
author
Andy Grover
committed
RDS: Make sure cmsgs aren't used in improper ways
It hasn't cropped up in the field, but this code ensures it is impossible to issue operations that pass an rdma cookie (DEST, MAP) in the same sendmsg call that's actually initiating rdma or atomic ops. Disallowing this perverse-but-technically-allowed usage makes silent RDMA heuristics slightly easier. Signed-off-by: Andy Grover <andy.grover@oracle.com>
1 parent 2c3a5f9 commit aa0a4ef

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎net/rds/send.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ static int rds_rm_size(struct msghdr *msg, int data_len)
846846
{
847847
struct cmsghdr *cmsg;
848848
int size = 0;
849+
int cmsg_groups = 0;
849850
int retval;
850851

851852
for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) {
@@ -857,19 +858,23 @@ static int rds_rm_size(struct msghdr *msg, int data_len)
857858

858859
switch (cmsg->cmsg_type) {
859860
case RDS_CMSG_RDMA_ARGS:
861+
cmsg_groups |= 1;
860862
retval = rds_rdma_extra_size(CMSG_DATA(cmsg));
861863
if (retval < 0)
862864
return retval;
863865
size += retval;
866+
864867
break;
865868

866869
case RDS_CMSG_RDMA_DEST:
867870
case RDS_CMSG_RDMA_MAP:
871+
cmsg_groups |= 2;
868872
/* these are valid but do no add any size */
869873
break;
870874

871875
case RDS_CMSG_ATOMIC_CSWP:
872876
case RDS_CMSG_ATOMIC_FADD:
877+
cmsg_groups |= 1;
873878
size += sizeof(struct scatterlist);
874879
break;
875880

@@ -881,6 +886,10 @@ static int rds_rm_size(struct msghdr *msg, int data_len)
881886

882887
size += ceil(data_len, PAGE_SIZE) * sizeof(struct scatterlist);
883888

889+
/* Ensure (DEST, MAP) are never used with (ARGS, ATOMIC) */
890+
if (cmsg_groups == 3)
891+
return -EINVAL;
892+
884893
return size;
885894
}
886895

0 commit comments

Comments
 (0)