Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1322382 > unrolled thread
| Started by | Dan Carpenter <dan.carpenter@oracle.com> |
|---|---|
| First post | 2016-01-30 15:50 +0100 |
| Last post | 2016-01-31 01:40 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[patch] staging: rtl8712: memory corruption in wpa_set_encryption() Dan Carpenter <dan.carpenter@oracle.com> - 2016-01-30 15:50 +0100
Re: [patch] staging: rtl8712: memory corruption in wpa_set_encryption() Joshua Clayton <stillcompiling@gmail.com> - 2016-01-31 01:40 +0100
| From | Dan Carpenter <dan.carpenter@oracle.com> |
|---|---|
| Date | 2016-01-30 15:50 +0100 |
| Subject | [patch] staging: rtl8712: memory corruption in wpa_set_encryption() |
| Message-ID | <qWF0C-4FU-21@gated-at.bofh.it> |
->KeyMaterial is declared as a 16 byte array, but we only ever allocate
either 5 or 13 bytes of it. The problem is that we memset() all 16
bytes to zero so we're memsetting past the end of the allocated memory.
I fixed this in slightly lazy way, by just allocating 16 bytes. This
works but there is a lot more cleanup you could do to this code if you
wanted. Which is why this code is in staging.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index edfc680..db2e31bc 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -398,12 +398,9 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
wep_key_idx = 0;
if (wep_key_len > 0) {
wep_key_len = wep_key_len <= 5 ? 5 : 13;
- pwep = kmalloc((u32)(wep_key_len +
- FIELD_OFFSET(struct NDIS_802_11_WEP,
- KeyMaterial)), GFP_ATOMIC);
+ pwep = kzalloc(sizeof(*pwep), GFP_ATOMIC);
if (pwep == NULL)
return -ENOMEM;
- memset(pwep, 0, sizeof(struct NDIS_802_11_WEP));
pwep->KeyLength = wep_key_len;
pwep->Length = wep_key_len +
FIELD_OFFSET(struct NDIS_802_11_WEP,
[toc] | [next] | [standalone]
| From | Joshua Clayton <stillcompiling@gmail.com> |
|---|---|
| Date | 2016-01-31 01:40 +0100 |
| Message-ID | <qWOdz-3u8-1@gated-at.bofh.it> |
| In reply to | #1322382 |
On Saturday, January 30, 2016 05:41:10 PM Dan Carpenter wrote:
> ->KeyMaterial is declared as a 16 byte array, but we only ever allocate
> either 5 or 13 bytes of it. The problem is that we memset() all 16
> bytes to zero so we're memsetting past the end of the allocated memory.
>
> I fixed this in slightly lazy way, by just allocating 16 bytes. This
> works but there is a lot more cleanup you could do to this code if you
> wanted. Which is why this code is in staging.
Better in every way than a crazy variable alloc if you ask me.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> index edfc680..db2e31bc 100644
> --- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> +++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
> @@ -398,12 +398,9 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
> wep_key_idx = 0;
> if (wep_key_len > 0) {
> wep_key_len = wep_key_len <= 5 ? 5 : 13;
> - pwep = kmalloc((u32)(wep_key_len +
> - FIELD_OFFSET(struct NDIS_802_11_WEP,
> - KeyMaterial)), GFP_ATOMIC);
> + pwep = kzalloc(sizeof(*pwep), GFP_ATOMIC);
> if (pwep == NULL)
> return -ENOMEM;
> - memset(pwep, 0, sizeof(struct NDIS_802_11_WEP));
Should there be a newline after the "if" statement?
> pwep->KeyLength = wep_key_len;
> pwep->Length = wep_key_len +
> FIELD_OFFSET(struct NDIS_802_11_WEP,
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web