Skip to content

Conversation

@zengyijing
Copy link
Contributor

@zengyijing zengyijing commented Dec 8, 2025

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 behavior.

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

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>
@zengyijing zengyijing force-pushed the fix-fill-attr-zero-len branch from 807eb70 to 65a5630 Compare December 8, 2025 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant