Skip to content

Commit baa8caf

Browse files
sivarebbagondlaKalle Valo
authored and
Kalle Valo
committed
rsi: fix memory alignment issue in ARM32 platforms
During testing in ARM32 platforms, observed below kernel panic, as driver accessing data beyond the allocated memory while submitting URB to USB. Fix: Resolved this by specifying correct length by considering 64 bit alignment. so that, USB bus driver will access only allocated memory. Unit-test: Tested and confirm that driver bring up and scanning, connection and data transfer works fine with this fix. ...skipping... [ 25.389450] Unable to handle kernel paging request at virtual address 5aa11422 [ 25.403078] Internal error: Oops: 5 [#1] SMP ARM [ 25.407703] Modules linked in: rsi_usb [ 25.411473] CPU: 1 PID: 317 Comm: RX-Thread Not tainted 4.18.0-rc7 #1 [ 25.419221] Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree) [ 25.425764] PC is at skb_release_data+0x90/0x168 [ 25.430393] LR is at skb_release_all+0x28/0x2c [ 25.434842] pc : [<807435b0>] lr : [<80742ba0>] psr: 200e0013 5aa1141e [ 25.464633] Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none [ 25.477524] Process RX-Thread (pid: 317, stack limit = 0x(ptrval)) [ 25.483709] Stack: (0xedf69ed8 to 0xedf6a000) [ 25.569907] Backtrace: [ 25.572368] [<80743520>] (skb_release_data) from [<80742ba0>] (skb_release_all+0x28/0x2c) [ 25.580555] r9:7f00258c r8:00000001 r7:ee355000 r6:eddab0d0 r5:eddab000 r4:eddbb840 [ 25.588308] [<80742b78>] (skb_release_all) from [<807432cc>] (consume_skb+0x30/0x50) [ 25.596055] r5:eddab000 r4:eddbb840 [ 25.599648] [<8074329c>] (consume_skb) from [<7f00117c>] (rsi_usb_rx_thread+0x64/0x12c [rsi_usb]) [ 25.608524] r5:eddab000 r4:eddbb840 [ 25.612116] [<7f001118>] (rsi_usb_rx_thread [rsi_usb]) from [<80142750>] (kthread+0x11c/0x15c) [ 25.620735] r10:ee9ff9e0 r9:edcde3b8 r8:ee355000 r7:edf68000 r6:edd3a780 r5:00000000 [ 25.628567] r4:edcde380 [ 25.631110] [<80142634>] (kthread) from [<801010e8>] (ret_from_fork+0x14/0x2c) [ 25.638336] Exception stack(0xedf69fb0 to 0xedf69ff8) [ 25.682929] ---[ end trace 8236a5496f5b5d3b ]--- Signed-off-by: Siva Rebbagondla <[email protected]> Signed-off-by: Kalle Valo <[email protected]>
1 parent cb18e2e commit baa8caf

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

drivers/net/wireless/rsi/rsi_91x_usb.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,17 @@ static void rsi_rx_done_handler(struct urb *urb)
266266
if (urb->status)
267267
goto out;
268268

269-
if (urb->actual_length <= 0) {
270-
rsi_dbg(INFO_ZONE, "%s: Zero length packet\n", __func__);
269+
if (urb->actual_length <= 0 ||
270+
urb->actual_length > rx_cb->rx_skb->len) {
271+
rsi_dbg(INFO_ZONE, "%s: Invalid packet length = %d\n",
272+
__func__, urb->actual_length);
271273
goto out;
272274
}
273275
if (skb_queue_len(&dev->rx_q) >= RSI_MAX_RX_PKTS) {
274276
rsi_dbg(INFO_ZONE, "Max RX packets reached\n");
275277
goto out;
276278
}
277-
skb_put(rx_cb->rx_skb, urb->actual_length);
279+
skb_trim(rx_cb->rx_skb, urb->actual_length);
278280
skb_queue_tail(&dev->rx_q, rx_cb->rx_skb);
279281

280282
rsi_set_event(&dev->rx_thread.event);
@@ -308,6 +310,7 @@ static int rsi_rx_urb_submit(struct rsi_hw *adapter, u8 ep_num)
308310
if (!skb)
309311
return -ENOMEM;
310312
skb_reserve(skb, MAX_DWORD_ALIGN_BYTES);
313+
skb_put(skb, RSI_MAX_RX_USB_PKT_SIZE - MAX_DWORD_ALIGN_BYTES);
311314
dword_align_bytes = (unsigned long)skb->data & 0x3f;
312315
if (dword_align_bytes > 0)
313316
skb_push(skb, dword_align_bytes);
@@ -319,7 +322,7 @@ static int rsi_rx_urb_submit(struct rsi_hw *adapter, u8 ep_num)
319322
usb_rcvbulkpipe(dev->usbdev,
320323
dev->bulkin_endpoint_addr[ep_num - 1]),
321324
urb->transfer_buffer,
322-
RSI_MAX_RX_USB_PKT_SIZE,
325+
skb->len,
323326
rsi_rx_done_handler,
324327
rx_cb);
325328

0 commit comments

Comments
 (0)