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 88F5C4122C for ; Sat, 2 Mar 2024 21:54:30 +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=1709416470; cv=none; b=SQseQfHcHKaPZsB6L5nMUcpTvJE9qXxIWAvbhEgEzCoJbxXw6efWdQiDCABYCe6y2Qq5nPc3kISaoqGUNZtYo3A2vf2JYJtns07AkFBWS+jEnyEHh5Tpxwp0KwNt3sxFuT3I4Q3nVaIiRkyKoTCo5TRQVU0vgF0Lwwvj48KJ3fM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709416470; c=relaxed/simple; bh=3qzNBbzrN2+EIcyO4CeL8C+TuOUWsYKAdURPvota/jY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=udGPF2aSnt6dE3lGu9Ee+bGVjaiwivEiBq82xoWANE4IuVKd13IhXGAvlQZHdwYH99PBJYbeRnncM8YCI7HS/pXcorvwtv6bh76ox2S/6EQXEP/QGx/Tt1CKV4mH0WSXkDRD87RxUqDdI1P9U31MK6RAJEKmMICcihKPo1aDlSU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CImZJ+xN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="CImZJ+xN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10B88C433F1; Sat, 2 Mar 2024 21:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1709416470; bh=3qzNBbzrN2+EIcyO4CeL8C+TuOUWsYKAdURPvota/jY=; h=From:To:Cc:Subject:Date:Reply-to:From; b=CImZJ+xN5xzrrgQfRmFbsUnpwpW2bRPwt+W6/k/6XePYWAxUyettEm7Pxn2EMVJrI cGYG48YyzXxZMwM0ypXNTCrDkYQgadtGDjPzu8tqPnkgQcRxBXIYew2o26VwgqA4R+ D3DIRkgBpBb/KkOcHBZUbluC9G/78B69hj4CEmkY= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2023-52523: bpf, sockmap: Reject sk_msg egress redirects to non-TCP sockets Date: Sat, 2 Mar 2024 22:53:07 +0100 Message-ID: <2024030253-CVE-2023-52523-5ae2@gregkh> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=4020; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=3qzNBbzrN2+EIcyO4CeL8C+TuOUWsYKAdURPvota/jY=; b=owGbwMvMwCRo6H6F97bub03G02pJDKmP529dub1SMKFk5jWnk5P91kb09Z0SjddX6omQ0BTNM U47c+9XRywLgyATg6yYIsuXbTxH91ccUvQytD0NM4eVCWQIAxenAExk5h2GudKLmBYdCg65snjd xdj7K9RFBG45VDHMdy5bUez45FjX9TP6kY8uz2T2m9J1HgA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Description =========== In the Linux kernel, the following vulnerability has been resolved: bpf, sockmap: Reject sk_msg egress redirects to non-TCP sockets With a SOCKMAP/SOCKHASH map and an sk_msg program user can steer messages sent from one TCP socket (s1) to actually egress from another TCP socket (s2): tcp_bpf_sendmsg(s1) // = sk_prot->sendmsg tcp_bpf_send_verdict(s1) // __SK_REDIRECT case tcp_bpf_sendmsg_redir(s2) tcp_bpf_push_locked(s2) tcp_bpf_push(s2) tcp_rate_check_app_limited(s2) // expects tcp_sock tcp_sendmsg_locked(s2) // ditto There is a hard-coded assumption in the call-chain, that the egress socket (s2) is a TCP socket. However in commit 122e6c79efe1 ("sock_map: Update sock type checks for UDP") we have enabled redirects to non-TCP sockets. This was done for the sake of BPF sk_skb programs. There was no indention to support sk_msg send-to-egress use case. As a result, attempts to send-to-egress through a non-TCP socket lead to a crash due to invalid downcast from sock to tcp_sock: BUG: kernel NULL pointer dereference, address: 000000000000002f ... Call Trace: ? show_regs+0x60/0x70 ? __die+0x1f/0x70 ? page_fault_oops+0x80/0x160 ? do_user_addr_fault+0x2d7/0x800 ? rcu_is_watching+0x11/0x50 ? exc_page_fault+0x70/0x1c0 ? asm_exc_page_fault+0x27/0x30 ? tcp_tso_segs+0x14/0xa0 tcp_write_xmit+0x67/0xce0 __tcp_push_pending_frames+0x32/0xf0 tcp_push+0x107/0x140 tcp_sendmsg_locked+0x99f/0xbb0 tcp_bpf_push+0x19d/0x3a0 tcp_bpf_sendmsg_redir+0x55/0xd0 tcp_bpf_send_verdict+0x407/0x550 tcp_bpf_sendmsg+0x1a1/0x390 inet_sendmsg+0x6a/0x70 sock_sendmsg+0x9d/0xc0 ? sockfd_lookup_light+0x12/0x80 __sys_sendto+0x10e/0x160 ? syscall_enter_from_user_mode+0x20/0x60 ? __this_cpu_preempt_check+0x13/0x20 ? lockdep_hardirqs_on+0x82/0x110 __x64_sys_sendto+0x1f/0x30 do_syscall_64+0x38/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd Reject selecting a non-TCP sockets as redirect target from a BPF sk_msg program to prevent the crash. When attempted, user will receive an EACCES error from send/sendto/sendmsg() syscall. The Linux kernel CVE team has assigned CVE-2023-52523 to this issue. Affected and fixed versions =========================== Issue introduced in 5.13 with commit 122e6c79efe1 and fixed in 5.15.135 with commit bc8b89b69638 Issue introduced in 5.13 with commit 122e6c79efe1 and fixed in 6.1.57 with commit b8f97e47b6fb Issue introduced in 5.13 with commit 122e6c79efe1 and fixed in 6.5.7 with commit ded6e448028f Issue introduced in 5.13 with commit 122e6c79efe1 and fixed in 6.6 with commit b80e31baa436 Please see https://www.kernel.org or a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2023-52523 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: net/core/sock_map.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/bc8b89b6963803a123f64aa9494155a037b3d728 https://git.kernel.org/stable/c/b8f97e47b6fb84fcf2f5a22e725eefb6cf5070c2 https://git.kernel.org/stable/c/ded6e448028f0f91b6af35985afca01fa02a9089 https://git.kernel.org/stable/c/b80e31baa43614e086a9d29dc1151932b1bd7fc5