introduce a generic PKG_CONFIG_DEPENDS for packages that need to be reconfigured...
[openwrt.git] / package / mac80211 / patches / 510-b43-poison-rx-buffers.patch
1 This patch adds poisoning and sanity checking to the RX DMA buffers.
2 This is used for protection against buggy hardware/firmware that raises
3 RX interrupts without doing an actual DMA transfer.
4
5 This mechanism protects against rare "bad packets" (due to uninitialized skb data)
6 and rare kernel crashes due to uninitialized RX headers.
7
8 The poison is selected to not match on valid frames and to be cheap for checking.
9
10 The poison check mechanism _might_ trigger incorrectly, if we are voluntarily
11 receiving frames with bad PLCP headers. However, this is nonfatal, because the
12 chance of such a match is basically zero and in case it happens it just results
13 in dropping the packet.
14 Bad-PLCP RX defaults to off, and you should leave it off unless you want to listen
15 to the latest news broadcasted by your microwave oven.
16
17 This patch also moves the initialization of the RX-header "length" field in front of
18 the mapping of the DMA buffer. The CPU should not touch the buffer after we mapped it.
19
20 Cc: stable@kernel.org
21 Reported-by: Francesco Gringoli <francesco.gringoli@ing.unibs.it>
22 Signed-off-by: Michael Buesch <mb@bu3sch.de>
23
24 ---
25
26 --- a/drivers/net/wireless/b43/dma.c
27 +++ b/drivers/net/wireless/b43/dma.c
28 @@ -555,11 +555,32 @@ address_error:
29 return 1;
30 }
31
32 +static bool b43_rx_buffer_is_poisoned(struct b43_dmaring *ring, struct sk_buff *skb)
33 +{
34 + unsigned char *f = skb->data + ring->frameoffset;
35 +
36 + return ((f[0] & f[1] & f[2] & f[3] & f[4] & f[5] & f[6] & f[7]) == 0xFF);
37 +}
38 +
39 +static void b43_poison_rx_buffer(struct b43_dmaring *ring, struct sk_buff *skb)
40 +{
41 + struct b43_rxhdr_fw4 *rxhdr;
42 + unsigned char *frame;
43 +
44 + /* This poisons the RX buffer to detect DMA failures. */
45 +
46 + rxhdr = (struct b43_rxhdr_fw4 *)(skb->data);
47 + rxhdr->frame_len = 0;
48 +
49 + B43_WARN_ON(ring->rx_buffersize < ring->frameoffset + sizeof(struct b43_plcp_hdr6) + 2);
50 + frame = skb->data + ring->frameoffset;
51 + memset(frame, 0xFF, sizeof(struct b43_plcp_hdr6) + 2 /* padding */);
52 +}
53 +
54 static int setup_rx_descbuffer(struct b43_dmaring *ring,
55 struct b43_dmadesc_generic *desc,
56 struct b43_dmadesc_meta *meta, gfp_t gfp_flags)
57 {
58 - struct b43_rxhdr_fw4 *rxhdr;
59 dma_addr_t dmaaddr;
60 struct sk_buff *skb;
61
62 @@ -568,6 +589,7 @@ static int setup_rx_descbuffer(struct b4
63 skb = __dev_alloc_skb(ring->rx_buffersize, gfp_flags);
64 if (unlikely(!skb))
65 return -ENOMEM;
66 + b43_poison_rx_buffer(ring, skb);
67 dmaaddr = map_descbuffer(ring, skb->data, ring->rx_buffersize, 0);
68 if (b43_dma_mapping_error(ring, dmaaddr, ring->rx_buffersize, 0)) {
69 /* ugh. try to realloc in zone_dma */
70 @@ -578,6 +600,7 @@ static int setup_rx_descbuffer(struct b4
71 skb = __dev_alloc_skb(ring->rx_buffersize, gfp_flags);
72 if (unlikely(!skb))
73 return -ENOMEM;
74 + b43_poison_rx_buffer(ring, skb);
75 dmaaddr = map_descbuffer(ring, skb->data,
76 ring->rx_buffersize, 0);
77 if (b43_dma_mapping_error(ring, dmaaddr, ring->rx_buffersize, 0)) {
78 @@ -592,9 +615,6 @@ static int setup_rx_descbuffer(struct b4
79 ring->ops->fill_descriptor(ring, desc, dmaaddr,
80 ring->rx_buffersize, 0, 0, 0);
81
82 - rxhdr = (struct b43_rxhdr_fw4 *)(skb->data);
83 - rxhdr->frame_len = 0;
84 -
85 return 0;
86 }
87
88 @@ -1489,6 +1509,15 @@ static void dma_rx(struct b43_dmaring *r
89 goto drop;
90 }
91 }
92 + if (unlikely(b43_rx_buffer_is_poisoned(ring, skb))) {
93 + /* Something went wrong with the DMA.
94 + * The device did not touch the buffer and did not overwrite the poison. */
95 + b43dbg(ring->dev->wl, "DMA RX: Dropping poisoned buffer.\n");
96 + /* recycle the descriptor buffer. */
97 + sync_descbuffer_for_device(ring, meta->dmaaddr,
98 + ring->rx_buffersize);
99 + goto drop;
100 + }
101 if (unlikely(len > ring->rx_buffersize)) {
102 /* The data did not fit into one descriptor buffer
103 * and is split over multiple buffers.
This page took 0.051594 seconds and 5 git commands to generate.