Skip to content

Commit 1422403

Browse files
rgbriggspcmoore
authored andcommitted
audit: add gfp parameter to audit_log_nfcfg
Fixed an inconsistent use of GFP flags in nft_obj_notify() that used GFP_KERNEL when a GFP flag was passed in to that function. Given this allocated memory was then used in audit_log_nfcfg() it led to an audit of all other GFP allocations in net/netfilter/nf_tables_api.c and a modification of audit_log_nfcfg() to accept a GFP parameter. Reported-by: Dan Carptenter <[email protected]> Signed-off-by: Richard Guy Briggs <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 8e6cf36 commit 1422403

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

include/linux/audit.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ extern void __audit_fanotify(unsigned int response);
404404
extern void __audit_tk_injoffset(struct timespec64 offset);
405405
extern void __audit_ntp_log(const struct audit_ntp_data *ad);
406406
extern void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries,
407-
enum audit_nfcfgop op);
407+
enum audit_nfcfgop op, gfp_t gfp);
408408

409409
static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
410410
{
@@ -542,10 +542,10 @@ static inline void audit_ntp_log(const struct audit_ntp_data *ad)
542542

543543
static inline void audit_log_nfcfg(const char *name, u8 af,
544544
unsigned int nentries,
545-
enum audit_nfcfgop op)
545+
enum audit_nfcfgop op, gfp_t gfp)
546546
{
547547
if (audit_enabled)
548-
__audit_log_nfcfg(name, af, nentries, op);
548+
__audit_log_nfcfg(name, af, nentries, op, gfp);
549549
}
550550

551551
extern int audit_n_rules;
@@ -683,7 +683,7 @@ static inline void audit_ptrace(struct task_struct *t)
683683

684684
static inline void audit_log_nfcfg(const char *name, u8 af,
685685
unsigned int nentries,
686-
enum audit_nfcfgop op)
686+
enum audit_nfcfgop op, gfp_t gfp)
687687
{ }
688688

689689
#define audit_n_rules 0

kernel/auditsc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,12 +2572,12 @@ void __audit_ntp_log(const struct audit_ntp_data *ad)
25722572
}
25732573

25742574
void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries,
2575-
enum audit_nfcfgop op)
2575+
enum audit_nfcfgop op, gfp_t gfp)
25762576
{
25772577
struct audit_buffer *ab;
25782578
char comm[sizeof(current->comm)];
25792579

2580-
ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_NETFILTER_CFG);
2580+
ab = audit_log_start(audit_context(), gfp, AUDIT_NETFILTER_CFG);
25812581
if (!ab)
25822582
return;
25832583
audit_log_format(ab, "table=%s family=%u entries=%u op=%s",

net/bridge/netfilter/ebtables.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ static int do_replace_finish(struct net *net, struct ebt_replace *repl,
10471047
vfree(counterstmp);
10481048

10491049
audit_log_nfcfg(repl->name, AF_BRIDGE, repl->nentries,
1050-
AUDIT_XT_OP_REPLACE);
1050+
AUDIT_XT_OP_REPLACE, GFP_KERNEL);
10511051
return ret;
10521052

10531053
free_unlock:
@@ -1123,7 +1123,7 @@ static void __ebt_unregister_table(struct net *net, struct ebt_table *table)
11231123
list_del(&table->list);
11241124
mutex_unlock(&ebt_mutex);
11251125
audit_log_nfcfg(table->name, AF_BRIDGE, table->private->nentries,
1126-
AUDIT_XT_OP_UNREGISTER);
1126+
AUDIT_XT_OP_UNREGISTER, GFP_KERNEL);
11271127
EBT_ENTRY_ITERATE(table->private->entries, table->private->entries_size,
11281128
ebt_cleanup_entry, net, NULL);
11291129
if (table->private->nentries)
@@ -1218,7 +1218,7 @@ int ebt_register_table(struct net *net, const struct ebt_table *input_table,
12181218
}
12191219

12201220
audit_log_nfcfg(repl->name, AF_BRIDGE, repl->nentries,
1221-
AUDIT_XT_OP_REGISTER);
1221+
AUDIT_XT_OP_REGISTER, GFP_KERNEL);
12221222
return ret;
12231223
free_unlock:
12241224
mutex_unlock(&ebt_mutex);

net/netfilter/nf_tables_api.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,8 @@ static void nf_tables_table_notify(const struct nft_ctx *ctx, int event)
702702
ctx->table->use,
703703
event == NFT_MSG_NEWTABLE ?
704704
AUDIT_NFT_OP_TABLE_REGISTER :
705-
AUDIT_NFT_OP_TABLE_UNREGISTER);
705+
AUDIT_NFT_OP_TABLE_UNREGISTER,
706+
GFP_KERNEL);
706707
kfree(buf);
707708

708709
if (!ctx->report &&
@@ -1448,7 +1449,8 @@ static void nf_tables_chain_notify(const struct nft_ctx *ctx, int event)
14481449
ctx->chain->use,
14491450
event == NFT_MSG_NEWCHAIN ?
14501451
AUDIT_NFT_OP_CHAIN_REGISTER :
1451-
AUDIT_NFT_OP_CHAIN_UNREGISTER);
1452+
AUDIT_NFT_OP_CHAIN_UNREGISTER,
1453+
GFP_KERNEL);
14521454
kfree(buf);
14531455

14541456
if (!ctx->report &&
@@ -2724,7 +2726,8 @@ static void nf_tables_rule_notify(const struct nft_ctx *ctx,
27242726
rule->handle,
27252727
event == NFT_MSG_NEWRULE ?
27262728
AUDIT_NFT_OP_RULE_REGISTER :
2727-
AUDIT_NFT_OP_RULE_UNREGISTER);
2729+
AUDIT_NFT_OP_RULE_UNREGISTER,
2730+
GFP_KERNEL);
27282731
kfree(buf);
27292732

27302733
if (!ctx->report &&
@@ -3737,7 +3740,8 @@ static void nf_tables_set_notify(const struct nft_ctx *ctx,
37373740
set->field_count,
37383741
event == NFT_MSG_NEWSET ?
37393742
AUDIT_NFT_OP_SET_REGISTER :
3740-
AUDIT_NFT_OP_SET_UNREGISTER);
3743+
AUDIT_NFT_OP_SET_UNREGISTER,
3744+
gfp_flags);
37413745
kfree(buf);
37423746

37433747
if (!ctx->report &&
@@ -4864,7 +4868,8 @@ static void nf_tables_setelem_notify(const struct nft_ctx *ctx,
48644868
set->handle,
48654869
event == NFT_MSG_NEWSETELEM ?
48664870
AUDIT_NFT_OP_SETELEM_REGISTER :
4867-
AUDIT_NFT_OP_SETELEM_UNREGISTER);
4871+
AUDIT_NFT_OP_SETELEM_UNREGISTER,
4872+
GFP_KERNEL);
48684873
kfree(buf);
48694874

48704875
if (!ctx->report && !nfnetlink_has_listeners(net, NFNLGRP_NFTABLES))
@@ -5956,7 +5961,8 @@ static int nf_tables_dump_obj(struct sk_buff *skb, struct netlink_callback *cb)
59565961
audit_log_nfcfg(buf,
59575962
family,
59585963
obj->handle,
5959-
AUDIT_NFT_OP_OBJ_RESET);
5964+
AUDIT_NFT_OP_OBJ_RESET,
5965+
GFP_KERNEL);
59605966
kfree(buf);
59615967
}
59625968

@@ -6071,13 +6077,14 @@ static int nf_tables_getobj(struct net *net, struct sock *nlsk,
60716077
reset = true;
60726078

60736079
if (reset) {
6074-
char *buf = kasprintf(GFP_KERNEL, "%s:%llu;?:0",
6080+
char *buf = kasprintf(GFP_ATOMIC, "%s:%llu;?:0",
60756081
table->name, table->handle);
60766082

60776083
audit_log_nfcfg(buf,
60786084
family,
60796085
obj->handle,
6080-
AUDIT_NFT_OP_OBJ_RESET);
6086+
AUDIT_NFT_OP_OBJ_RESET,
6087+
GFP_KERNEL);
60816088
kfree(buf);
60826089
}
60836090

@@ -6156,15 +6163,16 @@ void nft_obj_notify(struct net *net, const struct nft_table *table,
61566163
{
61576164
struct sk_buff *skb;
61586165
int err;
6159-
char *buf = kasprintf(GFP_KERNEL, "%s:%llu;?:0",
6166+
char *buf = kasprintf(gfp, "%s:%llu;?:0",
61606167
table->name, table->handle);
61616168

61626169
audit_log_nfcfg(buf,
61636170
family,
61646171
obj->handle,
61656172
event == NFT_MSG_NEWOBJ ?
61666173
AUDIT_NFT_OP_OBJ_REGISTER :
6167-
AUDIT_NFT_OP_OBJ_UNREGISTER);
6174+
AUDIT_NFT_OP_OBJ_UNREGISTER,
6175+
GFP_KERNEL);
61686176
kfree(buf);
61696177

61706178
if (!report &&
@@ -6954,7 +6962,8 @@ static void nf_tables_flowtable_notify(struct nft_ctx *ctx,
69546962
flowtable->hooknum,
69556963
event == NFT_MSG_NEWFLOWTABLE ?
69566964
AUDIT_NFT_OP_FLOWTABLE_REGISTER :
6957-
AUDIT_NFT_OP_FLOWTABLE_UNREGISTER);
6965+
AUDIT_NFT_OP_FLOWTABLE_UNREGISTER,
6966+
GFP_KERNEL);
69586967
kfree(buf);
69596968

69606969
if (ctx->report &&
@@ -7078,7 +7087,7 @@ static void nf_tables_gen_notify(struct net *net, struct sk_buff *skb,
70787087
int err;
70797088

70807089
audit_log_nfcfg("?:0;?:0", 0, net->nft.base_seq,
7081-
AUDIT_NFT_OP_GEN_REGISTER);
7090+
AUDIT_NFT_OP_GEN_REGISTER, GFP_KERNEL);
70827091

70837092
if (nlmsg_report(nlh) &&
70847093
!nfnetlink_has_listeners(net, NFNLGRP_NFTABLES))

net/netfilter/x_tables.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,8 @@ xt_replace_table(struct xt_table *table,
14101410

14111411
audit_log_nfcfg(table->name, table->af, private->number,
14121412
!private->number ? AUDIT_XT_OP_REGISTER :
1413-
AUDIT_XT_OP_REPLACE);
1413+
AUDIT_XT_OP_REPLACE,
1414+
GFP_KERNEL);
14141415
return private;
14151416
}
14161417
EXPORT_SYMBOL_GPL(xt_replace_table);
@@ -1473,7 +1474,7 @@ void *xt_unregister_table(struct xt_table *table)
14731474
list_del(&table->list);
14741475
mutex_unlock(&xt[table->af].mutex);
14751476
audit_log_nfcfg(table->name, table->af, private->number,
1476-
AUDIT_XT_OP_UNREGISTER);
1477+
AUDIT_XT_OP_UNREGISTER, GFP_KERNEL);
14771478
kfree(table);
14781479

14791480
return private;

0 commit comments

Comments
 (0)