0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/gfp.h>
0012
0013 #include "include/audit.h"
0014 #include "include/capability.h"
0015 #include "include/cred.h"
0016 #include "include/policy.h"
0017 #include "include/ipc.h"
0018 #include "include/sig_names.h"
0019
0020
0021 static inline int map_signal_num(int sig)
0022 {
0023 if (sig > SIGRTMAX)
0024 return SIGUNKNOWN;
0025 else if (sig >= SIGRTMIN)
0026 return sig - SIGRTMIN + SIGRT_BASE;
0027 else if (sig < MAXMAPPED_SIG)
0028 return sig_map[sig];
0029 return SIGUNKNOWN;
0030 }
0031
0032
0033
0034
0035
0036
0037
0038 static const char *audit_signal_mask(u32 mask)
0039 {
0040 if (mask & MAY_READ)
0041 return "receive";
0042 if (mask & MAY_WRITE)
0043 return "send";
0044 return "";
0045 }
0046
0047
0048
0049
0050
0051
0052 static void audit_signal_cb(struct audit_buffer *ab, void *va)
0053 {
0054 struct common_audit_data *sa = va;
0055
0056 if (aad(sa)->request & AA_SIGNAL_PERM_MASK) {
0057 audit_log_format(ab, " requested_mask=\"%s\"",
0058 audit_signal_mask(aad(sa)->request));
0059 if (aad(sa)->denied & AA_SIGNAL_PERM_MASK) {
0060 audit_log_format(ab, " denied_mask=\"%s\"",
0061 audit_signal_mask(aad(sa)->denied));
0062 }
0063 }
0064 if (aad(sa)->signal == SIGUNKNOWN)
0065 audit_log_format(ab, "signal=unknown(%d)",
0066 aad(sa)->unmappedsig);
0067 else if (aad(sa)->signal < MAXMAPPED_SIGNAME)
0068 audit_log_format(ab, " signal=%s", sig_names[aad(sa)->signal]);
0069 else
0070 audit_log_format(ab, " signal=rtmin+%d",
0071 aad(sa)->signal - SIGRT_BASE);
0072 audit_log_format(ab, " peer=");
0073 aa_label_xaudit(ab, labels_ns(aad(sa)->label), aad(sa)->peer,
0074 FLAGS_NONE, GFP_ATOMIC);
0075 }
0076
0077 static int profile_signal_perm(struct aa_profile *profile,
0078 struct aa_label *peer, u32 request,
0079 struct common_audit_data *sa)
0080 {
0081 struct aa_perms perms;
0082 unsigned int state;
0083
0084 if (profile_unconfined(profile) ||
0085 !PROFILE_MEDIATES(profile, AA_CLASS_SIGNAL))
0086 return 0;
0087
0088 aad(sa)->peer = peer;
0089
0090 state = aa_dfa_next(profile->policy.dfa,
0091 profile->policy.start[AA_CLASS_SIGNAL],
0092 aad(sa)->signal);
0093 aa_label_match(profile, peer, state, false, request, &perms);
0094 aa_apply_modes_to_perms(profile, &perms);
0095 return aa_check_perms(profile, &perms, request, sa, audit_signal_cb);
0096 }
0097
0098 int aa_may_signal(struct aa_label *sender, struct aa_label *target, int sig)
0099 {
0100 struct aa_profile *profile;
0101 DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_SIGNAL);
0102
0103 aad(&sa)->signal = map_signal_num(sig);
0104 aad(&sa)->unmappedsig = sig;
0105 return xcheck_labels(sender, target, profile,
0106 profile_signal_perm(profile, target, MAY_WRITE, &sa),
0107 profile_signal_perm(profile, sender, MAY_READ, &sa));
0108 }