All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Iooss <nicolas.iooss@m4x.org>
To: Stephen Smalley <stephen.smalley@gmail.com>
Cc: selinux <Selinux@tycho.nsa.gov>
Subject: Re: Bug in libselinux/src/setrans_client.c
Date: Sat, 04 Jan 2014 12:14:46 +0100	[thread overview]
Message-ID: <52C7ED26.7000502@m4x.org> (raw)
In-Reply-To: <CAB9W1A0+me3z9_c7qBxWRBxecX1yKCjqjO7vtNtcb0kHG+-xLQ@mail.gmail.com>

I've reported this bug to coreutils' bug tracker and the caller is going
to be fixed: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16335

Thanks,

Nicolas

On 30/12/2013 17:11, Stephen Smalley wrote :
> Calling *setfilecon() with a NULL context is a bug in the caller, just
> like calling strlen() with a NULL string.
> Fix the callers, please.
> 
> On Wed, Dec 25, 2013 at 9:36 AM, Nicolas Iooss <nicolas.iooss@m4x.org> wrote:
>> 2013/12/23 Daniel J Walsh wrote:
>>>
>>> On 12/21/2013 09:27 AM, Nicolas Iooss wrote:
>>>> My first message was not so clear. The check in
>>>> libselinux/src/lsetfilecon.c line 35 [1] doesn't work because
>>>> selinux_trans_to_raw_context(context, &rcontext) returns 0 and sets
>>>> rcontext to NULL. This is why I'm asking to change the return value to
>>>> something else if you want "cp -a" working. This fix is not to introduce a
>>>> new feature but to fix an existing one.
>>>>
>>>> Nicolas
>>>>
>>>
>>> How about if we add a check on lsetfilecon_raw?  Changing the behaviour on
>>> selinux_trans_to_raw_context might cause other problems.
>>
>> I agree. I've found
>> http://selinuxproject.org/page/LibselinuxAPISummary which says
>> precisely for selinux_trans_to_raw_context: "If passed NULL, sets the
>> returned context to NULL and returns 0." As this feature is
>> documented, callers may rely on it and changing this behavior is
>> likely to break things.
>>
>> Moreover setfilecon_raw and fsetfilecon_raw have the same NULL-pointer
>> dereference issue. Do these functions need a patch too?
>>
>> By the way, other callers of selinux_trans_to_raw_context may also
>> share this bug: avc_context_to_sid, security_canonicalize_context,
>> security_check_context, etc. Is doing a segmentation fault the
>> expected way to tell the caller it used a NULL pointer and should have
>> manually checked every parameter before calling any libselinux
>> function?
>>
>> Thanks and merry Christmas!
>>
>> Nicolas
>>
>>>
>>>
>>> diff --git a/libselinux/src/lsetfilecon.c b/libselinux/src/lsetfilecon.c
>>> index 461e3f7..af3775e 100644
>>> - --- a/libselinux/src/lsetfilecon.c
>>> +++ b/libselinux/src/lsetfilecon.c
>>> @@ -9,6 +9,10 @@
>>>
>>>  int lsetfilecon_raw(const char *path, const security_context_t context)
>>>  {
>>> +       if (! context) {
>>> +               errno=EINVAL;
>>> +               return -1;
>>> +       }
>>>         return lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1
>>>                          0);
>>>  }
>>
>> _______________________________________________
>> Selinux mailing list
>> Selinux@tycho.nsa.gov
>> To unsubscribe, send email to Selinux-leave@tycho.nsa.gov.
>> To get help, send an email containing "help" to Selinux-request@tycho.nsa.gov.

  parent reply	other threads:[~2014-01-04 11:14 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-21 14:03 Bug in libselinux/src/setrans_client.c Nicolas Iooss
     [not found] ` <CAPJdAQBu3=ZyEqUqn_eq4HagfGZZP3-9u_Taimozkkt4EjGfZg@mail.gmail.com>
2013-12-21 14:27   ` Nicolas Iooss
2013-12-23 14:46     ` Daniel J Walsh
2013-12-23 19:08       ` Stephen Smalley
2013-12-23 20:49         ` Nicolas Iooss
2013-12-25 14:36       ` Nicolas Iooss
2013-12-25 14:51         ` Francis Cunnane
2013-12-30 16:11         ` Stephen Smalley
2013-12-31  3:11           ` Matthew Thode
2013-12-31  7:33             ` Francis Cunnane
2013-12-31 18:52               ` Matthew Thode
2013-12-31 19:02                 ` Francis Cunnane
2014-01-06 15:56                 ` Daniel J Walsh
2014-01-06 17:49                   ` Stephen Smalley
2014-01-06 18:00                     ` Daniel J Walsh
2014-01-06 18:11                       ` Stephen Smalley
2014-01-06 20:59                         ` Daniel J Walsh
2014-01-07 13:59               ` Mailing list etiquette Stephen Smalley
2014-01-04 11:14           ` Nicolas Iooss [this message]
2013-12-31 15:33         ` Bug in libselinux/src/setrans_client.c Daniel J Walsh
2013-12-31 15:36         ` 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=52C7ED26.7000502@m4x.org \
    --to=nicolas.iooss@m4x.org \
    --cc=Selinux@tycho.nsa.gov \
    --cc=stephen.smalley@gmail.com \
    /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.