1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * AppArmor security module
5 * This file contains AppArmor network mediation definitions.
7 * Copyright (C) 1998-2008 Novell/SUSE
8 * Copyright 2009-2017 Canonical Ltd.
15 #include <linux/path.h>
17 #include "apparmorfs.h"
22 #define AA_MAY_SEND AA_MAY_WRITE
23 #define AA_MAY_RECEIVE AA_MAY_READ
25 #define AA_MAY_SHUTDOWN AA_MAY_DELETE
27 #define AA_MAY_CONNECT AA_MAY_OPEN
28 #define AA_MAY_ACCEPT 0x00100000
30 #define AA_MAY_BIND 0x00200000
31 #define AA_MAY_LISTEN 0x00400000
33 #define AA_MAY_SETOPT 0x01000000
34 #define AA_MAY_GETOPT 0x02000000
36 #define NET_PERMS_MASK (AA_MAY_SEND | AA_MAY_RECEIVE | AA_MAY_CREATE | \
37 AA_MAY_SHUTDOWN | AA_MAY_BIND | AA_MAY_LISTEN | \
38 AA_MAY_CONNECT | AA_MAY_ACCEPT | AA_MAY_SETATTR | \
39 AA_MAY_GETATTR | AA_MAY_SETOPT | AA_MAY_GETOPT)
41 #define NET_FS_PERMS (AA_MAY_SEND | AA_MAY_RECEIVE | AA_MAY_CREATE | \
42 AA_MAY_SHUTDOWN | AA_MAY_CONNECT | AA_MAY_RENAME |\
43 AA_MAY_SETATTR | AA_MAY_GETATTR | AA_MAY_CHMOD | \
44 AA_MAY_CHOWN | AA_MAY_CHGRP | AA_MAY_LOCK | \
47 #define NET_PEER_MASK (AA_MAY_SEND | AA_MAY_RECEIVE | AA_MAY_CONNECT | \
50 struct aa_label *label;
51 struct aa_label *peer;
54 #define SK_CTX(X) ((X)->sk_security)
55 static inline struct aa_sk_ctx *aa_sock(const struct sock *sk)
57 return sk->sk_security;
60 #define DEFINE_AUDIT_NET(NAME, OP, SK, F, T, P) \
61 struct lsm_network_audit NAME ## _net = { .sk = (SK), \
63 DEFINE_AUDIT_DATA(NAME, \
64 ((SK) && (F) != AF_UNIX) ? LSM_AUDIT_DATA_NET : \
65 LSM_AUDIT_DATA_NONE, \
68 NAME.common.u.net = &(NAME ## _net); \
69 NAME.net.type = (T); \
70 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, \
77 #define af_select(FAMILY, FN, DEF_FN) \
94 extern struct aa_sfs_entry aa_sfs_entry_network[];
96 void audit_net_cb(struct audit_buffer *ab, void *va);
97 int aa_profile_af_perm(struct aa_profile *profile,
98 struct apparmor_audit_data *ad,
99 u32 request, u16 family, int type);
100 int aa_af_perm(const struct cred *subj_cred, struct aa_label *label,
101 const char *op, u32 request, u16 family,
102 int type, int protocol);
103 static inline int aa_profile_af_sk_perm(struct aa_profile *profile,
104 struct apparmor_audit_data *ad,
108 return aa_profile_af_perm(profile, ad, request, sk->sk_family,
111 int aa_sk_perm(const char *op, u32 request, struct sock *sk);
113 int aa_sock_file_perm(const struct cred *subj_cred, struct aa_label *label,
114 const char *op, u32 request,
115 struct socket *sock);
117 int apparmor_secmark_check(struct aa_label *label, char *op, u32 request,
118 u32 secid, const struct sock *sk);
120 #endif /* __AA_NET_H */