Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * AppArmor security module
4 *
5 * This file contains AppArmor network mediation definitions.
6 *
7 * Copyright (C) 1998-2008 Novell/SUSE
8 * Copyright 2009-2017 Canonical Ltd.
9 */
10
11#ifndef __AA_NET_H
12#define __AA_NET_H
13
14#include <net/sock.h>
15#include <linux/path.h>
16
17#include "apparmorfs.h"
18#include "label.h"
19#include "perms.h"
20#include "policy.h"
21
22#define AA_MAY_SEND AA_MAY_WRITE
23#define AA_MAY_RECEIVE AA_MAY_READ
24
25#define AA_MAY_SHUTDOWN AA_MAY_DELETE
26
27#define AA_MAY_CONNECT AA_MAY_OPEN
28#define AA_MAY_ACCEPT 0x00100000
29
30#define AA_MAY_BIND 0x00200000
31#define AA_MAY_LISTEN 0x00400000
32
33#define AA_MAY_SETOPT 0x01000000
34#define AA_MAY_GETOPT 0x02000000
35
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)
40
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 | \
45 AA_MAY_MPROT)
46
47#define NET_PEER_MASK (AA_MAY_SEND | AA_MAY_RECEIVE | AA_MAY_CONNECT | \
48 AA_MAY_ACCEPT)
49struct aa_sk_ctx {
50 struct aa_label __rcu *label;
51 struct aa_label __rcu *peer;
52 struct aa_label __rcu *peer_lastupdate; /* ptr cmp only, no deref */
53};
54
55static inline struct aa_sk_ctx *aa_sock(const struct sock *sk)
56{
57 return sk->sk_security + apparmor_blob_sizes.lbs_sock;
58}
59
60#define DEFINE_AUDIT_NET(NAME, OP, CRED, SK, F, T, P) \
61 struct lsm_network_audit NAME ## _net = { .sk = (SK), \
62 .family = (F)}; \
63 DEFINE_AUDIT_DATA(NAME, \
64 ((SK) && (F) != AF_UNIX) ? LSM_AUDIT_DATA_NET : \
65 LSM_AUDIT_DATA_NONE, \
66 AA_CLASS_NET, \
67 OP); \
68 NAME.common.u.net = &(NAME ## _net); \
69 NAME.subj_cred = (CRED); \
70 NAME.net.type = (T); \
71 NAME.net.protocol = (P)
72
73#define DEFINE_AUDIT_SK(NAME, OP, CRED, SK) \
74 DEFINE_AUDIT_NET(NAME, OP, CRED, SK, (SK)->sk_family, (SK)->sk_type, \
75 (SK)->sk_protocol)
76
77
78struct aa_secmark {
79 u8 audit;
80 u8 deny;
81 u32 secid;
82 char *label;
83};
84
85extern struct aa_sfs_entry aa_sfs_entry_network[];
86extern struct aa_sfs_entry aa_sfs_entry_networkv9[];
87
88int aa_do_perms(struct aa_profile *profile, struct aa_policydb *policy,
89 aa_state_t state, u32 request, struct aa_perms *p,
90 struct apparmor_audit_data *ad);
91/* passing in state returned by XXX_mediates_AF() */
92aa_state_t aa_match_to_prot(struct aa_policydb *policy, aa_state_t state,
93 u32 request, u16 af, int type, int protocol,
94 struct aa_perms **p, const char **info);
95void audit_net_cb(struct audit_buffer *ab, void *va);
96int aa_profile_af_perm(struct aa_profile *profile,
97 struct apparmor_audit_data *ad,
98 u32 request, u16 family, int type, int protocol);
99int aa_af_perm(const struct cred *subj_cred, struct aa_label *label,
100 const char *op, u32 request, u16 family,
101 int type, int protocol);
102static inline int aa_profile_af_sk_perm(struct aa_profile *profile,
103 struct apparmor_audit_data *ad,
104 u32 request,
105 struct sock *sk)
106{
107 return aa_profile_af_perm(profile, ad, request, sk->sk_family,
108 sk->sk_type, sk->sk_protocol);
109}
110int aa_sk_perm(const char *op, u32 request, struct sock *sk);
111
112int aa_sock_file_perm(const struct cred *subj_cred, struct aa_label *label,
113 const char *op, u32 request,
114 struct file *file);
115
116int apparmor_secmark_check(struct aa_label *label, char *op, u32 request,
117 u32 secid, const struct sock *sk);
118
119#endif /* __AA_NET_H */