* [PATCH] hwmon: (dimmtemp) Fix bitmap handling
@ 2022-05-17 20:17 Guenter Roeck
2022-05-18 20:54 ` Winiarska, Iwona
0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2022-05-17 20:17 UTC (permalink / raw)
To: Hardware Monitoring; +Cc: Jean Delvare, Guenter Roeck, Iwona Winiarska
Building arm:allmodconfig may fail with the following error.
In function 'fortify_memcpy_chk',
inlined from 'bitmap_copy' at include/linux/bitmap.h:261:2,
inlined from 'bitmap_copy_clear_tail' at include/linux/bitmap.h:270:2,
inlined from 'bitmap_from_u64' at include/linux/bitmap.h:622:2,
inlined from 'check_populated_dimms' at
drivers/hwmon/peci/dimmtemp.c:284:2:
include/linux/fortify-string.h:344:25: error:
call to '__write_overflow_field' declared with attribute warning:
detected write beyond size of field (1st parameter)
The problematic code is
bitmap_from_u64(priv->dimm_mask, dimm_mask);
dimm_mask is declared as u64, but the bitmap in priv->dimm_mask is only
24 bit wide. On 32-bit systems, this results in writes over the end of
the bitmap.
Fix the problem by using u32 instead of u64 for dimm_mask. This is
currently sufficient, and a compile time check to ensure that the number
of dimms does not exceed the bit map size is already in place.
Fixes: 73bc1b885dae ("hwmon: peci: Add dimmtemp driver")
Cc: Iwona Winiarska <iwona.winiarska@intel.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/hwmon/peci/dimmtemp.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/hwmon/peci/dimmtemp.c b/drivers/hwmon/peci/dimmtemp.c
index 3c71b5546bcb..0a633bda3668 100644
--- a/drivers/hwmon/peci/dimmtemp.c
+++ b/drivers/hwmon/peci/dimmtemp.c
@@ -220,7 +220,7 @@ static int check_populated_dimms(struct peci_dimmtemp *priv)
int chan_rank_max = priv->gen_info->chan_rank_max;
int dimm_idx_max = priv->gen_info->dimm_idx_max;
u32 chan_rank_empty = 0;
- u64 dimm_mask = 0;
+ u32 dimm_mask = 0;
int chan_rank, dimm_idx, ret;
u32 pcs;
@@ -279,9 +279,9 @@ static int check_populated_dimms(struct peci_dimmtemp *priv)
return -EAGAIN;
}
- dev_dbg(priv->dev, "Scanned populated DIMMs: %#llx\n", dimm_mask);
+ dev_dbg(priv->dev, "Scanned populated DIMMs: %#x\n", dimm_mask);
- bitmap_from_u64(priv->dimm_mask, dimm_mask);
+ bitmap_from_arr32(priv->dimm_mask, &dimm_mask, DIMM_NUMS_MAX);
return 0;
}
--
2.35.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] hwmon: (dimmtemp) Fix bitmap handling
2022-05-17 20:17 [PATCH] hwmon: (dimmtemp) Fix bitmap handling Guenter Roeck
@ 2022-05-18 20:54 ` Winiarska, Iwona
0 siblings, 0 replies; 2+ messages in thread
From: Winiarska, Iwona @ 2022-05-18 20:54 UTC (permalink / raw)
To: linux, linux-hwmon; +Cc: jdelvare
On Tue, 2022-05-17 at 13:17 -0700, Guenter Roeck wrote:
> Building arm:allmodconfig may fail with the following error.
>
> In function 'fortify_memcpy_chk',
> inlined from 'bitmap_copy' at include/linux/bitmap.h:261:2,
> inlined from 'bitmap_copy_clear_tail' at include/linux/bitmap.h:270:2,
> inlined from 'bitmap_from_u64' at include/linux/bitmap.h:622:2,
> inlined from 'check_populated_dimms' at
> drivers/hwmon/peci/dimmtemp.c:284:2:
> include/linux/fortify-string.h:344:25: error:
> call to '__write_overflow_field' declared with attribute warning:
> detected write beyond size of field (1st parameter)
>
> The problematic code is
> bitmap_from_u64(priv->dimm_mask, dimm_mask);
>
> dimm_mask is declared as u64, but the bitmap in priv->dimm_mask is only
> 24 bit wide. On 32-bit systems, this results in writes over the end of
> the bitmap.
>
> Fix the problem by using u32 instead of u64 for dimm_mask. This is
> currently sufficient, and a compile time check to ensure that the number
> of dimms does not exceed the bit map size is already in place.
>
> Fixes: 73bc1b885dae ("hwmon: peci: Add dimmtemp driver")
> Cc: Iwona Winiarska <iwona.winiarska@intel.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Iwona Winiarska <iwona.winiarska@intel.com>
Thanks
-Iwona
> ---
> drivers/hwmon/peci/dimmtemp.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-18 20:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-17 20:17 [PATCH] hwmon: (dimmtemp) Fix bitmap handling Guenter Roeck
2022-05-18 20:54 ` Winiarska, Iwona
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.