Skip to content

Commit

Permalink
net/tls: Fix inverted error codes to avoid endless loop
Browse files Browse the repository at this point in the history
sendfile() calls can hang endless with using Kernel TLS if a socket error occurs.
Socket error codes must be inverted by Kernel TLS before returning because
they are stored with positive sign. If returned non-inverted they are
interpreted as number of bytes sent, causing endless looping of the
splice mechanic behind sendfile().

Signed-off-by: Robert Hering <r.hering@avm.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
r.hering@avm.de authored and David S. Miller committed Jan 15, 2018
1 parent 95ef498 commit 30be8f8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/net/tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static inline bool tls_is_pending_open_record(struct tls_context *tls_ctx)

static inline void tls_err_abort(struct sock *sk)
{
sk->sk_err = -EBADMSG;
sk->sk_err = EBADMSG;
sk->sk_error_report(sk);
}

Expand Down
4 changes: 2 additions & 2 deletions net/tls/tls_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)

while (msg_data_left(msg)) {
if (sk->sk_err) {
ret = sk->sk_err;
ret = -sk->sk_err;
goto send_end;
}

Expand Down Expand Up @@ -544,7 +544,7 @@ int tls_sw_sendpage(struct sock *sk, struct page *page,
size_t copy, required_size;

if (sk->sk_err) {
ret = sk->sk_err;
ret = -sk->sk_err;
goto sendpage_end;
}

Expand Down

0 comments on commit 30be8f8

Please sign in to comment.