2 * AppArmor security module
4 * This file contains AppArmor network mediation definitions.
6 * Copyright (C) 1998-2008 Novell/SUSE
7 * Copyright 2009-2017 Canonical Ltd.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation, version 2 of the
19 #include <linux/path.h>
21 #include "apparmorfs.h"
26 #define AA_MAY_SEND AA_MAY_WRITE
27 #define AA_MAY_RECEIVE AA_MAY_READ
29 #define AA_MAY_SHUTDOWN AA_MAY_DELETE
31 #define AA_MAY_CONNECT AA_MAY_OPEN
32 #define AA_MAY_ACCEPT 0x00100000
34 #define AA_MAY_BIND 0x00200000
35 #define AA_MAY_LISTEN 0x00400000
37 #define AA_MAY_SETOPT 0x01000000
38 #define AA_MAY_GETOPT 0x02000000
40 #define NET_PERMS_MASK (AA_MAY_SEND | AA_MAY_RECEIVE | AA_MAY_CREATE | \
41 AA_MAY_SHUTDOWN | AA_MAY_BIND | AA_MAY_LISTEN | \
42 AA_MAY_CONNECT | AA_MAY_ACCEPT | AA_MAY_SETATTR | \
43 AA_MAY_GETATTR | AA_MAY_SETOPT | AA_MAY_GETOPT)
45 #define NET_FS_PERMS (AA_MAY_SEND | AA_MAY_RECEIVE | AA_MAY_CREATE | \
46 AA_MAY_SHUTDOWN | AA_MAY_CONNECT | AA_MAY_RENAME |\
47 AA_MAY_SETATTR | AA_MAY_GETATTR | AA_MAY_CHMOD | \
48 AA_MAY_CHOWN | AA_MAY_CHGRP | AA_MAY_LOCK | \
51 #define NET_PEER_MASK (AA_MAY_SEND | AA_MAY_RECEIVE | AA_MAY_CONNECT | \
54 struct aa_label
*label
;
55 struct aa_label
*peer
;
59 #define SK_CTX(X) ((X)->sk_security)
60 #define SOCK_ctx(X) SOCK_INODE(X)->i_security
61 #define DEFINE_AUDIT_NET(NAME, OP, SK, F, T, P) \
62 struct lsm_network_audit NAME ## _net = { .sk = (SK), \
64 DEFINE_AUDIT_DATA(NAME, \
65 ((SK) && (F) != AF_UNIX) ? LSM_AUDIT_DATA_NET : \
66 LSM_AUDIT_DATA_NONE, \
68 NAME.u.net = &(NAME ## _net); \
69 aad(&NAME)->net.type = (T); \
70 aad(&NAME)->net.protocol = (P)
72 #define DEFINE_AUDIT_SK(NAME, OP, SK) \
73 DEFINE_AUDIT_NET(NAME, OP, SK, (SK)->sk_family, (SK)->sk_type, \
76 /* struct aa_net - network confinement data
77 * @allow: basic network families permissions
78 * @audit: which network permissions to force audit
79 * @quiet: which network permissions to quiet rejects
88 extern struct aa_sfs_entry aa_sfs_entry_network
[];
90 void audit_net_cb(struct audit_buffer
*ab
, void *va
);
91 int aa_profile_af_perm(struct aa_profile
*profile
, struct common_audit_data
*sa
,
92 u32 request
, u16 family
, int type
);
93 int aa_af_perm(struct aa_label
*label
, const char *op
, u32 request
, u16 family
,
94 int type
, int protocol
);
95 static inline int aa_profile_af_sk_perm(struct aa_profile
*profile
,
96 struct common_audit_data
*sa
,
100 return aa_profile_af_perm(profile
, sa
, request
, sk
->sk_family
,
103 int aa_sk_perm(const char *op
, u32 request
, struct sock
*sk
);
105 int aa_sock_file_perm(struct aa_label
*label
, const char *op
, u32 request
,
106 struct socket
*sock
);
109 static inline void aa_free_net_rules(struct aa_net
*new)
114 #endif /* __AA_NET_H */