Skip to contentSkip to conversation

vDPA: fix incorrect VDPA_ATTR_MAX value

PATCH In review [email protected] 2 participants 3 messages Apr 15, 2024 – Apr 16, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vDPA: fix incorrect VDPA_ATTR_MAX value

From: Vasiliy Kovalev <[email protected]>

The VDPA_ATTR_MAX value should correspond to the index of the last available member of the structure, not their total number.

Otherwise, it can lead to interpretation errors in other functions when the structure (.maxattr = VDPA_ATTR_MAX) member is actually incremented by one and refers to invalid data.

Fixes 33b347503f01 ("vdpa: Define vdpa mgmt device, ops and a netlink interface")
---
 include/uapi/linux/vdpa.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/uapi/linux/vdpa.h +2 -1
index 43c51698195ceb..ab132a09565232 100644
@@ -74,7 +74,8 @@ enum vdpa_attr {
 	VDPA_ATTR_DEV_BLK_CFG_FLUSH,		/* u8 */
 
 	/* new attributes must be added above here */
-	VDPA_ATTR_MAX,
+	__VDPA_ATTR_MAX,
+	VDPA_ATTR_MAX	= __VDPA_ATTR_MAX - 1,
 };
 
 #endif
Signature · 1 line
2.33.8
#1 lore raw
Quoted 5 lines · On Tue, Apr 16, 2024 at 12:39 AM <[email protected]> wrote:

From: Vasiliy Kovalev <[email protected]>

The VDPA_ATTR_MAX value should correspond to the index of the last available member of the structure, not their total number.

I think it's too late to change. More below.

Quoted 16 lines

Otherwise, it can lead to interpretation errors in other functions when the structure (.maxattr = VDPA_ATTR_MAX) member is actually incremented by one and refers to invalid data.

Fixes 33b347503f01 ("vdpa: Define vdpa mgmt device, ops and a netlink interface")
---
 include/uapi/linux/vdpa.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/uapi/linux/vdpa.h +0 -0
index 43c51698195ceb..ab132a09565232 100644

include/uapi/linux/vdpa.h enum vdpa_attr { · line 78

Quoted 6 lines
include/uapi/linux/vdpa.h +2 -1
@@ -74,7 +74,8 @@ enum vdpa_attr {
        VDPA_ATTR_DEV_BLK_CFG_FLUSH,            /* u8 */
 
        /* new attributes must be added above here */
-       VDPA_ATTR_MAX,
+       __VDPA_ATTR_MAX,
+       VDPA_ATTR_MAX   = __VDPA_ATTR_MAX - 1,

Having a MAX in uapi is problematic as it may confuse the userspace. I think the correct way is to drop it from uAPI.

Thanks

Quoted 7 lines
include/uapi/linux/vdpa.h +0 -1
 };
 
 #endif
--

2.33.8

#2 lore raw
Quoted 28 lines · Jason Wang
Quoted 5 lines · On Tue, Apr 16, 2024 at 12:39 AM <[email protected]> wrote:

From: Vasiliy Kovalev <[email protected]>

The VDPA_ATTR_MAX value should correspond to the index of the last available member of the structure, not their total number.

I think it's too late to change. More below.

Quoted 18 lines

Otherwise, it can lead to interpretation errors in other functions when the structure (.maxattr = VDPA_ATTR_MAX) member is actually incremented by one and refers to invalid data.

Fixes 33b347503f01 ("vdpa: Define vdpa mgmt device, ops and a netlink interface")
---
 include/uapi/linux/vdpa.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/uapi/linux/vdpa.h +0 -0
index 43c51698195ceb..ab132a09565232 100644
@@ -74,7 +74,8 @@ enum vdpa_attr {
        VDPA_ATTR_DEV_BLK_CFG_FLUSH,            /* u8 */
 
Quoted 7 lines

include/uapi/linux/vdpa.h enum vdpa_attr { · line 78

Quoted 4 lines
include/uapi/linux/vdpa.h +2 -1
        /* new attributes must be added above here */
-       VDPA_ATTR_MAX,
+       __VDPA_ATTR_MAX,
+       VDPA_ATTR_MAX   = __VDPA_ATTR_MAX - 1,

Having a MAX in uapi is problematic as it may confuse the userspace. I think the correct way is to drop it from uAPI.

Too late to drop as well probably ...

Thanks

Quoted 10 lines

Thanks

Quoted 7 lines
include/uapi/linux/vdpa.h +0 -1
 };
 
 #endif
--

2.33.8