]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
netfilter: nf_tables: upfront validation of data via nft_data_init()
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 8 Aug 2022 17:30:06 +0000 (19:30 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 7 Oct 2022 08:39:25 +0000 (10:39 +0200)
commit3274c8b94693018f2e8d242abbf1d9e605d4c7dd
treee2b62626c63451c6b8a323fc0f9ab67d28e962e3
parent003e24bd832b1d2aff3d35ad1a2799ed358f0fe3
netfilter: nf_tables: upfront validation of data via nft_data_init()

BugLink: https://bugs.launchpad.net/bugs/1991717
[ Upstream commit 341b6941608762d8235f3fd1e45e4d7114ed8c2c ]

Instead of parsing the data and then validate that type and length are
correct, pass a description of the expected data so it can be validated
upfront before parsing it to bail out earlier.

This patch adds a new .size field to specify the maximum size of the
data area. The .len field is optional and it is used as an input/output
field, it provides the specific length of the expected data in the input
path. If then .len field is not specified, then obtained length from the
netlink attribute is stored. This is required by cmp, bitwise, range and
immediate, which provide no netlink attribute that describes the data
length. The immediate expression uses the destination register type to
infer the expected data type.

Relying on opencoded validation of the expected data might lead to
subtle bugs as described in 7e6bc1f6cabc ("netfilter: nf_tables:
stricter validation of element data").

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
include/net/netfilter/nf_tables.h
net/netfilter/nf_tables_api.c
net/netfilter/nft_bitwise.c
net/netfilter/nft_cmp.c
net/netfilter/nft_immediate.c
net/netfilter/nft_range.c