All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] RDMA/irdma: avoid fortify-string warning in irdma_clr_wqes
@ 2023-05-23 11:18 Arnd Bergmann
  2023-05-24 19:55 ` Saleem, Shiraz
  2023-06-01 16:09 ` Jason Gunthorpe
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2023-05-23 11:18 UTC (permalink / raw)
  To: Mustafa Ismail, Shiraz Saleem, Jason Gunthorpe, Leon Romanovsky
  Cc: Arnd Bergmann, Sindhu-Devale, linux-rdma, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

Commit df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3") triggers
a warning for fortified memset():

In function 'fortify_memset_chk',
    inlined from 'irdma_clr_wqes' at drivers/infiniband/hw/irdma/uk.c:103:4:
include/linux/fortify-string.h:493:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
  493 |                         __write_overflow_field(p_size_field, size);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The problem here isthat the inner array only has four 8-byte elements,
so clearing 4096 bytes overflows that. As this structure is part of an
outer array, change the code to pass a pointer to the irdma_qp_quanta
instead, and change the size argument for readability, matching the
comment above it.

Fixes: 551c46edc769 ("RDMA/irdma: Add user/kernel shared libraries")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/infiniband/hw/irdma/uk.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/infiniband/hw/irdma/uk.c b/drivers/infiniband/hw/irdma/uk.c
index 16183e894da7..dd428d915c17 100644
--- a/drivers/infiniband/hw/irdma/uk.c
+++ b/drivers/infiniband/hw/irdma/uk.c
@@ -93,16 +93,18 @@ static int irdma_nop_1(struct irdma_qp_uk *qp)
  */
 void irdma_clr_wqes(struct irdma_qp_uk *qp, u32 qp_wqe_idx)
 {
-	__le64 *wqe;
+	struct irdma_qp_quanta *sq;
 	u32 wqe_idx;
 
 	if (!(qp_wqe_idx & 0x7F)) {
 		wqe_idx = (qp_wqe_idx + 128) % qp->sq_ring.size;
-		wqe = qp->sq_base[wqe_idx].elem;
+		sq = qp->sq_base + wqe_idx;
 		if (wqe_idx)
-			memset(wqe, qp->swqe_polarity ? 0 : 0xFF, 0x1000);
+			memset(sq, qp->swqe_polarity ? 0 : 0xFF,
+			       128 * sizeof(*sq));
 		else
-			memset(wqe, qp->swqe_polarity ? 0xFF : 0, 0x1000);
+			memset(sq, qp->swqe_polarity ? 0xFF : 0,
+			       128 * sizeof(*sq));
 	}
 }
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH] RDMA/irdma: avoid fortify-string warning in irdma_clr_wqes
  2023-05-23 11:18 [PATCH] RDMA/irdma: avoid fortify-string warning in irdma_clr_wqes Arnd Bergmann
@ 2023-05-24 19:55 ` Saleem, Shiraz
  2023-06-01 16:09 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Saleem, Shiraz @ 2023-05-24 19:55 UTC (permalink / raw)
  To: Arnd Bergmann, Ismail, Mustafa, Jason Gunthorpe, Leon Romanovsky
  Cc: Arnd Bergmann, Devale, Sindhu, linux-rdma, linux-kernel

> Subject: [PATCH] RDMA/irdma: avoid fortify-string warning in irdma_clr_wqes
> 
> From: Arnd Bergmann <arnd@arndb.de>
> 
> Commit df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3") triggers a warning for
> fortified memset():
> 
> In function 'fortify_memset_chk',
>     inlined from 'irdma_clr_wqes' at drivers/infiniband/hw/irdma/uk.c:103:4:
> include/linux/fortify-string.h:493:25: error: call to '__write_overflow_field' declared
> with attribute warning: detected write beyond size of field (1st parameter); maybe
> use struct_group()? [-Werror=attribute-warning]
>   493 |                         __write_overflow_field(p_size_field, size);
>       |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> The problem here isthat the inner array only has four 8-byte elements, so clearing
> 4096 bytes overflows that. As this structure is part of an outer array, change the
> code to pass a pointer to the irdma_qp_quanta instead, and change the size
> argument for readability, matching the comment above it.
> 
> Fixes: 551c46edc769 ("RDMA/irdma: Add user/kernel shared libraries")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/infiniband/hw/irdma/uk.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/irdma/uk.c b/drivers/infiniband/hw/irdma/uk.c
> index 16183e894da7..dd428d915c17 100644
> --- a/drivers/infiniband/hw/irdma/uk.c
> +++ b/drivers/infiniband/hw/irdma/uk.c
> @@ -93,16 +93,18 @@ static int irdma_nop_1(struct irdma_qp_uk *qp)
>   */
>  void irdma_clr_wqes(struct irdma_qp_uk *qp, u32 qp_wqe_idx)  {
> -	__le64 *wqe;
> +	struct irdma_qp_quanta *sq;
>  	u32 wqe_idx;
> 
>  	if (!(qp_wqe_idx & 0x7F)) {
>  		wqe_idx = (qp_wqe_idx + 128) % qp->sq_ring.size;
> -		wqe = qp->sq_base[wqe_idx].elem;
> +		sq = qp->sq_base + wqe_idx;
>  		if (wqe_idx)
> -			memset(wqe, qp->swqe_polarity ? 0 : 0xFF, 0x1000);
> +			memset(sq, qp->swqe_polarity ? 0 : 0xFF,
> +			       128 * sizeof(*sq));
>  		else
> -			memset(wqe, qp->swqe_polarity ? 0xFF : 0, 0x1000);
> +			memset(sq, qp->swqe_polarity ? 0xFF : 0,
> +			       128 * sizeof(*sq));
>  	}
>  }
> 
> --
Acked-by: Shiraz Saleem <shiraz.saleem@intel.com>




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RDMA/irdma: avoid fortify-string warning in irdma_clr_wqes
  2023-05-23 11:18 [PATCH] RDMA/irdma: avoid fortify-string warning in irdma_clr_wqes Arnd Bergmann
  2023-05-24 19:55 ` Saleem, Shiraz
@ 2023-06-01 16:09 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2023-06-01 16:09 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Mustafa Ismail, Shiraz Saleem, Leon Romanovsky, Arnd Bergmann,
	Sindhu-Devale, linux-rdma, linux-kernel

On Tue, May 23, 2023 at 01:18:45PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> Commit df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3") triggers
> a warning for fortified memset():
> 
> In function 'fortify_memset_chk',
>     inlined from 'irdma_clr_wqes' at drivers/infiniband/hw/irdma/uk.c:103:4:
> include/linux/fortify-string.h:493:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
>   493 |                         __write_overflow_field(p_size_field, size);
>       |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> The problem here isthat the inner array only has four 8-byte elements,
> so clearing 4096 bytes overflows that. As this structure is part of an
> outer array, change the code to pass a pointer to the irdma_qp_quanta
> instead, and change the size argument for readability, matching the
> comment above it.
> 
> Fixes: 551c46edc769 ("RDMA/irdma: Add user/kernel shared libraries")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> Acked-by: Shiraz Saleem <shiraz.saleem@intel.com>
> ---
>  drivers/infiniband/hw/irdma/uk.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)

Applied to for-next, thanks

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-01 16:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-23 11:18 [PATCH] RDMA/irdma: avoid fortify-string warning in irdma_clr_wqes Arnd Bergmann
2023-05-24 19:55 ` Saleem, Shiraz
2023-06-01 16:09 ` Jason Gunthorpe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.