Re: [RFC PATCH 2/4] selinux: clarify task subjective and objective credentials

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Mar 10, 2021 at 11:32 PM Paul Moore <paul@xxxxxxxxxxxxxx> wrote:
> On Tue, Mar 9, 2021 at 10:06 PM John Johansen
> <john.johansen@xxxxxxxxxxxxx> wrote:
> > On 2/19/21 3:29 PM, Paul Moore wrote:

...

> > > @@ -2034,11 +2047,8 @@ static inline u32 open_file_to_av(struct file *file)
> > >
> > >  static int selinux_binder_set_context_mgr(struct task_struct *mgr)
> > >  {
> > > -     u32 mysid = current_sid();
> > > -     u32 mgrsid = task_sid(mgr);
> > > -
> > >       return avc_has_perm(&selinux_state,
> > > -                         mysid, mgrsid, SECCLASS_BINDER,
> > > +                         current_sid(), task_sid_obj(mgr), SECCLASS_BINDER,
> > >                           BINDER__SET_CONTEXT_MGR, NULL);
> > >  }
> > >
> > > @@ -2046,8 +2056,8 @@ static int selinux_binder_transaction(struct task_struct *from,
> > >                                     struct task_struct *to)
> > >  {
> > >       u32 mysid = current_sid();
> > > -     u32 fromsid = task_sid(from);
> > > -     u32 tosid = task_sid(to);
> > > +     u32 fromsid = task_sid_subj(from);
> >
> > fromsid potentially gets used as both the subject and the object the following
> > permission checks. It makes sense to use the same cred for both checks but
> > what I am not sure about yet is whether its actually safe to use the subject
> > sid when the task isn't current.
> >
> > ie. I am still trying to determine if there is a race here between the transaction
> > request and the permission check.
>
> Okay, I see what you are concerned about now ... and unfortunately I'm
> not seeing a lot of precedence in the kernel for this type of usage
> either; the closest I can find is something like task_lock(), but that
> doesn't seem to cover the subjective creds.  In fact, looking at
> override_creds(), there is nothing preventing a task from changing
> it's subjective creds at any point in time.
>
> Beyond the task_sid_subj() code here, looking back at patch 1 and the
> use of security_task_getsecid_subj() we look to be mostly safe (where
> safe means we are only inspecting the current task) with the exception
> of the binder code once again.  There are some other exceptions but
> they are in the ptrace and audit code, both of which should be okay
> given the nature and calling context of the code.
>
> The problem really does seem to be just binder, and as I look at
> binder userspace example code, I'm starting to wonder if binder is
> setup properly to operate sanely in a situation where a process
> overrides its subject creds.  It may be that we always need to use the
> objective/real creds with binder.  Jeff, any binder insight here you
> can share with us?
>
> > > +     u32 tosid = task_sid_subj(to);
> > its not clear to me that using the subj for to is correct
>
> Yes, I believe you are correct.  Jeff, I know you looked at this code
> already, but I'm guessing you may have missed this (just as I did when
> I wrote it); are you okay with changing 'tosid' in
> selinux_binder_transaction() to the task's objective credentials?

Hearing no comments from the Android/binder folks, I'm in the process
of switching this patchset to always use the objective creds in the
case of binder.  It's safe and I'm not sure binder is really prepared
for the idea of a task changing it's creds anyway.

Once the kernel builds and passes some basic sanity checks I'll repost
the patches for review and inclusion, minus the AppArmor patch.

-- 
paul moore
www.paul-moore.com



[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux