This is a note to let you know that I've just added the patch titled netfilter: nf_tables: validate registers coming from userspace. to the 4.14-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: netfilter-nf_tables-validate-registers-coming-from-userspace.patch and it can be found in the queue-4.14 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From stable-owner@xxxxxxxxxxxxxxx Sat May 27 16:08:12 2023 From: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> Date: Sat, 27 May 2023 18:08:04 +0200 Subject: netfilter: nf_tables: validate registers coming from userspace. To: netfilter-devel@xxxxxxxxxxxxxxx Cc: gregkh@xxxxxxxxxxxxxxxxxxx, stable@xxxxxxxxxxxxxxx, sashal@xxxxxxxxxx Message-ID: <20230527160811.67779-5-pablo@xxxxxxxxxxxxx> From: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> [ 6e1acfa387b9ff82cfc7db8cc3b6959221a95851 ] Bail out in case userspace uses unsupported registers. Fixes: 49499c3e6e18 ("netfilter: nf_tables: switch registers to 32 bit addressing") Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- net/netfilter/nf_tables_api.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -5615,26 +5615,23 @@ int nft_parse_u32_check(const struct nla } EXPORT_SYMBOL_GPL(nft_parse_u32_check); -/** - * nft_parse_register - parse a register value from a netlink attribute - * - * @attr: netlink attribute - * - * Parse and translate a register value from a netlink attribute. - * Registers used to be 128 bit wide, these register numbers will be - * mapped to the corresponding 32 bit register numbers. - */ -static unsigned int nft_parse_register(const struct nlattr *attr) +static int nft_parse_register(const struct nlattr *attr, u32 *preg) { unsigned int reg; reg = ntohl(nla_get_be32(attr)); switch (reg) { case NFT_REG_VERDICT...NFT_REG_4: - return reg * NFT_REG_SIZE / NFT_REG32_SIZE; + *preg = reg * NFT_REG_SIZE / NFT_REG32_SIZE; + break; + case NFT_REG32_00...NFT_REG32_15: + *preg = reg + NFT_REG_SIZE / NFT_REG32_SIZE - NFT_REG32_00; + break; default: - return reg + NFT_REG_SIZE / NFT_REG32_SIZE - NFT_REG32_00; + return -ERANGE; } + + return 0; } /** @@ -5685,7 +5682,10 @@ int nft_parse_register_load(const struct u32 reg; int err; - reg = nft_parse_register(attr); + err = nft_parse_register(attr, ®); + if (err < 0) + return err; + err = nft_validate_register_load(reg, len); if (err < 0) return err; @@ -5761,7 +5761,10 @@ int nft_parse_register_store(const struc int err; u32 reg; - reg = nft_parse_register(attr); + err = nft_parse_register(attr, ®); + if (err < 0) + return err; + err = nft_validate_register_store(ctx, reg, data, type, len); if (err < 0) return err; Patches currently in stable-queue which might be from stable-owner@xxxxxxxxxxxxxxx are queue-4.14/netfilter-nftables-add-nft_parse_register_load-and-use-it.patch queue-4.14/netfilter-nftables-add-nft_parse_register_store-and-use-it.patch queue-4.14/netfilter-nf_tables-fix-register-ordering.patch queue-4.14/netfilter-nftables-statify-nft_parse_register.patch queue-4.14/netfilter-nf_tables-validate-registers-coming-from-userspace.patch queue-4.14/netfilter-nft_dynset-do-not-reject-set-updates-with-nft_set_eval.patch queue-4.14/netfilter-nf_tables-do-not-allow-set_id-to-refer-to-another-table.patch queue-4.14/netfilter-nf_tables-stricter-validation-of-element-data.patch queue-4.14/netfilter-nf_tables-add-nft_setelem_parse_key.patch queue-4.14/netfilter-nf_tables-do-not-allow-rule_id-to-refer-to-another-chain.patch queue-4.14/netfilter-nf_tables-allow-up-to-64-bytes-in-the-set-element-data-area.patch