Skip to contentSkip to conversation

usb: f_fs: Clear OS Extended descriptor counts to zero in ffs_data_reset()

PATCH Superseded Sriharsha Allenki 2 participants 3 messages Apr 2, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: f_fs: Clear OS Extended descriptor counts to zero in ffs_data_reset()

From: Udipto Goswami <[email protected]>

For userspace functions using OS Descriptors, if a function also supplies Extended Property descriptors currently the counts and lengths stored in the ms_os_descs_ext_prop_{count,name_len,data_len} variables are not getting reset to 0 during an unbind or when the epfiles are closed. If the same function is re-bound and the descriptors are re-written, this results in those count/length variables to monotonically increase causing the VLA allocation in _ffs_func_bind() to grow larger and larger at each bind/unbind cycle and eventually fail to allocate.

Fix this by clearing the ms_os_descs_ext_prop count & lengths to 0 in ffs_data_reset().

Change-Id I3b292fe5386ab54b53df2b9f15f07430dc3df24a
Fixes f0175ab51993 ("usb: gadget: f_fs: OS descriptors support")
---
 drivers/usb/gadget/function/f_fs.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/gadget/function/f_fs.c +4 -0
index c81023b195c3..10f01f974f67 100644
@@ -1813,6 +1813,10 @@ static void ffs_data_reset(struct ffs_data *ffs)
 	ffs->state = FFS_READ_DESCRIPTORS;
 	ffs->setup_state = FFS_NO_SETUP;
 	ffs->flags = 0;
+
+	ffs->ms_os_descs_ext_prop_count = 0;
+	ffs->ms_os_descs_ext_prop_name_len = 0;
+	ffs->ms_os_descs_ext_prop_data_len = 0;
 }
 
 
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Sriharsha Allenki

From: Udipto Goswami <[email protected]>

For userspace functions using OS Descriptors, if a function also supplies Extended Property descriptors currently the counts and lengths stored in the ms_os_descs_ext_prop_{count,name_len,data_len} variables are not getting reset to 0 during an unbind or when the epfiles are closed. If the same function is re-bound and the descriptors are re-written, this results in those count/length variables to monotonically increase causing the VLA allocation in _ffs_func_bind() to grow larger and larger at each bind/unbind cycle and eventually fail to allocate.

Quoted 4 lines

Fix this by clearing the ms_os_descs_ext_prop count & lengths to 0 in ffs_data_reset().

Change-Id: I3b292fe5386ab54b53df2b9f15f07430dc3df24a

Please remove this.

Quoted 13 lines
Fixes f0175ab51993 ("usb: gadget: f_fs: OS descriptors support")
---
 drivers/usb/gadget/function/f_fs.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/gadget/function/f_fs.c +0 -0
index c81023b195c3..10f01f974f67 100644

drivers/usb/gadget/function/f_fs.c static void ffs_data_reset(struct ffs_data *ffs) · line 1822

Quoted 10 lines
drivers/usb/gadget/function/f_fs.c +4 -0
@@ -1813,6 +1813,10 @@ static void ffs_data_reset(struct ffs_data *ffs)
 	ffs->state = FFS_READ_DESCRIPTORS;
 	ffs->setup_state = FFS_NO_SETUP;
 	ffs->flags = 0;
+
+	ffs->ms_os_descs_ext_prop_count = 0;
+	ffs->ms_os_descs_ext_prop_name_len = 0;
+	ffs->ms_os_descs_ext_prop_data_len = 0;
 }
 
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#2 lore raw

Hi,

Quoted 12 lines · Manu Gautam
Quoted 11 lines · Sriharsha Allenki

From: Udipto Goswami <[email protected]>

For userspace functions using OS Descriptors, if a function also supplies Extended Property descriptors currently the counts and lengths stored in the ms_os_descs_ext_prop_{count,name_len,data_len} variables are not getting reset to 0 during an unbind or when the epfiles are closed. If the same function is re-bound and the descriptors are re-written, this results in those count/length variables to monotonically increase causing the VLA allocation in _ffs_func_bind() to grow larger and larger at each bind/unbind cycle and eventually fail to allocate.

Quoted 5 lines
Quoted 4 lines

Fix this by clearing the ms_os_descs_ext_prop count & lengths to 0 in ffs_data_reset().

Change-Id: I3b292fe5386ab54b53df2b9f15f07430dc3df24a

Please remove this.

Thanks Manu, sent v2 after removing it.

Quoted 8 lines
Quoted 8 lines
Fixes f0175ab51993 ("usb: gadget: f_fs: OS descriptors support")
---
 drivers/usb/gadget/function/f_fs.c | 4 ++++
 1 file changed, 4 insertions(+)
Quoted 16 lines
Quoted 5 lines
drivers/usb/gadget/function/f_fs.c +0 -0
index c81023b195c3..10f01f974f67 100644

drivers/usb/gadget/function/f_fs.c static void ffs_data_reset(struct ffs_data *ffs) · line 1822

Quoted 10 lines
drivers/usb/gadget/function/f_fs.c +4 -0
@@ -1813,6 +1813,10 @@ static void ffs_data_reset(struct ffs_data *ffs)
 	ffs->state = FFS_READ_DESCRIPTORS;
 	ffs->setup_state = FFS_NO_SETUP;
 	ffs->flags = 0;
+
+	ffs->ms_os_descs_ext_prop_count = 0;
+	ffs->ms_os_descs_ext_prop_name_len = 0;
+	ffs->ms_os_descs_ext_prop_data_len = 0;
 }
 
 

Thanks,
Sriharsha