Linux-Security-Module Archive on lore.kernel.org
 help / color / Atom feed
* security_task_getsecid() and subjective vs objective task creds
@ 2021-02-18 19:34 Paul Moore
  2021-02-18 21:40 ` Casey Schaufler
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Paul Moore @ 2021-02-18 19:34 UTC (permalink / raw)
  To: linux-security-module, selinux, linux-audit

Hi all,

When looking into a problem I noticed that audit was recording the
wrong subject label for a process.  Doing a bit of digging I realized
this was caused by the SELinux security_task_getsecid() implementation
returning the objective security label (taken from task->real_cred),
and not the subjective security label (taken from task->cred).

Looking around at the other LSMs which implement this hook, Smack and
AppArmor, it appears they both do the same thing: return the objective
security ID for the process.  Looking quickly at the various non-LSM
callers of the security_task_getsecid() hook, it unfortunately looks
like all of them expect the subjective security ID to be returned.
The only caller I'm not 100% confident in is binder, but from what I
can tell it looks like they are expecting the subjective ID too.

At least we are consistently wrong :)

How do we want to fix this?  The obvious fix is to change the SELinux,
AppArmor, and Smack security_task_getsecid() implementations to return
the subjective security ID (->cred), and likely make a note in
lsm_hooks.h, but if someone can see a case where we would need both
the subjective and objective security labels speak up and we can
introduce a new hook for the subjective label, and likely add a "_obj"
to the end of the existing hook to help make it more clear.  If
neither of those options are acceptable, we could convert all of the
existing callers to use something like the line below (assumes
current), but that is the least appealing option as far as I'm
concerned.

  security_cred_getsecid(current_cred(), &sid);

Opinions?

-- 
paul moore
www.paul-moore.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: security_task_getsecid() and subjective vs objective task creds
  2021-02-18 19:34 security_task_getsecid() and subjective vs objective task creds Paul Moore
@ 2021-02-18 21:40 ` Casey Schaufler
  2021-02-19 19:17   ` Paul Moore
  2021-02-18 22:07 ` Casey Schaufler
  2021-02-20  2:54 ` James Morris
  2 siblings, 1 reply; 7+ messages in thread
From: Casey Schaufler @ 2021-02-18 21:40 UTC (permalink / raw)
  To: Paul Moore, linux-security-module, selinux, linux-audit; +Cc: Casey Schaufler

On 2/18/2021 11:34 AM, Paul Moore wrote:
> Hi all,
>
> When looking into a problem I noticed that audit was recording the
> wrong subject label for a process.  Doing a bit of digging I realized
> this was caused by the SELinux security_task_getsecid() implementation
> returning the objective security label (taken from task->real_cred),
> and not the subjective security label (taken from task->cred).
>
> Looking around at the other LSMs which implement this hook, Smack and
> AppArmor, it appears they both do the same thing: return the objective
> security ID for the process.  Looking quickly at the various non-LSM
> callers of the security_task_getsecid() hook, it unfortunately looks
> like all of them expect the subjective security ID to be returned.
> The only caller I'm not 100% confident in is binder, but from what I
> can tell it looks like they are expecting the subjective ID too.
>
> At least we are consistently wrong :)

We may have come down with a case of helperitis. 

>
> How do we want to fix this?  The obvious fix is to change the SELinux,
> AppArmor, and Smack security_task_getsecid() implementations to return
> the subjective security ID (->cred), and likely make a note in
> lsm_hooks.h,

That would be my choice.

>  but if someone can see a case where we would need both
> the subjective and objective security labels speak up and we can
> introduce a new hook for the subjective label, and likely add a "_obj"
> to the end of the existing hook to help make it more clear.  If
> neither of those options are acceptable, we could convert all of the
> existing callers to use something like the line below (assumes
> current), but that is the least appealing option as far as I'm
> concerned.
>
>   security_cred_getsecid(current_cred(), &sid);
>
> Opinions?

If the objective cred isn't being used in the access control decision
it seems pointless to add it to the audit record. If there is a case
where the task is being treated as an object, signal delivery comes to
mind, you still want the objective credential. So it seems like care
may be required to ensure that the correct value (sub vs obj) is
used.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: security_task_getsecid() and subjective vs objective task creds
  2021-02-18 19:34 security_task_getsecid() and subjective vs objective task creds Paul Moore
  2021-02-18 21:40 ` Casey Schaufler
@ 2021-02-18 22:07 ` Casey Schaufler
  2021-02-18 22:50   ` Steve Grubb
  2021-02-20  2:54 ` James Morris
  2 siblings, 1 reply; 7+ messages in thread
From: Casey Schaufler @ 2021-02-18 22:07 UTC (permalink / raw)
  To: Paul Moore, linux-security-module, selinux, linux-audit; +Cc: Casey Schaufler

On 2/18/2021 11:34 AM, Paul Moore wrote:
> Hi all,
>
> When looking into a problem I noticed that audit was recording the
> wrong subject label for a process.  Doing a bit of digging I realized
> this was caused by the SELinux security_task_getsecid() implementation
> returning the objective security label (taken from task->real_cred),
> and not the subjective security label (taken from task->cred).
>
> Looking around at the other LSMs which implement this hook, Smack and
> AppArmor, it appears they both do the same thing: return the objective
> security ID for the process.  Looking quickly at the various non-LSM
> callers of the security_task_getsecid() hook, it unfortunately looks
> like all of them expect the subjective security ID to be returned.
> The only caller I'm not 100% confident in is binder, but from what I
> can tell it looks like they are expecting the subjective ID too.
>
> At least we are consistently wrong :)

We may have come down with a case of helperitis. 

> How do we want to fix this?  The obvious fix is to change the SELinux,
> AppArmor, and Smack security_task_getsecid() implementations to return
> the subjective security ID (->cred), and likely make a note in
> lsm_hooks.h,

That would be my choice.

>  but if someone can see a case where we would need both
> the subjective and objective security labels speak up and we can
> introduce a new hook for the subjective label, and likely add a "_obj"
> to the end of the existing hook to help make it more clear.  If
> neither of those options are acceptable, we could convert all of the
> existing callers to use something like the line below (assumes
> current), but that is the least appealing option as far as I'm
> concerned.
>
>   security_cred_getsecid(current_cred(), &sid);
>
> Opinions?

If the objective cred isn't being used in the access control decision
it seems pointless to add it to the audit record. If there is a case
where the task is being treated as an object, signal delivery comes to
mind, you still want the objective credential. So it seems like care
may be required to ensure that the correct value (sub vs obj) is
used.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: security_task_getsecid() and subjective vs objective task creds
  2021-02-18 22:07 ` Casey Schaufler
@ 2021-02-18 22:50   ` Steve Grubb
  0 siblings, 0 replies; 7+ messages in thread
From: Steve Grubb @ 2021-02-18 22:50 UTC (permalink / raw)
  To: Paul Moore, linux-security-module, selinux, linux-audit; +Cc: Casey Schaufler

On Thursday, February 18, 2021 5:07:52 PM EST Casey Schaufler wrote:
> On 2/18/2021 11:34 AM, Paul Moore wrote:
> > Hi all,
> > 
> > When looking into a problem I noticed that audit was recording the
> > wrong subject label for a process.  Doing a bit of digging I realized
> > this was caused by the SELinux security_task_getsecid() implementation
> > returning the objective security label (taken from task->real_cred),
> > and not the subjective security label (taken from task->cred).
> > 
> > Looking around at the other LSMs which implement this hook, Smack and
> > AppArmor, it appears they both do the same thing: return the objective
> > security ID for the process.  Looking quickly at the various non-LSM
> > callers of the security_task_getsecid() hook, it unfortunately looks
> > like all of them expect the subjective security ID to be returned.
> > The only caller I'm not 100% confident in is binder, but from what I
> > can tell it looks like they are expecting the subjective ID too.
> > 
> > At least we are consistently wrong :)
> 
> We may have come down with a case of helperitis.
> 
> > How do we want to fix this?  The obvious fix is to change the SELinux,
> > AppArmor, and Smack security_task_getsecid() implementations to return
> > the subjective security ID (->cred), and likely make a note in
> > lsm_hooks.h,
> 
> That would be my choice.
> 
> >  but if someone can see a case where we would need both
> > 
> > the subjective and objective security labels speak up and we can
> > introduce a new hook for the subjective label, and likely add a "_obj"
> > to the end of the existing hook to help make it more clear.  If
> > neither of those options are acceptable, we could convert all of the
> > existing callers to use something like the line below (assumes
> > current), but that is the least appealing option as far as I'm
> > concerned.
> > 
> >   security_cred_getsecid(current_cred(), &sid);
> > 
> > Opinions?
> 
> If the objective cred isn't being used in the access control decision
> it seems pointless to add it to the audit record. If there is a case
> where the task is being treated as an object, signal delivery comes to
> mind, you still want the objective credential. So it seems like care
> may be required to ensure that the correct value (sub vs obj) is
> used.

Yes, ptrace, process_vm_readv, process_vm_writev, pidfd_open, 
process_madvise, pidfd_send_signal all seem to operate on a different process 
and might be candidates for an OBJ_PID record which is where it would get 
recorded.

-Steve



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: security_task_getsecid() and subjective vs objective task creds
  2021-02-18 21:40 ` Casey Schaufler
@ 2021-02-19 19:17   ` Paul Moore
  0 siblings, 0 replies; 7+ messages in thread
From: Paul Moore @ 2021-02-19 19:17 UTC (permalink / raw)
  To: Casey Schaufler; +Cc: linux-security-module, selinux, linux-audit

On Thu, Feb 18, 2021 at 4:40 PM Casey Schaufler <casey@schaufler-ca.com> wrote:
> On 2/18/2021 11:34 AM, Paul Moore wrote:

...

> > How do we want to fix this?  The obvious fix is to change the SELinux,
> > AppArmor, and Smack security_task_getsecid() implementations to return
> > the subjective security ID (->cred), and likely make a note in
> > lsm_hooks.h,
>
> That would be my choice.

As I've dug into this more, it does look like that is closest to being
correct, but there are still a few callers where it looks like the
objective creds are needed.  I think the correct thing to do is
convert the existing hook to use the subjective creds and add a
"_subj" at the end, while also creating a new
security_task_getsecid_obj() hook to return the objective cred and
updating those few callers that need it.

I'll see about making the associated changes to the Smack and AppArmor
code too, but that will obviously need some heavy review by you and
John.

--
paul moore
www.paul-moore.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: security_task_getsecid() and subjective vs objective task creds
  2021-02-18 19:34 security_task_getsecid() and subjective vs objective task creds Paul Moore
  2021-02-18 21:40 ` Casey Schaufler
  2021-02-18 22:07 ` Casey Schaufler
@ 2021-02-20  2:54 ` James Morris
  2021-02-20 14:50   ` Paul Moore
  2 siblings, 1 reply; 7+ messages in thread
From: James Morris @ 2021-02-20  2:54 UTC (permalink / raw)
  To: Paul Moore; +Cc: linux-security-module, selinux, linux-audit

On Thu, 18 Feb 2021, Paul Moore wrote:

> Hi all,
> 
> When looking into a problem I noticed that audit was recording the
> wrong subject label for a process.

Is this a public bug? It would be good to know what the extent of this 
issue may be and whether it warrants a CVE.

-- 
James Morris
<jmorris@namei.org>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: security_task_getsecid() and subjective vs objective task creds
  2021-02-20  2:54 ` James Morris
@ 2021-02-20 14:50   ` Paul Moore
  0 siblings, 0 replies; 7+ messages in thread
From: Paul Moore @ 2021-02-20 14:50 UTC (permalink / raw)
  To: James Morris; +Cc: linux-security-module, selinux, linux-audit

On Fri, Feb 19, 2021 at 9:55 PM James Morris <jmorris@namei.org> wrote:
> On Thu, 18 Feb 2021, Paul Moore wrote:
>
> > Hi all,
> >
> > When looking into a problem I noticed that audit was recording the
> > wrong subject label for a process.
>
> Is this a public bug? It would be good to know what the extent of this
> issue may be and whether it warrants a CVE.

Let me rephrase, "When looking into a problem with some new patches
that I am working on I noticed ...".

I am not aware of any public bugs relating to this subj/obj confusion,
this was simply something I noticed while doing some new work.  I
would post those patches now, but they are still incomplete.
Regardless, this subj/obj confusion is something we should resolve.

-- 
paul moore
www.paul-moore.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-18 19:34 security_task_getsecid() and subjective vs objective task creds Paul Moore
2021-02-18 21:40 ` Casey Schaufler
2021-02-19 19:17   ` Paul Moore
2021-02-18 22:07 ` Casey Schaufler
2021-02-18 22:50   ` Steve Grubb
2021-02-20  2:54 ` James Morris
2021-02-20 14:50   ` Paul Moore

Linux-Security-Module Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-security-module/0 linux-security-module/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-security-module linux-security-module/ https://lore.kernel.org/linux-security-module \
		linux-security-module@vger.kernel.org
	public-inbox-index linux-security-module

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-security-module


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git