Skip to content

Commit 7e9be11

Browse files
Phil Sutterummakynes
authored andcommitted
netfilter: nf_tables: Audit log setelem reset
Since set element reset is not integrated into nf_tables' transaction logic, an explicit log call is needed, similar to NFT_MSG_GETOBJ_RESET handling. For the sake of simplicity, catchall element reset will always generate a dedicated log entry. This relieves nf_tables_dump_set() from having to adjust the logged element count depending on whether a catchall element was found or not. Fixes: 079cd63 ("netfilter: nf_tables: Introduce NFT_MSG_GETSETELEM_RESET") Signed-off-by: Phil Sutter <[email protected]> Reviewed-by: Richard Guy Briggs <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 69c5d28 commit 7e9be11

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

include/linux/audit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ enum audit_nfcfgop {
117117
AUDIT_NFT_OP_OBJ_RESET,
118118
AUDIT_NFT_OP_FLOWTABLE_REGISTER,
119119
AUDIT_NFT_OP_FLOWTABLE_UNREGISTER,
120+
AUDIT_NFT_OP_SETELEM_RESET,
120121
AUDIT_NFT_OP_INVALID,
121122
};
122123

kernel/auditsc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ static const struct audit_nfcfgop_tab audit_nfcfgs[] = {
143143
{ AUDIT_NFT_OP_OBJ_RESET, "nft_reset_obj" },
144144
{ AUDIT_NFT_OP_FLOWTABLE_REGISTER, "nft_register_flowtable" },
145145
{ AUDIT_NFT_OP_FLOWTABLE_UNREGISTER, "nft_unregister_flowtable" },
146+
{ AUDIT_NFT_OP_SETELEM_RESET, "nft_reset_setelem" },
146147
{ AUDIT_NFT_OP_INVALID, "nft_invalid" },
147148
};
148149

net/netfilter/nf_tables_api.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ static const u8 nft2audit_op[NFT_MSG_MAX] = { // enum nf_tables_msg_types
102102
[NFT_MSG_NEWFLOWTABLE] = AUDIT_NFT_OP_FLOWTABLE_REGISTER,
103103
[NFT_MSG_GETFLOWTABLE] = AUDIT_NFT_OP_INVALID,
104104
[NFT_MSG_DELFLOWTABLE] = AUDIT_NFT_OP_FLOWTABLE_UNREGISTER,
105+
[NFT_MSG_GETSETELEM_RESET] = AUDIT_NFT_OP_SETELEM_RESET,
105106
};
106107

107108
static void nft_validate_state_update(struct nft_table *table, u8 new_validate_state)
@@ -5624,13 +5625,25 @@ static int nf_tables_dump_setelem(const struct nft_ctx *ctx,
56245625
return nf_tables_fill_setelem(args->skb, set, elem, args->reset);
56255626
}
56265627

5628+
static void audit_log_nft_set_reset(const struct nft_table *table,
5629+
unsigned int base_seq,
5630+
unsigned int nentries)
5631+
{
5632+
char *buf = kasprintf(GFP_ATOMIC, "%s:%u", table->name, base_seq);
5633+
5634+
audit_log_nfcfg(buf, table->family, nentries,
5635+
AUDIT_NFT_OP_SETELEM_RESET, GFP_ATOMIC);
5636+
kfree(buf);
5637+
}
5638+
56275639
struct nft_set_dump_ctx {
56285640
const struct nft_set *set;
56295641
struct nft_ctx ctx;
56305642
};
56315643

56325644
static int nft_set_catchall_dump(struct net *net, struct sk_buff *skb,
5633-
const struct nft_set *set, bool reset)
5645+
const struct nft_set *set, bool reset,
5646+
unsigned int base_seq)
56345647
{
56355648
struct nft_set_elem_catchall *catchall;
56365649
u8 genmask = nft_genmask_cur(net);
@@ -5646,6 +5659,8 @@ static int nft_set_catchall_dump(struct net *net, struct sk_buff *skb,
56465659

56475660
elem.priv = catchall->elem;
56485661
ret = nf_tables_fill_setelem(skb, set, &elem, reset);
5662+
if (reset && !ret)
5663+
audit_log_nft_set_reset(set->table, base_seq, 1);
56495664
break;
56505665
}
56515666

@@ -5725,12 +5740,17 @@ static int nf_tables_dump_set(struct sk_buff *skb, struct netlink_callback *cb)
57255740
set->ops->walk(&dump_ctx->ctx, set, &args.iter);
57265741

57275742
if (!args.iter.err && args.iter.count == cb->args[0])
5728-
args.iter.err = nft_set_catchall_dump(net, skb, set, reset);
5743+
args.iter.err = nft_set_catchall_dump(net, skb, set,
5744+
reset, cb->seq);
57295745
rcu_read_unlock();
57305746

57315747
nla_nest_end(skb, nest);
57325748
nlmsg_end(skb, nlh);
57335749

5750+
if (reset && args.iter.count > args.iter.skip)
5751+
audit_log_nft_set_reset(table, cb->seq,
5752+
args.iter.count - args.iter.skip);
5753+
57345754
if (args.iter.err && args.iter.err != -EMSGSIZE)
57355755
return args.iter.err;
57365756
if (args.iter.count == cb->args[0])
@@ -5955,13 +5975,13 @@ static int nf_tables_getsetelem(struct sk_buff *skb,
59555975
struct netlink_ext_ack *extack = info->extack;
59565976
u8 genmask = nft_genmask_cur(info->net);
59575977
u8 family = info->nfmsg->nfgen_family;
5978+
int rem, err = 0, nelems = 0;
59585979
struct net *net = info->net;
59595980
struct nft_table *table;
59605981
struct nft_set *set;
59615982
struct nlattr *attr;
59625983
struct nft_ctx ctx;
59635984
bool reset = false;
5964-
int rem, err = 0;
59655985

59665986
table = nft_table_lookup(net, nla[NFTA_SET_ELEM_LIST_TABLE], family,
59675987
genmask, 0);
@@ -6004,8 +6024,13 @@ static int nf_tables_getsetelem(struct sk_buff *skb,
60046024
NL_SET_BAD_ATTR(extack, attr);
60056025
break;
60066026
}
6027+
nelems++;
60076028
}
60086029

6030+
if (reset)
6031+
audit_log_nft_set_reset(table, nft_pernet(net)->base_seq,
6032+
nelems);
6033+
60096034
return err;
60106035
}
60116036

0 commit comments

Comments
 (0)