John Johansen | 0ed3b28 | 2010-07-29 14:48:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * AppArmor security module |
| 3 | * |
| 4 | * This file contains AppArmor ipc mediation |
| 5 | * |
| 6 | * Copyright (C) 1998-2008 Novell/SUSE |
John Johansen | b2d09ae | 2017-06-09 14:22:14 -0700 | [diff] [blame^] | 7 | * Copyright 2009-2017 Canonical Ltd. |
John Johansen | 0ed3b28 | 2010-07-29 14:48:05 -0700 | [diff] [blame] | 8 | * |
| 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 Morris | 33f8bf5 | 2011-08-29 10:40:54 +1000 | [diff] [blame] | 22 | #include "include/ipc.h" |
John Johansen | 0ed3b28 | 2010-07-29 14:48:05 -0700 | [diff] [blame] | 23 | |
| 24 | /* call back to audit ptrace fields */ |
John Johansen | 637f688 | 2017-06-09 08:14:28 -0700 | [diff] [blame] | 25 | static void audit_ptrace_cb(struct audit_buffer *ab, void *va) |
John Johansen | 0ed3b28 | 2010-07-29 14:48:05 -0700 | [diff] [blame] | 26 | { |
| 27 | struct common_audit_data *sa = va; |
John Johansen | b2d09ae | 2017-06-09 14:22:14 -0700 | [diff] [blame^] | 28 | |
John Johansen | ef88a7a | 2017-01-16 00:43:02 -0800 | [diff] [blame] | 29 | audit_log_format(ab, " peer="); |
John Johansen | 637f688 | 2017-06-09 08:14:28 -0700 | [diff] [blame] | 30 | aa_label_xaudit(ab, labels_ns(aad(sa)->label), aad(sa)->peer, |
| 31 | FLAGS_NONE, GFP_ATOMIC); |
John Johansen | 0ed3b28 | 2010-07-29 14:48:05 -0700 | [diff] [blame] | 32 | } |
| 33 | |
John Johansen | b2d09ae | 2017-06-09 14:22:14 -0700 | [diff] [blame^] | 34 | static int cross_ptrace_perm(struct aa_profile *tracer, |
| 35 | struct aa_profile *tracee, u32 request, |
| 36 | struct common_audit_data *sa) |
John Johansen | 0ed3b28 | 2010-07-29 14:48:05 -0700 | [diff] [blame] | 37 | { |
John Johansen | b2d09ae | 2017-06-09 14:22:14 -0700 | [diff] [blame^] | 38 | /* policy uses the old style capability check for ptrace */ |
| 39 | if (profile_unconfined(tracer) || tracer == tracee) |
| 40 | return 0; |
John Johansen | 0ed3b28 | 2010-07-29 14:48:05 -0700 | [diff] [blame] | 41 | |
John Johansen | b2d09ae | 2017-06-09 14:22:14 -0700 | [diff] [blame^] | 42 | 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 Johansen | ef88a7a | 2017-01-16 00:43:02 -0800 | [diff] [blame] | 46 | |
John Johansen | b2d09ae | 2017-06-09 14:22:14 -0700 | [diff] [blame^] | 47 | return aa_audit(AUDIT_APPARMOR_AUTO, tracer, sa, audit_ptrace_cb); |
John Johansen | 0ed3b28 | 2010-07-29 14:48:05 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /** |
| 51 | * aa_may_ptrace - test if tracer task can trace the tracee |
John Johansen | b2d09ae | 2017-06-09 14:22:14 -0700 | [diff] [blame^] | 52 | * @tracer: label of the task doing the tracing (NOT NULL) |
| 53 | * @tracee: task label to be traced |
| 54 | * @request: permission request |
John Johansen | 0ed3b28 | 2010-07-29 14:48:05 -0700 | [diff] [blame] | 55 | * |
| 56 | * Returns: %0 else error code if permission denied or error |
| 57 | */ |
John Johansen | b2d09ae | 2017-06-09 14:22:14 -0700 | [diff] [blame^] | 58 | int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee, |
| 59 | u32 request) |
John Johansen | 0ed3b28 | 2010-07-29 14:48:05 -0700 | [diff] [blame] | 60 | { |
John Johansen | b2d09ae | 2017-06-09 14:22:14 -0700 | [diff] [blame^] | 61 | DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, OP_PTRACE); |
John Johansen | 0ed3b28 | 2010-07-29 14:48:05 -0700 | [diff] [blame] | 62 | |
John Johansen | b2d09ae | 2017-06-09 14:22:14 -0700 | [diff] [blame^] | 63 | return xcheck_labels_profiles(tracer, tracee, cross_ptrace_perm, |
| 64 | request, &sa); |
John Johansen | 0ed3b28 | 2010-07-29 14:48:05 -0700 | [diff] [blame] | 65 | } |
| 66 | |
John Johansen | 0ed3b28 | 2010-07-29 14:48:05 -0700 | [diff] [blame] | 67 | |