[BUG 220033][PATCH] if_ixgb: Fix a possible sleep-under-mutex bug in ixge_get_buf

Jia-Ju Bai baijiaju1990 at 163.com
Sun Jun 18 09:20:38 UTC 2017


The ixgb driver may sleep under a mutex, and the function call path is:
ixgb_init [acquire the mutex]
  ixgb_init_locked
    ixgb_setup_receive_structures
      ixgb_allocate_receive_structures
        ixgb_get_buf
          bus_dmamap_load(BUS_DMA_WAITOK) --> may sleep

The possible fix of these bugs is to set the last parameter in bus_dmamap_load to "BUS_DMA_NOWAIT".

This bug is found by a static analysis tool written by myself, and it is checked by my review of the FreeBSD code.

Signed-off-by: Jia-Ju Bai <baijiaju1990 at 163.com>
---
 sys/dev/ixgb/if_ixgb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/dev/ixgb/if_ixgb.c b/sys/dev/ixgb/if_ixgb.c
index 430c13c72d1..e6d02dd172e 100644
--- a/sys/dev/ixgb/if_ixgb.c
+++ b/sys/dev/ixgb/if_ixgb.c
@@ -1811,7 +1811,7 @@ ixgb_get_buf(int i, struct adapter * adapter,
 	 */
 	error = bus_dmamap_load(adapter->rxtag, rx_buffer->map,
 				mtod(mp, void *), mp->m_len,
-				ixgb_dmamap_cb, &paddr, 0);
+				ixgb_dmamap_cb, &paddr, BUS_DMA_NOWAIT);
 	if (error) {
 		m_free(mp);
 		return (error);
-- 
2.13.0




More information about the freebsd-net mailing list