Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * AppArmor security module
0004  *
0005  * This file contains AppArmor ipc mediation
0006  *
0007  * Copyright (C) 1998-2008 Novell/SUSE
0008  * Copyright 2009-2017 Canonical Ltd.
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  * audit_signal_mask - convert mask to permission string
0034  * @mask: permission mask to convert
0035  *
0036  * Returns: pointer to static string
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  * audit_cb - call back for signal specific audit fields
0049  * @ab: audit_buffer  (NOT NULL)
0050  * @va: audit struct to audit values of  (NOT NULL)
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     /* TODO: secondary cache check <profile, profile, perm> */
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 }