Skip to content

Commit a553461

Browse files
committed
Merge branch 'net-tls-fix-encryption-error-path'
Vadim Fedorenko says: ==================== net/tls: fix encryption error path The problem with data stream corruption was found in KTLS transmit path with small socket send buffers and large amount of data. bpf_exec_tx_verdict() frees open record on any type of error including EAGAIN, ENOMEM and ENOSPC while callers are able to recover this transient errors. Also wrong error code was returned to user space in that case. This patchset fixes the problems. ==================== Acked-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2 parents 04ba6b7 + 635d939 commit a553461

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

net/tls/tls_sw.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ static int tls_push_record(struct sock *sk, int flags,
780780

781781
static int bpf_exec_tx_verdict(struct sk_msg *msg, struct sock *sk,
782782
bool full_record, u8 record_type,
783-
size_t *copied, int flags)
783+
ssize_t *copied, int flags)
784784
{
785785
struct tls_context *tls_ctx = tls_get_ctx(sk);
786786
struct tls_sw_context_tx *ctx = tls_sw_ctx_tx(tls_ctx);
@@ -796,9 +796,10 @@ static int bpf_exec_tx_verdict(struct sk_msg *msg, struct sock *sk,
796796
psock = sk_psock_get(sk);
797797
if (!psock || !policy) {
798798
err = tls_push_record(sk, flags, record_type);
799-
if (err && err != -EINPROGRESS) {
799+
if (err && sk->sk_err == EBADMSG) {
800800
*copied -= sk_msg_free(sk, msg);
801801
tls_free_open_rec(sk);
802+
err = -sk->sk_err;
802803
}
803804
if (psock)
804805
sk_psock_put(sk, psock);
@@ -824,9 +825,10 @@ static int bpf_exec_tx_verdict(struct sk_msg *msg, struct sock *sk,
824825
switch (psock->eval) {
825826
case __SK_PASS:
826827
err = tls_push_record(sk, flags, record_type);
827-
if (err && err != -EINPROGRESS) {
828+
if (err && sk->sk_err == EBADMSG) {
828829
*copied -= sk_msg_free(sk, msg);
829830
tls_free_open_rec(sk);
831+
err = -sk->sk_err;
830832
goto out_err;
831833
}
832834
break;
@@ -916,7 +918,8 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
916918
unsigned char record_type = TLS_RECORD_TYPE_DATA;
917919
bool is_kvec = iov_iter_is_kvec(&msg->msg_iter);
918920
bool eor = !(msg->msg_flags & MSG_MORE);
919-
size_t try_to_copy, copied = 0;
921+
size_t try_to_copy;
922+
ssize_t copied = 0;
920923
struct sk_msg *msg_pl, *msg_en;
921924
struct tls_rec *rec;
922925
int required_size;
@@ -1118,7 +1121,7 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
11181121

11191122
release_sock(sk);
11201123
mutex_unlock(&tls_ctx->tx_lock);
1121-
return copied ? copied : ret;
1124+
return copied > 0 ? copied : ret;
11221125
}
11231126

11241127
static int tls_sw_do_sendpage(struct sock *sk, struct page *page,
@@ -1132,7 +1135,7 @@ static int tls_sw_do_sendpage(struct sock *sk, struct page *page,
11321135
struct sk_msg *msg_pl;
11331136
struct tls_rec *rec;
11341137
int num_async = 0;
1135-
size_t copied = 0;
1138+
ssize_t copied = 0;
11361139
bool full_record;
11371140
int record_room;
11381141
int ret = 0;
@@ -1234,7 +1237,7 @@ static int tls_sw_do_sendpage(struct sock *sk, struct page *page,
12341237
}
12351238
sendpage_end:
12361239
ret = sk_stream_error(sk, flags, ret);
1237-
return copied ? copied : ret;
1240+
return copied > 0 ? copied : ret;
12381241
}
12391242

12401243
int tls_sw_sendpage_locked(struct sock *sk, struct page *page,

0 commit comments

Comments
 (0)