]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gpio: cdev: check if uAPI v2 config attributes are correctly zeroed
authorBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Thu, 21 May 2026 08:42:16 +0000 (10:42 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Thu, 21 May 2026 10:00:04 +0000 (12:00 +0200)
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")
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Link: https://patch.msgid.link/20260521-gpio-cdev-attr-padding-check-v3-1-ec3bcbe2e358@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
drivers/gpio/gpiolib-cdev.c

index f36b7c06996d70b2286edbd181899e4c572b9086..82f27db0b2304679eae4c4f28302e9845d7cbaa3 100644 (file)
@@ -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);