Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

RDMA/ucma: Check for a cm_id->device in all user calls that need it

This is done by auditing all callers of ucma_get_ctx and switching the
ones that unconditionally touch ->device to ucma_get_ctx_dev. This covers
a little less than half of the call sites.

The 11 remaining call sites to ucma_get_ctx() were manually audited.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>

authored by

Jason Gunthorpe and committed by
Doug Ledford
8b77586b e33514f2

+24 -12
+24 -12
drivers/infiniband/core/ucma.c
··· 159 159 complete(&ctx->comp); 160 160 } 161 161 162 + /* 163 + * Same as ucm_get_ctx but requires that ->cm_id->device is valid, eg that the 164 + * CM_ID is bound. 165 + */ 166 + static struct ucma_context *ucma_get_ctx_dev(struct ucma_file *file, int id) 167 + { 168 + struct ucma_context *ctx = ucma_get_ctx(file, id); 169 + 170 + if (IS_ERR(ctx)) 171 + return ctx; 172 + if (!ctx->cm_id->device) { 173 + ucma_put_ctx(ctx); 174 + return ERR_PTR(-EINVAL); 175 + } 176 + return ctx; 177 + } 178 + 162 179 static void ucma_close_event_id(struct work_struct *work) 163 180 { 164 181 struct ucma_event *uevent_close = container_of(work, struct ucma_event, close_work); ··· 751 734 if (copy_from_user(&cmd, inbuf, sizeof(cmd))) 752 735 return -EFAULT; 753 736 754 - ctx = ucma_get_ctx(file, cmd.id); 737 + ctx = ucma_get_ctx_dev(file, cmd.id); 755 738 if (IS_ERR(ctx)) 756 739 return PTR_ERR(ctx); 757 740 ··· 1067 1050 if (!cmd.conn_param.valid) 1068 1051 return -EINVAL; 1069 1052 1070 - ctx = ucma_get_ctx(file, cmd.id); 1053 + ctx = ucma_get_ctx_dev(file, cmd.id); 1071 1054 if (IS_ERR(ctx)) 1072 1055 return PTR_ERR(ctx); 1073 1056 ··· 1109 1092 if (copy_from_user(&cmd, inbuf, sizeof(cmd))) 1110 1093 return -EFAULT; 1111 1094 1112 - ctx = ucma_get_ctx(file, cmd.id); 1095 + ctx = ucma_get_ctx_dev(file, cmd.id); 1113 1096 if (IS_ERR(ctx)) 1114 1097 return PTR_ERR(ctx); 1115 1098 ··· 1137 1120 if (copy_from_user(&cmd, inbuf, sizeof(cmd))) 1138 1121 return -EFAULT; 1139 1122 1140 - ctx = ucma_get_ctx(file, cmd.id); 1123 + ctx = ucma_get_ctx_dev(file, cmd.id); 1141 1124 if (IS_ERR(ctx)) 1142 1125 return PTR_ERR(ctx); 1143 1126 ··· 1156 1139 if (copy_from_user(&cmd, inbuf, sizeof(cmd))) 1157 1140 return -EFAULT; 1158 1141 1159 - ctx = ucma_get_ctx(file, cmd.id); 1142 + ctx = ucma_get_ctx_dev(file, cmd.id); 1160 1143 if (IS_ERR(ctx)) 1161 1144 return PTR_ERR(ctx); 1162 1145 ··· 1184 1167 if (cmd.qp_state > IB_QPS_ERR) 1185 1168 return -EINVAL; 1186 1169 1187 - ctx = ucma_get_ctx(file, cmd.id); 1170 + ctx = ucma_get_ctx_dev(file, cmd.id); 1188 1171 if (IS_ERR(ctx)) 1189 1172 return PTR_ERR(ctx); 1190 - 1191 - if (!ctx->cm_id->device) { 1192 - ret = -EINVAL; 1193 - goto out; 1194 - } 1195 1173 1196 1174 resp.qp_attr_mask = 0; 1197 1175 memset(&qp_attr, 0, sizeof qp_attr); ··· 1396 1384 else 1397 1385 return -EINVAL; 1398 1386 1399 - ctx = ucma_get_ctx(file, cmd->id); 1387 + ctx = ucma_get_ctx_dev(file, cmd->id); 1400 1388 if (IS_ERR(ctx)) 1401 1389 return PTR_ERR(ctx); 1402 1390