2014-12-22 17:38:15

by Larry Finger

[permalink] [raw]
Subject: [PATCH for 3.19] rtlwifi: Fix error when accessing unmapped memory in skb

Under heavy memory pressure, it is possible for the allocation of a
new skb to fail. When this happens, the kernel gets a memory access
violation. Previous versions of the drivers would drop the read request;
however, this logic was missed in the 3.18 update. This patch restores
the previous behavior.

Reported-by: Eric Biggers <[email protected]>
Signed-off-by: Larry Finger <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: Stable <[email protected]> [3.18]
---
drivers/net/wireless/rtlwifi/pci.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c
index 846a2e6..55334ca 100644
--- a/drivers/net/wireless/rtlwifi/pci.c
+++ b/drivers/net/wireless/rtlwifi/pci.c
@@ -912,13 +912,15 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
}
end:
if (rtlpriv->use_new_trx_flow) {
- _rtl_pci_init_one_rxdesc(hw, (u8 *)buffer_desc,
- rxring_idx,
- rtlpci->rx_ring[rxring_idx].idx);
+ if (!_rtl_pci_init_one_rxdesc(hw, (u8 *)buffer_desc,
+ rxring_idx,
+ rtlpci->rx_ring[rxring_idx].idx))
+ return;
} else {
- _rtl_pci_init_one_rxdesc(hw, (u8 *)pdesc, rxring_idx,
- rtlpci->rx_ring[rxring_idx].idx);
-
+ if (!_rtl_pci_init_one_rxdesc(hw, (u8 *)pdesc,
+ rxring_idx,
+ rtlpci->rx_ring[rxring_idx].idx))
+ return;
if (rtlpci->rx_ring[rxring_idx].idx ==
rtlpci->rxringcount - 1)
rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc,
--
2.1.2



2014-12-22 22:41:25

by Larry Finger

[permalink] [raw]
Subject: Re: [PATCH for 3.19] rtlwifi: Fix error when accessing unmapped memory in skb

On 12/22/2014 01:48 PM, Eric Biggers wrote:
> Is this really the same behavior as 3.17? In 3.17, allocating the new skb is
> one of the first things the interrupt handler does, and if that fails it drops
> the packet and keeps using the old skb. In this proposal, it's only after the
> packet has been received and the old skb has been freed that a new one is
> allocated. And if that fails --- well, what are you expecting to happen
> exactly?

You are correct. In trying to get a small patch for stable, I missed some
important points.

Please look at the attached patch. I think it handles the skb allocations
correctly. The critical point is that _rtl_pci_init_one_rxdesc() cannot be
allowed to fail to allocate an skb while in the interrupt path. Now, I have
already allocated the skb before the call and bypassed this routine if the
allocation fails. After a couple of crashes, this one now works for the case
when the allocation wouldn't fail anyway. I will likely pull the allocation out
of _rtl_pci_init_one_rxdesc() in all cases for the final patch.

@Kalle: Please drop the patch I submitted this morning with this subject. It
would not help the problem. I will resubmit after I am sure of the proper fix.

Thanks,

Larry



Attachments:
fix_skb_alloc_v2 (3.14 kB)

2014-12-22 23:33:08

by Eric Biggers

[permalink] [raw]
Subject: Re: [PATCH for 3.19] rtlwifi: Fix error when accessing unmapped memory in skb

On Mon, Dec 22, 2014 at 04:41:22PM -0600, Larry Finger wrote:
> Please look at the attached patch. I think it handles the skb allocations
> correctly. The critical point is that _rtl_pci_init_one_rxdesc() cannot be
> allowed to fail to allocate an skb while in the interrupt path. Now, I have
> already allocated the skb before the call and bypassed this routine if the
> allocation fails. After a couple of crashes, this one now works for the case
> when the allocation wouldn't fail anyway. I will likely pull the allocation
> out of _rtl_pci_init_one_rxdesc() in all cases for the final patch.

Well, it's looking better. But what seems strange to me is that
_rtl_pci_init_one_rxdesc() will map the skb for DMA, even though in the error
path it was never unmapped from the previous use. The 3.17 version will neither
unmap nor map the skb in the error path.

I also suspect that trying to share _rtl_pci_init_one_rxdesc() between the
driver initialization and the interrupt handler is just confusing matters.
Perhaps only the ->set_desc() calls should be shared?

In any case, I assume it would be a good idea to, for testing, inject some
random skb allocation failures and make sure the driver still works smoothly
except for some dropped packets.

2014-12-23 06:37:39

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH for 3.19] rtlwifi: Fix error when accessing unmapped memory in skb

Larry Finger <[email protected]> writes:

> You are correct. In trying to get a small patch for stable, I missed
> some important points.
>
> Please look at the attached patch. I think it handles the skb
> allocations correctly. The critical point is that
> _rtl_pci_init_one_rxdesc() cannot be allowed to fail to allocate an
> skb while in the interrupt path. Now, I have already allocated the skb
> before the call and bypassed this routine if the allocation fails.
> After a couple of crashes, this one now works for the case when the
> allocation wouldn't fail anyway. I will likely pull the allocation out
> of _rtl_pci_init_one_rxdesc() in all cases for the final patch.
>
> @Kalle: Please drop the patch I submitted this morning with this
> subject. It would not help the problem. I will resubmit after I am
> sure of the proper fix.

Ack. I'll wait for v2.

--
Kalle Valo

2014-12-22 19:48:45

by Eric Biggers

[permalink] [raw]
Subject: Re: [PATCH for 3.19] rtlwifi: Fix error when accessing unmapped memory in skb

Is this really the same behavior as 3.17? In 3.17, allocating the new skb is
one of the first things the interrupt handler does, and if that fails it drops
the packet and keeps using the old skb. In this proposal, it's only after the
packet has been received and the old skb has been freed that a new one is
allocated. And if that fails --- well, what are you expecting to happen
exactly?