net/tls: don’t ignore netdev notifications if no TLS features [Linux 5.2]

net/tls: don’t ignore netdev notifications if no TLS features [Linux 5.2]

This Linux kernel change "net/tls: don’t ignore netdev notifications if no TLS features" is included in the Linux 5.2 release. This change is authored by Jakub Kicinski <jakub.kicinski [at] netronome.com> on Tue May 21 19:02:02 2019 -0700. The commit for this change in Linux stable tree is c3f4a6c (patch).

net/tls: don't ignore netdev notifications if no TLS features

On device surprise removal path (the notifier) we can't
bail just because the features are disabled.  They may
have been enabled during the lifetime of the device.
This bug leads to leaking netdev references and
use-after-frees if there are active connections while
device features are cleared.

Fixes: e8f69799810c ("net/tls: Add generic NIC offload infrastructure")
Signed-off-by: Jakub Kicinski <[email protected]>
Reviewed-by: Dirk van der Merwe <[email protected]>
Signed-off-by: David S. Miller <[email protected]>

There are 3 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 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 0765044..b95c408 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -997,7 +997,8 @@ static int tls_dev_event(struct notifier_block *this, unsigned long event,
 {
    struct net_device *dev = netdev_notifier_info_to_dev(ptr);

-   if (!(dev->features & (NETIF_F_HW_TLS_RX | NETIF_F_HW_TLS_TX)))
+   if (!dev->tlsdev_ops &&
+       !(dev->features & (NETIF_F_HW_TLS_RX | NETIF_F_HW_TLS_TX)))
        return NOTIFY_DONE;

    switch (event) {

Leave a Reply

Your email address will not be published. Required fields are marked *