Bug 1225079 (CVE-2023-52828) - VUL-0: CVE-2023-52828: kernel: bpf: Detect IP == ksym.end as part of BPF program
Summary: VUL-0: CVE-2023-52828: kernel: bpf: Detect IP == ksym.end as part of BPF program
Status: RESOLVED FIXED
Alias: CVE-2023-52828
Product: SUSE Security Incidents
Classification: Novell Products
Component: Incidents (show other bugs)
Version: unspecified
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Security Team bot
QA Contact: Security Team bot
URL: https://smash.suse.de/issue/406978/
Whiteboard: CVSSv3.1:SUSE:CVE-2023-52828:5.5:(AV:...
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-23 08:05 UTC by SMASH SMASH
Modified: 2024-07-10 08:46 UTC (History)
2 users (show)

See Also:
Found By: Security Response Team
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description SMASH SMASH 2024-05-23 08:05:50 UTC
In the Linux kernel, the following vulnerability has been resolved:

bpf: Detect IP == ksym.end as part of BPF program

Now that bpf_throw kfunc is the first such call instruction that has
noreturn semantics within the verifier, this also kicks in dead code
elimination in unprecedented ways. For one, any instruction following
a bpf_throw call will never be marked as seen. Moreover, if a callchain
ends up throwing, any instructions after the call instruction to the
eventually throwing subprog in callers will also never be marked as
seen.

The tempting way to fix this would be to emit extra 'int3' instructions
which bump the jited_len of a program, and ensure that during runtime
when a program throws, we can discover its boundaries even if the call
instruction to bpf_throw (or to subprogs that always throw) is emitted
as the final instruction in the program.

An example of such a program would be this:

do_something():
	...
	r0 = 0
	exit

foo():
	r1 = 0
	call bpf_throw
	r0 = 0
	exit

bar(cond):
	if r1 != 0 goto pc+2
	call do_something
	exit
	call foo
	r0 = 0  // Never seen by verifier
	exit	//

main(ctx):
	r1 = ...
	call bar
	r0 = 0
	exit

Here, if we do end up throwing, the stacktrace would be the following:

bpf_throw
foo
bar
main

In bar, the final instruction emitted will be the call to foo, as such,
the return address will be the subsequent instruction (which the JIT
emits as int3 on x86). This will end up lying outside the jited_len of
the program, thus, when unwinding, we will fail to discover the return
address as belonging to any program and end up in a panic due to the
unreliable stack unwinding of BPF programs that we never expect.

To remedy this case, make bpf_prog_ksym_find treat IP == ksym.end as
part of the BPF program, so that is_bpf_text_address returns true when
such a case occurs, and we are able to unwind reliably when the final
instruction ends up being a call instruction.

References:
http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2023-52828
https://git.kernel.org/pub/scm/linux/security/vulns.git/plain/cve/published/2023/CVE-2023-52828.mbox
https://git.kernel.org/stable/c/6058e4829696412457729a00734969acc6fd1d18
https://git.kernel.org/stable/c/cf353904a82873e952633fcac4385c2fcd3a46e1
https://git.kernel.org/stable/c/aa42a7cb92647786719fe9608685da345883878f
https://git.kernel.org/stable/c/327b92e8cb527ae097961ffd1610c720481947f5
https://git.kernel.org/stable/c/821a7e4143af115b840ec199eb179537e18af922
https://git.kernel.org/stable/c/66d9111f3517f85ef2af0337ece02683ce0faf21
https://www.cve.org/CVERecord?id=CVE-2023-52828
https://bugzilla.redhat.com/show_bug.cgi?id=2282668
Comment 3 Shung-Hsi Yu 2024-06-05 06:12:06 UTC
66d9111f3517 ("bpf: Detect IP == ksym.end as part of BPF program") is only needed when BPF exception is supported (through the bpf_throw kfunc), which actually belong to the same series[1].

Since we do not support BPF exception in our kernel yet, we are not affected.

Reassigning back to security team.

1: https://lore.kernel.org/all/20230912233214.1518551-1-memxor@gmail.com/
Comment 4 Thomas Leroy 2024-07-10 08:46:02 UTC
(In reply to Shung-Hsi Yu from comment #3)
> 66d9111f3517 ("bpf: Detect IP == ksym.end as part of BPF program") is only
> needed when BPF exception is supported (through the bpf_throw kfunc), which
> actually belong to the same series[1].
> 
> Since we do not support BPF exception in our kernel yet, we are not affected.
> 
> Reassigning back to security team.
> 
> 1: https://lore.kernel.org/all/20230912233214.1518551-1-memxor@gmail.com/

Thanks for the analysis. Closing