Lines Matching +full:a +full:- +full:h

1 // SPDX-License-Identifier: GPL-2.0-only
11 #include <linux/types.h>
12 #include <linux/stddef.h>
13 #include <linux/kernel.h>
14 #include <linux/gfp.h>
15 #include <linux/fs.h>
16 #include <linux/init.h>
17 #include <net/sock.h>
18 #include <linux/un.h>
19 #include <net/af_unix.h>
20 #include <linux/audit.h>
21 #include <linux/ipv6.h>
22 #include <linux/ip.h>
23 #include <net/ip.h>
24 #include <net/ipv6.h>
25 #include <linux/tcp.h>
26 #include <linux/udp.h>
27 #include <linux/dccp.h>
28 #include <linux/sctp.h>
29 #include <linux/lsm_audit.h>
30 #include <linux/security.h>
47 ad->u.net->v4info.saddr = ih->saddr; in ipv4_skb_to_auditdata()
48 ad->u.net->v4info.daddr = ih->daddr; in ipv4_skb_to_auditdata()
51 *proto = ih->protocol; in ipv4_skb_to_auditdata()
53 if (ntohs(ih->frag_off) & IP_OFFSET) in ipv4_skb_to_auditdata()
56 switch (ih->protocol) { in ipv4_skb_to_auditdata()
60 ad->u.net->sport = th->source; in ipv4_skb_to_auditdata()
61 ad->u.net->dport = th->dest; in ipv4_skb_to_auditdata()
67 ad->u.net->sport = uh->source; in ipv4_skb_to_auditdata()
68 ad->u.net->dport = uh->dest; in ipv4_skb_to_auditdata()
74 ad->u.net->sport = dh->dccph_sport; in ipv4_skb_to_auditdata()
75 ad->u.net->dport = dh->dccph_dport; in ipv4_skb_to_auditdata()
81 ad->u.net->sport = sh->source; in ipv4_skb_to_auditdata()
82 ad->u.net->dport = sh->dest; in ipv4_skb_to_auditdata()
86 ret = -EINVAL; in ipv4_skb_to_auditdata()
108 ad->u.net->v6info.saddr = ip6->saddr; in ipv6_skb_to_auditdata()
109 ad->u.net->v6info.daddr = ip6->daddr; in ipv6_skb_to_auditdata()
114 nexthdr = ip6->nexthdr; in ipv6_skb_to_auditdata()
128 ad->u.net->sport = th->source; in ipv6_skb_to_auditdata()
129 ad->u.net->dport = th->dest; in ipv6_skb_to_auditdata()
139 ad->u.net->sport = uh->source; in ipv6_skb_to_auditdata()
140 ad->u.net->dport = uh->dest; in ipv6_skb_to_auditdata()
150 ad->u.net->sport = dh->dccph_sport; in ipv6_skb_to_auditdata()
151 ad->u.net->dport = dh->dccph_dport; in ipv6_skb_to_auditdata()
160 ad->u.net->sport = sh->source; in ipv6_skb_to_auditdata()
161 ad->u.net->dport = sh->dest; in ipv6_skb_to_auditdata()
165 ret = -EINVAL; in ipv6_skb_to_auditdata()
192 * dump_common_audit_data - helper to dump common audit data
194 * @a : common audit data
198 struct common_audit_data *a) in dump_common_audit_data() argument
200 char comm[sizeof(current->comm)]; in dump_common_audit_data()
207 BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2); in dump_common_audit_data()
212 switch (a->type) { in dump_common_audit_data()
216 audit_log_format(ab, " ipc_key=%d ", a->u.ipc_id); in dump_common_audit_data()
219 audit_log_format(ab, " capability=%d ", a->u.cap); in dump_common_audit_data()
224 audit_log_d_path(ab, " path=", &a->u.path); in dump_common_audit_data()
226 inode = d_backing_inode(a->u.path.dentry); in dump_common_audit_data()
229 audit_log_untrustedstring(ab, inode->i_sb->s_id); in dump_common_audit_data()
230 audit_log_format(ab, " ino=%lu", inode->i_ino); in dump_common_audit_data()
237 audit_log_d_path(ab, " path=", &a->u.file->f_path); in dump_common_audit_data()
239 inode = file_inode(a->u.file); in dump_common_audit_data()
242 audit_log_untrustedstring(ab, inode->i_sb->s_id); in dump_common_audit_data()
243 audit_log_format(ab, " ino=%lu", inode->i_ino); in dump_common_audit_data()
250 audit_log_d_path(ab, " path=", &a->u.op->path); in dump_common_audit_data()
252 inode = a->u.op->path.dentry->d_inode; in dump_common_audit_data()
255 audit_log_untrustedstring(ab, inode->i_sb->s_id); in dump_common_audit_data()
256 audit_log_format(ab, " ino=%lu", inode->i_ino); in dump_common_audit_data()
259 audit_log_format(ab, " ioctlcmd=0x%hx", a->u.op->cmd); in dump_common_audit_data()
266 spin_lock(&a->u.dentry->d_lock); in dump_common_audit_data()
267 audit_log_untrustedstring(ab, a->u.dentry->d_name.name); in dump_common_audit_data()
268 spin_unlock(&a->u.dentry->d_lock); in dump_common_audit_data()
270 inode = d_backing_inode(a->u.dentry); in dump_common_audit_data()
273 audit_log_untrustedstring(ab, inode->i_sb->s_id); in dump_common_audit_data()
274 audit_log_format(ab, " ino=%lu", inode->i_ino); in dump_common_audit_data()
283 inode = a->u.inode; in dump_common_audit_data()
287 spin_lock(&dentry->d_lock); in dump_common_audit_data()
288 audit_log_untrustedstring(ab, dentry->d_name.name); in dump_common_audit_data()
289 spin_unlock(&dentry->d_lock); in dump_common_audit_data()
292 audit_log_untrustedstring(ab, inode->i_sb->s_id); in dump_common_audit_data()
293 audit_log_format(ab, " ino=%lu", inode->i_ino); in dump_common_audit_data()
298 struct task_struct *tsk = a->u.tsk; in dump_common_audit_data()
302 char comm[sizeof(tsk->comm)]; in dump_common_audit_data()
311 if (a->u.net->sk) { in dump_common_audit_data()
312 const struct sock *sk = a->u.net->sk; in dump_common_audit_data()
318 switch (sk->sk_family) { in dump_common_audit_data()
322 print_ipv4_addr(ab, inet->inet_rcv_saddr, in dump_common_audit_data()
323 inet->inet_sport, in dump_common_audit_data()
325 print_ipv4_addr(ab, inet->inet_daddr, in dump_common_audit_data()
326 inet->inet_dport, in dump_common_audit_data()
334 print_ipv6_addr(ab, &sk->sk_v6_rcv_saddr, in dump_common_audit_data()
335 inet->inet_sport, in dump_common_audit_data()
337 print_ipv6_addr(ab, &sk->sk_v6_daddr, in dump_common_audit_data()
338 inet->inet_dport, in dump_common_audit_data()
345 addr = smp_load_acquire(&u->addr); in dump_common_audit_data()
348 if (u->path.dentry) { in dump_common_audit_data()
349 audit_log_d_path(ab, " path=", &u->path); in dump_common_audit_data()
352 len = addr->len-sizeof(short); in dump_common_audit_data()
353 p = &addr->name->sun_path[0]; in dump_common_audit_data()
363 switch (a->u.net->family) { in dump_common_audit_data()
365 print_ipv4_addr(ab, a->u.net->v4info.saddr, in dump_common_audit_data()
366 a->u.net->sport, in dump_common_audit_data()
368 print_ipv4_addr(ab, a->u.net->v4info.daddr, in dump_common_audit_data()
369 a->u.net->dport, in dump_common_audit_data()
373 print_ipv6_addr(ab, &a->u.net->v6info.saddr, in dump_common_audit_data()
374 a->u.net->sport, in dump_common_audit_data()
376 print_ipv6_addr(ab, &a->u.net->v6info.daddr, in dump_common_audit_data()
377 a->u.net->dport, in dump_common_audit_data()
381 if (a->u.net->netif > 0) { in dump_common_audit_data()
385 dev = dev_get_by_index(&init_net, a->u.net->netif); in dump_common_audit_data()
387 audit_log_format(ab, " netif=%s", dev->name); in dump_common_audit_data()
394 audit_log_format(ab, " key_serial=%u", a->u.key_struct.key); in dump_common_audit_data()
395 if (a->u.key_struct.key_desc) { in dump_common_audit_data()
397 audit_log_untrustedstring(ab, a->u.key_struct.key_desc); in dump_common_audit_data()
403 audit_log_untrustedstring(ab, a->u.kmod_name); in dump_common_audit_data()
410 memcpy(&sbn_pfx.s6_addr, &a->u.ibpkey->subnet_prefix, in dump_common_audit_data()
411 sizeof(a->u.ibpkey->subnet_prefix)); in dump_common_audit_data()
413 a->u.ibpkey->pkey, &sbn_pfx); in dump_common_audit_data()
418 a->u.ibendport->dev_name, in dump_common_audit_data()
419 a->u.ibendport->port); in dump_common_audit_data()
423 lockdown_reasons[a->u.reason]); in dump_common_audit_data()
426 audit_log_format(ab, " anonclass=%s", a->u.anonclass); in dump_common_audit_data()
428 } /* switch (a->type) */ in dump_common_audit_data()
432 * common_lsm_audit - generic LSM auditing function
433 * @a: auxiliary audit data
434 * @pre_audit: lsm-specific pre-audit callback
435 * @post_audit: lsm-specific post-audit callback
440 void common_lsm_audit(struct common_audit_data *a, in common_lsm_audit() argument
446 if (a == NULL) in common_lsm_audit()
456 pre_audit(ab, a); in common_lsm_audit()
458 dump_common_audit_data(ab, a); in common_lsm_audit()
461 post_audit(ab, a); in common_lsm_audit()