From patchwork Tue Jun 25 08:24:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 807395 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E02A31474A0; Tue, 25 Jun 2024 08:25:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719303911; cv=none; b=lfn5toCX72oa0r+p4VxfUQrWYrS91qeRAYUi2cZYGORRdDZnG1vQ9Q7tBt9VVIyQ7qv0uQ6gbkxIcSmh79noBQWxBcM8pZh2qLe4+4L2Yz5Yio9MEl79CGEUXNC0k+Go5z2bYG8feX6duy96ajJ7iyEhqfxUGacOWvNM6VHk/04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719303911; c=relaxed/simple; bh=GV6RzNRiu+NFo0nRbcqXXn65F5CbOzF0HE2HroGeUgE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f6IAmCD0aw9ZbJ6ImTiImegRxfGgXLMkJscvmSDJPrsOuX4RfOE1O5Jbsdj/knFQOFldognp7HSAacyKT9X+9uCag150ZwRkVyayMB9ZfKqdqZl9WqBxlNBmQv+UmW58kWi9CVudSP+bj4GwqEPnRZk9QmgwCI3piuS7KslCsOY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HAwZY4P5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HAwZY4P5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1580C32789; Tue, 25 Jun 2024 08:25:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719303909; bh=GV6RzNRiu+NFo0nRbcqXXn65F5CbOzF0HE2HroGeUgE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HAwZY4P5qnXs2cHBEiga+yj3iGNMFi82pL8hcLO4Z/X9mfIlAfJP3ikVng5IqjOw/ Q5CiSd7an7Rj/WKCXer4As5VbEOF9/02bh/dnme43GzluUPsjN3pyXQGpkQaFsDHLR fHD1dfLFhbF8QnjXwZHCTl3qDES+49dgr646WyzBhMtDpfl6HkviUoA4ctf76nS5w8 dx8WXRWWbU2djtRuKkCjwVxUPhvX/tyzKuX2nj0yqXsqzR1iRNzmEN2myZXBBGYrhC tgAmSZHcTIDtWrjzNc7vie/YN2bHF1UCMv7ScDhQvGXsdSST6KqDkWFxv3ZZfoTnsJ 7OPqDpfkWvtcw== From: Geliang Tang To: John Fastabend , Jakub Sitnicki , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Mykyta Yatsenko , Miao Xu , Yuran Pereira , Huacai Chen , Tiezhu Yang Cc: Geliang Tang , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 1/4] skmsg: null check for sg_page in sk_msg_recvmsg Date: Tue, 25 Jun 2024 16:24:36 +0800 Message-ID: <072709ce77b04dc77523d4e8763c1fb47bf0913d.1719302367.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Run the following BPF selftests on Loongarch: ./test_progs -t sockmap_basic A Kernel panic occurs: ''' Oops[#1]: CPU: 22 PID: 2824 Comm: test_progs Tainted: G OE 6.10.0-rc2+ #18 Hardware name: LOONGSON Dabieshan/Loongson-TC542F0, BIOS Loongson-UDK2018-V4.0.11 pc 9000000004162774 ra 90000000048bf6c0 tp 90001000aa16c000 sp 90001000aa16fb90 a0 0000000000000000 a1 0000000000000000 a2 0000000000000000 a3 90001000aa16fd70 a4 0000000000000800 a5 0000000000000000 a6 000055557b63aae8 a7 00000000000000cf t0 0000000000000000 t1 0000000000004000 t2 0000000000000048 t3 0000000000000000 t4 0000000000000001 t5 0000000000000002 t6 0000000000000001 t7 0000000000000002 t8 0000000000000018 u0 9000000004856150 s9 0000000000000000 s0 0000000000000000 s1 0000000000000000 s2 90001000aa16fd70 s3 0000000000000000 s4 0000000000000000 s5 0000000000004000 s6 900010009284dc00 s7 0000000000000001 s8 900010009284dc00 ra: 90000000048bf6c0 sk_msg_recvmsg+0x120/0x560 ERA: 9000000004162774 copy_page_to_iter+0x74/0x1c0 CRMD: 000000b0 (PLV0 -IE -DA +PG DACF=CC DACM=CC -WE) PRMD: 0000000c (PPLV0 +PIE +PWE) EUEN: 00000007 (+FPE +SXE +ASXE -BTE) ECFG: 00071c1d (LIE=0,2-4,10-12 VS=7) ESTAT: 00010000 [PIL] (IS= ECode=1 EsubCode=0) BADV: 0000000000000040 PRID: 0014c011 (Loongson-64bit, Loongson-3C5000) Modules linked in: bpf_testmod(OE) xt_CHECKSUM xt_MASQUERADE xt_conntrack Process test_progs (pid: 2824, threadinfo=0000000000863a31, task=000000001cba0874) Stack : 0000000000000001 fffffffffffffffc 0000000000000000 0000000000000000 0000000000000018 0000000000000000 0000000000000000 90000000048bf6c0 90000000052cd638 90001000aa16fd70 900010008bf51580 900010009284f000 90000000049f2b90 900010009284f188 900010009284f178 90001000861d4780 9000100084dccd00 0000000000000800 0000000000000007 fffffffffffffff2 000000000453e92f 90000000049aae34 90001000aa16fd60 900010009284f000 0000000000000000 0000000000000000 900010008bf51580 90000000049f2b90 0000000000000001 0000000000000000 9000100084dc3a10 900010009284f1ac 90001000aa16fd40 0000555559953278 0000000000000001 0000000000000000 90001000aa16fdc8 9000000005a5a000 90001000861d4780 0000000000000800 ... Call Trace: [<9000000004162774>] copy_page_to_iter+0x74/0x1c0 [<90000000048bf6c0>] sk_msg_recvmsg+0x120/0x560 [<90000000049f2b90>] tcp_bpf_recvmsg_parser+0x170/0x4e0 [<90000000049aae34>] inet_recvmsg+0x54/0x100 [<900000000481ad5c>] sock_recvmsg+0x7c/0xe0 [<900000000481e1a8>] __sys_recvfrom+0x108/0x1c0 [<900000000481e27c>] sys_recvfrom+0x1c/0x40 [<9000000004c076ec>] do_syscall+0x8c/0xc0 [<9000000003731da4>] handle_syscall+0xc4/0x160 Code: 0010b09b 440125a0 0011df8d <28c10364> 0012b70c 00133305 0013b1ac 0010dc84 00151585 ---[ end trace 0000000000000000 ]--- Kernel panic - not syncing: Fatal exception Kernel relocated by 0x3510000 .text @ 0x9000000003710000 .data @ 0x9000000004d70000 .bss @ 0x9000000006469400 ---[ end Kernel panic - not syncing: Fatal exception ]--- ''' This is because "sg_page(sge)" is NULL in that case. This patch adds null check for it in sk_msg_recvmsg() to fix this error. Fixes: 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface") Signed-off-by: Geliang Tang --- net/core/skmsg.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index fd20aae30be2..bafcc1e2eadf 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -432,6 +432,8 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg, sge = sk_msg_elem(msg_rx, i); copy = sge->length; page = sg_page(sge); + if (!page) + goto out; if (copied + copy > len) copy = len - copied; copy = copy_page_to_iter(page, sge->offset, copy, iter); From patchwork Tue Jun 25 08:24:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 807394 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 118601474A0; Tue, 25 Jun 2024 08:25:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719303925; cv=none; b=Y0P6tmTwAhYw5iXvfw9crtHylGSsxhwJPnKdgTQwbP5q14+kDQKi/NqBN0wVEr3buoHj8bKN7b8bAul1o6U8se0DXUcI5emrmxXTqpaUkZUwV1diPbHD/6+1aCp1pBWZhEtzHpB7JZwugNlUvRDd2z11hvLvgO1EqChHcDVqFxQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719303925; c=relaxed/simple; bh=Bh7S+Is8s0WxM/UarsSsROTHakfmcXDoWorFr9rAb1g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jQHYGMi2xLBp4OujWjA0QIy35qpRHy6CARKP9EiKQ5mtTTSs4l3w0dJgAGoQBEFukSYLMv3YTrhMni6GlKPsrD5rFlYts/EMB2te+f79339nVHEOKB8pBEuGkH7O4U3+kcR9ZrwEMfcLCvkm662TfZoONzO/WNFnKbrP0kXe97c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m33CQZh5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m33CQZh5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F41E6C32781; Tue, 25 Jun 2024 08:25:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719303924; bh=Bh7S+Is8s0WxM/UarsSsROTHakfmcXDoWorFr9rAb1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m33CQZh58IyuyT7tjqDy+rtNuhQ1kI1LP2QE1lMGLo4KIKdSolRNgg3Ht+XV0xTyM B2zKqtRJoK5cXP6SgD/0SG0Ff96ZwoHFrGO73ZVgSAkWMYKHb0OvXn5BbI9SWvRqaJ A/VgC9blz6Y3hQeEl+ssb2vrNYPy7Z1h77XEKi/tn/kXZugp8XJ6x7xMK8SJ5V0fa5 cP8jt6qZA9seay2xI/KkbJct3ptoP6LqyZX+tiZNxS1xq8SR6E+itObFS4ZHC8neFH WGGB4Wbs/pOHvgGOE3dZmYlPQaXcKjvmobjcD57GBj51a9C9J2+a7JiBAmd+5hf7LJ LbYd3PhqXBQ5A== From: Geliang Tang To: John Fastabend , Jakub Sitnicki , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Mykyta Yatsenko , Miao Xu , Yuran Pereira , Huacai Chen , Tiezhu Yang Cc: Geliang Tang , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 3/4] inet: null check for close in inet_release Date: Tue, 25 Jun 2024 16:24:38 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Run the following BPF selftests on Loongarch: ./test_progs -t sockmap_listen A Kernel panic occurs: ''' Oops[#1]: CPU: 49 PID: 233429 Comm: new_name Tainted: G OE 6.10.0-rc2+ #20 Hardware name: LOONGSON Dabieshan/Loongson-TC542F0, BIOS Loongson-UDK2018-V4.0.11 pc 0000000000000000 ra 90000000051ea4a0 tp 900030008549c000 sp 900030008549fe00 a0 9000300152524a00 a1 0000000000000000 a2 900030008549fe38 a3 900030008549fe30 a4 900030008549fe30 a5 90003000c58c8d80 a6 0000000000000000 a7 0000000000000039 t0 0000000000000000 t1 90003000c58c8d80 t2 0000000000000001 t3 0000000000000000 t4 0000000000000001 t5 900000011a1bf580 t6 900000011a3aff60 t7 000000000000006b t8 00000fffffffffff u0 0000000000000000 s9 00007fffbbe9e930 s0 9000300152524a00 s1 90003000c58c8d00 s2 9000000006c81568 s3 0000000000000000 s4 90003000c58c8d80 s5 00007ffff236a000 s6 00007ffffbc292b0 s7 00007ffffbc29998 s8 00007fffbbe9f180 ra: 90000000051ea4a0 inet_release+0x60/0xc0 ERA: 0000000000000000 0x0 CRMD: 000000b0 (PLV0 -IE -DA +PG DACF=CC DACM=CC -WE) PRMD: 0000000c (PPLV0 +PIE +PWE) EUEN: 00000000 (-FPE -SXE -ASXE -BTE) ECFG: 00071c1d (LIE=0,2-4,10-12 VS=7) ESTAT: 00030000 [PIF] (IS= ECode=3 EsubCode=0) BADV: 0000000000000000 PRID: 0014c011 (Loongson-64bit, Loongson-3C5000) Modules linked in: xt_CHECKSUM xt_MASQUERADE xt_conntrack ipt_REJECT nf_nat_tftp Process new_name (pid: 233429, threadinfo=00000000b9196405, task=00000000c01df45b) Stack : 0000000000000000 90003000c58c8e20 90003000c58c8d00 900000000505960c 0000000000000000 9000000101c6ad20 9000300086524540 00000000082e0003 900030008bf57400 90000000050596bc 900030008bf57400 900000000434acac 0000000000000016 00007ffff224e060 00007fffbbe9f180 900030008bf57400 0000000000000000 9000000004341ce0 00007fffbbe9f180 00007ffff2369000 900030008549fec0 90000000054476ec 000000000000006b 9000000003f71da4 000000000000003a 00007ffff22b8a44 00007fffbbe9f8e0 00007fffbbe9e680 ffffffffffffffda 0000000000000000 0000000000000000 0000000000000000 00007fffbbe9f288 0000000000000000 0000000000000000 0000000000000039 84c2431493ceab6e 84c23ceb2827425e 0000000000000007 00007ffff2271600 ... Call Trace: [<900000000505960c>] __sock_release+0x4c/0xe0 [<90000000050596bc>] sock_close+0x1c/0x40 [<900000000434acac>] __fput+0xec/0x2e0 [<9000000004341ce0>] sys_close+0x40/0xa0 [<90000000054476ec>] do_syscall+0x8c/0xc0 [<9000000003f71da4>] handle_syscall+0xc4/0x160 Code: (Bad address in era) ---[ end trace 0000000000000000 ]--- Kernel panic - not syncing: Fatal exception Kernel relocated by 0x3d50000 .text @ 0x9000000003f50000 .data @ 0x90000000055b0000 .bss @ 0x9000000006ca9400 ---[ end Kernel panic - not syncing: Fatal exception ]--- ''' This is because "sk->sk_prot->close" pointer is NULL in that case. This patch adds null check for it in inet_release() to fix this error. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Geliang Tang --- net/ipv4/af_inet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index b24d74616637..34a719e98c69 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -434,7 +434,8 @@ int inet_release(struct socket *sock) if (sock_flag(sk, SOCK_LINGER) && !(current->flags & PF_EXITING)) timeout = sk->sk_lingertime; - sk->sk_prot->close(sk, timeout); + if (sk->sk_prot->close) + sk->sk_prot->close(sk, timeout); sock->sk = NULL; } return 0;