2022-09-28 08:20:01

by Marcus Folkesson

[permalink] [raw]
Subject: [PATCH] HID: hid-sensor-custom: set fixed size for custom attributes

This is no bugfix (so no Fixes: tag is necessary) as it is
taken care of in hid_sensor_custom_add_attributes().

The motivation for this patch is that:
hid_sensor_custom_field.attr_name and
hid_sensor_custom_field.attrs
has the size of HID_CUSTOM_TOTAL_ATTRS and used in same context.

We compare against HID_CUSTOM_TOTAL_ATTRS when
looping through hid_custom_attrs.

We will silent the smatch error:
hid_sensor_custom_add_attributes() error: buffer overflow
'hid_custom_attrs' 8 <= 10

Signed-off-by: Marcus Folkesson <[email protected]>
---
drivers/hid/hid-sensor-custom.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c
index 32c2306e240d..602465ad2745 100644
--- a/drivers/hid/hid-sensor-custom.c
+++ b/drivers/hid/hid-sensor-custom.c
@@ -62,7 +62,7 @@ struct hid_sensor_sample {
u32 raw_len;
} __packed;

-static struct attribute hid_custom_attrs[] = {
+static struct attribute hid_custom_attrs[HID_CUSTOM_TOTAL_ATTRS] = {
{.name = "name", .mode = S_IRUGO},
{.name = "units", .mode = S_IRUGO},
{.name = "unit-expo", .mode = S_IRUGO},
--
2.37.1


2022-10-02 13:41:38

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH] HID: hid-sensor-custom: set fixed size for custom attributes

On Wed, 28 Sep 2022 09:59:13 +0200
Marcus Folkesson <[email protected]> wrote:

> This is no bugfix (so no Fixes: tag is necessary) as it is
> taken care of in hid_sensor_custom_add_attributes().
>
> The motivation for this patch is that:
> hid_sensor_custom_field.attr_name and
> hid_sensor_custom_field.attrs
> has the size of HID_CUSTOM_TOTAL_ATTRS and used in same context.
>
> We compare against HID_CUSTOM_TOTAL_ATTRS when
> looping through hid_custom_attrs.
>
> We will silent the smatch error:
> hid_sensor_custom_add_attributes() error: buffer overflow
> 'hid_custom_attrs' 8 <= 10
>
> Signed-off-by: Marcus Folkesson <[email protected]>
Slightly ugly fix, but I guess it's the easiest solution.

Acked-by: Jonathan Cameron <[email protected]>

> ---
> drivers/hid/hid-sensor-custom.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c
> index 32c2306e240d..602465ad2745 100644
> --- a/drivers/hid/hid-sensor-custom.c
> +++ b/drivers/hid/hid-sensor-custom.c
> @@ -62,7 +62,7 @@ struct hid_sensor_sample {
> u32 raw_len;
> } __packed;
>
> -static struct attribute hid_custom_attrs[] = {
> +static struct attribute hid_custom_attrs[HID_CUSTOM_TOTAL_ATTRS] = {
> {.name = "name", .mode = S_IRUGO},
> {.name = "units", .mode = S_IRUGO},
> {.name = "unit-expo", .mode = S_IRUGO},