[CBR 7.9] netfilter: nf_tables: Reject tables of unsupported family #448
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[CBR 7.9]
CVE-2023-6040
VULN-7622
Problem
https://www.openwall.com/lists/oss-security/2024/01/12/1
Applicability: yes
The
nf_tables
module is enabled in CBR 7.9:The fixing commit f1082dd is not present in the affected file's
net/netfilter/nf_tables_api.c
history forciqcbr7_9
, nor was it backported.The bug can't be blamed on a single commit - there is no "fixes" commit indicated in f1082dd to check whether it exists in
ciqcbr7_9
history or not. However, without replicating Ant Security Lab's analysis it can be reasonably assumed that the bug is present in CBR 7.9 based on the following arguments:xt_find_target
function exists innet/netfilter/x_tables.c
and it does dereference thext
array a couple of times without boundary checking:kernel-src-tree/net/netfilter/x_tables.c
Line 231 in d93daad
kernel-src-tree/net/netfilter/x_tables.c
Line 232 in d93daad
kernel-src-tree/net/netfilter/x_tables.c
Line 236 in d93daad
kernel-src-tree/net/netfilter/x_tables.c
Line 243 in d93daad
nf_logger_find_get
function exists innet/netfilter/nf_log.c
and the globalloggers
variable is dereferenced withpf
kernel-src-tree/net/netfilter/nf_log.c
Line 173 in d93daad
kernel-src-tree/net/netfilter/nf_log.c
Line 180 in d93daad
kernel-src-tree/net/netfilter/nf_log.c
Line 191 in d93daad
Solution
Naively cherry-picking the f1082dd commit leads to many conflicts but they aren't indicative of any semantic mismatches between the patch and
net/netfilter/nf_tables_api.c
file underciqcbr7_9
revision. The changes were applied manually as they appear in the diff. Two changes compared to mainline were made:CONFIG_NF_TABLES_NETDEV
case was removed because that option is not even available inciqcbr7_9
yet.IS_ENABLED(...)
macro instead of justCONFIG_NF_TABLES_BRIDGE
because all of them are of type "tristate" inciqcbr7_9
, unlike in the newer kernels where they are "bool" and a simple#ifdef
is sufficient:kernel-src-tree/net/netfilter/Kconfig
Line 447 in d93daad
kernel-src-tree/net/ipv4/netfilter/Kconfig
Line 42 in d93daad
kernel-src-tree/net/ipv4/netfilter/Kconfig
Line 70 in d93daad
kernel-src-tree/net/bridge/netfilter/Kconfig
Line 7 in d93daad
kernel-src-tree/net/ipv6/netfilter/Kconfig
Line 31 in d93daad
Compare with
ciqlts9_2
, for example:kernel-src-tree/net/netfilter/Kconfig
Line 489 in f85f16c
kernel-src-tree/net/ipv4/netfilter/Kconfig
Line 25 in f85f16c
kernel-src-tree/net/ipv4/netfilter/Kconfig
Line 54 in f85f16c
kernel-src-tree/net/netfilter/Kconfig
Line 494 in f85f16c
kernel-src-tree/net/bridge/netfilter/Kconfig
Line 9 in f85f16c
kernel-src-tree/net/ipv6/netfilter/Kconfig
Line 21 in f85f16c
kABI check: passed
Boot test: passed
See implied boot test passing in the Specific tests section.
Selftests: skipped
It was attempted to use the
netfilter:*
selftests from Rocky LTS 8.6 version to test the nf tables module in CBR 7.9, as most of them are just bash scripts jugglingip
,nft
,nc
andconntrack
calls to create network setups. Unfortunately, thenft
version available in CBR 7.9 didn't recognize the call syntax of reading from stdinused extensively in the scripts. Where the more explicit form was used
it could not understand the provided configuration, like
In short, the
nft
tool was too old.Specific tests: passed
The modified function
nf_tables_newtable
can be quite easily reached from the userspace with thenft add table…
command. With config options mapping to the third arguments asall of supported table types are accepted in the patched kernel, just as they are in the reference kernel:
specific-test-reference.log
specific-test-patch.log
A test version of the kernel for both the reference and the patch was prepared, with the
CONFIG_NF_TABLES_ARP
option disabledto gauge
nft
's reaction for creating the unsupportedarp
table.Patch:
The "Operation not supported" message aligns with the
-EOPNOTSUPP
value returned in the branch added tonf_tables_newtable
function:specific-test-patch-no-arp.log
Reference:
The
arp
argument is likewise rejected, as expected, although with a different message implying a later point in the code path, where the problems indicated in the CVE may manifest.specific-test-reference-no-arp.log
Commentary
Technically this bug may not be applicable to Rocky CBR 7.9, as no table type is unsupported - all of
NF_TABLES_INET
,NF_TABLES_IPV4
,NF_TABLES_ARP
,NF_TABLES_BRIDGE
,NF_TABLES_NETDEV
,NF_TABLES_IPV6
options are enabled inconfigs/kernel-3.10.0-x86_64.config
and thenft_supported_family(family)
call may just as well always evaluate totrue
(same applies to #440 and #438). However, this would require showing thatfamily
variable won't ever assume any other value thanNFPROTO_INET
,NFPROTO_IPV4
,NFPROTO_ARP
,NFPROTO_BRIDGE
,NFPROTO_IPV6
, which thenft
calls given previously suggest, but which would nevertheless need to be proved by kernel code investigation. Considering that this was realized after the patch was already made and tested it's now cheaper to include it instead of pursuing this analysis.