Skip to contentSkip to conversation

net/tls: refine the branch condition in tls_dev_event

PATCH Superseded Kang Chen 3 participants 5 messages Mar 17, 2023

Subsystems (3)
lore
Share & tools
lore

Kang Chen

author
#0 lore raw

PATCH 1/1 net/tls: refine the branch condition in tls_dev_event

dev->tlsdev_ops may be null and cause null pointer dereference later.

Fixes eeb2efaf36c7 ("net/tls: generalize the resync callback")
---
 net/tls/tls_device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/tls/tls_device.c +2 -1
index a7cc4f9faac2..f30a8fe373c2 100644
@@ -1449,7 +1449,8 @@ static int tls_dev_event(struct notifier_block *this, unsigned long event,
 		if (netif_is_bond_master(dev))
 			return NOTIFY_DONE;
 		if ((dev->features & NETIF_F_HW_TLS_RX) &&
-		    !dev->tlsdev_ops->tls_dev_resync)
+		   (!dev->tlsdev_ops || (dev->tlsdev_ops &&
+		    !dev->tlsdev_ops->tls_dev_resync)))
 			return NOTIFY_BAD;
 
 		if  (dev->tlsdev_ops &&
Signature · 1 line
2.34.1
#1 lore raw

The 03/17/2023 15:16, Kang Chen wrote:

Hi,

Quoted 2 lines

dev->tlsdev_ops may be null and cause null pointer dereference later.

In the subject of your patch, you should specify which tree is this patch targeting. When you create the patch you can use:
git format-patch ... --subject-prefix "PATCH net" ...

Quoted 12 lines
Fixes eeb2efaf36c7 ("net/tls: generalize the resync callback")
---
 net/tls/tls_device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/tls/tls_device.c +0 -0
index a7cc4f9faac2..f30a8fe373c2 100644

net/tls/tls_device.c static int tls_dev_event(struct notifier_block *this, unsigned long event, · line 1453

Quoted 6 lines
net/tls/tls_device.c +2 -1
@@ -1449,7 +1449,8 @@ static int tls_dev_event(struct notifier_block *this, unsigned long event,
                if (netif_is_bond_master(dev))
                        return NOTIFY_DONE;
                if ((dev->features & NETIF_F_HW_TLS_RX) &&
-                   !dev->tlsdev_ops->tls_dev_resync)
+                  (!dev->tlsdev_ops || (dev->tlsdev_ops &&
+                   !dev->tlsdev_ops->tls_dev_resync)))

This can be simply written like:
(!dev->tlvdev_ops || !dev->tlvdev_ops->tls_dev_resync)

On the second condition you know already that dev->tlvdev_ops is not NULL.

Quoted 6 lines
net/tls/tls_device.c +0 -1
                        return NOTIFY_BAD;
 
                if  (dev->tlsdev_ops &&
--

2.34.1

Signature · 1 line
/Horatiu
author
#2 lore raw

PATCH v2 1/1 net/tls: refine the branch condition in tls_dev_event

dev->tlsdev_ops may be null and cause null pointer dereference later.

Fixes eeb2efaf36c7 ("net/tls: generalize the resync callback")

---
v2 -> v1: simplify the condition

 net/tls/tls_device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/tls/tls_device.c +2 -1
index a7cc4f9faac2..45b07162d062 100644
@@ -1449,7 +1449,8 @@ static int tls_dev_event(struct notifier_block *this, unsigned long event,
 		if (netif_is_bond_master(dev))
 			return NOTIFY_DONE;
 		if ((dev->features & NETIF_F_HW_TLS_RX) &&
-		    !dev->tlsdev_ops->tls_dev_resync)
+		   (!dev->tlsdev_ops ||
+		    !dev->tlsdev_ops->tls_dev_resync))
 			return NOTIFY_BAD;
 
 		if  (dev->tlsdev_ops &&
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#3 lore raw
Quoted 2 lines · Kang Chen

dev->tlsdev_ops may be null and cause null pointer dereference later.

Quoted 26 lines
Fixes eeb2efaf36c7 ("net/tls: generalize the resync callback")

---
v2 -> v1: simplify the condition

 net/tls/tls_device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/tls/tls_device.c +2 -2
index a7cc4f9faac2..45b07162d062 100644
@@ -1449,7 +1449,8 @@ static int tls_dev_event(struct notifier_block *this, unsigned long event,
                if (netif_is_bond_master(dev))
                        return NOTIFY_DONE;
                if ((dev->features & NETIF_F_HW_TLS_RX) &&
-                   !dev->tlsdev_ops->tls_dev_resync)
+                  (!dev->tlsdev_ops ||
+                   !dev->tlsdev_ops->tls_dev_resync))
                        return NOTIFY_BAD;
 
                if  (dev->tlsdev_ops &&
--

2.34.1

Signature · 1 line
/Horatiu
maintainer
#4 lore raw
In reply to Kang Chen
Quoted 1 line · On Fri, 17 Mar 2023 16:33:38 +0800 Kang Chen wrote:

dev->tlsdev_ops may be null and cause null pointer dereference later.

It'd be a driver bug to report NETIF_F_HW_TLS_RX but not have ops.