
Linux Kernel 1-Day Analysis & Exploitation
La fonction nft_parse_register ne valide pas le cas où l'argument arg passe par le défaut, ce qui provoque un OOB dans la pile de la fonction nft_do_chain.
À ce moment, en utilisant l'expression de payload, on peut à la fois lire et écrire.
Le payload effectue les opérations suivantes :

Autrement dit, en ajustant correctement l'index, on peut effectuer une lecture/écriture OOB dans la pile.
Cependant, il existe une fonction de validation pour les 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;
Dans le code ci-dessus, il faut satisfaire reg * NFT_REG32_SIZE + len > sizeof_field(struct nft_regs, data).
En insérant les constantes, il suffit de vérifier reg * 4 + len > 80.
C'est-à-dire qu'il faut ajuster len en fonction de 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;
}
}