
Linux Kernel 1-Day Analysis & Exploitation
In the nft_parse_register function, because there is no validation when the arg defaults, an out-of-bounds (OOB) occurs on the stack of the nft_do_chain function.
At this point, using the payload expression allows both read and write.
The payload operates as follows:

That is, by appropriately adjusting the index, OOB read/write on the stack is possible.
However, there is a function that validates regs.
default:
if (reg < NFT_REG_1 * NFT_REG_SIZE / NFT_REG32_SIZE)
return -EINVAL;
if (len == 0)
return -EINVAL;
if (reg * NFT_REG32_SIZE + len >
sizeof_field(struct nft_regs, data))
return -ERANGE;
if (data != NULL && type != NFT_DATA_VALUE)
return -EINVAL;
return 0;
Looking at the code above, it must satisfy reg * NFT_REG32_SIZE + len > sizeof_field(struct nft_regs, data).
Plugging in constants, it must satisfy reg * 4 + len > 80.
That is, you need to adjust len appropriately according to reg.
nft_regs
struct nft_regs {
union {
u32 data[20];
struct nft_verdict verdict;
};
};
nft_do_chain
unsigned int
nft_do_chain(struct nft_pktinfo *pkt, void *priv)
{
const struct nft_chain *chain = priv, *basechain = chain;
const struct net *net = nft_net(pkt);
struct nft_rule *const *rules;
const struct nft_rule *rule;
const struct nft_expr *expr, *last;
struct nft_regs regs;
...
}
nft_parse_register
static unsigned int nft_parse_register(const struct nlattr *attr)
{
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;
default:
return reg + NFT_REG_SIZE / NFT_REG32_SIZE - NFT_REG32_00;
}
}