wifi: rtw88: fix incorrect error codes in rtw_debugfs_copy_from_user
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/2 wifi: rtw88: fix incorrect error codes in rtw_debugfs_copy_from_user
If there is a failure during copy_from_user, rtw_debugfs_copy_from_user should return negative error code instead of a positive value count.
Fix this bug by returning correct error code. Moreover, the check of buffer against null is removed since it will be handled by copy_from_user.
--- drivers/net/wireless/realtek/rtw88/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw88/debug.c +2 -2
@@ -183,8 +183,8 @@ static int rtw_debugfs_copy_from_user(char tmp[], int size, tmp_len = (count > size -1 ? size -1 : count); -if (!buffer ||copy_from_user (tmp, buffer, tmp_len)) -return count; +if (copy_from_user (tmp, buffer, tmp_len)) +return -EFAULT ; tmp[tmp_len] ='\0' ;
Signature · 1 line
2.40.0
Quoted 11 lines
-----Original Message-----
From: Zhang Shurong <[email protected]>
Sent: Wednesday, April 26, 2023 12:24 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Zhang Shurong <[email protected]>
Subject: [PATCH v2 1/2] wifi: rtw88: fix incorrect error codes inrtw_debugfs_copy_from_user
Quoted 8 lines
If there is a failure during
copy_from_user,rtw_debugfs_copy_from_usershould return negative error code instead of a positive value count.Fix this bug by returning correct error code. Moreover, the check of buffer against null is removed since it will be handled by
copy_from_user.Signed-off-by Zhang Shurong <[email protected]>
Quoted 21 lines
--- drivers/net/wireless/realtek/rtw88/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/wireless/realtek/rtw88/debug.c +2
-3@@ -183,8 +183,8 @@ static int rtw_debugfs_copy_from_user(char tmp[], int size, tmp_len = (count > size -1 ? size -1 : count); -if (!buffer ||copy_from_user (tmp, buffer, tmp_len)) -return count; +if (copy_from_user (tmp, buffer, tmp_len)) +return -EFAULT ; tmp[tmp_len] ='\0' ; --2.40.0
Ping-Ke Shih
maintainerQuoted 22 lines
-----Original Message-----
From: Ping-Ke Shih <[email protected]>
Sent: Wednesday, April 26, 2023 12:29 PM
To: Zhang Shurong <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v2 1/2] wifi: rtw88: fix incorrect error codes inrtw_debugfs_copy_from_userQuoted 12 lines
-----Original Message-----
From: Zhang Shurong <[email protected]>
Sent: Wednesday, April 26, 2023 12:24 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Zhang Shurong <[email protected]>
Subject: [PATCH v2 1/2] wifi: rtw88: fix incorrect error codes inrtw_debugfs_copy_from_userIf there is a failure during
copy_from_user,rtw_debugfs_copy_from_usershould return negative error code instead of a positive value count.
Quoted 7 lines
Quoted 5 lines
Fix this bug by returning correct error code. Moreover, the check of buffer against null is removed since it will be handled by
copy_from_user.Signed-off-by Zhang Shurong <[email protected]>Reviewed-by Ping-Ke Shih <[email protected]>
I would take back this temporarily because of below.
Quoted 13 lines
Quoted 13 lines
--- drivers/net/wireless/realtek/rtw88/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/wireless/realtek/rtw88/debug.c +0
-0@@ -183,8 +183,8 @@ static int rtw_debugfs_copy_from_user(char tmp[], int size, tmp_len = (count > size -1 ? size -1 : count);
Quoted 7 lines
drivers/net/wireless/realtek/rtw88/debug.c static int rtw_debugfs_copy_from_user(char tmp[], int size, · line 190
Quoted 7 lines
drivers/net/wireless/realtek/rtw88/debug.c +2
-2-if (!buffer ||copy_from_user (tmp, buffer, tmp_len)) -return count; +if (copy_from_user (tmp, buffer, tmp_len)) +return -EFAULT ; tmp[tmp_len] ='\0' ;
In the second patch, you check 'ret < 0' instead of 'ret'. That looks like you can possibly return positive value (e.g. count), but actually only return 0 or - EFAULT after this patch. So, I would like change first or second patch to make them intuitive.
return 0 or -EFAULT --> check by if (ret)
return 0 or -EFAULT or count --> check by if (ret < 0)
+ ret = rtw_debugfs_copy_from_user(tmp, sizeof(tmp), buffer, count, 2);
+ if (ret < 0)
+ return ret;
PATCH v2 2/2 wifi: rtw88: fix incorrect error codes in rtw_debugfs_set_*
In reply to a message not in the archiveIf there is a failure during copy_from_user or user-provided data buffer is invalid, rtw_debugfs_set_* should return negative error code instead of a positive value count.
Fix this bug by returning correct error code.
--- drivers/net/wireless/realtek/rtw88/debug.c | 55 ++++++++++++++++------ 1 file changed, 41 insertions(+), 14 deletions(-)
drivers/net/wireless/realtek/rtw88/debug.c +41 -14
@@ -201,13 +201,16 @@ static ssize_t rtw_debugfs_set_read_reg(struct file *filp,char tmp[32 +1 ];u32 addr, len;int num; +int ret; -rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,2 ); + ret =rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,2 ); +if (ret <0 ) +return ret; num =sscanf (tmp,"%x %x" , &addr, &len);if (num !=2 ) -return count; +return -EINVAL ;if (len !=1 && len !=2 && len !=4 ) {rtw_warn (rtwdev,"read reg setting wrong len\n" );
@@ -288,8 +291,11 @@ static ssize_t rtw_debugfs_set_rsvd_page(struct file *filp,char tmp[32 +1 ];u32 offset, page_num;int num; +int ret; -rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,2 ); + ret =rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,2 ); +if (ret <0 ) +return ret; num =sscanf (tmp,"%d %d" , &offset, &page_num);
@@ -314,8 +320,11 @@ static ssize_t rtw_debugfs_set_single_input(struct file *filp,char tmp[32 +1 ];u32 input;int num; +int ret; -rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,1 ); + ret =rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,1 ); +if (ret <0 ) +return ret; num =kstrtoint (tmp,0 , &input);
@@ -338,14 +347,17 @@ static ssize_t rtw_debugfs_set_write_reg(struct file *filp,char tmp[32 +1 ];u32 addr, val, len;int num; +int ret; -rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,3 ); + ret =rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,3 ); +if (ret <0 ) +return ret;/* write BB/MAC register */ num =sscanf (tmp,"%x %x %x" , &addr, &val, &len);if (num !=3 ) -return count; +return -EINVAL ;switch (len) {case 1 :
@@ -381,8 +393,11 @@ static ssize_t rtw_debugfs_set_h2c(struct file *filp,char tmp[32 +1 ];u8 param[8 ];int num; +int ret; -rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,3 ); + ret =rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,3 ); +if (ret <0 ) +return ret; num = sscanf(tmp, "%hhx,%hhx,%hhx,%hhx,%hhx,%hhx,%hhx,%hhx", ¶m[0], ¶m[1], ¶m[2], ¶m[3],
@@ -408,14 +423,17 @@ static ssize_t rtw_debugfs_set_rf_write(struct file *filp,char tmp[32 +1 ];u32 path, addr, mask, val;int num; +int ret; -rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,4 ); + ret =rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,4 ); +if (ret <0 ) +return ret; num =sscanf (tmp,"%x %x %x %x" , &path, &addr, &mask, &val);if (num !=4 ) {rtw_warn (rtwdev,"invalid args, [path] [addr] [mask] [val]\n" ); -return count; +return -EINVAL ; }mutex_lock (&rtwdev->mutex);
@@ -438,14 +456,17 @@ static ssize_t rtw_debugfs_set_rf_read(struct file *filp,char tmp[32 +1 ];u32 path, addr, mask;int num; +int ret; -rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,3 ); + ret =rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,3 ); +if (ret <0 ) +return ret; num =sscanf (tmp,"%x %x %x" , &path, &addr, &mask);if (num !=3 ) {rtw_warn (rtwdev,"invalid args, [path] [addr] [mask] [val]\n" ); -return count; +return -EINVAL ; } debugfs_priv->rf_path = path;
@@ -467,7 +488,9 @@ static ssize_t rtw_debugfs_set_fix_rate(struct file *filp,char tmp[32 +1 ];int ret; -rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,1 ); + ret =rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,1 ); +if (ret <0 ) +return ret; ret =kstrtou8 (tmp,0 , &fix_rate);if (ret) {
@@ -860,7 +883,9 @@ static ssize_t rtw_debugfs_set_coex_enable(struct file *filp,bool enable;int ret; -rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,1 ); + ret =rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,1 ); +if (ret <0 ) +return ret; ret =kstrtobool (tmp, &enable);if (ret) {
@@ -930,7 +955,9 @@ static ssize_t rtw_debugfs_set_fw_crash(struct file *filp,bool input;int ret; -rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,1 ); + ret =rtw_debugfs_copy_from_user (tmp,sizeof (tmp), buffer, count,1 ); +if (ret <0 ) +return ret; ret =kstrtobool (tmp, &input);if (ret)
Signature · 1 line
2.40.0