Skip to content

Commit a7bff11

Browse files
vvfedorenkodavem330
authored andcommitted
net/tls: fix encryption error checking
bpf_exec_tx_verdict() can return negative value for copied variable. In that case this value will be pushed back to caller and the real error code will be lost. Fix it using signed type and checking for positive value. Fixes: d10523d ("net/tls: free the record on encryption error") Fixes: d3b18ad ("tls: add bpf support to sk_msg handling") Signed-off-by: Vadim Fedorenko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 04ba6b7 commit a7bff11

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

net/tls/tls_sw.c

Lines changed: 6 additions & 5 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);
@@ -916,7 +916,8 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
916916
unsigned char record_type = TLS_RECORD_TYPE_DATA;
917917
bool is_kvec = iov_iter_is_kvec(&msg->msg_iter);
918918
bool eor = !(msg->msg_flags & MSG_MORE);
919-
size_t try_to_copy, copied = 0;
919+
size_t try_to_copy;
920+
ssize_t copied = 0;
920921
struct sk_msg *msg_pl, *msg_en;
921922
struct tls_rec *rec;
922923
int required_size;
@@ -1118,7 +1119,7 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
11181119

11191120
release_sock(sk);
11201121
mutex_unlock(&tls_ctx->tx_lock);
1121-
return copied ? copied : ret;
1122+
return copied > 0 ? copied : ret;
11221123
}
11231124

11241125
static int tls_sw_do_sendpage(struct sock *sk, struct page *page,
@@ -1132,7 +1133,7 @@ static int tls_sw_do_sendpage(struct sock *sk, struct page *page,
11321133
struct sk_msg *msg_pl;
11331134
struct tls_rec *rec;
11341135
int num_async = 0;
1135-
size_t copied = 0;
1136+
ssize_t copied = 0;
11361137
bool full_record;
11371138
int record_room;
11381139
int ret = 0;
@@ -1234,7 +1235,7 @@ static int tls_sw_do_sendpage(struct sock *sk, struct page *page,
12341235
}
12351236
sendpage_end:
12361237
ret = sk_stream_error(sk, flags, ret);
1237-
return copied ? copied : ret;
1238+
return copied > 0 ? copied : ret;
12381239
}
12391240

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

0 commit comments

Comments
 (0)