775-bgmac-check-length-of-received-frame.patch 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. From 2d12a9abf3f81de5b51852e3cfcba8cedac82642 Mon Sep 17 00:00:00 2001
  2. From: Hauke Mehrtens <hauke@hauke-m.de>
  3. Date: Fri, 6 Dec 2013 01:14:52 +0100
  4. Subject: [PATCH] bgmac: check length of received frame
  5. ---
  6. drivers/net/ethernet/broadcom/bgmac.c | 9 ++++++++-
  7. 1 file changed, 8 insertions(+), 1 deletion(-)
  8. --- a/drivers/net/ethernet/broadcom/bgmac.c
  9. +++ b/drivers/net/ethernet/broadcom/bgmac.c
  10. @@ -363,6 +363,27 @@ static int bgmac_dma_rx_read(struct bgma
  11. dma_addr_t old_dma_addr = slot->dma_addr;
  12. int err;
  13. + if (len > BGMAC_RX_MAX_FRAME_SIZE) {
  14. + struct bgmac_dma_desc *dma_desc = ring->cpu_base + ring->start;
  15. +
  16. + bgmac_err(bgmac, "Hardware reported invalid packet length %d for slot %d!\n", len, ring->start);
  17. + bgmac_err(bgmac, "flags: 0x%04X\n", flags);
  18. + bgmac_err(bgmac, "ctl0: 0x%08X\tctl1: 0x%08X\n", le32_to_cpu(dma_desc->ctl0), le32_to_cpu(dma_desc->ctl1));
  19. +
  20. + bgmac_err(bgmac, " BGMAC_DMA_RX_CTL: 0x%08X\n", bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_RX_CTL));
  21. + bgmac_err(bgmac, " BGMAC_DMA_RX_INDEX: 0x%08X\n", bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_RX_INDEX));
  22. + bgmac_err(bgmac, "BGMAC_DMA_RX_RINGLO: 0x%08X\n", bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_RX_RINGLO));
  23. + bgmac_err(bgmac, "BGMAC_DMA_RX_RINGHI: 0x%08X\n", bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_RX_RINGHI));
  24. + bgmac_err(bgmac, "BGMAC_DMA_RX_STATUS: 0x%08X\n", bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_RX_STATUS));
  25. + bgmac_err(bgmac, " BGMAC_DMA_RX_ERROR: 0x%08X\n", bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_RX_ERROR));
  26. +
  27. + dma_sync_single_for_device(dma_dev,
  28. + slot->dma_addr,
  29. + BGMAC_RX_BUF_SIZE,
  30. + DMA_FROM_DEVICE);
  31. + break;
  32. + }
  33. +
  34. /* Check for poison and drop or pass the packet */
  35. if (len == 0xdead && flags == 0xbeef) {
  36. bgmac_err(bgmac, "Found poisoned packet at slot %d, DMA issue!\n",