Skip to content

Commit 4052bb3

Browse files
committed
netfilter: nf_tables: Audit log setelem reset
JIRA: https://issues.redhat.com/browse/RHEL-9127 Conflicts: Minor context diff due to unrelated upstream commit 00c320f ("netfilter: nf_tables: make validation state per table") This patch is a backport of the following upstream commit: commit 7e9be11 Author: Phil Sutter <[email protected]> Date: Tue Aug 29 19:51:57 2023 +0200 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]> Signed-off-by: Ricardo Robaina <[email protected]>
1 parent 50cd468 commit 4052bb3

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
@@ -100,6 +100,7 @@ static const u8 nft2audit_op[NFT_MSG_MAX] = { // enum nf_tables_msg_types
100100
[NFT_MSG_NEWFLOWTABLE] = AUDIT_NFT_OP_FLOWTABLE_REGISTER,
101101
[NFT_MSG_GETFLOWTABLE] = AUDIT_NFT_OP_INVALID,
102102
[NFT_MSG_DELFLOWTABLE] = AUDIT_NFT_OP_FLOWTABLE_UNREGISTER,
103+
[NFT_MSG_GETSETELEM_RESET] = AUDIT_NFT_OP_SETELEM_RESET,
103104
};
104105

105106
static void nft_validate_state_update(struct net *net, u8 new_validate_state)
@@ -5196,13 +5197,25 @@ static int nf_tables_dump_setelem(const struct nft_ctx *ctx,
51965197
return nf_tables_fill_setelem(args->skb, set, elem, args->reset);
51975198
}
51985199

5200+
static void audit_log_nft_set_reset(const struct nft_table *table,
5201+
unsigned int base_seq,
5202+
unsigned int nentries)
5203+
{
5204+
char *buf = kasprintf(GFP_ATOMIC, "%s:%u", table->name, base_seq);
5205+
5206+
audit_log_nfcfg(buf, table->family, nentries,
5207+
AUDIT_NFT_OP_SETELEM_RESET, GFP_ATOMIC);
5208+
kfree(buf);
5209+
}
5210+
51995211
struct nft_set_dump_ctx {
52005212
const struct nft_set *set;
52015213
struct nft_ctx ctx;
52025214
};
52035215

52045216
static int nft_set_catchall_dump(struct net *net, struct sk_buff *skb,
5205-
const struct nft_set *set, bool reset)
5217+
const struct nft_set *set, bool reset,
5218+
unsigned int base_seq)
52065219
{
52075220
struct nft_set_elem_catchall *catchall;
52085221
u8 genmask = nft_genmask_cur(net);
@@ -5218,6 +5231,8 @@ static int nft_set_catchall_dump(struct net *net, struct sk_buff *skb,
52185231

52195232
elem.priv = catchall->elem;
52205233
ret = nf_tables_fill_setelem(skb, set, &elem, reset);
5234+
if (reset && !ret)
5235+
audit_log_nft_set_reset(set->table, base_seq, 1);
52215236
break;
52225237
}
52235238

@@ -5297,12 +5312,17 @@ static int nf_tables_dump_set(struct sk_buff *skb, struct netlink_callback *cb)
52975312
set->ops->walk(&dump_ctx->ctx, set, &args.iter);
52985313

52995314
if (!args.iter.err && args.iter.count == cb->args[0])
5300-
args.iter.err = nft_set_catchall_dump(net, skb, set, reset);
5315+
args.iter.err = nft_set_catchall_dump(net, skb, set,
5316+
reset, cb->seq);
53015317
rcu_read_unlock();
53025318

53035319
nla_nest_end(skb, nest);
53045320
nlmsg_end(skb, nlh);
53055321

5322+
if (reset && args.iter.count > args.iter.skip)
5323+
audit_log_nft_set_reset(table, cb->seq,
5324+
args.iter.count - args.iter.skip);
5325+
53065326
if (args.iter.err && args.iter.err != -EMSGSIZE)
53075327
return args.iter.err;
53085328
if (args.iter.count == cb->args[0])
@@ -5541,13 +5561,13 @@ static int nf_tables_getsetelem(struct sk_buff *skb,
55415561
struct netlink_ext_ack *extack = info->extack;
55425562
u8 genmask = nft_genmask_cur(info->net);
55435563
u8 family = info->nfmsg->nfgen_family;
5564+
int rem, err = 0, nelems = 0;
55445565
struct net *net = info->net;
55455566
struct nft_table *table;
55465567
struct nft_set *set;
55475568
struct nlattr *attr;
55485569
struct nft_ctx ctx;
55495570
bool reset = false;
5550-
int rem, err = 0;
55515571

55525572
table = nft_table_lookup(net, nla[NFTA_SET_ELEM_LIST_TABLE], family,
55535573
genmask, 0);
@@ -5590,8 +5610,13 @@ static int nf_tables_getsetelem(struct sk_buff *skb,
55905610
NL_SET_BAD_ATTR(extack, attr);
55915611
break;
55925612
}
5613+
nelems++;
55935614
}
55945615

5616+
if (reset)
5617+
audit_log_nft_set_reset(table, nft_pernet(net)->base_seq,
5618+
nelems);
5619+
55955620
return err;
55965621
}
55975622

0 commit comments

Comments
 (0)