netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: davem@davemloft.net, john.fastabend@gmail.com
Cc: netdev@vger.kernel.org, oss-drivers@netronome.com,
	borisp@mellanox.com, aviadye@mellanox.com, daniel@iogearbox.net,
	Jakub Kicinski <jakub.kicinski@netronome.com>,
	syzbot+df0d4ec12332661dd1f9@syzkaller.appspotmail.com,
	Simon Horman <simon.horman@netronome.com>
Subject: [PATCH net 2/8] net/tls: free the record on encryption error
Date: Wed, 27 Nov 2019 12:16:40 -0800	[thread overview]
Message-ID: <20191127201646.25455-3-jakub.kicinski@netronome.com> (raw)
In-Reply-To: <20191127201646.25455-1-jakub.kicinski@netronome.com>

When tls_do_encryption() fails the SG lists are left with the
SG_END and SG_CHAIN marks in place. One could hope that once
encryption fails we will never see the record again, but that
is in fact not true. Commit d3b18ad31f93 ("tls: add bpf support
to sk_msg handling") added special handling to ENOMEM and ENOSPC
errors which mean we may see the same record re-submitted.

As suggested by John free the record, the BPF code is already
doing just that.

Reported-by: syzbot+df0d4ec12332661dd1f9@syzkaller.appspotmail.com
Fixes: d3b18ad31f93 ("tls: add bpf support to sk_msg handling")
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
---
 net/tls/tls_sw.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 70e3c0c1af50..dbba51b69d21 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -771,8 +771,14 @@ static int bpf_exec_tx_verdict(struct sk_msg *msg, struct sock *sk,
 
 	policy = !(flags & MSG_SENDPAGE_NOPOLICY);
 	psock = sk_psock_get(sk);
-	if (!psock || !policy)
-		return tls_push_record(sk, flags, record_type);
+	if (!psock || !policy) {
+		err = tls_push_record(sk, flags, record_type);
+		if (err) {
+			*copied -= sk_msg_free(sk, msg);
+			tls_free_open_rec(sk);
+		}
+		return err;
+	}
 more_data:
 	enospc = sk_msg_full(msg);
 	if (psock->eval == __SK_NONE) {
-- 
2.23.0


  parent reply	other threads:[~2019-11-27 20:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-27 20:16 [PATCH net 0/8] net: tls: fix scatter-gather list issues Jakub Kicinski
2019-11-27 20:16 ` [PATCH net 1/8] net/tls: take into account that bpf_exec_tx_verdict() may free the record Jakub Kicinski
2019-11-28  4:40   ` John Fastabend
2019-11-27 20:16 ` Jakub Kicinski [this message]
2019-11-28  4:41   ` [PATCH net 2/8] net/tls: free the record on encryption error John Fastabend
2019-11-27 20:16 ` [PATCH net 3/8] net: skmsg: fix TLS 1.3 crash with full sk_msg Jakub Kicinski
2019-11-27 20:16 ` [PATCH net 4/8] selftests/tls: add a test for fragmented messages Jakub Kicinski
2019-11-27 20:16 ` [PATCH net 5/8] net/tls: remove the dead inplace_crypto code Jakub Kicinski
2019-11-27 20:16 ` [PATCH net 6/8] net/tls: use sg_next() to walk sg entries Jakub Kicinski
2019-11-27 20:16 ` [PATCH net 7/8] selftests: bpf: test_sockmap: handle file creation failures gracefully Jakub Kicinski
2019-11-27 20:16 ` [PATCH net 8/8] selftests: bpf: correct perror strings Jakub Kicinski
2019-11-29  6:44 ` [PATCH net 0/8] net: tls: fix scatter-gather list issues David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191127201646.25455-3-jakub.kicinski@netronome.com \
    --to=jakub.kicinski@netronome.com \
    --cc=aviadye@mellanox.com \
    --cc=borisp@mellanox.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=john.fastabend@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    --cc=simon.horman@netronome.com \
    --cc=syzbot+df0d4ec12332661dd1f9@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).