From patchwork Fri Mar 15 18:08:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13593825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1502BC54E58 for ; Fri, 15 Mar 2024 18:10:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5DC238013B; Fri, 15 Mar 2024 14:10:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 517B6800B4; Fri, 15 Mar 2024 14:10:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B80E8013B; Fri, 15 Mar 2024 14:10:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 29D33800B4 for ; Fri, 15 Mar 2024 14:10:46 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F21CE1402FD for ; Fri, 15 Mar 2024 18:10:45 +0000 (UTC) X-FDA: 81900064050.15.487247C Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by imf22.hostedemail.com (Postfix) with ESMTP id 0A530C0002 for ; Fri, 15 Mar 2024 18:10:43 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=googlemail.com header.s=20230601 header.b=GZX1GCRt; dmarc=pass (policy=quarantine) header.from=googlemail.com; spf=pass (imf22.hostedemail.com: domain of cgzones@googlemail.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=cgzones@googlemail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710526244; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5vvztQ9R6kS3LLaEzPtb4PkQkdZH06n2URzp7Npwuwk=; b=zlpPqNQpxJp0RXwOY5jgsdeWB2pZo3D0XquGSg5HOHQ/nibetWTN28lMo7COgemSNDDFBz 6NP35IoXkSQWINXTfIV7S8V1ZGqGEq1mWdiUBfYIFs+qD5o5L+/nDys02cJdPHTtf+nc9M cpt0HbHRwu0JQdkhozAap+xSi9CQXfI= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=googlemail.com header.s=20230601 header.b=GZX1GCRt; dmarc=pass (policy=quarantine) header.from=googlemail.com; spf=pass (imf22.hostedemail.com: domain of cgzones@googlemail.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=cgzones@googlemail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710526244; a=rsa-sha256; cv=none; b=ifWPaGnxQVINPpo73SycPKZwL2ZQ7vL0mzrj0D3fGw+p4v2iO1Ncan1E1+E1qVjHNcKv0H p6hCYnED7Mrb/tqIdzg6SIasI3UoAUKL2LyfVPeJvJIZaUP+gBC/EJPxui1QSON+zJO6os W5kilbYvRbvHE3udJQhKTpO0yi8ZaGA= Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a466f796fc1so287583466b.3 for ; Fri, 15 Mar 2024 11:10:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1710526242; x=1711131042; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5vvztQ9R6kS3LLaEzPtb4PkQkdZH06n2URzp7Npwuwk=; b=GZX1GCRtrlrFKgmwhyV5GHgHflNIy43qo3v2Oezk1wFDOonsaJaKKMG9UDXwPHl70m kqeSd3Yren7udPqfmP2Xlqg6/wutiCsJkcU9b6NE3EbhoULcZr1wVNCK6OB9+vnky7NF Mu14Llbx+KswhPS+U5JN6tfknayxuOQV+L/Hv4VheYRuhu370Ac5O0Gs6hGS9/IasRjr hk+n7PkXVsrOYeuNdeMNicVjv4qUjA/o12QMdx3nbBQayv8B2PArUs39uIyr/P0bi5p9 UW+NzkKPUG+0gqkcAsInvABv+39IYx2gRy9y1JkMPdiI863awl01BaDyTP9nKSe0aF0k 0CLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710526242; x=1711131042; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5vvztQ9R6kS3LLaEzPtb4PkQkdZH06n2URzp7Npwuwk=; b=awh1StTo5eRw8s5a6j2PrWDTvpv1L3eWo9qezDVDSXwpqmyI5ganFMK4le3ug//4MP PmW50fb+PzAcQLUsDzWrT/NG3E5s6He6kGFnIpNT34HXjGMEMfjuiW18ItM+krr1546G 1N1F+txPE13KkxNWWG3Bu5clgBGwObF7VCPZKxrquXiv5ck6g6X2B4RNQI+E/HEYfFvj WPKq8mlKbbHj7s5hf0AljgFcbK75qHMKGY+t2sT+FnmNEswUECW9JcrqZl56m9utsuUf lGWdoJZyDo0IWLv1YnB3RhXZNFpS+oMgI+4Ta3gkaJ3y88iJZyA0eTretTpIiHl5TVlM cAng== X-Forwarded-Encrypted: i=1; AJvYcCU+26jnibHcUmQZD6hozUpEuV79n6jl6qIIxWT5mbjdRy0s9Rq33TZVyagYMak7TjOaXmL+MPoiANihRsEwGF+01nk= X-Gm-Message-State: AOJu0YyZDZ8hV5dwUfgrmX+qDNBMWTf/fLrmSyjWKOQnNaFSLUdjz34U ei6WQ69WO5CNoqO6ppSLktSTIAEqehViOm83f6fRbDVdUEJGXJIP X-Google-Smtp-Source: AGHT+IGmE1hE7r5LCz1k5oYh5+BcCGT9TTZYLN0ExtvMuVZ15iQOYj4bzU0GgE1LYLz2d9qOed8Jmg== X-Received: by 2002:a17:906:7fc8:b0:a46:2760:3c9b with SMTP id r8-20020a1709067fc800b00a4627603c9bmr3360991ejs.34.1710526242402; Fri, 15 Mar 2024 11:10:42 -0700 (PDT) Received: from ddev.DebianHome (dynamic-095-119-217-226.95.119.pool.telefonica.de. [95.119.217.226]) by smtp.gmail.com with ESMTPSA id jx11-20020a170906ca4b00b00a46937bc44esm510480ejb.135.2024.03.15.11.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 11:10:41 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: linux-security-module@vger.kernel.org Cc: Eric Biederman , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Paul Moore , James Morris , "Serge E. Hallyn" , Khadija Kamran , Andrii Nakryiko , Casey Schaufler , Alexei Starovoitov , Ondrej Mosnacek , Roberto Sassu , Alfred Piccioni , John Johansen , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/2] lsm: introduce new hook security_vm_execstack Date: Fri, 15 Mar 2024 19:08:48 +0100 Message-ID: <20240315181032.645161-2-cgzones@googlemail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240315181032.645161-1-cgzones@googlemail.com> References: <20240315181032.645161-1-cgzones@googlemail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: amgo9hxqa4rd3rsqerjfe53srcrirb95 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0A530C0002 X-HE-Tag: 1710526243-979330 X-HE-Meta: U2FsdGVkX18fysRcIuMOMp0s7/7JMs3M/hTLtO2cDW40tClka9vveYeiLKyk0AZd3J5t9N/sISy+/aHFWVHwKLRlk0ckKnUDJ8bExIEQ57E/yJitvUlgX8maTBnO6jLrBqefeV7dpZt+FAaXyGS8t0Ljn5XM8PLcubqqqD3xNfgvjOs/tAw9xyUejR39gi+8RHxK7Bh5qXNOOoY+MqUkr5gkTBQkItOeGFfXPuOb/G4TCXJB5S4z4CugokZ5CQhvG9U0kA4oYW/WPqbcGFkiRfyQ2Y74m0Mddzym8PltRzwwYCoIVWzJAra7AX2gZKs0tB/bJcPDTwp9cG73+CcRKsaoMuJNANXQOHkg0tbtUQlwpS5jCSmL4gYsk+Iz8ijIb8fyNgHWnqmITs7c2ZvwWlwSW5BnZUzYeozGvrlPpEqwh6tGmMD5CrmAcGINrfosjncQnM9ZWlMC0GhUDmgqlzBVY8TaeMqbZg/NUljp3ICSclLEhNJak6wr9b/H7na/9xm7nzd4eZcU7WmvKzyu9ijlQcV0/sx4rx3nSWo7Nb5Qx/ATDAalGXGnwkTa4QCSNyHA1PnlOWzHlF+m7UALFxnvYUca99sPLf/CvSJz4xii6M3ALyN10Ih3b18wRQRR1WVWVMdTOFvQPvB0sXW+pgpnHNV/Q5wWgkv5Rdz2KNtQW92iX7DBoZI7DOXfSTCo18zA7Yv3ziItTVsHI1I0YhCBeP8XEJeWfuPFCfZslkbzTTfqC6Et5HjHTCgAo1iSOWoTE9gadVv3uh+gXvq/J/u8bNkJ7XwtOtYIVRKUb44JtagpZ4NbG7Vs++QH0UPOpLEd4tapi897G9nhwjo/WR6iqOX8U2rQ+DjtZtYA9gIf5Lo++oe1Wwogg8x9Blws/Gwx0O4J90jt56u9qSnaTlyQo+5ZDIe2gRBB4QLLvk+RiZHhU8v7KH82ckTlmVvwIjF6MWwzeJOdBXorO41 /Ke3hjqT jIMFQevPGVlqi9PydBMYT8nzlUzB653MuF2effukGHXkiUeOjnbP3yhtFclr4lWnWXJGcwpJaNBhr2b56dn1SVeg3p6VQixsx6Vw/g3PEvqgmnV0ERn71/pAl8ZI0YgrdYlrmzA57cM7SfWox4xgK3hz1cg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a new hook guarding instantiations of programs with executable stack. They are being warned about since commit 47a2ebb7f505 ("execve: warn if process starts with executable stack"). Lets give LSMs the ability to control their presence on a per application basis. Signed-off-by: Christian Göttsche --- fs/exec.c | 4 ++++ include/linux/lsm_hook_defs.h | 1 + include/linux/security.h | 6 ++++++ security/security.c | 13 +++++++++++++ 4 files changed, 24 insertions(+) diff --git a/fs/exec.c b/fs/exec.c index 8cdd5b2dd09c..e6f9e980c6b1 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -829,6 +829,10 @@ int setup_arg_pages(struct linux_binprm *bprm, BUG_ON(prev != vma); if (unlikely(vm_flags & VM_EXEC)) { + ret = security_vm_execstack(); + if (ret) + goto out_unlock; + pr_warn_once("process '%pD4' started with executable stack\n", bprm->file); } diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index 185924c56378..b31d0744e7e7 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -49,6 +49,7 @@ LSM_HOOK(int, 0, syslog, int type) LSM_HOOK(int, 0, settime, const struct timespec64 *ts, const struct timezone *tz) LSM_HOOK(int, 1, vm_enough_memory, struct mm_struct *mm, long pages) +LSM_HOOK(int, 0, vm_execstack, void) LSM_HOOK(int, 0, bprm_creds_for_exec, struct linux_binprm *bprm) LSM_HOOK(int, 0, bprm_creds_from_file, struct linux_binprm *bprm, const struct file *file) LSM_HOOK(int, 0, bprm_check_security, struct linux_binprm *bprm) diff --git a/include/linux/security.h b/include/linux/security.h index d0eb20f90b26..084b96814970 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -294,6 +294,7 @@ int security_quota_on(struct dentry *dentry); int security_syslog(int type); int security_settime64(const struct timespec64 *ts, const struct timezone *tz); int security_vm_enough_memory_mm(struct mm_struct *mm, long pages); +int security_vm_execstack(void); int security_bprm_creds_for_exec(struct linux_binprm *bprm); int security_bprm_creds_from_file(struct linux_binprm *bprm, const struct file *file); int security_bprm_check(struct linux_binprm *bprm); @@ -624,6 +625,11 @@ static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages) return __vm_enough_memory(mm, pages, cap_vm_enough_memory(mm, pages)); } +static inline int security_vm_execstack(void) +{ + return 0; +} + static inline int security_bprm_creds_for_exec(struct linux_binprm *bprm) { return 0; diff --git a/security/security.c b/security/security.c index 0144a98d3712..f75240d0d99d 100644 --- a/security/security.c +++ b/security/security.c @@ -1125,6 +1125,19 @@ int security_vm_enough_memory_mm(struct mm_struct *mm, long pages) return __vm_enough_memory(mm, pages, cap_sys_admin); } +/** + * security_vm_execstack() - Check if starting a program with executable stack + * is allowed + * + * Check whether starting a program with an executable stack is allowed. + * + * Return: Returns 0 if permission is granted. + */ +int security_vm_execstack(void) +{ + return call_int_hook(vm_execstack); +} + /** * security_bprm_creds_for_exec() - Prepare the credentials for exec() * @bprm: binary program information From patchwork Fri Mar 15 18:08:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13593824 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B9BDC54E67 for ; Fri, 15 Mar 2024 18:10:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 62A168013A; Fri, 15 Mar 2024 14:10:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D9B8800B4; Fri, 15 Mar 2024 14:10:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47A058013A; Fri, 15 Mar 2024 14:10:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 365C0800B4 for ; Fri, 15 Mar 2024 14:10:44 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CC6C21A0287 for ; Fri, 15 Mar 2024 18:10:43 +0000 (UTC) X-FDA: 81900063966.04.0F333C8 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by imf27.hostedemail.com (Postfix) with ESMTP id CFA0940016 for ; Fri, 15 Mar 2024 18:10:41 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=googlemail.com header.s=20230601 header.b=GKJeDKSG; spf=pass (imf27.hostedemail.com: domain of cgzones@googlemail.com designates 209.85.167.51 as permitted sender) smtp.mailfrom=cgzones@googlemail.com; dmarc=pass (policy=quarantine) header.from=googlemail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710526241; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=uZ0fcTtTD0fe4SyWRrePksxxOrhm45+SyvujsTCShkE=; b=cOqnQzU7dtyFJXkfNM/7o6IbFuv+eIGaBkJdlpYPiFRRi+0g8umlWAhs/szB7m+BMJ1Rb+ X5UloRY6WJaaVpkOcT1UWPMnK8tm+KFbt5t8aEu6/Pd0fHhRHBKuC500tAWMvp8l76wq+z KN/VCxs9lxWq+FJs7si6ybvcqFne3YE= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=googlemail.com header.s=20230601 header.b=GKJeDKSG; spf=pass (imf27.hostedemail.com: domain of cgzones@googlemail.com designates 209.85.167.51 as permitted sender) smtp.mailfrom=cgzones@googlemail.com; dmarc=pass (policy=quarantine) header.from=googlemail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710526242; a=rsa-sha256; cv=none; b=Ejzw/bgmZC4YivKeOMnA5xIs5TnGQYzs8b4QBTHE/ECLRo97T3PbNklRhHRTQ2shW161ls gO73pCc2fsZsgz0jRPi+tYtuqP7L0j9HeDetg48OAugItpYo27jEjpgyGFb6nefOWxg3CV qcbP4qAGLvn15fAOUaiDkO77rRWmDPk= Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-513dbb5a1f9so996464e87.2 for ; Fri, 15 Mar 2024 11:10:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1710526240; x=1711131040; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uZ0fcTtTD0fe4SyWRrePksxxOrhm45+SyvujsTCShkE=; b=GKJeDKSGeH78fXKuY7AxT1oEhSIE1HJJCpg4DWmy3NPXZft+PsIM3PaLJpBOjr+NPe bkvoqpBYGPtEo/oKyu0CEGyoTbiQQ+M2GlKYZWwmIu350ygwFU2mFnvPHsMr5HiT0/YK MnB/tLDJg+HtSt4LR+N+HVfMHXAwKUhjYB+ihqsoEuLfiul5j2SQBV66ioL1q2UK9n89 1UFDgOn7R/80GaRUHXTHVFFW5bvHlK4c6/Gr9Pf6CtChxeT3VrjNVikgev5bEVBH0gLs bwl8Kp6BF8a+avS3J5NQtm74PQlm14wXgtK9BLYn9SaBFLb635tr7soLKQV1cBjzqx04 /piw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710526240; x=1711131040; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uZ0fcTtTD0fe4SyWRrePksxxOrhm45+SyvujsTCShkE=; b=J7B3UXXH6nIzyCJtW2h5cAN8X0xnrajMYuTJjt8ZCk+X5EIvdmXNAzusjwFTWCgDAD D5ht+kEEAkaQRp/+hYgxAv8pEJZieG/0fQSeg2glEJTmSd/6SECCSW6T9SD2OO/COgFA 2F4TLf83X9RnIVdx0eZ5H4ZPGHWByNcwYVDAeeJAWJIKmvtszJRw10lgkX7Ys7cIq5+A C0TXwQAGdX2v4UxXn4+5mneFeH1lVDo/y/dVdjYV72LERo3RXPn0QwHO2a+FMb8y6PrH nvrwubDf0SCd2hj4e03sm9Lr5ErJiu8K+oU/g/nj4Ioywq1zNm/a3cQkEy5G9Zf5UaZG xQ1Q== X-Forwarded-Encrypted: i=1; AJvYcCXMrhVMU6wNkG3NpFKLlgm+8YlwNtFLjKrgb+9zokamp7fDDPDXRgfywGxwyCiq7qZgU4fyhkztdtQTts6ZwAAorww= X-Gm-Message-State: AOJu0YzeGu51T6D50cq4q8PejTq0Ts6ASMrCvphVCxzpNnjrH3O7Yymz QbU78WR05S6fV4yykFr40lf/tAGxXVno7teR26dQEomHy5kUiT+2 X-Google-Smtp-Source: AGHT+IEmiwrd4RrzijlKpRPRn/2mZElzaqpXLjQrJS1Vo5fvprxZg222wGzTFeFiS5qSlSXAJenLSA== X-Received: by 2002:a19:3850:0:b0:513:c757:33d9 with SMTP id d16-20020a193850000000b00513c75733d9mr3931656lfj.53.1710526239712; Fri, 15 Mar 2024 11:10:39 -0700 (PDT) Received: from ddev.DebianHome (dynamic-095-119-217-226.95.119.pool.telefonica.de. [95.119.217.226]) by smtp.gmail.com with ESMTPSA id jx11-20020a170906ca4b00b00a46937bc44esm510480ejb.135.2024.03.15.11.10.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 11:10:39 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: linux-security-module@vger.kernel.org Cc: Alexander Viro , Christian Brauner , Jan Kara , Eric Biederman , Kees Cook , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Ondrej Mosnacek , Khadija Kamran , Andrii Nakryiko , Casey Schaufler , Alexei Starovoitov , Roberto Sassu , Guillaume Nault , John Johansen , Alfred Piccioni , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, selinux@vger.kernel.org Subject: [RFC PATCH 2/2] selinux: wire up new execstack LSM hook Date: Fri, 15 Mar 2024 19:08:47 +0100 Message-ID: <20240315181032.645161-1-cgzones@googlemail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: CFA0940016 X-Rspam-User: X-Stat-Signature: y3sbf8kufr64ux4kiz8fc7phuijnbha8 X-Rspamd-Server: rspam01 X-HE-Tag: 1710526241-137150 X-HE-Meta: U2FsdGVkX18XoLOyedHO594hGHKDndkZo0XjHlvmOTqNmZ2ctYuS34yXSClG3v0HQusyz7P3eze7+NvPeMGfqp9W+MCMXJZYmnn9cur/X763G7v2Rt6+HZb4Nf3IybSEKLePMsEUHvfgOKWfDJBnQabq3Yp0CpyhsYzkdSDI7fomytgjqtbDUUfCKskBemIxdW6Uc/zQo6/fVPJlbaPJDPZJTLJuOzMhvpjIpxr2TOJFyZCTzqP0CxN3NboapAdHdtNDXCLj2zyInWhiB24lnEKQx+WnDnJrmRdy8to9CyLD8K4FcYtL78dTqOLI/kTJ/fap5SUAQpumxWM0uIze8DS5zM9K6fqkIs6F9PTay2Z1OzsCSuZUUhiDpdALZtiUtpPDAhZ7Cv8C3cd1RlCs/GtWpRWcw0TFqPa992UqMfagCt45RoJozewPngEY1kQOP5ktt+Qo1UwHYZCUgO7zfwowE6G8r+cGFPnkoIW2LBRA4Yja5GVmDKgsEKvL+ravOmrOoEfwwTETDc8rr7k0pJkXEyCBeSDu4n5IdWAZ2qvaOjXwy2066ifPGhamvtSeySHl9UOITi//L0yCxE5bhmbAkSXptGRxl0xrDKOJIABxxTglbFUugWto1+8vIPSY4hov/K2sOYrx9JLs1QebUtjFsyNrL8z2DacmrIewzN9LXhD9EykEQo9lyijf5vTQfynfvGBurdJWDzPP3wNDVEmKT7E2azqm/1GX1jNpIEXcY0eLwWF+HSSkz5y+tBycwWavISdc36VjVfXqrdNtVd+5fpgElJf6VC9vbQCcBIG/L6bWQdZxQtfQ456e83YYDqUhgAnV8TAyxdLzIHydB+hYBXFuD1XCSZPM3jHNCvhtmVr98SaKph+449nkjdJ5q/kGCIm91HG7hher6ZYlwMcKANMpK2/Cbrl92XEdTi/dKDAeokL9iqT/RTSIaIj1GLd4mTMfB9pInHUzgkQ zP6+myyl 1bv2/XVL+gQm22mx/4yiCeCJTWJwipwjAF5z2OI+91zi5uhgEuR4c+t9Fz2BXVBovfBVJ1K5y0spA8Rk8a7sN1qVoU6in5P7bnOsaAOm2IYlQ9HUcU7zdeaKi4/B4+Oozpxul48Q9wkmwBbKWDiKnuGzxLLYzZ2DpFT+R+hbiP9xtMmllyJzGS75ZDgMMgtSUYWKqslMGuuuabLDpAczIlDDvLeMzMPYjNEuZ7P5Sfn4pV4ok0wGmu93MSpntoYJRbUyTvZg9iYi4wlgvLtM9GR53fk4OvUHRz5infayz1LCJYJoFZTSSyqNTW6DfuMRZSS1sLWiHEasFLCVJd27eg/RT/CwdTz8KNJ6zNXkjbUQHwFj6W59e6SzWcOOsqZerzGS+ODMNOvIzKD9Csrb+Cr+gYeqxw3sdwMMUmOSlAu460XRyECvPdDRb8EyVjXw+LVgdz2IP2bNWLbCY9DRy1f+1L3w2cCeGPTBqRW2k4tG6LjR7mFzQQ9KCExbRQIFZ1/LgGnQJcsCu69mmhYVuldDlPrjjQYCGJ4FsAOAv5O4p12f+r7cLFz1OcC97IWJVa6FPfSZzWgo/Js3PJ2gbZUYFJ8DIgvEdY1XUcberD3XJtxY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Perform a process { execstack } check unless virtual memory is marked executable by default. Signed-off-by: Christian Göttsche --- security/selinux/hooks.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index a0fde0641f77..daf901916836 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -113,6 +113,8 @@ struct selinux_state selinux_state; /* SECMARK reference count */ static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0); +static int default_noexec __ro_after_init; + #ifdef CONFIG_SECURITY_SELINUX_DEVELOP static int selinux_enforcing_boot __initdata; @@ -2221,6 +2223,18 @@ static int selinux_vm_enough_memory(struct mm_struct *mm, long pages) return cap_sys_admin; } +static int selinux_vm_execstack(void) +{ + u32 sid; + + if (!default_noexec) + return 0; + + sid = current_sid(); + return avc_has_perm(sid, sid, SECCLASS_PROCESS, + PROCESS__EXECSTACK, NULL); +} + /* binprm security operations */ static u32 ptrace_parent_sid(void) @@ -3767,8 +3781,6 @@ static int selinux_file_ioctl_compat(struct file *file, unsigned int cmd, return selinux_file_ioctl(file, cmd, arg); } -static int default_noexec __ro_after_init; - static int file_map_prot_check(struct file *file, unsigned long prot, int shared) { const struct cred *cred = current_cred(); @@ -7120,6 +7132,7 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = { LSM_HOOK_INIT(quota_on, selinux_quota_on), LSM_HOOK_INIT(syslog, selinux_syslog), LSM_HOOK_INIT(vm_enough_memory, selinux_vm_enough_memory), + LSM_HOOK_INIT(vm_execstack, selinux_vm_execstack), LSM_HOOK_INIT(netlink_send, selinux_netlink_send),