Skip to content

Commit 45a0642

Browse files
committed
audit: kernel generated netlink traffic should have a portid of 0
We were setting the portid incorrectly in the netlink message headers, fix that to always be 0 (nlmsg_pid = 0). Signed-off-by: Paul Moore <paul@paul-moore.com> Reviewed-by: Richard Guy Briggs <rgb@redhat.com>
1 parent a9d1620 commit 45a0642

4 files changed

Lines changed: 14 additions & 29 deletions

File tree

‎include/linux/audit.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ extern void audit_log_task_info(struct audit_buffer *ab,
163163
extern int audit_update_lsm_rules(void);
164164

165165
/* Private API (for audit.c only) */
166-
extern int audit_rule_change(int type, __u32 portid, int seq,
167-
void *data, size_t datasz);
166+
extern int audit_rule_change(int type, int seq, void *data, size_t datasz);
168167
extern int audit_list_rules_send(struct sk_buff *request_skb, int seq);
169168

170169
extern u32 audit_enabled;

‎kernel/audit.c‎

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,6 @@ static struct sock *audit_get_sk(const struct net *net)
250250
return aunet->sk;
251251
}
252252

253-
static void audit_set_portid(struct audit_buffer *ab, __u32 portid)
254-
{
255-
if (ab) {
256-
struct nlmsghdr *nlh = nlmsg_hdr(ab->skb);
257-
nlh->nlmsg_pid = portid;
258-
}
259-
}
260-
261253
void audit_panic(const char *message)
262254
{
263255
switch (audit_failure) {
@@ -816,7 +808,7 @@ int audit_send_list(void *_dest)
816808
return 0;
817809
}
818810

819-
struct sk_buff *audit_make_reply(__u32 portid, int seq, int type, int done,
811+
struct sk_buff *audit_make_reply(int seq, int type, int done,
820812
int multi, const void *payload, int size)
821813
{
822814
struct sk_buff *skb;
@@ -829,7 +821,7 @@ struct sk_buff *audit_make_reply(__u32 portid, int seq, int type, int done,
829821
if (!skb)
830822
return NULL;
831823

832-
nlh = nlmsg_put(skb, portid, seq, t, size, flags);
824+
nlh = nlmsg_put(skb, 0, seq, t, size, flags);
833825
if (!nlh)
834826
goto out_kfree_skb;
835827
data = nlmsg_data(nlh);
@@ -873,7 +865,6 @@ static int audit_send_reply_thread(void *arg)
873865
static void audit_send_reply(struct sk_buff *request_skb, int seq, int type, int done,
874866
int multi, const void *payload, int size)
875867
{
876-
u32 portid = NETLINK_CB(request_skb).portid;
877868
struct net *net = sock_net(NETLINK_CB(request_skb).sk);
878869
struct sk_buff *skb;
879870
struct task_struct *tsk;
@@ -883,12 +874,12 @@ static void audit_send_reply(struct sk_buff *request_skb, int seq, int type, int
883874
if (!reply)
884875
return;
885876

886-
skb = audit_make_reply(portid, seq, type, done, multi, payload, size);
877+
skb = audit_make_reply(seq, type, done, multi, payload, size);
887878
if (!skb)
888879
goto out;
889880

890881
reply->net = get_net(net);
891-
reply->portid = portid;
882+
reply->portid = NETLINK_CB(request_skb).portid;
892883
reply->skb = skb;
893884

894885
tsk = kthread_run(audit_send_reply_thread, reply, "audit_send_reply");
@@ -1072,7 +1063,7 @@ static int audit_replace(pid_t pid)
10721063
{
10731064
struct sk_buff *skb;
10741065

1075-
skb = audit_make_reply(0, 0, AUDIT_REPLACE, 0, 0, &pid, sizeof(pid));
1066+
skb = audit_make_reply(0, AUDIT_REPLACE, 0, 0, &pid, sizeof(pid));
10761067
if (!skb)
10771068
return -ENOMEM;
10781069
return auditd_send_unicast_skb(skb);
@@ -1242,7 +1233,6 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
12421233
size--;
12431234
audit_log_n_untrustedstring(ab, data, size);
12441235
}
1245-
audit_set_portid(ab, NETLINK_CB(skb).portid);
12461236
audit_log_end(ab);
12471237
}
12481238
break;
@@ -1256,8 +1246,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
12561246
audit_log_end(ab);
12571247
return -EPERM;
12581248
}
1259-
err = audit_rule_change(msg_type, NETLINK_CB(skb).portid,
1260-
seq, data, nlmsg_len(nlh));
1249+
err = audit_rule_change(msg_type, seq, data, nlmsg_len(nlh));
12611250
break;
12621251
case AUDIT_LIST_RULES:
12631252
err = audit_list_rules_send(skb, seq);

‎kernel/audit.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ extern int audit_uid_comparator(kuid_t left, u32 op, kuid_t right);
237237
extern int audit_gid_comparator(kgid_t left, u32 op, kgid_t right);
238238
extern int parent_len(const char *path);
239239
extern int audit_compare_dname_path(const char *dname, const char *path, int plen);
240-
extern struct sk_buff *audit_make_reply(__u32 portid, int seq, int type,
241-
int done, int multi,
240+
extern struct sk_buff *audit_make_reply(int seq, int type, int done, int multi,
242241
const void *payload, int size);
243242
extern void audit_panic(const char *message);
244243

‎kernel/auditfilter.c‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ int audit_del_rule(struct audit_entry *entry)
10331033
}
10341034

10351035
/* List rules using struct audit_rule_data. */
1036-
static void audit_list_rules(__u32 portid, int seq, struct sk_buff_head *q)
1036+
static void audit_list_rules(int seq, struct sk_buff_head *q)
10371037
{
10381038
struct sk_buff *skb;
10391039
struct audit_krule *r;
@@ -1048,15 +1048,15 @@ static void audit_list_rules(__u32 portid, int seq, struct sk_buff_head *q)
10481048
data = audit_krule_to_data(r);
10491049
if (unlikely(!data))
10501050
break;
1051-
skb = audit_make_reply(portid, seq, AUDIT_LIST_RULES,
1052-
0, 1, data,
1051+
skb = audit_make_reply(seq, AUDIT_LIST_RULES, 0, 1,
1052+
data,
10531053
sizeof(*data) + data->buflen);
10541054
if (skb)
10551055
skb_queue_tail(q, skb);
10561056
kfree(data);
10571057
}
10581058
}
1059-
skb = audit_make_reply(portid, seq, AUDIT_LIST_RULES, 1, 1, NULL, 0);
1059+
skb = audit_make_reply(seq, AUDIT_LIST_RULES, 1, 1, NULL, 0);
10601060
if (skb)
10611061
skb_queue_tail(q, skb);
10621062
}
@@ -1085,13 +1085,11 @@ static void audit_log_rule_change(char *action, struct audit_krule *rule, int re
10851085
/**
10861086
* audit_rule_change - apply all rules to the specified message type
10871087
* @type: audit message type
1088-
* @portid: target port id for netlink audit messages
10891088
* @seq: netlink audit message sequence (serial) number
10901089
* @data: payload data
10911090
* @datasz: size of payload data
10921091
*/
1093-
int audit_rule_change(int type, __u32 portid, int seq, void *data,
1094-
size_t datasz)
1092+
int audit_rule_change(int type, int seq, void *data, size_t datasz)
10951093
{
10961094
int err = 0;
10971095
struct audit_entry *entry;
@@ -1150,7 +1148,7 @@ int audit_list_rules_send(struct sk_buff *request_skb, int seq)
11501148
skb_queue_head_init(&dest->q);
11511149

11521150
mutex_lock(&audit_filter_mutex);
1153-
audit_list_rules(portid, seq, &dest->q);
1151+
audit_list_rules(seq, &dest->q);
11541152
mutex_unlock(&audit_filter_mutex);
11551153

11561154
tsk = kthread_run(audit_send_list, dest, "audit_send_list");

0 commit comments

Comments
 (0)