All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Smalley <sds@tycho.nsa.gov>
To: Eric Paris <eparis@redhat.com>
Cc: selinux@tycho.nsa.gov
Subject: Re: [PATCH] SELinux: apply a different permission to ptrace a child vs non-child
Date: Fri, 30 Mar 2012 16:28:38 -0400	[thread overview]
Message-ID: <1333139318.8293.50.camel@moss-pluto> (raw)
In-Reply-To: <20120330201334.23363.14917.stgit@paris.rdu.redhat.com>

On Fri, 2012-03-30 at 16:13 -0400, Eric Paris wrote:
> Some applications, like gdb, are able to ptrace both children or other
> completely unrelated tasks.  We would like to be able to discern these two
> things and to be able to allow gdb to ptrace it's children, but not to be
> able to ptrace unrelated tasks for security reasons.
> 
> This patch implements a new permission ptrace_child which is checked
> INSTEAD of ptrace if and ONLY if the ptrace_child policy capability is
> enabled.  We need a seperate policy cap because we are actually reducing
> the scope of ptrace.  If we used the default unknown permission handler we
> would run into trouble as new kernel with old policy would be weaker than
> old kernel with old policy.
> 
> Signed-off-by: Eric Paris <eparis@redhat.com>
> ---
> 
>  security/selinux/hooks.c            |   38 +++++++++++++++++++++++++++++++++++
>  security/selinux/include/classmap.h |    2 +-
>  security/selinux/include/security.h |    2 ++
>  security/selinux/selinuxfs.c        |    3 ++-
>  security/selinux/ss/services.c      |    3 +++
>  5 files changed, 46 insertions(+), 2 deletions(-)
> 
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index ba74635..5cee787 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -1805,6 +1805,39 @@ static inline u32 open_file_to_av(struct file *file)
>  
>  /* Hook functions begin here. */
>  
> +/**
> + * task_is_descendant - walk up a process family tree looking for a match
> + * @parent: the process to compare against while walking up from child
> + * @child: the process to start from while looking upwards for parent
> + *
> + * Returns 1 if child is a descendant of parent, 0 if not.
> + */
> +static int task_is_descendant(struct task_struct *parent,
> +			      struct task_struct *child)
> +{
> +	int rc = 0;
> +	struct task_struct *walker = child;
> +
> +	if (!parent || !child)
> +		return 0;
> +
> +	rcu_read_lock();
> +	if (!thread_group_leader(parent))
> +		parent = rcu_dereference(parent->group_leader);
> +	while (walker->pid > 0) {
> +		if (!thread_group_leader(walker))
> +			walker = rcu_dereference(walker->group_leader);
> +		if (walker == parent) {
> +			rc = 1;
> +			break;
> +		}
> +		walker = rcu_dereference(walker->real_parent);
> +	}
> +	rcu_read_unlock();
> +
> +	return rc;
> +}
> +
>  static int selinux_ptrace_access_check(struct task_struct *child,
>  				     unsigned int mode)
>  {

Same function as in yama?  So it should go to common code, ideally in
the core kernel since it is fairly tightly coupled to the process
implementation.

I guess you decide TRACEME wasn't a sufficient distinguisher.  However,
will this suffice?  Seems like yama had to keep adding exceptions and
allow the task to tell the kernel who to allowed to trace it.  Would
hate to add this only to find that it still doesn't allow you to deny
ptrace by default, since that was your motivation, right?

-- 
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

  reply	other threads:[~2012-03-30 20:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-30 20:13 [PATCH] SELinux: apply a different permission to ptrace a child vs non-child Eric Paris
2012-03-30 20:28 ` Stephen Smalley [this message]
2012-03-30 20:37   ` Eric Paris
2012-04-01 10:23     ` Daniel J Walsh

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=1333139318.8293.50.camel@moss-pluto \
    --to=sds@tycho.nsa.gov \
    --cc=eparis@redhat.com \
    --cc=selinux@tycho.nsa.gov \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.