* [PATCH v3] gpio: cdev: check if uAPI v2 config attributes are correctly zeroed
@ 2026-05-21 8:42 Bartosz Golaszewski
2026-05-21 8:59 ` Kent Gibson
2026-05-21 12:38 ` Bartosz Golaszewski
0 siblings, 2 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2026-05-21 8:42 UTC (permalink / raw)
To: Bartosz Golaszewski, Kent Gibson, Linus Walleij
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
We check the padding of other uAPI v2 structures but not that of line
config attributes. For used attributes: check if their padding is
zeroed, for unused: check if the entire structure is zeroed.
Fixes: 3c0d9c635ae2 ("gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
Changes in v3:
- Don't try to check unused attributes if there are none
- Don't reuse the loop iterator from the attribute padding check
- Link to v2: https://patch.msgid.link/20260520-gpio-cdev-attr-padding-check-v2-1-0010daf8059f@oss.qualcomm.com
Changes in v2:
- Make checking even stricter: check if padding is zeroed for used
attributes, for unused ones: check if the entire struct is zeroed
- Link to v1: https://patch.msgid.link/20260519-gpio-cdev-attr-padding-check-v1-1-a0c6d4a698bf@oss.qualcomm.com
---
drivers/gpio/gpiolib-cdev.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index f36b7c06996d70b2286edbd181899e4c572b9086..82f27db0b2304679eae4c4f28302e9845d7cbaa3 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -1184,6 +1184,7 @@ static int gpio_v2_line_flags_validate(u64 flags)
static int gpio_v2_line_config_validate(struct gpio_v2_line_config *lc,
unsigned int num_lines)
{
+ size_t unused_attrs;
unsigned int i;
u64 flags;
int ret;
@@ -1191,9 +1192,21 @@ static int gpio_v2_line_config_validate(struct gpio_v2_line_config *lc,
if (lc->num_attrs > GPIO_V2_LINE_NUM_ATTRS_MAX)
return -EINVAL;
+ unused_attrs = GPIO_V2_LINE_NUM_ATTRS_MAX - lc->num_attrs;
+
if (!mem_is_zero(lc->padding, sizeof(lc->padding)))
return -EINVAL;
+ for (i = 0; i < lc->num_attrs; i++) {
+ if (lc->attrs[i].attr.padding != 0)
+ return -EINVAL;
+ }
+
+ if (unused_attrs) {
+ if (!mem_is_zero(&lc->attrs[lc->num_attrs], unused_attrs * sizeof(*lc->attrs)))
+ return -EINVAL;
+ }
+
for (i = 0; i < num_lines; i++) {
flags = gpio_v2_line_config_flags(lc, i);
ret = gpio_v2_line_flags_validate(flags);
---
base-commit: 6a50ba100ace43f43c87384367eb2d2605fcc16c
change-id: 20260519-gpio-cdev-attr-padding-check-7e52c98a3de7
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] gpio: cdev: check if uAPI v2 config attributes are correctly zeroed
2026-05-21 8:42 [PATCH v3] gpio: cdev: check if uAPI v2 config attributes are correctly zeroed Bartosz Golaszewski
@ 2026-05-21 8:59 ` Kent Gibson
2026-05-21 12:38 ` Bartosz Golaszewski
1 sibling, 0 replies; 3+ messages in thread
From: Kent Gibson @ 2026-05-21 8:59 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Bartosz Golaszewski, Linus Walleij, linux-gpio, linux-kernel
On Thu, May 21, 2026 at 10:42:16AM +0200, Bartosz Golaszewski wrote:
> We check the padding of other uAPI v2 structures but not that of line
> config attributes. For used attributes: check if their padding is
> zeroed, for unused: check if the entire structure is zeroed.
>
> Fixes: 3c0d9c635ae2 ("gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL")
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
> ---
> Changes in v3:
> - Don't try to check unused attributes if there are none
> - Don't reuse the loop iterator from the attribute padding check
> - Link to v2: https://patch.msgid.link/20260520-gpio-cdev-attr-padding-check-v2-1-0010daf8059f@oss.qualcomm.com
>
> Changes in v2:
> - Make checking even stricter: check if padding is zeroed for used
> attributes, for unused ones: check if the entire struct is zeroed
> - Link to v1: https://patch.msgid.link/20260519-gpio-cdev-attr-padding-check-v1-1-a0c6d4a698bf@oss.qualcomm.com
> ---
> drivers/gpio/gpiolib-cdev.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
> index f36b7c06996d70b2286edbd181899e4c572b9086..82f27db0b2304679eae4c4f28302e9845d7cbaa3 100644
> --- a/drivers/gpio/gpiolib-cdev.c
> +++ b/drivers/gpio/gpiolib-cdev.c
> @@ -1184,6 +1184,7 @@ static int gpio_v2_line_flags_validate(u64 flags)
> static int gpio_v2_line_config_validate(struct gpio_v2_line_config *lc,
> unsigned int num_lines)
> {
> + size_t unused_attrs;
> unsigned int i;
> u64 flags;
> int ret;
> @@ -1191,9 +1192,21 @@ static int gpio_v2_line_config_validate(struct gpio_v2_line_config *lc,
> if (lc->num_attrs > GPIO_V2_LINE_NUM_ATTRS_MAX)
> return -EINVAL;
>
> + unused_attrs = GPIO_V2_LINE_NUM_ATTRS_MAX - lc->num_attrs;
> +
> if (!mem_is_zero(lc->padding, sizeof(lc->padding)))
> return -EINVAL;
>
> + for (i = 0; i < lc->num_attrs; i++) {
> + if (lc->attrs[i].attr.padding != 0)
> + return -EINVAL;
> + }
> +
> + if (unused_attrs) {
> + if (!mem_is_zero(&lc->attrs[lc->num_attrs], unused_attrs * sizeof(*lc->attrs)))
> + return -EINVAL;
> + }
> +
> for (i = 0; i < num_lines; i++) {
> flags = gpio_v2_line_config_flags(lc, i);
> ret = gpio_v2_line_flags_validate(flags);
>
> ---
> base-commit: 6a50ba100ace43f43c87384367eb2d2605fcc16c
> change-id: 20260519-gpio-cdev-attr-padding-check-7e52c98a3de7
>
> Best regards,
> --
> Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] gpio: cdev: check if uAPI v2 config attributes are correctly zeroed
2026-05-21 8:42 [PATCH v3] gpio: cdev: check if uAPI v2 config attributes are correctly zeroed Bartosz Golaszewski
2026-05-21 8:59 ` Kent Gibson
@ 2026-05-21 12:38 ` Bartosz Golaszewski
1 sibling, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2026-05-21 12:38 UTC (permalink / raw)
To: Bartosz Golaszewski, Kent Gibson, Linus Walleij,
Bartosz Golaszewski
Cc: linux-gpio, linux-kernel
On Thu, 21 May 2026 10:42:16 +0200, Bartosz Golaszewski wrote:
> We check the padding of other uAPI v2 structures but not that of line
> config attributes. For used attributes: check if their padding is
> zeroed, for unused: check if the entire structure is zeroed.
>
>
Applied, thanks!
[1/1] gpio: cdev: check if uAPI v2 config attributes are correctly zeroed
https://git.kernel.org/brgl/c/3e6ccd790ed69bedd3d9626d01dd35cf9821c121
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-21 12:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-21 8:42 [PATCH v3] gpio: cdev: check if uAPI v2 config attributes are correctly zeroed Bartosz Golaszewski
2026-05-21 8:59 ` Kent Gibson
2026-05-21 12:38 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox