diff options
author | Paul Moore <paul@paul-moore.com> | 2017-05-02 10:16:05 -0400 |
---|---|---|
committer | Paul Moore <paul@paul-moore.com> | 2017-05-02 10:16:05 -0400 |
commit | 45a0642b4d021a2f50d5db9c191b5bfe60bfa1c7 (patch) | |
tree | d63e9090ba3ebaa02cb6c94717b5c285c1fd93ec | |
parent | a9d1620877748375cf60b43ef3fa5f61ab6d9f24 (diff) |
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>
-rw-r--r-- | include/linux/audit.h | 3 | ||||
-rw-r--r-- | kernel/audit.c | 23 | ||||
-rw-r--r-- | kernel/audit.h | 3 | ||||
-rw-r--r-- | kernel/auditfilter.c | 14 |
4 files changed, 14 insertions, 29 deletions
diff --git a/include/linux/audit.h b/include/linux/audit.h index 504e784b7ffa..cc0497c39472 100644 --- a/include/linux/audit.h +++ b/include/linux/audit.h | |||
@@ -163,8 +163,7 @@ extern void audit_log_task_info(struct audit_buffer *ab, | |||
163 | extern int audit_update_lsm_rules(void); | 163 | extern int audit_update_lsm_rules(void); |
164 | 164 | ||
165 | /* Private API (for audit.c only) */ | 165 | /* Private API (for audit.c only) */ |
166 | extern int audit_rule_change(int type, __u32 portid, int seq, | 166 | extern int audit_rule_change(int type, int seq, void *data, size_t datasz); |
167 | void *data, size_t datasz); | ||
168 | extern int audit_list_rules_send(struct sk_buff *request_skb, int seq); | 167 | extern int audit_list_rules_send(struct sk_buff *request_skb, int seq); |
169 | 168 | ||
170 | extern u32 audit_enabled; | 169 | extern u32 audit_enabled; |
diff --git a/kernel/audit.c b/kernel/audit.c index eff602c1aa79..b40f3c4727e1 100644 --- a/kernel/audit.c +++ b/kernel/audit.c | |||
@@ -250,14 +250,6 @@ static struct sock *audit_get_sk(const struct net *net) | |||
250 | return aunet->sk; | 250 | return aunet->sk; |
251 | } | 251 | } |
252 | 252 | ||
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 | |||
261 | void audit_panic(const char *message) | 253 | void audit_panic(const char *message) |
262 | { | 254 | { |
263 | switch (audit_failure) { | 255 | switch (audit_failure) { |
@@ -816,7 +808,7 @@ int audit_send_list(void *_dest) | |||
816 | return 0; | 808 | return 0; |
817 | } | 809 | } |
818 | 810 | ||
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, |
820 | int multi, const void *payload, int size) | 812 | int multi, const void *payload, int size) |
821 | { | 813 | { |
822 | struct sk_buff *skb; | 814 | struct sk_buff *skb; |
@@ -829,7 +821,7 @@ struct sk_buff *audit_make_reply(__u32 portid, int seq, int type, int done, | |||
829 | if (!skb) | 821 | if (!skb) |
830 | return NULL; | 822 | return NULL; |
831 | 823 | ||
832 | nlh = nlmsg_put(skb, portid, seq, t, size, flags); | 824 | nlh = nlmsg_put(skb, 0, seq, t, size, flags); |
833 | if (!nlh) | 825 | if (!nlh) |
834 | goto out_kfree_skb; | 826 | goto out_kfree_skb; |
835 | data = nlmsg_data(nlh); | 827 | data = nlmsg_data(nlh); |
@@ -873,7 +865,6 @@ static int audit_send_reply_thread(void *arg) | |||
873 | static void audit_send_reply(struct sk_buff *request_skb, int seq, int type, int done, | 865 | static void audit_send_reply(struct sk_buff *request_skb, int seq, int type, int done, |
874 | int multi, const void *payload, int size) | 866 | int multi, const void *payload, int size) |
875 | { | 867 | { |
876 | u32 portid = NETLINK_CB(request_skb).portid; | ||
877 | struct net *net = sock_net(NETLINK_CB(request_skb).sk); | 868 | struct net *net = sock_net(NETLINK_CB(request_skb).sk); |
878 | struct sk_buff *skb; | 869 | struct sk_buff *skb; |
879 | struct task_struct *tsk; | 870 | struct task_struct *tsk; |
@@ -883,12 +874,12 @@ static void audit_send_reply(struct sk_buff *request_skb, int seq, int type, int | |||
883 | if (!reply) | 874 | if (!reply) |
884 | return; | 875 | return; |
885 | 876 | ||
886 | skb = audit_make_reply(portid, seq, type, done, multi, payload, size); | 877 | skb = audit_make_reply(seq, type, done, multi, payload, size); |
887 | if (!skb) | 878 | if (!skb) |
888 | goto out; | 879 | goto out; |
889 | 880 | ||
890 | reply->net = get_net(net); | 881 | reply->net = get_net(net); |
891 | reply->portid = portid; | 882 | reply->portid = NETLINK_CB(request_skb).portid; |
892 | reply->skb = skb; | 883 | reply->skb = skb; |
893 | 884 | ||
894 | tsk = kthread_run(audit_send_reply_thread, reply, "audit_send_reply"); | 885 | tsk = kthread_run(audit_send_reply_thread, reply, "audit_send_reply"); |
@@ -1072,7 +1063,7 @@ static int audit_replace(pid_t pid) | |||
1072 | { | 1063 | { |
1073 | struct sk_buff *skb; | 1064 | struct sk_buff *skb; |
1074 | 1065 | ||
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)); |
1076 | if (!skb) | 1067 | if (!skb) |
1077 | return -ENOMEM; | 1068 | return -ENOMEM; |
1078 | return auditd_send_unicast_skb(skb); | 1069 | return auditd_send_unicast_skb(skb); |
@@ -1242,7 +1233,6 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
1242 | size--; | 1233 | size--; |
1243 | audit_log_n_untrustedstring(ab, data, size); | 1234 | audit_log_n_untrustedstring(ab, data, size); |
1244 | } | 1235 | } |
1245 | audit_set_portid(ab, NETLINK_CB(skb).portid); | ||
1246 | audit_log_end(ab); | 1236 | audit_log_end(ab); |
1247 | } | 1237 | } |
1248 | break; | 1238 | break; |
@@ -1256,8 +1246,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
1256 | audit_log_end(ab); | 1246 | audit_log_end(ab); |
1257 | return -EPERM; | 1247 | return -EPERM; |
1258 | } | 1248 | } |
1259 | err = audit_rule_change(msg_type, NETLINK_CB(skb).portid, | 1249 | err = audit_rule_change(msg_type, seq, data, nlmsg_len(nlh)); |
1260 | seq, data, nlmsg_len(nlh)); | ||
1261 | break; | 1250 | break; |
1262 | case AUDIT_LIST_RULES: | 1251 | case AUDIT_LIST_RULES: |
1263 | err = audit_list_rules_send(skb, seq); | 1252 | err = audit_list_rules_send(skb, seq); |
diff --git a/kernel/audit.h b/kernel/audit.h index 0d87f8ab8778..18f3c2deeccf 100644 --- a/kernel/audit.h +++ b/kernel/audit.h | |||
@@ -237,8 +237,7 @@ extern int audit_uid_comparator(kuid_t left, u32 op, kuid_t right); | |||
237 | extern int audit_gid_comparator(kgid_t left, u32 op, kgid_t right); | 237 | extern int audit_gid_comparator(kgid_t left, u32 op, kgid_t right); |
238 | extern int parent_len(const char *path); | 238 | extern int parent_len(const char *path); |
239 | extern int audit_compare_dname_path(const char *dname, const char *path, int plen); | 239 | 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, | 240 | extern struct sk_buff *audit_make_reply(int seq, int type, int done, int multi, |
241 | int done, int multi, | ||
242 | const void *payload, int size); | 241 | const void *payload, int size); |
243 | extern void audit_panic(const char *message); | 242 | extern void audit_panic(const char *message); |
244 | 243 | ||
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index 239d11c3122c..0b0aa5854dac 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c | |||
@@ -1033,7 +1033,7 @@ out: | |||
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | /* List rules using struct audit_rule_data. */ | 1035 | /* 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) |
1037 | { | 1037 | { |
1038 | struct sk_buff *skb; | 1038 | struct sk_buff *skb; |
1039 | struct audit_krule *r; | 1039 | struct audit_krule *r; |
@@ -1048,15 +1048,15 @@ static void audit_list_rules(__u32 portid, int seq, struct sk_buff_head *q) | |||
1048 | data = audit_krule_to_data(r); | 1048 | data = audit_krule_to_data(r); |
1049 | if (unlikely(!data)) | 1049 | if (unlikely(!data)) |
1050 | break; | 1050 | break; |
1051 | skb = audit_make_reply(portid, seq, AUDIT_LIST_RULES, | 1051 | skb = audit_make_reply(seq, AUDIT_LIST_RULES, 0, 1, |
1052 | 0, 1, data, | 1052 | data, |
1053 | sizeof(*data) + data->buflen); | 1053 | sizeof(*data) + data->buflen); |
1054 | if (skb) | 1054 | if (skb) |
1055 | skb_queue_tail(q, skb); | 1055 | skb_queue_tail(q, skb); |
1056 | kfree(data); | 1056 | kfree(data); |
1057 | } | 1057 | } |
1058 | } | 1058 | } |
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); |
1060 | if (skb) | 1060 | if (skb) |
1061 | skb_queue_tail(q, skb); | 1061 | skb_queue_tail(q, skb); |
1062 | } | 1062 | } |
@@ -1085,13 +1085,11 @@ static void audit_log_rule_change(char *action, struct audit_krule *rule, int re | |||
1085 | /** | 1085 | /** |
1086 | * audit_rule_change - apply all rules to the specified message type | 1086 | * audit_rule_change - apply all rules to the specified message type |
1087 | * @type: audit message type | 1087 | * @type: audit message type |
1088 | * @portid: target port id for netlink audit messages | ||
1089 | * @seq: netlink audit message sequence (serial) number | 1088 | * @seq: netlink audit message sequence (serial) number |
1090 | * @data: payload data | 1089 | * @data: payload data |
1091 | * @datasz: size of payload data | 1090 | * @datasz: size of payload data |
1092 | */ | 1091 | */ |
1093 | int audit_rule_change(int type, __u32 portid, int seq, void *data, | 1092 | int audit_rule_change(int type, int seq, void *data, size_t datasz) |
1094 | size_t datasz) | ||
1095 | { | 1093 | { |
1096 | int err = 0; | 1094 | int err = 0; |
1097 | struct audit_entry *entry; | 1095 | struct audit_entry *entry; |
@@ -1150,7 +1148,7 @@ int audit_list_rules_send(struct sk_buff *request_skb, int seq) | |||
1150 | skb_queue_head_init(&dest->q); | 1148 | skb_queue_head_init(&dest->q); |
1151 | 1149 | ||
1152 | mutex_lock(&audit_filter_mutex); | 1150 | mutex_lock(&audit_filter_mutex); |
1153 | audit_list_rules(portid, seq, &dest->q); | 1151 | audit_list_rules(seq, &dest->q); |
1154 | mutex_unlock(&audit_filter_mutex); | 1152 | mutex_unlock(&audit_filter_mutex); |
1155 | 1153 | ||
1156 | tsk = kthread_run(audit_send_list, dest, "audit_send_list"); | 1154 | tsk = kthread_run(audit_send_list, dest, "audit_send_list"); |