Skip to content

Commit 807eb70

Browse files
committed
libibverbs: Skip zero-length memcpy in fill_attr_in()
fill_attr_in() unconditionally calls memcpy() when len <= sizeof(u64), even if len is zero. In commit d9af497 ("verbs: Add ibv_cmd_alloc/free commands for DMA handle"), the call fill_attr_in_enum(cmdb, UVERBS_ATTR_ALLOC_DMAH_TPH_MEM_TYPE, attr->tph_mem_type, NULL, 0); started passing a NULL data pointer together with len == 0, which leads to memcpy() being invoked with a NULL source address. While nothing is actually copied, some compilers and sanitizers treat this as undefined behavior and emit errors. Avoid this by skipping memcpy() when len is zero. Zero-length attributes have no payload, so this does not change behaviour. fill_attr_in() was originally introduced in commit c344635 ("verbs: Add basic infrastructure support for the kabi ioctl"). Fixes: d9af497 ("verbs: Add ibv_cmd_alloc/free commands for DMA handle") Signed-off-by: Yijing Zeng <zengyijing19900106@gmail.com>
1 parent 2241546 commit 807eb70

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

libibverbs/cmd_ioctl.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,12 @@ fill_attr_in(struct ibv_command_buffer *cmd, uint16_t attr_id, const void *data,
280280
cmd->buffer_error = 1;
281281

282282
attr->len = len;
283-
if (len <= sizeof(uint64_t))
284-
memcpy(&attr->data, data, len);
285-
else
283+
if (len <= sizeof(uint64_t)) {
284+
if (len > 0)
285+
memcpy(&attr->data, data, len);
286+
} else {
286287
attr->data = ioctl_ptr_to_u64(data);
288+
}
287289

288290
return attr;
289291
}

0 commit comments

Comments
 (0)