Skip to content

Commit

Permalink
wusb: replace memset by memzero_explicit
Browse files Browse the repository at this point in the history
Memset on a local variable may be removed when it is called just before the
variable goes out of scope.  Using memzero_explicit defeats this
optimization.  A simplified version of the semantic patch that makes this
change is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
identifier x;
type T;
@@

{
... when any
T x[...];
... when any
    when exists
- memset
+ memzero_explicit
  (x,
-0,
  ...)
... when != x
    when strict
}
// </smpl>

This change was suggested by Daniel Borkmann <dborkman@redhat.com>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Julia Lawall authored and Greg Kroah-Hartman committed Dec 3, 2014
1 parent b19e5f0 commit eb94ec7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion drivers/usb/wusbcore/dev-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static ssize_t wusb_ck_store(struct device *dev,
if (wusbhc == NULL)
return -ENODEV;
result = wusb_dev_4way_handshake(wusbhc, usb_dev->wusb_dev, &ck);
memset(&ck, 0, sizeof(ck));
memzero_explicit(&ck, sizeof(ck));
wusbhc_put(wusbhc);
return result < 0 ? result : size;
}
Expand Down
8 changes: 4 additions & 4 deletions drivers/usb/wusbcore/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,10 @@ int wusb_dev_4way_handshake(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev,
error_hs2:
error_hs1:
memset(hs, 0, 3*sizeof(hs[0]));
memset(&keydvt_out, 0, sizeof(keydvt_out));
memset(&keydvt_in, 0, sizeof(keydvt_in));
memset(&ccm_n, 0, sizeof(ccm_n));
memset(mic, 0, sizeof(mic));
memzero_explicit(&keydvt_out, sizeof(keydvt_out));
memzero_explicit(&keydvt_in, sizeof(keydvt_in));
memzero_explicit(&ccm_n, sizeof(ccm_n));
memzero_explicit(mic, sizeof(mic));
if (result < 0)
wusb_dev_set_encryption(usb_dev, 0);
error_dev_set_encryption:
Expand Down

0 comments on commit eb94ec7

Please sign in to comment.