net/tls: avoid NULL pointer deref on nskb->sk in fallback [Linux 5.1]

net/tls: avoid NULL pointer deref on nskb->sk in fallback [Linux 5.1]

This Linux kernel change "net/tls: avoid NULL pointer deref on nskb->sk in fallback" is included in the Linux 5.1 release. This change is authored by Jakub Kicinski <jakub.kicinski [at] netronome.com> on Mon Apr 29 12:19:12 2019 -0700. The commit for this change in Linux stable tree is 2dcb003 (patch).

net/tls: avoid NULL pointer deref on nskb->sk in fallback

update_chksum() accesses nskb->sk before it has been set
by complete_skb(), move the init up.

Fixes: e8f69799810c ("net/tls: Add generic NIC offload infrastructure")
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

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_fallback.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/tls/tls_device_fallback.c b/net/tls/tls_device_fallback.c
index a3ebd4b..c3a5fe6 100644
--- a/net/tls/tls_device_fallback.c
+++ b/net/tls/tls_device_fallback.c
@@ -201,13 +201,14 @@ static void complete_skb(struct sk_buff *nskb, struct sk_buff *skb, int headln)

    skb_put(nskb, skb->len);
    memcpy(nskb->data, skb->data, headln);
-   update_chksum(nskb, headln);

    nskb->destructor = skb->destructor;
    nskb->sk = sk;
    skb->destructor = NULL;
    skb->sk = NULL;

+   update_chksum(nskb, headln);
+
    delta = nskb->truesize - skb->truesize;
    if (likely(delta < 0))
        WARN_ON_ONCE(refcount_sub_and_test(-delta, &sk->sk_wmem_alloc));

Leave a Reply

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