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+HZb4Nf3IybSEKLePMsEUHvfgOKWfDJBnQabq3Yp0Cpy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JRbUyTvZg9iYi4wlgvLtM9GR53fk4OvUHRz5infayz1LCJYJoFZTSSyqNTW6DfuMRZSS1sLWiHEasFLCVJd27eg/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),