0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef __AA_NET_H
0012 #define __AA_NET_H
0013
0014 #include <net/sock.h>
0015 #include <linux/path.h>
0016
0017 #include "apparmorfs.h"
0018 #include "label.h"
0019 #include "perms.h"
0020 #include "policy.h"
0021
0022 #define AA_MAY_SEND AA_MAY_WRITE
0023 #define AA_MAY_RECEIVE AA_MAY_READ
0024
0025 #define AA_MAY_SHUTDOWN AA_MAY_DELETE
0026
0027 #define AA_MAY_CONNECT AA_MAY_OPEN
0028 #define AA_MAY_ACCEPT 0x00100000
0029
0030 #define AA_MAY_BIND 0x00200000
0031 #define AA_MAY_LISTEN 0x00400000
0032
0033 #define AA_MAY_SETOPT 0x01000000
0034 #define AA_MAY_GETOPT 0x02000000
0035
0036 #define NET_PERMS_MASK (AA_MAY_SEND | AA_MAY_RECEIVE | AA_MAY_CREATE | \
0037 AA_MAY_SHUTDOWN | AA_MAY_BIND | AA_MAY_LISTEN | \
0038 AA_MAY_CONNECT | AA_MAY_ACCEPT | AA_MAY_SETATTR | \
0039 AA_MAY_GETATTR | AA_MAY_SETOPT | AA_MAY_GETOPT)
0040
0041 #define NET_FS_PERMS (AA_MAY_SEND | AA_MAY_RECEIVE | AA_MAY_CREATE | \
0042 AA_MAY_SHUTDOWN | AA_MAY_CONNECT | AA_MAY_RENAME |\
0043 AA_MAY_SETATTR | AA_MAY_GETATTR | AA_MAY_CHMOD | \
0044 AA_MAY_CHOWN | AA_MAY_CHGRP | AA_MAY_LOCK | \
0045 AA_MAY_MPROT)
0046
0047 #define NET_PEER_MASK (AA_MAY_SEND | AA_MAY_RECEIVE | AA_MAY_CONNECT | \
0048 AA_MAY_ACCEPT)
0049 struct aa_sk_ctx {
0050 struct aa_label *label;
0051 struct aa_label *peer;
0052 };
0053
0054 #define SK_CTX(X) ((X)->sk_security)
0055 #define SOCK_ctx(X) SOCK_INODE(X)->i_security
0056 #define DEFINE_AUDIT_NET(NAME, OP, SK, F, T, P) \
0057 struct lsm_network_audit NAME ## _net = { .sk = (SK), \
0058 .family = (F)}; \
0059 DEFINE_AUDIT_DATA(NAME, \
0060 ((SK) && (F) != AF_UNIX) ? LSM_AUDIT_DATA_NET : \
0061 LSM_AUDIT_DATA_NONE, \
0062 OP); \
0063 NAME.u.net = &(NAME ## _net); \
0064 aad(&NAME)->net.type = (T); \
0065 aad(&NAME)->net.protocol = (P)
0066
0067 #define DEFINE_AUDIT_SK(NAME, OP, SK) \
0068 DEFINE_AUDIT_NET(NAME, OP, SK, (SK)->sk_family, (SK)->sk_type, \
0069 (SK)->sk_protocol)
0070
0071
0072 #define af_select(FAMILY, FN, DEF_FN) \
0073 ({ \
0074 int __e; \
0075 switch ((FAMILY)) { \
0076 default: \
0077 __e = DEF_FN; \
0078 } \
0079 __e; \
0080 })
0081
0082 struct aa_secmark {
0083 u8 audit;
0084 u8 deny;
0085 u32 secid;
0086 char *label;
0087 };
0088
0089 extern struct aa_sfs_entry aa_sfs_entry_network[];
0090
0091 void audit_net_cb(struct audit_buffer *ab, void *va);
0092 int aa_profile_af_perm(struct aa_profile *profile, struct common_audit_data *sa,
0093 u32 request, u16 family, int type);
0094 int aa_af_perm(struct aa_label *label, const char *op, u32 request, u16 family,
0095 int type, int protocol);
0096 static inline int aa_profile_af_sk_perm(struct aa_profile *profile,
0097 struct common_audit_data *sa,
0098 u32 request,
0099 struct sock *sk)
0100 {
0101 return aa_profile_af_perm(profile, sa, request, sk->sk_family,
0102 sk->sk_type);
0103 }
0104 int aa_sk_perm(const char *op, u32 request, struct sock *sk);
0105
0106 int aa_sock_file_perm(struct aa_label *label, const char *op, u32 request,
0107 struct socket *sock);
0108
0109 int apparmor_secmark_check(struct aa_label *label, char *op, u32 request,
0110 u32 secid, const struct sock *sk);
0111
0112 #endif