]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net/tls: free record only on encryption error
authorVadim Fedorenko <vfedorenko@novek.ru>
Wed, 20 May 2020 08:41:44 +0000 (11:41 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 22 May 2020 00:20:06 +0000 (17:20 -0700)
We cannot free record on any transient error because it leads to
losing previos data. Check socket error to know whether record must
be freed or not.

Fixes: c7e51a9c5c83 ("net/tls: free the record on encryption error")
Signed-off-by: Vadim Fedorenko <vfedorenko@novek.ru>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/tls/tls_sw.c

index 57f80823330e12f5bcea877784d2488b6a86e735..2d399b6c407564b5da022ab358d92468359c0ece 100644 (file)
@@ -796,9 +796,10 @@ static int bpf_exec_tx_verdict(struct sk_msg *msg, struct sock *sk,
        psock = sk_psock_get(sk);
        if (!psock || !policy) {
                err = tls_push_record(sk, flags, record_type);
-               if (err && err != -EINPROGRESS) {
+               if (err && sk->sk_err == EBADMSG) {
                        *copied -= sk_msg_free(sk, msg);
                        tls_free_open_rec(sk);
+                       err = -sk->sk_err;
                }
                if (psock)
                        sk_psock_put(sk, psock);
@@ -824,9 +825,10 @@ more_data:
        switch (psock->eval) {
        case __SK_PASS:
                err = tls_push_record(sk, flags, record_type);
-               if (err && err != -EINPROGRESS) {
+               if (err && sk->sk_err == EBADMSG) {
                        *copied -= sk_msg_free(sk, msg);
                        tls_free_open_rec(sk);
+                       err = -sk->sk_err;
                        goto out_err;
                }
                break;