From: Stephen Smalley <sds@tycho.nsa.gov>
To: Nick Kralevich <nnk@google.com>
Cc: Daniel Cashman <dcashman@android.com>,
SELinux <selinux@tycho.nsa.gov>,
Jeffrey Vander Stoep <jeffv@google.com>
Subject: Re: getpidcon with pid == 0 (Was: Re: [PATCH 2/2] libselinux: procattr: return einval for <= 0 pid args.)
Date: Wed, 24 Feb 2016 10:32:13 -0500 [thread overview]
Message-ID: <56CDCCFD.9020009@tycho.nsa.gov> (raw)
In-Reply-To: <CAFJ0LnHvFe6PkGp2BGKj-cQ-e11kFo9DacB_MbP9xFmi5S=DNA@mail.gmail.com>
On 02/24/2016 10:25 AM, Nick Kralevich wrote:
> A quick Google search for "getpidcon(0" shows only the Android bug.
>
> https://www.google.com/webhp#q=%22getpidcon(0%22
>
> -- Nick
Yes, I looked through searchcode.com results for getpidcon (not just
with a hardcoded 0 but also looking for any cases where they assume that
setting a variable pid == 0 degenerates to getcon behavior), and didn't
see anything.
I've also asked the Fedora SELinux maintainers if they know of anything
that would break.
>
> On Wed, Feb 24, 2016 at 6:49 AM, Stephen Smalley <sds@tycho.nsa.gov
> <mailto:sds@tycho.nsa.gov>> wrote:
>
> On 02/23/2016 03:24 PM, Daniel Cashman wrote:
>
> From: dcashman <dcashman@android.com <mailto: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
> <mailto: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)
>
>
>
>
>
> --
> Nick Kralevich | Android Security | nnk@google.com
> <mailto:nnk@google.com> | 650.214.4037
next prev parent reply other threads:[~2016-02-24 15:32 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 ` getpidcon with pid == 0 (Was: Re: [PATCH 2/2] libselinux: procattr: return einval for <= 0 pid args.) Stephen Smalley
2016-02-24 15:25 ` Nick Kralevich
2016-02-24 15:32 ` Stephen Smalley [this message]
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=56CDCCFD.9020009@tycho.nsa.gov \
--to=sds@tycho.nsa.gov \
--cc=dcashman@android.com \
--cc=jeffv@google.com \
--cc=nnk@google.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.