Skip to content

Commit 1e70212

Browse files
keeskuba-moo
authored andcommitted
hinic: Replace memcpy() with direct assignment
Under CONFIG_FORTIFY_SOURCE=y and CONFIG_UBSAN_BOUNDS=y, Clang is bugged here for calculating the size of the destination buffer (0x10 instead of 0x14). This copy is a fixed size (sizeof(struct fw_section_info_st)), with the source and dest being struct fw_section_info_st, so the memcpy should be safe, assuming the index is within bounds, which is UBSAN_BOUNDS's responsibility to figure out. Avoid the whole thing and just do a direct assignment. This results in no change to the executable code. [This is a duplicate of commit 2c0ab32 ("hinic: Replace memcpy() with direct assignment") which was applied to net-next.] Cc: Nick Desaulniers <[email protected]> Cc: Tom Rix <[email protected]> Cc: [email protected] Link: ClangBuiltLinux#1592 Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Tested-by: Nathan Chancellor <[email protected]> # build Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 877fe9d commit 1e70212

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

drivers/net/ethernet/huawei/hinic/hinic_devlink.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ static bool check_image_valid(struct hinic_devlink_priv *priv, const u8 *buf,
4343

4444
for (i = 0; i < fw_image->fw_info.fw_section_cnt; i++) {
4545
len += fw_image->fw_section_info[i].fw_section_len;
46-
memcpy(&host_image->image_section_info[i],
47-
&fw_image->fw_section_info[i],
48-
sizeof(struct fw_section_info_st));
46+
host_image->image_section_info[i] = fw_image->fw_section_info[i];
4947
}
5048

5149
if (len != fw_image->fw_len ||

0 commit comments

Comments
 (0)