Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: nf_tables: fix type mismatch with error return from nft_parse_u32_check

Commit 36b701fae12ac ("netfilter: nf_tables: validate maximum value of
u32 netlink attributes") introduced nft_parse_u32_check with a return
value of "unsigned int", yet on error it returns "-ERANGE".

This patch corrects the mismatch by changing the return value to "int",
which happens to match the actual users of nft_parse_u32_check already.

Found by Coverity, CID 1373930.

Note that commit 21a9e0f1568ea ("netfilter: nft_exthdr: fix error
handling in nft_exthdr_init()) attempted to address the issue, but
did not address the return type of nft_parse_u32_check.

Signed-off-by: John W. Linville <linville@tuxdriver.com>
Cc: Laura Garcia Liebana <nevola@gmail.com>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: 36b701fae12ac ("netfilter: nf_tables: validate maximum value...")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

John W. Linville and committed by
Pablo Neira Ayuso
f1d505bb 444f9017

+2 -2
+1 -1
include/net/netfilter/nf_tables.h
··· 145 145 return type == NFT_DATA_VERDICT ? NFT_REG_VERDICT : NFT_REG_1 * NFT_REG_SIZE / NFT_REG32_SIZE; 146 146 } 147 147 148 - unsigned int nft_parse_u32_check(const struct nlattr *attr, int max, u32 *dest); 148 + int nft_parse_u32_check(const struct nlattr *attr, int max, u32 *dest); 149 149 unsigned int nft_parse_register(const struct nlattr *attr); 150 150 int nft_dump_register(struct sk_buff *skb, unsigned int attr, unsigned int reg); 151 151
+1 -1
net/netfilter/nf_tables_api.c
··· 4422 4422 * Otherwise a 0 is returned and the attribute value is stored in the 4423 4423 * destination variable. 4424 4424 */ 4425 - unsigned int nft_parse_u32_check(const struct nlattr *attr, int max, u32 *dest) 4425 + int nft_parse_u32_check(const struct nlattr *attr, int max, u32 *dest) 4426 4426 { 4427 4427 u32 val; 4428 4428