]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
staging: rtl: fix possible NULL pointer dereference
authorArnd Bergmann <arnd@arndb.de>
Wed, 11 Jan 2017 14:53:08 +0000 (15:53 +0100)
committerJiri Slaby <jslaby@suse.cz>
Mon, 13 Mar 2017 20:40:23 +0000 (21:40 +0100)
commit 6e017006022abfea5d2466cad936065f45763ad1 upstream.

gcc-7 detects that wlanhdr_to_ethhdr() in two drivers calls memcpy() with
a destination argument that an earlier function call may have set to NULL:

staging/rtl8188eu/core/rtw_recv.c: In function 'wlanhdr_to_ethhdr':
staging/rtl8188eu/core/rtw_recv.c:1318:2: warning: argument 1 null where non-null expected [-Wnonnull]
staging/rtl8712/rtl871x_recv.c: In function 'r8712_wlanhdr_to_ethhdr':
staging/rtl8712/rtl871x_recv.c:649:2: warning: argument 1 null where non-null expected [-Wnonnull]

I'm fixing this by adding a NULL pointer check and returning failure
from the function, which is hopefully already handled properly.

This seems to date back to when the drivers were originally added,
so backporting the fix to stable seems appropriate. There are other
related realtek drivers in the kernel, but none of them contain a
function with a similar name or produce this warning.

Fixes: 1cc18a22b96b ("staging: r8188eu: Add files for new driver - part 5")
Fixes: 2865d42c78a9 ("staging: r8712u: Add the new driver to the mainline kernel")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
drivers/staging/rtl8188eu/core/rtw_recv.c
drivers/staging/rtl8712/rtl871x_recv.c

index 33243ed40a1e98d704fd545c4c8fac809c2ea046..36834165705d40837297ff068287d3e9184fde21 100644 (file)
@@ -1502,6 +1502,9 @@ _func_enter_;
                ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0)));
        }
 
+       if (!ptr)
+               return _FAIL;
+
        memcpy(ptr, pattrib->dst, ETH_ALEN);
        memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
 
index 274c359279ef387dd730b1277f1e0ec6bf522459..820d3dd50de14265222d8f9272ea7dd10b7757b0 100644 (file)
@@ -641,11 +641,16 @@ sint r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe)
                /* append rx status for mp test packets */
                ptr = recvframe_pull(precvframe, (rmv_len -
                      sizeof(struct ethhdr) + 2) - 24);
+               if (!ptr)
+                       return _FAIL;
                memcpy(ptr, get_rxmem(precvframe), 24);
                ptr += 24;
-       } else
+       } else {
                ptr = recvframe_pull(precvframe, (rmv_len -
                      sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0)));
+               if (!ptr)
+                       return _FAIL;
+       }
 
        memcpy(ptr, pattrib->dst, ETH_ALEN);
        memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);