From: "Christian Göttsche" <cgzones@googlemail.com>
To: Casey Schaufler <casey@schaufler-ca.com>
Cc: linux-security-module@vger.kernel.org,
Eric Biederman <ebiederm@xmission.com>,
Kees Cook <keescook@chromium.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Paul Moore <paul@paul-moore.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
Khadija Kamran <kamrankhadijadj@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Ondrej Mosnacek <omosnace@redhat.com>,
Roberto Sassu <roberto.sassu@huawei.com>,
Alfred Piccioni <alpic@google.com>,
John Johansen <john.johansen@canonical.com>,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 1/2] lsm: introduce new hook security_vm_execstack
Date: Fri, 15 Mar 2024 19:30:23 +0100 [thread overview]
Message-ID: <CAJ2a_DfGHBuVBLTWniNektRsY_6P=x37XT-31+P6mV9dgJvt0Q@mail.gmail.com> (raw)
In-Reply-To: <f6d1b9fc-dfb1-4fd8-bfa0-bd1349c4a1c1@schaufler-ca.com>
On Fri, 15 Mar 2024 at 19:22, Casey Schaufler <casey@schaufler-ca.com> wrote:
>
> On 3/15/2024 11:08 AM, Christian Göttsche wrote:
> > 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.
>
> This seems like a hideously expensive way to implement a flag
> disallowing execution of programs with executable stacks. What's
> wrong with adding a flag VM_NO_EXECUTABLE_STACK?
That would be global and not on a per application basis.
One might want to exempt known legacy programs.
Also is performance a concern for this today's rare occurrence?
> >
> > Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> > ---
> > 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
next prev parent reply other threads:[~2024-03-15 18:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-15 18:08 [RFC PATCH 2/2] selinux: wire up new execstack LSM hook Christian Göttsche
2024-03-15 18:08 ` [RFC PATCH 1/2] lsm: introduce new hook security_vm_execstack Christian Göttsche
2024-03-15 18:22 ` Casey Schaufler
2024-03-15 18:30 ` Christian Göttsche [this message]
2024-03-15 18:41 ` Casey Schaufler
2024-03-15 20:22 ` Paul Moore
2024-03-16 3:24 ` Kees Cook
2024-03-19 23:10 ` Paul Moore
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJ2a_DfGHBuVBLTWniNektRsY_6P=x37XT-31+P6mV9dgJvt0Q@mail.gmail.com' \
--to=cgzones@googlemail.com \
--cc=alpic@google.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=brauner@kernel.org \
--cc=casey@schaufler-ca.com \
--cc=ebiederm@xmission.com \
--cc=jack@suse.cz \
--cc=jmorris@namei.org \
--cc=john.johansen@canonical.com \
--cc=kamrankhadijadj@gmail.com \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-security-module@vger.kernel.org \
--cc=omosnace@redhat.com \
--cc=paul@paul-moore.com \
--cc=roberto.sassu@huawei.com \
--cc=serge@hallyn.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).