Subject: CVE-2024-27050: libbpf: Use OPTS_SET() macro in bpf_xdp_query()

From: Greg Kroah-Hartman <[email-masked]>

Description
===========

In the Linux kernel, the following vulnerability has been resolved:

libbpf: Use OPTS_SET() macro in bpf_xdp_query()

When the feature_flags and xdp_zc_max_segs fields were added to the libbpf
bpf_xdp_query_opts, the code writing them did not use the OPTS_SET() macro.
This causes libbpf to write to those fields unconditionally, which means
that programs compiled against an older version of libbpf (with a smaller
size of the bpf_xdp_query_opts struct) will have its stack corrupted by
libbpf writing out of bounds.

The patch adding the feature_flags field has an early bail out if the
feature_flags field is not part of the opts struct (via the OPTS_HAS)
macro, but the patch adding xdp_zc_max_segs does not. For consistency, this
fix just changes the assignments to both fields to use the OPTS_SET()
macro.

The Linux kernel CVE team has assigned CVE-2024-27050 to this issue.

Affected and fixed versions
===========================

	Issue introduced in 6.6 with commit 13ce2daa259a and fixed in 6.6.23 with commit fa5bef5e80c6
	Issue introduced in 6.6 with commit 13ce2daa259a and fixed in 6.7.11 with commit 682ddd62abd4
	Issue introduced in 6.6 with commit 13ce2daa259a and fixed in 6.8.2 with commit cd3be9843247
	Issue introduced in 6.6 with commit 13ce2daa259a and fixed in 6.9 with commit 92a871ab9fa5

Please see https://www.kernel.org for 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-2024-27050
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:
	tools/lib/bpf/netlink.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/fa5bef5e80c6a3321b2b1a7070436f3bc5daf07c
	https://git.kernel.org/stable/c/682ddd62abd4bdcee7584246903e7a2df005fe0d
	https://git.kernel.org/stable/c/cd3be9843247edb8fc6fcd8d8237cbce2bc19f5e
	https://git.kernel.org/stable/c/92a871ab9fa59a74d013bc04f321026a057618e7