提交 876c99dd 编写于 作者: Z Ziyang Xuan 提交者: Zheng Zengkai

net/tls: fix tls_sk_proto_close executed repeatedly

stable inclusion
from stable-v5.10.127
commit e82376b632473790781a182b10823a4b5dbf6606
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5XDDK

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=e82376b632473790781a182b10823a4b5dbf6606

--------------------------------

[ Upstream commit 69135c57 ]

After setting the sock ktls, update ctx->sk_proto to sock->sk_prot by
tls_update(), so now ctx->sk_proto->close is tls_sk_proto_close(). When
close the sock, tls_sk_proto_close() is called for sock->sk_prot->close
is tls_sk_proto_close(). But ctx->sk_proto->close() will be executed later
in tls_sk_proto_close(). Thus tls_sk_proto_close() executed repeatedly
occurred. That will trigger the following bug.
Reviewed-by: NWei Li <liwei391@huawei.com>

=================================================================
KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017]
RIP: 0010:tls_sk_proto_close+0xd8/0xaf0 net/tls/tls_main.c:306
Call Trace:
 <TASK>
 tls_sk_proto_close+0x356/0xaf0 net/tls/tls_main.c:329
 inet_release+0x12e/0x280 net/ipv4/af_inet.c:428
 __sock_release+0xcd/0x280 net/socket.c:650
 sock_close+0x18/0x20 net/socket.c:1365

Updating a proto which is same with sock->sk_prot is incorrect. Add proto
and sock->sk_prot equality check at the head of tls_update() to fix it.

Fixes: 95fa1454 ("bpf: sockmap/tls, close can race with map free")
Reported-by: syzbot+29c3c12f3214b85ad081@syzkaller.appspotmail.com
Signed-off-by: NZiyang Xuan <william.xuanziyang@huawei.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 0e671024
...@@ -787,6 +787,9 @@ static void tls_update(struct sock *sk, struct proto *p, ...@@ -787,6 +787,9 @@ static void tls_update(struct sock *sk, struct proto *p,
{ {
struct tls_context *ctx; struct tls_context *ctx;
if (sk->sk_prot == p)
return;
ctx = tls_get_ctx(sk); ctx = tls_get_ctx(sk);
if (likely(ctx)) { if (likely(ctx)) {
ctx->sk_write_space = write_space; ctx->sk_write_space = write_space;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册