Advertisement
Guest User

r8152: Trying to fix NULL pointer dereference in r8152_poll

a guest
Mar 13th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.68 KB | None | 0 0
  1. From e71a776c8c66916f84b9054add9b53baebf68fef Mon Sep 17 00:00:00 2001
  2. From: Petr Vorel <petr.vorel@gmail.com>
  3. Date: Mon, 13 Mar 2017 12:48:08 +0100
  4. Subject: [PATCH 1/1] r8152: Fix NULL pointer dereference in r8152_poll
  5.  
  6. commit 7489bdadb7d1 (r8152: check rx after napi is enabled) causes null
  7. pointer dereference when using device as under root:
  8.  
  9.  # rmmod r8152 # or lsusb -v
  10. NOHZ: local_softirq_pending 08
  11. BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
  12. IP: r8152_poll+0x125/0x570 [r8152]
  13. PGD 89b4cf067
  14. PUD 898ff2067
  15. PMD 0
  16. Oops: 0002 [#1] PREEMPT SMP
  17.  
  18. Fixes: 7489bdadb7d1 ("r8152: check rx after napi is enabled")
  19.  
  20. Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
  21. Reviewed-by: Eric Dumazet <eric.dumazet@gmail.com>
  22. ---
  23. drivers/net/usb/r8152.c | 20 +++++++++++++++++++-
  24.  1 file changed, 19 insertions(+), 1 deletion(-)
  25.  
  26. diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
  27. index 986243c932cc..4b3285e0e777 100644
  28. --- a/drivers/net/usb/r8152.c
  29. +++ b/drivers/net/usb/r8152.c
  30. @@ -1180,7 +1180,9 @@ static void read_bulk_callback(struct urb *urb)
  31.         spin_lock(&tp->rx_lock);
  32.         list_add_tail(&agg->list, &tp->rx_done);
  33.         spin_unlock(&tp->rx_lock);
  34. +       local_bh_disable();
  35.         napi_schedule(&tp->napi);
  36. +       local_bh_enable();
  37.         return;
  38.     case -ESHUTDOWN:
  39.         set_bit(RTL8152_UNPLUG, &tp->flags);
  40. @@ -1243,8 +1245,10 @@ static void write_bulk_callback(struct urb *urb)
  41.     if (test_bit(RTL8152_UNPLUG, &tp->flags))
  42.         return;
  43.  
  44. +   local_bh_disable();
  45.     if (!skb_queue_empty(&tp->tx_queue))
  46.         napi_schedule(&tp->napi);
  47. +   local_bh_enable();
  48.  }
  49.  
  50.  static void intr_callback(struct urb *urb)
  51. @@ -1933,12 +1937,14 @@ static int r8152_poll(struct napi_struct *napi, int budget)
  52.     bottom_half(tp);
  53.  
  54.     if (work_done < budget) {
  55. +       local_bh_disable();
  56.         napi_complete(napi);
  57.         if (!list_empty(&tp->rx_done))
  58.             napi_schedule(napi);
  59.         else if (!skb_queue_empty(&tp->tx_queue) &&
  60.              !list_empty(&tp->tx_free))
  61.             napi_schedule(napi);
  62. +       local_bh_enable();
  63.     }
  64.  
  65.     return work_done;
  66. @@ -1974,7 +1980,9 @@ int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags)
  67.         netif_err(tp, rx_err, tp->netdev,
  68.               "Couldn't submit rx[%p], ret = %d\n", agg, ret);
  69.  
  70. +       local_bh_disable();
  71.         napi_schedule(&tp->napi);
  72. +       local_bh_enable();
  73.     }
  74.  
  75.     return ret;
  76. @@ -2095,7 +2103,9 @@ static netdev_tx_t rtl8152_start_xmit(struct sk_buff *skb,
  77.             schedule_delayed_work(&tp->schedule, 0);
  78.         } else {
  79.             usb_mark_last_busy(tp->udev);
  80. +           local_bh_disable();
  81.             napi_schedule(&tp->napi);
  82. +           local_bh_enable();
  83.         }
  84.     } else if (skb_queue_len(&tp->tx_queue) > tp->tx_qlen) {
  85.         netif_stop_queue(netdev);
  86. @@ -3206,8 +3216,11 @@ static void rtl_work_func_t(struct work_struct *work)
  87.  
  88.     /* don't schedule napi before linking */
  89.     if (test_and_clear_bit(SCHEDULE_NAPI, &tp->flags) &&
  90. -       netif_carrier_ok(tp->netdev))
  91. +       netif_carrier_ok(tp->netdev)) {
  92. +       local_bh_disable();
  93.         napi_schedule(&tp->napi);
  94. +       local_bh_enable();
  95. +   }
  96.  
  97.     mutex_unlock(&tp->control);
  98.  
  99. @@ -3561,8 +3574,10 @@ static int rtl8152_post_reset(struct usb_interface *intf)
  100.     netif_wake_queue(netdev);
  101.     usb_submit_urb(tp->intr_urb, GFP_KERNEL);
  102.  
  103. +   local_bh_disable();
  104.     if (!list_empty(&tp->rx_done))
  105.         napi_schedule(&tp->napi);
  106. +   local_bh_enable();
  107.  
  108.     return 0;
  109.  }
  110. @@ -3703,8 +3718,11 @@ static int rtl8152_resume(struct usb_interface *intf)
  111.             napi_enable(&tp->napi);
  112.             clear_bit(SELECTIVE_SUSPEND, &tp->flags);
  113.             smp_mb__after_atomic();
  114. +
  115. +           local_bh_disable();
  116.             if (!list_empty(&tp->rx_done))
  117.                 napi_schedule(&tp->napi);
  118. +           local_bh_enable();
  119.         } else {
  120.             tp->rtl_ops.up(tp);
  121.             netif_carrier_off(tp->netdev);
  122. --
  123. 2.12.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement