Skip to contentSkip to conversation

staging: rtl8723bs: make memcmp() calls consistent

PATCH In review Nicolas Iooss 4 participants 6 messages Dec 10, 2017 – Dec 13, 2017 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8723bs: make memcmp() calls consistent

rtw_pm_set() uses memcmp() with 5-chars strings and a length of 4 when parsing extra, and then parses extra+4 as an int:

    if (!memcmp(extra, "lps =", 4)) {
        sscanf(extra+4, "%u", &mode);
    /* ... */
    } else if (!memcmp(extra, "ips =", 4)) {
        sscanf(extra+4, "%u", &mode);

The space between the key ("lps" and "ips") and the equal sign seems suspicious. Remove it in order to make the calls to memcmp() consistent.

---
 drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c +2 -2
index 3fca0c2d4c8d..ffcfefefc898 100644
@@ -4561,10 +4561,10 @@ static int rtw_pm_set(struct net_device *dev,
 
 	DBG_871X("[%s] extra = %s\n", __func__, extra);
 
-	if (!memcmp(extra, "lps =", 4)) {
+	if (!memcmp(extra, "lps=", 4)) {
 		sscanf(extra+4, "%u", &mode);
 		ret = rtw_pm_set_lps(padapter, mode);
-	} else if (!memcmp(extra, "ips =", 4)) {
+	} else if (!memcmp(extra, "ips=", 4)) {
 		sscanf(extra+4, "%u", &mode);
 		ret = rtw_pm_set_ips(padapter, mode);
 	} else {
Signature · 1 line
2.15.0
#1 lore raw
Quoted 11 lines · Nicolas Iooss

rtw_pm_set() uses memcmp() with 5-chars strings and a length of 4 when parsing extra, and then parses extra+4 as an int:

    if (!memcmp(extra, "lps =", 4)) {
        sscanf(extra+4, "%u", &mode);
    /* ... */
    } else if (!memcmp(extra, "ips =", 4)) {
        sscanf(extra+4, "%u", &mode);

The space between the key ("lps" and "ips") and the equal sign seems suspicious. Remove it in order to make the calls to memcmp() consistent.

But you now just changing the parsing logic. What broke because of this? Did you test this codepath with your patch?

I'm not disagreeing that this code seems really odd, but it must be working as-is for someone, to change this logic will break their system :(

thanks,

greg k-h

#2 lore raw

Hi,

Quoted 13 lines · Greg Kroah-Hartman
Quoted 11 lines · Nicolas Iooss

rtw_pm_set() uses memcmp() with 5-chars strings and a length of 4 when parsing extra, and then parses extra+4 as an int:

     if (!memcmp(extra, "lps =", 4)) {
         sscanf(extra+4, "%u", &mode);
     /* ... */
     } else if (!memcmp(extra, "ips =", 4)) {
         sscanf(extra+4, "%u", &mode);

The space between the key ("lps" and "ips") and the equal sign seems suspicious. Remove it in order to make the calls to memcmp() consistent.

Quoted 6 lines

But you now just changing the parsing logic. What broke because of this? Did you test this codepath with your patch?

I'm not disagreeing that this code seems really odd, but it must be working as-is for someone, to change this logic will break their system :(

I don't think this code can work actually, for the memcmp to match the extra argument must start with e.g. : "lps =" but then mode gets read as: sscanf(extra+4, "%u", &mode);, with extra + 4 pointing at the "=" in the extra arg, so sscanf will stop right away and store 0 in mode.

The rtw_pm_set function is only used in the rtw_private_handler[] function pointer array, which itself is used here:

struct iw_handler_def rtw_handlers_def = {
.standard = rtw_handlers,
.num_standard = ARRAY_SIZE(rtw_handlers),
#if defined(CONFIG_WEXT_PRIV)
.private = rtw_private_handler,
.private_args = (struct iw_priv_args *)rtw_private_args, .num_private = ARRAY_SIZE(rtw_private_handler), .num_private_args = ARRAY_SIZE(rtw_private_args),
#endif
.get_wireless_stats = rtw_get_wireless_stats,
};

So this is for a private extension to the iw interface. I think that as part of the cleanup of this driver in staging we should just remove all private extensions, which will nicely fix the broken function by simply removing it :)

Regards,

Hans

#3 lore raw
Quoted 19 lines · Hans de Goede

Hi,

Quoted 16 lines · Greg Kroah-Hartman
Quoted 11 lines · Nicolas Iooss

rtw_pm_set() uses memcmp() with 5-chars strings and a length of 4 when parsing extra, and then parses extra+4 as an int:

     if (!memcmp(extra, "lps =", 4)) {
         sscanf(extra+4, "%u", &mode);
     /* ... */
     } else if (!memcmp(extra, "ips =", 4)) {
         sscanf(extra+4, "%u", &mode);

The space between the key ("lps" and "ips") and the equal sign seems suspicious. Remove it in order to make the calls to memcmp() consistent.

But you now just changing the parsing logic. What broke because of this? Did you test this codepath with your patch?

Quoted 6 lines
Quoted 3 lines

I'm not disagreeing that this code seems really odd, but it must be working as-is for someone, to change this logic will break their system :(

I don't think this code can work actually, for the memcmp to match the extra argument must start with e.g. : "lps ="

No, the extra argument just has to start with "lps ", so something like "lps 1234" would "work". The memcmp call could just as well use "lps ".

but then mode

Quoted 3 lines

gets read as: sscanf(extra+4, "%u", &mode);, with extra + 4 pointing at the "=" in the extra arg, so sscanf will stop right away and store 0 in mode.

See above, we don't know there's a "=" at extra+4. But in any case, I don't think sscanf stores anything if there are no digits (and then it would return 0 since no specifiers matched - the code also lacks a check of the sscanf return value). But mode is initialized, so it's not going to use some stack garbage.

All in all, some cleanup seems warranted. Why not just do a sscanf("lps %u", ...) call and properly check the return value of that? With whatever prefix string one thinks would be most appropriate.

Quoted 4 lines

So this is for a private extension to the iw interface. I think that as part of the cleanup of this driver in staging we should just remove all private extensions, which will nicely fix the broken function by simply removing it :)

Yeah, that would also work...

Rasmus

#4 lore raw

Hi,

Quoted 24 lines · Rasmus Villemoes
Quoted 23 lines · Hans de Goede

Hi,

Quoted 19 lines · Greg Kroah-Hartman
Quoted 11 lines · Nicolas Iooss

rtw_pm_set() uses memcmp() with 5-chars strings and a length of 4 when parsing extra, and then parses extra+4 as an int:

      if (!memcmp(extra, "lps =", 4)) {
          sscanf(extra+4, "%u", &mode);
      /* ... */
      } else if (!memcmp(extra, "ips =", 4)) {
          sscanf(extra+4, "%u", &mode);

The space between the key ("lps" and "ips") and the equal sign seems suspicious. Remove it in order to make the calls to memcmp() consistent.

But you now just changing the parsing logic. What broke because of this? Did you test this codepath with your patch?

I'm not disagreeing that this code seems really odd, but it must be working as-is for someone, to change this logic will break their system :(

Quoted 5 lines
Quoted 2 lines

I don't think this code can work actually, for the memcmp to match the extra argument must start with e.g. : "lps ="

No, the extra argument just has to start with "lps ", so something like "lps 1234" would "work". The memcmp call could just as well use "lps ".

Ah yes, you're right, it only compares the first 4 chars.

Quoted 15 lines

but then mode

Quoted 3 lines

gets read as: sscanf(extra+4, "%u", &mode);, with extra + 4 pointing at the "=" in the extra arg, so sscanf will stop right away and store 0 in mode.

See above, we don't know there's a "=" at extra+4. But in any case, I don't think sscanf stores anything if there are no digits (and then it would return 0 since no specifiers matched - the code also lacks a check of the sscanf return value). But mode is initialized, so it's not going to use some stack garbage.

All in all, some cleanup seems warranted. Why not just do a sscanf("lps %u", ...) call and properly check the return value of that? With whatever prefix string one thinks would be most appropriate.

Quoted 6 lines
Quoted 4 lines

So this is for a private extension to the iw interface. I think that as part of the cleanup of this driver in staging we should just remove all private extensions, which will nicely fix the broken function by simply removing it :)

Yeah, that would also work...

Either one is fine with me.

Regards,

Hans

#5 lore raw
In reply to Hans de Goede
Quoted 44 lines · Hans de Goede

Hi,

Quoted 13 lines · Greg Kroah-Hartman
Quoted 11 lines · Nicolas Iooss

rtw_pm_set() uses memcmp() with 5-chars strings and a length of 4 when parsing extra, and then parses extra+4 as an int:

     if (!memcmp(extra, "lps =", 4)) {
         sscanf(extra+4, "%u", &mode);
     /* ... */
     } else if (!memcmp(extra, "ips =", 4)) {
         sscanf(extra+4, "%u", &mode);

The space between the key ("lps" and "ips") and the equal sign seems suspicious. Remove it in order to make the calls to memcmp() consistent.

Quoted 6 lines

But you now just changing the parsing logic. What broke because of this? Did you test this codepath with your patch?

I'm not disagreeing that this code seems really odd, but it must be working as-is for someone, to change this logic will break their system :(

I don't think this code can work actually, for the memcmp to match the extra argument must start with e.g. : "lps =" but then mode gets read as: sscanf(extra+4, "%u", &mode);, with extra + 4 pointing at the "=" in the extra arg, so sscanf will stop right away and store 0 in mode.

The rtw_pm_set function is only used in the rtw_private_handler[] function pointer array, which itself is used here:

struct iw_handler_def rtw_handlers_def = {
.standard = rtw_handlers,
.num_standard = ARRAY_SIZE(rtw_handlers),
#if defined(CONFIG_WEXT_PRIV)
.private = rtw_private_handler,
.private_args = (struct iw_priv_args *)rtw_private_args, .num_private = ARRAY_SIZE(rtw_private_handler), .num_private_args = ARRAY_SIZE(rtw_private_args),
#endif
.get_wireless_stats = rtw_get_wireless_stats,
};

Quoted 4 lines

So this is for a private extension to the iw interface. I think that as part of the cleanup of this driver in staging we should just remove all private extensions, which will nicely fix the broken function by simply removing it :)

Yes, any private extensions should just be deleted.

thanks,

greg k-h