Skip to content

Commit e0b6648

Browse files
Phil Sutterummakynes
authored andcommitted
netfilter: nf_tables: Audit log dump reset after the fact
In theory, dumpreset may fail and invalidate the preceeding log message. Fix this and use the occasion to prepare for object reset locking, which benefits from a few unrelated changes: * Add an early call to nfnetlink_unicast if not resetting which effectively skips the audit logging but also unindents it. * Extract the table's name from the netlink attribute (which is verified via earlier table lookup) to not rely upon validity of the looked up table pointer. * Do not use local variable family, it will vanish. Fixes: 8e6cf36 ("audit: log nftables configuration change events") Signed-off-by: Phil Sutter <[email protected]> Reviewed-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent ea2306f commit e0b6648

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8055,6 +8055,7 @@ static int nf_tables_dump_obj_done(struct netlink_callback *cb)
80558055
static int nf_tables_getobj(struct sk_buff *skb, const struct nfnl_info *info,
80568056
const struct nlattr * const nla[])
80578057
{
8058+
const struct nftables_pernet *nft_net = nft_pernet(info->net);
80588059
struct netlink_ext_ack *extack = info->extack;
80598060
u8 genmask = nft_genmask_cur(info->net);
80608061
u8 family = info->nfmsg->nfgen_family;
@@ -8064,6 +8065,7 @@ static int nf_tables_getobj(struct sk_buff *skb, const struct nfnl_info *info,
80648065
struct sk_buff *skb2;
80658066
bool reset = false;
80668067
u32 objtype;
8068+
char *buf;
80678069
int err;
80688070

80698071
if (info->nlh->nlmsg_flags & NLM_F_DUMP) {
@@ -8102,27 +8104,23 @@ static int nf_tables_getobj(struct sk_buff *skb, const struct nfnl_info *info,
81028104
if (NFNL_MSG_TYPE(info->nlh->nlmsg_type) == NFT_MSG_GETOBJ_RESET)
81038105
reset = true;
81048106

8105-
if (reset) {
8106-
const struct nftables_pernet *nft_net;
8107-
char *buf;
8108-
8109-
nft_net = nft_pernet(net);
8110-
buf = kasprintf(GFP_ATOMIC, "%s:%u", table->name, nft_net->base_seq);
8111-
8112-
audit_log_nfcfg(buf,
8113-
family,
8114-
1,
8115-
AUDIT_NFT_OP_OBJ_RESET,
8116-
GFP_ATOMIC);
8117-
kfree(buf);
8118-
}
8119-
81208107
err = nf_tables_fill_obj_info(skb2, net, NETLINK_CB(skb).portid,
81218108
info->nlh->nlmsg_seq, NFT_MSG_NEWOBJ, 0,
81228109
family, table, obj, reset);
81238110
if (err < 0)
81248111
goto err_fill_obj_info;
81258112

8113+
if (!reset)
8114+
return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
8115+
8116+
buf = kasprintf(GFP_ATOMIC, "%.*s:%u",
8117+
nla_len(nla[NFTA_OBJ_TABLE]),
8118+
(char *)nla_data(nla[NFTA_OBJ_TABLE]),
8119+
nft_net->base_seq);
8120+
audit_log_nfcfg(buf, info->nfmsg->nfgen_family, 1,
8121+
AUDIT_NFT_OP_OBJ_RESET, GFP_ATOMIC);
8122+
kfree(buf);
8123+
81268124
return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
81278125

81288126
err_fill_obj_info:

0 commit comments

Comments
 (0)