From: Stephen Smalley <sds@tycho.nsa.gov>
To: Jann Horn <jann@thejh.net>,
security@kernel.org, Alexander Viro <viro@zeniv.linux.org.uk>,
Paul Moore <paul@paul-moore.com>,
Eric Paris <eparis@parisplace.org>,
James Morris <james.l.morris@oracle.com>,
"Serge E. Hallyn" <serge@hallyn.com>
Cc: Nick Kralevich <nnk@google.com>,
Janis Danisevskis <jdanis@google.com>,
linux-security-module@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/3] selinux: require EXECMEM for forced ptrace poke
Date: Thu, 29 Sep 2016 12:38:53 -0400 [thread overview]
Message-ID: <4b83b10c-2127-3d85-89a8-1d1ceccbfa3b@tycho.nsa.gov> (raw)
In-Reply-To: <1475103281-7989-4-git-send-email-jann@thejh.net>
On 09/28/2016 06:54 PM, Jann Horn wrote:
> This is a breaking change for SELinux users that restrict EXECMEM: It might
> break gdb if gdb is executed in a domain that does not have EXECMEM
> privilege over the debuggee domain.
Since this would break compatibility with existing SELinux policies, you
have to wrap it with a conditional on a policy capability that you can
then enable in newer policies. See commit
2be4d74f2fd45460d70d4fe65cc1972ef45bf849 for an example. This requires
a corresponding update to libsepol, and then adding the new policy
capability to your policy (in the policy_capabilities file).
>
> Unlike most other SELinux hooks, this one takes the subject credentials as
> an argument instead of looking up current_cred(). This is done because the
> security_forced_write() LSM hook can be invoked from within the write
> handler of /proc/$pid/mem, where current_cred() is pretty useless.
>
> Signed-off-by: Jann Horn <jann@thejh.net>
> Reviewed-by: Janis Danisevskis <jdanis@android.com>
> ---
> security/selinux/hooks.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index 13185a6..e36682a 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -2149,6 +2149,20 @@ static int selinux_ptrace_traceme(struct task_struct *parent)
> return task_has_perm(parent, current, PROCESS__PTRACE);
> }
>
> +static int selinux_forced_write(struct vm_area_struct *vma,
> + const struct cred *subject_cred,
> + const struct cred *object_cred)
> +{
> + /* Permitting a write to readonly memory is fine - making the readonly
> + * memory executable afterwards would require EXECMOD permission because
> + * anon_vma would be non-NULL.
> + */
> + if ((vma->vm_flags & VM_EXEC) == 0)
> + return 0;
> +
> + return cred_has_perm(subject_cred, object_cred, PROCESS__EXECMEM);
> +}
> +
> static int selinux_capget(struct task_struct *target, kernel_cap_t *effective,
> kernel_cap_t *inheritable, kernel_cap_t *permitted)
> {
> @@ -6033,6 +6047,7 @@ static struct security_hook_list selinux_hooks[] = {
>
> LSM_HOOK_INIT(ptrace_access_check, selinux_ptrace_access_check),
> LSM_HOOK_INIT(ptrace_traceme, selinux_ptrace_traceme),
> + LSM_HOOK_INIT(forced_write, selinux_forced_write),
> LSM_HOOK_INIT(capget, selinux_capget),
> LSM_HOOK_INIT(capset, selinux_capset),
> LSM_HOOK_INIT(capable, selinux_capable),
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
prev parent reply other threads:[~2016-09-29 16:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-28 22:54 [PATCH v2 0/3] fix SELinux W^X bypass via ptrace Jann Horn
2016-09-28 22:54 ` [PATCH v2 1/3] fs/exec: don't force writing memory access Jann Horn
2016-09-29 16:09 ` Oleg Nesterov
2016-09-28 22:54 ` [PATCH v2 2/3] mm: add LSM hook for writes to readonly memory Jann Horn
2016-09-28 23:22 ` Andy Lutomirski
2016-09-28 23:32 ` Jann Horn
2016-09-28 23:44 ` Jann Horn
2016-11-03 2:25 ` Jann Horn
2016-09-29 6:25 ` Ingo Molnar
2016-09-28 22:54 ` [PATCH v2 3/3] selinux: require EXECMEM for forced ptrace poke Jann Horn
2016-09-29 6:19 ` Ingo Molnar
2016-09-29 16:38 ` Stephen Smalley [this message]
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=4b83b10c-2127-3d85-89a8-1d1ceccbfa3b@tycho.nsa.gov \
--to=sds@tycho.nsa.gov \
--cc=eparis@parisplace.org \
--cc=james.l.morris@oracle.com \
--cc=jann@thejh.net \
--cc=jdanis@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-security-module@vger.kernel.org \
--cc=nnk@google.com \
--cc=paul@paul-moore.com \
--cc=security@kernel.org \
--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 NNTP newsgroup(s).