linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/tls: refine the branch condition in tls_dev_event
@ 2023-03-17  7:16 Kang Chen
  2023-03-17  8:15 ` Horatiu Vultur
  0 siblings, 1 reply; 5+ messages in thread
From: Kang Chen @ 2023-03-17  7:16 UTC (permalink / raw)
  To: borisp
  Cc: john.fastabend, kuba, davem, edumazet, pabeni, dirk.vandermerwe,
	netdev, linux-kernel, Kang Chen

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

Fixes: eeb2efaf36c7 ("net/tls: generalize the resync callback")
Signed-off-by: Kang Chen <void0red@gmail.com>
---
 net/tls/tls_device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
index a7cc4f9faac2..f30a8fe373c2 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -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 &&
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] net/tls: refine the branch condition in tls_dev_event
  2023-03-17  7:16 [PATCH] net/tls: refine the branch condition in tls_dev_event Kang Chen
@ 2023-03-17  8:15 ` Horatiu Vultur
  2023-03-17  8:33   ` [PATCH net v2] " Kang Chen
  0 siblings, 1 reply; 5+ messages in thread
From: Horatiu Vultur @ 2023-03-17  8:15 UTC (permalink / raw)
  To: Kang Chen
  Cc: borisp, john.fastabend, kuba, davem, edumazet, pabeni,
	dirk.vandermerwe, netdev, linux-kernel

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

Hi,

> 
> 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" ...

> 
> Fixes: eeb2efaf36c7 ("net/tls: generalize the resync callback")
> Signed-off-by: Kang Chen <void0red@gmail.com>
> ---
>  net/tls/tls_device.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
> index a7cc4f9faac2..f30a8fe373c2 100644
> --- a/net/tls/tls_device.c
> +++ b/net/tls/tls_device.c
> @@ -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.

>                         return NOTIFY_BAD;
> 
>                 if  (dev->tlsdev_ops &&
> --
> 2.34.1
> 

-- 
/Horatiu

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net v2] net/tls: refine the branch condition in tls_dev_event
  2023-03-17  8:15 ` Horatiu Vultur
@ 2023-03-17  8:33   ` Kang Chen
  2023-03-17  9:56     ` Horatiu Vultur
  2023-03-17 19:54     ` Jakub Kicinski
  0 siblings, 2 replies; 5+ messages in thread
From: Kang Chen @ 2023-03-17  8:33 UTC (permalink / raw)
  To: horatiu.vultur
  Cc: borisp, davem, dirk.vandermerwe, edumazet, john.fastabend, kuba,
	linux-kernel, netdev, pabeni, void0red

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

Fixes: eeb2efaf36c7 ("net/tls: generalize the resync callback")
Signed-off-by: Kang Chen <void0red@gmail.com>
---
v2 -> v1: simplify the condition

 net/tls/tls_device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
index a7cc4f9faac2..45b07162d062 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net v2] net/tls: refine the branch condition in tls_dev_event
  2023-03-17  8:33   ` [PATCH net v2] " Kang Chen
@ 2023-03-17  9:56     ` Horatiu Vultur
  2023-03-17 19:54     ` Jakub Kicinski
  1 sibling, 0 replies; 5+ messages in thread
From: Horatiu Vultur @ 2023-03-17  9:56 UTC (permalink / raw)
  To: Kang Chen
  Cc: borisp, davem, dirk.vandermerwe, edumazet, john.fastabend, kuba,
	linux-kernel, netdev, pabeni

The 03/17/2023 16:33, Kang Chen wrote:
> 
> dev->tlsdev_ops may be null and cause null pointer dereference later.

Reviewed-by: Horatiu Vultur <horatiu.vultur@microchip.com>
> 
> Fixes: eeb2efaf36c7 ("net/tls: generalize the resync callback")
> Signed-off-by: Kang Chen <void0red@gmail.com>
> ---
> v2 -> v1: simplify the condition
> 
>  net/tls/tls_device.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
> index a7cc4f9faac2..45b07162d062 100644
> --- a/net/tls/tls_device.c
> +++ b/net/tls/tls_device.c
> @@ -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
> 

-- 
/Horatiu

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net v2] net/tls: refine the branch condition in tls_dev_event
  2023-03-17  8:33   ` [PATCH net v2] " Kang Chen
  2023-03-17  9:56     ` Horatiu Vultur
@ 2023-03-17 19:54     ` Jakub Kicinski
  1 sibling, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2023-03-17 19:54 UTC (permalink / raw)
  To: Kang Chen
  Cc: horatiu.vultur, borisp, davem, dirk.vandermerwe, edumazet,
	john.fastabend, linux-kernel, netdev, pabeni

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-03-17 19:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-17  7:16 [PATCH] net/tls: refine the branch condition in tls_dev_event Kang Chen
2023-03-17  8:15 ` Horatiu Vultur
2023-03-17  8:33   ` [PATCH net v2] " Kang Chen
2023-03-17  9:56     ` Horatiu Vultur
2023-03-17 19:54     ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).