Skip to contentSkip to conversation

IB/uverbs: Add a check for uverbs_attr_get

PATCH In review Chuhong Yuan 2 participants 2 messages Oct 18, 2019 – Oct 22, 2019 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IB/uverbs: Add a check for uverbs_attr_get

Only uverbs_copy_to_struct_or_zero in uverbs_ioctl.c does not have a check for uverbs_attr_get.
Although its usage in uverbs_response has a check for attr's validity, UVERBS_HANDLER does not.
Therefore, it is better to add a check like other functions in uverbs_ioctl.c.

---
 drivers/infiniband/core/uverbs_ioctl.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/infiniband/core/uverbs_ioctl.c +3 -0
index 61758201d9b2..269938f59d3f 100644
@@ -795,6 +795,9 @@ int uverbs_copy_to_struct_or_zero(const struct uverbs_attr_bundle *bundle,
 {
 	const struct uverbs_attr *attr = uverbs_attr_get(bundle, idx);
 
+	if (IS_ERR(attr))
+		return PTR_ERR(attr);
+
 	if (size < attr->ptr_attr.len) {
 		if (clear_user(u64_to_user_ptr(attr->ptr_attr.data) + size,
 			       attr->ptr_attr.len - size))
Signature · 1 line
2.20.1
#1 lore raw
Quoted 11 lines · Chuhong Yuan

Only uverbs_copy_to_struct_or_zero in uverbs_ioctl.c does not have a check for uverbs_attr_get.
Although its usage in uverbs_response has a check for attr's validity, UVERBS_HANDLER does not.
Therefore, it is better to add a check like other functions in uverbs_ioctl.c.

---
 drivers/infiniband/core/uverbs_ioctl.c | 3 +++
 1 file changed, 3 insertions(+)

The call in uverbs_ioctl.c is safe as well, that code path checks that the attribute exists.

Still, it make sense that this check should be present, so applied to for-next with a clearer commit message

Thanks,
Jason