* [PATCH][next] RDMA/mlx4: Copy union directly
@ 2023-08-15 20:39 Gustavo A. R. Silva
2023-08-15 23:42 ` Kees Cook
2023-08-16 6:32 ` Leon Romanovsky
0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-15 20:39 UTC (permalink / raw)
To: Yishai Hadas, Jason Gunthorpe, Leon Romanovsky
Cc: linux-rdma, linux-kernel, Gustavo A. R. Silva, linux-hardening
Copy union directly instead of using memcpy().
Note that in this case, a direct assignment is more readable and
consistent with the subsequent assignments.
This addresses the following -Wstringop-overflow warning seen in s390
with defconfig:
drivers/infiniband/hw/mlx4/main.c:296:33: warning: writing 16 bytes into a region of size 0 [-Wstringop-overflow=]
296 | memcpy(&port_gid_table->gids[free].gid,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
297 | &attr->gid, sizeof(attr->gid));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This helps with the ongoing efforts to globally enable
-Wstringop-overflow.
Link: https://github.com/KSPP/linux/issues/308
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/infiniband/hw/mlx4/main.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index 216aacd72e4f..2d2cd17e02e6 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -293,8 +293,7 @@ static int mlx4_ib_add_gid(const struct ib_gid_attr *attr, void **context)
ret = -ENOMEM;
} else {
*context = port_gid_table->gids[free].ctx;
- memcpy(&port_gid_table->gids[free].gid,
- &attr->gid, sizeof(attr->gid));
+ port_gid_table->gids[free].gid = attr->gid;
port_gid_table->gids[free].gid_type = attr->gid_type;
port_gid_table->gids[free].vlan_id = vlan_id;
port_gid_table->gids[free].ctx->real_index = free;
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] RDMA/mlx4: Copy union directly
2023-08-15 20:39 [PATCH][next] RDMA/mlx4: Copy union directly Gustavo A. R. Silva
@ 2023-08-15 23:42 ` Kees Cook
2023-08-16 6:32 ` Leon Romanovsky
1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2023-08-15 23:42 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Yishai Hadas, Jason Gunthorpe, Leon Romanovsky, linux-rdma,
linux-kernel, linux-hardening
On Tue, Aug 15, 2023 at 02:39:53PM -0600, Gustavo A. R. Silva wrote:
> Copy union directly instead of using memcpy().
>
> Note that in this case, a direct assignment is more readable and
> consistent with the subsequent assignments.
>
> This addresses the following -Wstringop-overflow warning seen in s390
> with defconfig:
> drivers/infiniband/hw/mlx4/main.c:296:33: warning: writing 16 bytes into a region of size 0 [-Wstringop-overflow=]
> 296 | memcpy(&port_gid_table->gids[free].gid,
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 297 | &attr->gid, sizeof(attr->gid));
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hm, why did it think the union had a size of 0?
Regardless, it's a nice fix:
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] RDMA/mlx4: Copy union directly
2023-08-15 20:39 [PATCH][next] RDMA/mlx4: Copy union directly Gustavo A. R. Silva
2023-08-15 23:42 ` Kees Cook
@ 2023-08-16 6:32 ` Leon Romanovsky
1 sibling, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2023-08-16 6:32 UTC (permalink / raw)
To: Yishai Hadas, Jason Gunthorpe, Gustavo A. R. Silva
Cc: linux-rdma, linux-kernel, linux-hardening
On Tue, 15 Aug 2023 14:39:53 -0600, Gustavo A. R. Silva wrote:
> Copy union directly instead of using memcpy().
>
> Note that in this case, a direct assignment is more readable and
> consistent with the subsequent assignments.
>
> This addresses the following -Wstringop-overflow warning seen in s390
> with defconfig:
> drivers/infiniband/hw/mlx4/main.c:296:33: warning: writing 16 bytes into a region of size 0 [-Wstringop-overflow=]
> 296 | memcpy(&port_gid_table->gids[free].gid,
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 297 | &attr->gid, sizeof(attr->gid));
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> [...]
Applied, thanks!
[1/1] RDMA/mlx4: Copy union directly
https://git.kernel.org/rdma/rdma/c/18ddaeb03bdb65
Best regards,
--
Leon Romanovsky <leon@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-16 6:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-15 20:39 [PATCH][next] RDMA/mlx4: Copy union directly Gustavo A. R. Silva
2023-08-15 23:42 ` Kees Cook
2023-08-16 6:32 ` Leon Romanovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).