Commit 1de4f92
committed
libibverbs: Avoid memcpy from NULL in fill_attr_in()
fill_attr_in() unconditionally calls memcpy() when len <= sizeof(u64),
regardless of whether the data pointer is NULL. 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.
Fix this by only inlining small attributes when len <= sizeof(u64) and
the data pointer is non-NULL. In all other cases, including zero-length
attributes with a NULL data pointer, the pointer is stored via
ioctl_ptr_to_u64() instead. This preserves the existing behavior for
valid callers while avoiding memcpy() from NULL.
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 1de4f92
1 file changed
+3
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
283 | | - | |
| 283 | + | |
284 | 284 | | |
285 | | - | |
| 285 | + | |
286 | 286 | | |
| 287 | + | |
287 | 288 | | |
288 | 289 | | |
289 | 290 | | |
| |||
0 commit comments