From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6CF0C4361B for ; Sat, 19 Dec 2020 11:47:59 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5B4C323602 for ; Sat, 19 Dec 2020 11:47:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B4C323602 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94) (envelope-from ) id 1kqaiL-0001WH-5R; Sat, 19 Dec 2020 06:47:57 -0500 Received: from mout.gmx.net ([212.227.17.20]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1kqahp-0001Gt-WD for kernelnewbies@kernelnewbies.org; Sat, 19 Dec 2020 06:47:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1608378442; bh=5HhQfJiZsyD2aCN9LaAuqE+cF2aSZXGNaixxNt/EpkE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=O5GByO/Nw/Ctt5nYJDYMqP38W/eX08Rq2Y9yJ+w8XC1NNaRiau4ZgVE06T6CC45ZL 0HrjOHhU/q9avmLY662LjaCv2a/esu6vuroruE8fWENhnCEpTmK1QFfhK/slIblxza nBrhAP9uxJdQTeL/tX8rJ73ONMD5DMthMF7c0K0Q= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([83.52.231.213]) by mail.gmx.com (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MiJVG-1kCKXk1ODO-00fV0f; Sat, 19 Dec 2020 12:47:22 +0100 From: John Wood To: kernelnewbies@kernelnewbies.org Subject: [PATCH 1/4] security: Add LSM hook at the point where a task gets a fatal signal Date: Sat, 19 Dec 2020 12:46:38 +0100 Message-Id: <20201219114640.63024-2-john.wood@gmx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201219114640.63024-1-john.wood@gmx.com> References: <20201219114640.63024-1-john.wood@gmx.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:8rhsnmzB0ffVL+Of5dS1yitLw0HTqLYrVeJhufTl/LZY7W2hKov ouPXHwUSOAiUXcHGlefCfi+pKVkGdoVpnwWpz3ZiIWQxPOH9ZTVTRRfjmWDq4HQaCPfds0o NzV6FqWGie97svckCoNYFc/zbmcUZLeOgjuQZJWyOyVR7hU4omwTy5GOoX60kwNjfBYVMz+ N+mkCVc3NTY7ZRo3l0Caw== X-UI-Out-Filterresults: notjunk:1;V03:K0:s+ceHHKQi94=:iNr7f6RpZCBkfmRHsi4fFr erew32e/itD+wWlPkjPV+vKmTCJSARwZDjdxM3FcSlS1lU1XBMjYSfb5ZfJ1hhSFS7GykCCGC MygheClUTRvKGlEpEMDpTCG/x6SQBN8hvE+3wnQIB8V/uAoVu4c+9BzAHfLa97MEGI626bgsq wr/2t52jS2QRs/CU+YRv/t7Iqq82pu41ibzOMseMGc5XMqdJWCiXOawg9lGwlU/G+imwsjLZi GlVTtf1hQYB4csu41So6HYoM3au5Pli/4s+onRjfZtCV/2IZAKuUKBjg3c7l/ree4d06l18EJ zLdWn1VnoMpuOgrnbOn+SUWRauh7Bc5ODXeYQyhdKzBRWroChbNwrYv1/x8wQiiy1y0ncqSIh ae8iE21+qHSc19eRUZN6u/g6z+mt4VxCsLGTSEY/Ekrz3eZ2zGce7sTMd8duaAonXhTCCGeuP I0Juruv3MqKhjOIw+jpCIXbM8IeLs35DxKz8eSr34exjTmkjSPRkkyLj7EY1lZNO1oBySYrEY 649vhZv5zLF/Aei5Mxv6FkAh0ardKp7G+jer/Mo2ruMIbJKWAGSh2pY04d2ln8syvBXnhbDN5 Qq4HHrs+tIepoj5rhbQV2kqvaGZwvpmcBfTJiHrvHtLuFy6fJ243rvn6otwaIKxp4BiYXnx0b 9sjTTfBcsZ8VG5SH53Sjoa2JmWofp3Qn1nmJvlsgTO5NA8fxCgWbxhQfEADeHYPaOGt557mZW 6r0yM9Vx2jEv+L4qY/1FoWtofmYz8fqSQp8/FijtHAl7nGSkBJcxKBTFOHYsK9o/ufmkrSKAg kne9ug64fWV1Gh1wySS2VY5vQ1+KhqneZP4BkCoVIBiJCvmp9dCCzFg3akhulx+3lHgK3j80i 0W1uGPqM/363Ay31jvmw== Cc: John Wood X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org Add a security hook that allows a LSM to be notified when a task gets a fatal signal. This patch is a previous step on the way to compute the task crash period by the "brute" LSM (linux security module to detect and mitigate fork brute force attack against vulnerable userspace processes). Signed-off-by: John Wood --- include/linux/lsm_hook_defs.h | 1 + include/linux/lsm_hooks.h | 4 ++++ include/linux/security.h | 4 ++++ kernel/signal.c | 1 + security/security.c | 5 +++++ 5 files changed, 15 insertions(+) diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index 32a940117e7a..21aa120f3965 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -215,6 +215,7 @@ LSM_HOOK(int, -ENOSYS, task_prctl, int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) LSM_HOOK(void, LSM_RET_VOID, task_to_inode, struct task_struct *p, struct inode *inode) +LSM_HOOK(void, LSM_RET_VOID, task_fatal_signal, const kernel_siginfo_t *siginfo) LSM_HOOK(int, 0, ipc_permission, struct kern_ipc_perm *ipcp, short flag) LSM_HOOK(void, LSM_RET_VOID, ipc_getsecid, struct kern_ipc_perm *ipcp, u32 *secid) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index c503f7ab8afb..6b6063fcb4da 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -774,6 +774,10 @@ * security attributes, e.g. for /proc/pid inodes. * @p contains the task_struct for the task. * @inode contains the inode structure for the inode. + * @task_fatal_signal: + * This hook allows security modules to be notified when a task gets a + * fatal signal. + * @siginfo contains the signal information. * * Security hooks for Netlink messaging. * diff --git a/include/linux/security.h b/include/linux/security.h index 39642626a707..4f3fc487a71e 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -418,6 +418,7 @@ int security_task_kill(struct task_struct *p, struct kernel_siginfo *info, int security_task_prctl(int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5); void security_task_to_inode(struct task_struct *p, struct inode *inode); +void security_task_fatal_signal(const kernel_siginfo_t *siginfo); int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag); void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid); int security_msg_msg_alloc(struct msg_msg *msg); @@ -1140,6 +1141,9 @@ static inline int security_task_prctl(int option, unsigned long arg2, static inline void security_task_to_inode(struct task_struct *p, struct inode *inode) { } +static inline void security_task_fatal_signal(const kernel_siginfo_t *siginfo) +{ } + static inline int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag) { diff --git a/kernel/signal.c b/kernel/signal.c index ef8f2a28d37c..e7373e5a0566 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2735,6 +2735,7 @@ bool get_signal(struct ksignal *ksig) /* * Anything else is fatal, maybe with a core dump. */ + security_task_fatal_signal(&ksig->info); current->flags |= PF_SIGNALED; if (sig_kernel_coredump(signr)) { diff --git a/security/security.c b/security/security.c index a28045dc9e7f..4ee45c6ff4a4 100644 --- a/security/security.c +++ b/security/security.c @@ -1826,6 +1826,11 @@ void security_task_to_inode(struct task_struct *p, struct inode *inode) call_void_hook(task_to_inode, p, inode); } +void security_task_fatal_signal(const kernel_siginfo_t *siginfo) +{ + call_void_hook(task_fatal_signal, siginfo); +} + int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag) { return call_int_hook(ipc_permission, 0, ipcp, flag); -- 2.25.1 _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies