[SRU Impish 1/2] netdevice: add the case if dev is NULL

Thadeu Lima de Souza Cascardo cascardo at canonical.com
Tue Jun 21 19:09:11 UTC 2022


From: Yajun Deng <yajun.deng at linux.dev>

Add the case if dev is NULL in dev_{put, hold}, so the caller doesn't
need to care whether dev is NULL or not.

Signed-off-by: Yajun Deng <yajun.deng at linux.dev>
Signed-off-by: David S. Miller <davem at davemloft.net>
(cherry picked from commit b37a466837393af72fe8bcb8f1436410f3f173f3)
CVE-2022-28356
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo at canonical.com>
---
 include/linux/netdevice.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 12852a2d4fa3..34fcd1c67a30 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -4141,11 +4141,13 @@ void netdev_run_todo(void);
  */
 static inline void dev_put(struct net_device *dev)
 {
+	if (dev) {
 #ifdef CONFIG_PCPU_DEV_REFCNT
-	this_cpu_dec(*dev->pcpu_refcnt);
+		this_cpu_dec(*dev->pcpu_refcnt);
 #else
-	refcount_dec(&dev->dev_refcnt);
+		refcount_dec(&dev->dev_refcnt);
 #endif
+	}
 }
 
 /**
@@ -4156,11 +4158,13 @@ static inline void dev_put(struct net_device *dev)
  */
 static inline void dev_hold(struct net_device *dev)
 {
+	if (dev) {
 #ifdef CONFIG_PCPU_DEV_REFCNT
-	this_cpu_inc(*dev->pcpu_refcnt);
+		this_cpu_inc(*dev->pcpu_refcnt);
 #else
-	refcount_inc(&dev->dev_refcnt);
+		refcount_inc(&dev->dev_refcnt);
 #endif
+	}
 }
 
 /* Carrier loss detection, dial on demand. The functions netif_carrier_on
-- 
2.34.1




More information about the kernel-team mailing list