All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Smalley <sds@tycho.nsa.gov>
To: Daniel Cashman <dcashman@android.com>, selinux@tycho.nsa.gov
Subject: getpidcon with pid == 0 (Was: Re: [PATCH 2/2] libselinux: procattr: return einval for <= 0 pid args.)
Date: Wed, 24 Feb 2016 09:49:16 -0500	[thread overview]
Message-ID: <56CDC2EC.5050502@tycho.nsa.gov> (raw)
In-Reply-To: <1456259040-13721-3-git-send-email-dcashman@android.com>

On 02/23/2016 03:24 PM, Daniel Cashman wrote:
> From: dcashman <dcashman@android.com>
>
> getpidcon documentation does not specify that a pid of 0 refers to the
> current process, and getcon exists specifically to provide this
> functionality, and getpidcon(getpid()) would provide it as well.
> Disallow pid values <= 0 that may lead to unintended behavior in
> userspace object managers.

I'll try to see if there are any legitimate users of getpidcon with pid 
== 0.  If anyone on the list knows of one, please speak up.

>
> Signed-off-by: Daniel Cashman <dcashman@android.com>
> ---
>   libselinux/src/procattr.c | 14 ++++++++++++--
>   1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/libselinux/src/procattr.c b/libselinux/src/procattr.c
> index c20f003..eee4612 100644
> --- a/libselinux/src/procattr.c
> +++ b/libselinux/src/procattr.c
> @@ -306,11 +306,21 @@ static int setprocattrcon(const char * context,
>   #define getpidattr_def(fn, attr) \
>   	int get##fn##_raw(pid_t pid, char **c)	\
>   	{ \
> -		return getprocattrcon_raw(c, pid, #attr); \
> +		if (pid <= 0) { \
> +			errno = EINVAL; \
> +			return -1; \
> +		} else { \
> +			return getprocattrcon_raw(c, pid, #attr); \
> +		} \
>   	} \
>   	int get##fn(pid_t pid, char **c)	\
>   	{ \
> -		return getprocattrcon(c, pid, #attr); \
> +		if (pid <= 0) { \
> +			errno = EINVAL; \
> +			return -1; \
> +		} else { \
> +			return getprocattrcon(c, pid, #attr); \
> +		} \
>   	}
>
>   all_selfattr_def(con, current)
>

  parent reply	other threads:[~2016-02-24 14:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-23 20:23 [PATCH 0/2] Return error on invalid pids for procattr funcs Daniel Cashman
2016-02-23 20:23 ` [PATCH 1/2] libselinux: procattr: return error on invalid pid_t input Daniel Cashman
2016-02-23 20:24   ` [PATCH 2/2] libselinux: procattr: return einval for <= 0 pid args Daniel Cashman
2016-02-23 20:29     ` Daniel Cashman
2016-02-23 21:22       ` Nick Kralevich
2016-02-29 17:38         ` Stephen Smalley
2016-02-24 14:49     ` Stephen Smalley [this message]
2016-02-24 15:25       ` getpidcon with pid == 0 (Was: Re: [PATCH 2/2] libselinux: procattr: return einval for <= 0 pid args.) Nick Kralevich
2016-02-24 15:32         ` Stephen Smalley
2016-02-24 16:47           ` Petr Lautrbach
2016-02-24 14:21   ` [PATCH 1/2] libselinux: procattr: return error on invalid pid_t input Stephen Smalley

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=56CDC2EC.5050502@tycho.nsa.gov \
    --to=sds@tycho.nsa.gov \
    --cc=dcashman@android.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.