Skip to content

Commit ef81e45

Browse files
ummakynesgregkh
authored andcommitted
netfilter: nf_tables: Unbreak audit log reset
[ Upstream commit 9b5ba5c ] Deliver audit log from __nf_tables_dump_rules(), table dereference at the end of the table list loop might point to the list head, leading to this crash. [ 4137.407349] BUG: unable to handle page fault for address: 00000000001f3c50 [ 4137.407357] #PF: supervisor read access in kernel mode [ 4137.407359] #PF: error_code(0x0000) - not-present page [ 4137.407360] PGD 0 P4D 0 [ 4137.407363] Oops: 0000 [#1] PREEMPT SMP PTI [ 4137.407365] CPU: 4 PID: 500177 Comm: nft Not tainted 6.5.0+ torvalds#277 [ 4137.407369] RIP: 0010:string+0x49/0xd0 [ 4137.407374] Code: ff 77 36 45 89 d1 31 f6 49 01 f9 66 45 85 d2 75 19 eb 1e 49 39 f8 76 02 88 07 48 83 c7 01 83 c6 01 48 83 c2 01 4c 39 cf 74 07 <0f> b6 02 84 c0 75 e2 4c 89 c2 e9 58 e5 ff ff 48 c7 c0 0e b2 ff 81 [ 4137.407377] RSP: 0018:ffff8881179737f0 EFLAGS: 00010286 [ 4137.407379] RAX: 00000000001f2c50 RBX: ffff888117973848 RCX: ffff0a00ffffff04 [ 4137.407380] RDX: 00000000001f3c50 RSI: 0000000000000000 RDI: 0000000000000000 [ 4137.407381] RBP: 0000000000000000 R08: 0000000000000000 R09: 00000000ffffffff [ 4137.407383] R10: ffffffffffffffff R11: ffff88813584d200 R12: 0000000000000000 [ 4137.407384] R13: ffffffffa15cf709 R14: 0000000000000000 R15: ffffffffa15cf709 [ 4137.407385] FS: 00007fcfc18bb580(0000) GS:ffff88840e700000(0000) knlGS:0000000000000000 [ 4137.407387] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 4137.407388] CR2: 00000000001f3c50 CR3: 00000001055b2001 CR4: 00000000001706e0 [ 4137.407390] Call Trace: [ 4137.407392] <TASK> [ 4137.407393] ? __die+0x1b/0x60 [ 4137.407397] ? page_fault_oops+0x6b/0xa0 [ 4137.407399] ? exc_page_fault+0x60/0x120 [ 4137.407403] ? asm_exc_page_fault+0x22/0x30 [ 4137.407408] ? string+0x49/0xd0 [ 4137.407410] vsnprintf+0x257/0x4f0 [ 4137.407414] kvasprintf+0x3e/0xb0 [ 4137.407417] kasprintf+0x3e/0x50 [ 4137.407419] nf_tables_dump_rules+0x1c0/0x360 [nf_tables] [ 4137.407439] ? __alloc_skb+0xc3/0x170 [ 4137.407442] netlink_dump+0x170/0x330 [ 4137.407447] __netlink_dump_start+0x227/0x300 [ 4137.407449] nf_tables_getrule+0x205/0x390 [nf_tables] Deliver audit log only once at the end of the rule dump+reset for consistency with the set dump+reset. Ensure audit reset access to table under rcu read side lock. The table list iteration holds rcu read lock side, but recent audit code dereferences table object out of the rcu read lock side. Fixes: ea078ae ("netfilter: nf_tables: Audit log rule reset") Fixes: 7e9be11 ("netfilter: nf_tables: Audit log setelem reset") Signed-off-by: Pablo Neira Ayuso <[email protected]> Acked-by: Phil Sutter <[email protected]> Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent e3213ff commit ef81e45

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,6 +3480,10 @@ static int __nf_tables_dump_rules(struct sk_buff *skb,
34803480
cont_skip:
34813481
(*idx)++;
34823482
}
3483+
3484+
if (reset && *idx)
3485+
audit_log_rule_reset(table, cb->seq, *idx);
3486+
34833487
return 0;
34843488
}
34853489

@@ -3540,9 +3544,6 @@ static int nf_tables_dump_rules(struct sk_buff *skb,
35403544
done:
35413545
rcu_read_unlock();
35423546

3543-
if (reset && idx > cb->args[0])
3544-
audit_log_rule_reset(table, cb->seq, idx - cb->args[0]);
3545-
35463547
cb->args[0] = idx;
35473548
return skb->len;
35483549
}
@@ -5757,15 +5758,15 @@ static int nf_tables_dump_set(struct sk_buff *skb, struct netlink_callback *cb)
57575758
if (!args.iter.err && args.iter.count == cb->args[0])
57585759
args.iter.err = nft_set_catchall_dump(net, skb, set,
57595760
reset, cb->seq);
5760-
rcu_read_unlock();
5761-
57625761
nla_nest_end(skb, nest);
57635762
nlmsg_end(skb, nlh);
57645763

57655764
if (reset && args.iter.count > args.iter.skip)
57665765
audit_log_nft_set_reset(table, cb->seq,
57675766
args.iter.count - args.iter.skip);
57685767

5768+
rcu_read_unlock();
5769+
57695770
if (args.iter.err && args.iter.err != -EMSGSIZE)
57705771
return args.iter.err;
57715772
if (args.iter.count == cb->args[0])

0 commit comments

Comments
 (0)