Skip to content

Commit be783ab

Browse files
CIQ Kernel Automationroxanan1996
authored andcommitted
atl1c: Work around the DMA RX overflow issue
jira VULN-36010 cve CVE-2023-52834 commit-author Sieng-Piaw Liew <liew.s.piaw@gmail.com> commit 8656568 This is based on alx driver commit 881d032 ("net: alx: Work around the DMA RX overflow issue"). The alx and atl1c drivers had RX overflow error which was why a custom allocator was created to avoid certain addresses. The simpler workaround then created for alx driver, but not for atl1c due to lack of tester. Instead of using a custom allocator, check the allocated skb address and use skb_reserve() to move away from problematic 0x...fc0 address. Tested on AR8131 on Acer 4540. Signed-off-by: Sieng-Piaw Liew <liew.s.piaw@gmail.com> Link: https://lore.kernel.org/r/20230912010711.12036-1-liew.s.piaw@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com> (cherry picked from commit 8656568) Signed-off-by: CIQ Kernel Automation <ciq_kernel_automation@ciq.com>
1 parent 399a257 commit be783ab

2 files changed

Lines changed: 16 additions & 54 deletions

File tree

drivers/net/ethernet/atheros/atl1c/atl1c.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,12 @@ struct atl1c_rrd_ring {
504504
u16 next_to_use;
505505
u16 next_to_clean;
506506
struct napi_struct napi;
507-
struct page *rx_page;
508-
unsigned int rx_page_offset;
509507
};
510508

511509
/* board specific private data structure */
512510
struct atl1c_adapter {
513511
struct net_device *netdev;
514512
struct pci_dev *pdev;
515-
unsigned int rx_frag_size;
516513
struct atl1c_hw hw;
517514
struct atl1c_hw_stats hw_stats;
518515
struct mii_if_info mii; /* MII interface info */

drivers/net/ethernet/atheros/atl1c/atl1c_main.c

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -493,15 +493,10 @@ static int atl1c_set_mac_addr(struct net_device *netdev, void *p)
493493
static void atl1c_set_rxbufsize(struct atl1c_adapter *adapter,
494494
struct net_device *dev)
495495
{
496-
unsigned int head_size;
497496
int mtu = dev->mtu;
498497

499498
adapter->rx_buffer_len = mtu > AT_RX_BUF_SIZE ?
500499
roundup(mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN, 8) : AT_RX_BUF_SIZE;
501-
502-
head_size = SKB_DATA_ALIGN(adapter->rx_buffer_len + NET_SKB_PAD + NET_IP_ALIGN) +
503-
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
504-
adapter->rx_frag_size = roundup_pow_of_two(head_size);
505500
}
506501

507502
static netdev_features_t atl1c_fix_features(struct net_device *netdev,
@@ -974,7 +969,6 @@ static void atl1c_init_ring_ptrs(struct atl1c_adapter *adapter)
974969
static void atl1c_free_ring_resources(struct atl1c_adapter *adapter)
975970
{
976971
struct pci_dev *pdev = adapter->pdev;
977-
int i;
978972

979973
dma_free_coherent(&pdev->dev, adapter->ring_header.size,
980974
adapter->ring_header.desc, adapter->ring_header.dma);
@@ -987,12 +981,6 @@ static void atl1c_free_ring_resources(struct atl1c_adapter *adapter)
987981
kfree(adapter->tpd_ring[0].buffer_info);
988982
adapter->tpd_ring[0].buffer_info = NULL;
989983
}
990-
for (i = 0; i < adapter->rx_queue_count; ++i) {
991-
if (adapter->rrd_ring[i].rx_page) {
992-
put_page(adapter->rrd_ring[i].rx_page);
993-
adapter->rrd_ring[i].rx_page = NULL;
994-
}
995-
}
996984
}
997985

998986
/**
@@ -1764,48 +1752,11 @@ static inline void atl1c_rx_checksum(struct atl1c_adapter *adapter,
17641752
skb_checksum_none_assert(skb);
17651753
}
17661754

1767-
static struct sk_buff *atl1c_alloc_skb(struct atl1c_adapter *adapter,
1768-
u32 queue, bool napi_mode)
1769-
{
1770-
struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring[queue];
1771-
struct sk_buff *skb;
1772-
struct page *page;
1773-
1774-
if (adapter->rx_frag_size > PAGE_SIZE) {
1775-
if (likely(napi_mode))
1776-
return napi_alloc_skb(&rrd_ring->napi,
1777-
adapter->rx_buffer_len);
1778-
else
1779-
return netdev_alloc_skb_ip_align(adapter->netdev,
1780-
adapter->rx_buffer_len);
1781-
}
1782-
1783-
page = rrd_ring->rx_page;
1784-
if (!page) {
1785-
page = alloc_page(GFP_ATOMIC);
1786-
if (unlikely(!page))
1787-
return NULL;
1788-
rrd_ring->rx_page = page;
1789-
rrd_ring->rx_page_offset = 0;
1790-
}
1791-
1792-
skb = build_skb(page_address(page) + rrd_ring->rx_page_offset,
1793-
adapter->rx_frag_size);
1794-
if (likely(skb)) {
1795-
skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN);
1796-
rrd_ring->rx_page_offset += adapter->rx_frag_size;
1797-
if (rrd_ring->rx_page_offset >= PAGE_SIZE)
1798-
rrd_ring->rx_page = NULL;
1799-
else
1800-
get_page(page);
1801-
}
1802-
return skb;
1803-
}
1804-
18051755
static int atl1c_alloc_rx_buffer(struct atl1c_adapter *adapter, u32 queue,
18061756
bool napi_mode)
18071757
{
18081758
struct atl1c_rfd_ring *rfd_ring = &adapter->rfd_ring[queue];
1759+
struct atl1c_rrd_ring *rrd_ring = &adapter->rrd_ring[queue];
18091760
struct pci_dev *pdev = adapter->pdev;
18101761
struct atl1c_buffer *buffer_info, *next_info;
18111762
struct sk_buff *skb;
@@ -1824,13 +1775,27 @@ static int atl1c_alloc_rx_buffer(struct atl1c_adapter *adapter, u32 queue,
18241775
while (next_info->flags & ATL1C_BUFFER_FREE) {
18251776
rfd_desc = ATL1C_RFD_DESC(rfd_ring, rfd_next_to_use);
18261777

1827-
skb = atl1c_alloc_skb(adapter, queue, napi_mode);
1778+
/* When DMA RX address is set to something like
1779+
* 0x....fc0, it will be very likely to cause DMA
1780+
* RFD overflow issue.
1781+
*
1782+
* To work around it, we apply rx skb with 64 bytes
1783+
* longer space, and offset the address whenever
1784+
* 0x....fc0 is detected.
1785+
*/
1786+
if (likely(napi_mode))
1787+
skb = napi_alloc_skb(&rrd_ring->napi, adapter->rx_buffer_len + 64);
1788+
else
1789+
skb = netdev_alloc_skb(adapter->netdev, adapter->rx_buffer_len + 64);
18281790
if (unlikely(!skb)) {
18291791
if (netif_msg_rx_err(adapter))
18301792
dev_warn(&pdev->dev, "alloc rx buffer failed\n");
18311793
break;
18321794
}
18331795

1796+
if (((unsigned long)skb->data & 0xfff) == 0xfc0)
1797+
skb_reserve(skb, 64);
1798+
18341799
/*
18351800
* Make buffer alignment 2 beyond a 16 byte boundary
18361801
* this will result in a 16 byte aligned IP header after

0 commit comments

Comments
 (0)