Received: by 2002:ab2:7444:0:b0:1ef:eae8:a797 with SMTP id f4csp9037lqn; Fri, 15 Mar 2024 11:11:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVakrkE4nbBLsgTe5xKud4pi+0pDM+r4YbRw4lTmBj/dEeqaUhcEnyVYxrpvJ9UjSkV7DrT5XTzrFWIXAKNayef44xy4OAmb2rUTWgxuA== X-Google-Smtp-Source: AGHT+IFV9loSj/p5O2LRl55CKhCczi8CmQPpuSRFmw32YpQDrzLuWzY8yeXehDm0DNG3fFB1giDc X-Received: by 2002:a05:6512:12d6:b0:513:d524:3790 with SMTP id p22-20020a05651212d600b00513d5243790mr3501100lfg.43.1710526273479; Fri, 15 Mar 2024 11:11:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710526273; cv=pass; d=google.com; s=arc-20160816; b=x0LPl8L8p70xxEWvW4YvadmpDmVVXLJ3U1R2U9/5jH0/X1oP1m2otXCSCaTZ6i7eD7 wJoVaTBmyIK7SmvLM7smsT7/SfJdSpggq8s+kOGX4AHQpMvHztXPS5Ip31z62PFY9zWz mCA2HXJc3qyIqTO0nIuSdtY44ZwEjjZg4S/mRbfhb7Hl2H3KvYWZUXA0Q3UB9ufZvsj1 lLmwSsrvbPTetzdZjdPjf6ttqxQBVMaW6CzleZS6ccdA9Yd4k4aM5gk/qXX6pxwF1yO0 vi7KvYFJx4ZhkGmZVvB4Hq+Qruak6DaIrA/iQTsqZYi0A/rijefyjyrFSkj7QlItwIqa ZNug== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=5vvztQ9R6kS3LLaEzPtb4PkQkdZH06n2URzp7Npwuwk=; fh=iWheN8BjZVH6hYjV6zxuTDX7XaSU6NP0XOwcGYMvPr4=; b=lXnlIOWjcHUFRiNZjO7yHMUUjPk+3OQQbLYc/2ZcMXQ/UOj/W6bHWDHJ4Gm2cuOAnc 5/CSwT+nBkS9sOIPNy8Elp/ZCDcl7Mq3pTLh6ADNHQ+iPpLnT+ZNGi7pnBqsdcXsRapW +qGza2O//Aj1R33/PTmRMFVzjaOjiKCGrz++QGzXl60kmvcdlK+0dHmOgTwMj6FYxCoW 4v6nSNccCF/u5qlpHrkjeHvnwSIAYfH0fc74L71RzVUSvE39Ag/VafWhYBvV3oASTiEC tT09N3y11TLMnxMrewd18JTy/4Mqrpma66fw6AQlHC2/5FPBnSH5qRNihvXDTyX48oWd ZOpw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20230601 header.b="Z/ZWKzH7"; arc=pass (i=1 spf=pass spfdomain=googlemail.com dkim=pass dkdomain=googlemail.com dmarc=pass fromdomain=googlemail.com); spf=pass (google.com: domain of linux-kernel+bounces-104768-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104768-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e23-20020a170906505700b00a469b9ccde7si235330ejk.1051.2024.03.15.11.11.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 11:11:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104768-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@googlemail.com header.s=20230601 header.b="Z/ZWKzH7"; arc=pass (i=1 spf=pass spfdomain=googlemail.com dkim=pass dkdomain=googlemail.com dmarc=pass fromdomain=googlemail.com); spf=pass (google.com: domain of linux-kernel+bounces-104768-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104768-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F11131F241EC for ; Fri, 15 Mar 2024 18:11:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 410495102F; Fri, 15 Mar 2024 18:10:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=googlemail.com header.i=@googlemail.com header.b="Z/ZWKzH7" Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3146020310; Fri, 15 Mar 2024 18:10:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710526247; cv=none; b=pKzCBjFlL6V/oFYrAsgUqxRvwU8cvHB8Z9juWU9952lBXmcTcsLS1WDPPkJK+ayNDSpiuOKl812WXw58rqEJ7ROZqVafYinwIZy7EG3PneV78QgSh3RdVjXq9wClQNevfFvWll85AEGGn+b+fdcf8tW/QKFtmAx3WlB2r0gFU5I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710526247; c=relaxed/simple; bh=C25MXQHA40uV4GLLPq6rWFr+sjYebOCkqkMP+9WqSmU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nd+4xcKWg+My0LOEP6FfnyDcTUYMh1eAF+t7nPxQOd+2gS5v3kO5ZPLpWrZfPBs7Nh7KGkdZN6zHg/VdDmV8uPqkGHe3l+NwoaJHoHypRCp/GIDtVxcBPRWB5NvwE7WCq3gLmDcOIbFedvkI2JQqFjZtjTvWjNNVmEO5P0/sbgE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=googlemail.com; spf=pass smtp.mailfrom=googlemail.com; dkim=pass (2048-bit key) header.d=googlemail.com header.i=@googlemail.com header.b=Z/ZWKzH7; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=googlemail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=googlemail.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a3fb8b0b7acso260071866b.2; 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=vger.kernel.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=Z/ZWKzH7cPUad1ak3plQAJQ38lvCNL6ZX2lZy4gbAHMsSLuW48KMxlbV7PLAiY7bT2 1JZvrx8iuq6bbBoV9uB34upIHv25k8ehBJfoAWKlGFQjEg6qkqxs6HaO98EuAcGHZjp5 1FmzpR8KZe9mfNFMvPuotwtznIjBYWqfqF7LegDzo2pl5+Lc6Pou75LHYVjyKkM4Sv2O 0DPjaNkPJ3ufF4Ruye0PPkwMMelhDveLmRBbXNpio3nEsLi9Zac+QP/hjxWqMLOdPf62 d+aeVFpOUtZJc+yPdP8/rcqikrOWJsPA46fvtkvpycGAANI+3m5v7gp/dhWGSpITUsGf tWLQ== 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=ZQRc6XFi3azpBCOnJ5gu3tqGqMZd4vjHXBBB1OvITHg8vvl3AdwMvQ0FoaZo9Vzgo7 D6pVFkWjA63u/J6dXzLRhWxTWWBAlxpiZsMFI0M31MlVv3DR2owC3yD0hOVGapOCe0q3 teyQ77ODUccqNG+i34mLML9DiaFcPUhEHh8qD6saYeZQtEYruE7/pNV1ZrN0E5TQZxPC UXPJa8d78Es+V3G/CwRf/a3kaA7CFRCckDqE1dU/Zj/bxrQ/IQf0y8hfDmLklFOpb/3e wzu0tYlx/BSlVgNn205Vv6o5FDemp0aRe+1OUr+dG+ZHZ18oPo0eCMSkO5V/e8foeDEv AFOA== X-Forwarded-Encrypted: i=1; AJvYcCXm0D9gAiTCPlue9oyPrgGZJQixHIOEClROelifGv+PylfCAu3lLHhCTRqjvr7WBKoOsBP//zHboWBRmOFDmVjj+9clxLJGrDWlFqaGYvo4STAjR4cgjhgfIwaY7buL7V+cEPius4Fps2m+Fw== X-Gm-Message-State: AOJu0YzJx6NSkgdYTIhJThpCJFRxdMp6dfxcq41955icLfcjNvi4FLy6 Ro3m9XDtF3Pz6q/tZRIOiPshDl81IhJcRZ8y8KYAtNDh60+Or1mMGzn49WZAB6fDzg== 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=20G=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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 -- 2.43.0