Skip to content

Commit 84c455d

Browse files
committed
apparmor: add support for profiles to define the kill signal
Previously apparmor has only sent SIGKILL but there are cases where it can be useful to send a different signal. Allow the profile to optionally specify a different value. Signed-off-by: John Johansen <john.johansen@canonical.com>
1 parent 2e12c5f commit 84c455d

File tree

8 files changed

+34
-6
lines changed

8 files changed

+34
-6
lines changed

security/apparmor/apparmorfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,6 +2342,7 @@ static struct aa_sfs_entry aa_sfs_entry_domain[] = {
23422342
AA_SFS_FILE_BOOLEAN("computed_longest_left", 1),
23432343
AA_SFS_DIR("attach_conditions", aa_sfs_entry_attach),
23442344
AA_SFS_FILE_BOOLEAN("disconnected.path", 1),
2345+
AA_SFS_FILE_BOOLEAN("kill.signal", 1),
23452346
AA_SFS_FILE_STRING("version", "1.2"),
23462347
{ }
23472348
};

security/apparmor/audit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ int aa_audit(int type, struct aa_profile *profile,
192192
aa_audit_msg(type, ad, cb);
193193

194194
if (ad->type == AUDIT_APPARMOR_KILL)
195-
(void)send_sig_info(SIGKILL, NULL,
195+
(void)send_sig_info(profile->signal, NULL,
196196
ad->common.type == LSM_AUDIT_DATA_TASK &&
197197
ad->common.u.tsk ? ad->common.u.tsk : current);
198198

security/apparmor/include/ipc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
#include <linux/sched.h>
1515

16+
#define SIGUNKNOWN 0
17+
#define MAXMAPPED_SIG 35
18+
1619
int aa_may_signal(const struct cred *subj_cred, struct aa_label *sender,
1720
const struct cred *target_cred, struct aa_label *target,
1821
int sig);

security/apparmor/include/policy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ struct aa_profile {
236236
enum audit_mode audit;
237237
long mode;
238238
u32 path_flags;
239+
int signal;
239240
const char *disconnected;
240241

241242
struct aa_attachment attach;

security/apparmor/include/sig_names.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#include <linux/signal.h>
2-
3-
#define SIGUNKNOWN 0
4-
#define MAXMAPPED_SIG 35
5-
#define MAXMAPPED_SIGNAME (MAXMAPPED_SIG + 1)
6-
#define SIGRT_BASE 128
2+
#include "signal.h"
73

84
/* provide a mapping of arch signal to internal signal # for mediation
95
* those that are always an alias SIGCLD for SIGCLHD and SIGPOLL for SIGIO

security/apparmor/include/signal.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* AppArmor security module
4+
*
5+
* This file contains AppArmor ipc mediation function definitions.
6+
*
7+
* Copyright 2023 Canonical Ltd.
8+
*/
9+
10+
#ifndef __AA_SIGNAL_H
11+
#define __AA_SIGNAL_H
12+
13+
#define SIGUNKNOWN 0
14+
#define MAXMAPPED_SIG 35
15+
16+
#define MAXMAPPED_SIGNAME (MAXMAPPED_SIG + 1)
17+
#define SIGRT_BASE 128
18+
19+
#endif /* __AA_SIGNAL_H */

security/apparmor/policy.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ struct aa_profile *aa_alloc_profile(const char *hname, struct aa_proxy *proxy,
364364
profile->label.flags |= FLAG_PROFILE;
365365
profile->label.vec[0] = profile;
366366

367+
profile->signal = SIGKILL;
367368
/* refcount released by caller */
368369
return profile;
369370

security/apparmor/policy_unpack.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "include/policy.h"
3030
#include "include/policy_unpack.h"
3131
#include "include/policy_compat.h"
32+
#include "include/signal.h"
3233

3334
/* audit callback for unpack fields */
3435
static void audit_cb(struct audit_buffer *ab, void *va)
@@ -916,6 +917,12 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
916917
(void) aa_unpack_strdup(e, &disconnected, "disconnected");
917918
profile->disconnected = disconnected;
918919

920+
/* optional */
921+
(void) aa_unpack_u32(e, &profile->signal, "kill");
922+
if (profile->signal < 1 && profile->signal > MAXMAPPED_SIG) {
923+
info = "profile kill.signal invalid value";
924+
goto fail;
925+
}
919926
/* per profile debug flags (complain, audit) */
920927
if (!aa_unpack_nameX(e, AA_STRUCT, "flags")) {
921928
info = "profile missing flags";

0 commit comments

Comments
 (0)