blob: f81649369f056da6fd2b79e55c806f2c1c0786db [file] [log] [blame]
John Johansen0ed3b282010-07-29 14:48:05 -07001/*
2 * AppArmor security module
3 *
4 * This file contains AppArmor ipc mediation
5 *
6 * Copyright (C) 1998-2008 Novell/SUSE
John Johansenb2d09ae2017-06-09 14:22:14 -07007 * Copyright 2009-2017 Canonical Ltd.
John Johansen0ed3b282010-07-29 14:48:05 -07008 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation, version 2 of the
12 * License.
13 */
14
15#include <linux/gfp.h>
16#include <linux/ptrace.h>
17
18#include "include/audit.h"
19#include "include/capability.h"
20#include "include/context.h"
21#include "include/policy.h"
James Morris33f8bf52011-08-29 10:40:54 +100022#include "include/ipc.h"
John Johansen0ed3b282010-07-29 14:48:05 -070023
24/* call back to audit ptrace fields */
John Johansen637f6882017-06-09 08:14:28 -070025static void audit_ptrace_cb(struct audit_buffer *ab, void *va)
John Johansen0ed3b282010-07-29 14:48:05 -070026{
27 struct common_audit_data *sa = va;
John Johansenb2d09ae2017-06-09 14:22:14 -070028
John Johansenef88a7a2017-01-16 00:43:02 -080029 audit_log_format(ab, " peer=");
John Johansen637f6882017-06-09 08:14:28 -070030 aa_label_xaudit(ab, labels_ns(aad(sa)->label), aad(sa)->peer,
31 FLAGS_NONE, GFP_ATOMIC);
John Johansen0ed3b282010-07-29 14:48:05 -070032}
33
John Johansenb2d09ae2017-06-09 14:22:14 -070034static int cross_ptrace_perm(struct aa_profile *tracer,
35 struct aa_profile *tracee, u32 request,
36 struct common_audit_data *sa)
John Johansen0ed3b282010-07-29 14:48:05 -070037{
John Johansenb2d09ae2017-06-09 14:22:14 -070038 /* policy uses the old style capability check for ptrace */
39 if (profile_unconfined(tracer) || tracer == tracee)
40 return 0;
John Johansen0ed3b282010-07-29 14:48:05 -070041
John Johansenb2d09ae2017-06-09 14:22:14 -070042 aad(sa)->label = &tracer->label;
43 aad(sa)->peer = &tracee->label;
44 aad(sa)->request = 0;
45 aad(sa)->error = aa_capable(&tracer->label, CAP_SYS_PTRACE, 1);
John Johansenef88a7a2017-01-16 00:43:02 -080046
John Johansenb2d09ae2017-06-09 14:22:14 -070047 return aa_audit(AUDIT_APPARMOR_AUTO, tracer, sa, audit_ptrace_cb);
John Johansen0ed3b282010-07-29 14:48:05 -070048}
49
50/**
51 * aa_may_ptrace - test if tracer task can trace the tracee
John Johansenb2d09ae2017-06-09 14:22:14 -070052 * @tracer: label of the task doing the tracing (NOT NULL)
53 * @tracee: task label to be traced
54 * @request: permission request
John Johansen0ed3b282010-07-29 14:48:05 -070055 *
56 * Returns: %0 else error code if permission denied or error
57 */
John Johansenb2d09ae2017-06-09 14:22:14 -070058int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee,
59 u32 request)
John Johansen0ed3b282010-07-29 14:48:05 -070060{
John Johansenb2d09ae2017-06-09 14:22:14 -070061 DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_PTRACE);
John Johansen0ed3b282010-07-29 14:48:05 -070062
John Johansenb2d09ae2017-06-09 14:22:14 -070063 return xcheck_labels_profiles(tracer, tracee, cross_ptrace_perm,
64 request, &sa);
John Johansen0ed3b282010-07-29 14:48:05 -070065}
66
John Johansen0ed3b282010-07-29 14:48:05 -070067