All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Moore <paul.moore@hp.com>
To: Steffen Klassert <steffen.klassert@secunet.com>
Cc: linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov
Subject: Re: [PATCH 05/10] selinux: selinux_xfrm_decode_session check for socket sid
Date: Wed, 23 Feb 2011 16:16:38 -0500	[thread overview]
Message-ID: <201102231616.39183.paul.moore@hp.com> (raw)
In-Reply-To: <20110222121143.GC20852@secunet.com>

On Tuesday, February 22, 2011 7:11:43 AM Steffen Klassert wrote:
> On Wed, Feb 16, 2011 at 03:11:25PM -0500, Paul Moore wrote:
> > On Mon, 2011-02-14 at 14:20 +0100, Steffen Klassert wrote:
> > > selinux_xfrm_decode_session is used to decode the security identifyer
> > > of the originating flow. So return the sid of the socket instead of
> > > SECSID_NULL, if we have socket context but no secpath. This is
> > > needed because ip_xfrm_me_harder (and selinux_xfrm_decode_session)
> > > is invoked on outbound packets and before the xfrm transformations,
> > > therefore we have no secpath and the sid of a labeled IPsec SA usually
> > > does not match SECSID_NULL.
> > > 
> > > Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
> > 
> > Granted, it has been some time since I've looked at the labeled IPsec
> > code in some detail so I might be a little off here, but is it possible
> > to move the xfrm_decode LSM hook to an area on the outbound processing
> > where we do have a valid secpath?
> 
> No, we don't have a secpath for outbound packets. The secpath is used to
> do a inbound policy check, check the used SA against their selectors etc.
> With these checks we ensure that the packet is transformed back to it's
> native form in the right way. That's not needed on outbound packets,
> so we don't record a secpath in this case. The lack of a outbound
> secpath was also the problem I mentioned in the introduction mail
> of the patchset.

Be warned: most of this reply is just me tossing out ideas ...

Okay, so basically selinux_xfrm_decode_session() is a total waste of time in 
the output path, yes?  I'm looking at the current code and it does nothing if 
the sec_path is NULL, so I'm wondering why we even keep it around for the 
outbound path.

> > If not, I'd rather see us split this
> > hook so that we preserve the existing xfrm_decode_session() hook for
> > input (I believe it is also used for input, yes?) and create a new hook
> > which only grabs the sksec's label on output (preferably named so that
> > it is clear this is the socket's label and not the SA's label).
> 
> I think that's not possible too. The security_xfrm_decode_session()
> hook is used from within xfrm_decode_session(). This function
> is used in codepaths that are used for both, inbound and outbound
> processing (xfrm_lookup, xfrm_policy_check etc.).

This makes me wonder if the LSM hook is even in the right place.

> The xfrm_decode_session() function simply fills a 'struct flowi' with
> the informations of the originating flow whenever these informations
> are needed, selinux_xfrm_decode_session just adds the sid the
> that struct.
> 
> In the case we are constructing a 'struct flowi' within the outbound
> packet path, we use selinux_sk_getsecid() which just adds the
> sksec label from the socket if we have socket context.
> 
> So with this patch we would use the secpath's sid on inbound
> packets and the sksec label from the socket if we are on
> oubound packet processing with socket context, when we construct
> a 'struct flowi' from xfrm_decode_session().

I _really_ think we need to split the inbound and outbound handling for xfrm.  
I suppose we can always fall back to selecting the right path based on the 
presence of a sec_path pointer, but I would rather see us get rid of an 
unnecessary conditional.

The inbound handling can stick with the logic in selinux_xfrm_decode_session() 
but the outbound handling should follow similar logic to how we determine the 
network peer label in selinux_ip_postroute().

 1. If we have a valid sk_security_stuct, use it.
 2. If we are forwarding the packet, call selinux_skb_peerlbl_sid().
 3. If all else fails, use SECINITSID_KERNEL.

--
paul moore
linux @ hp

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

  parent reply	other threads:[~2011-02-23 21:16 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20110214131651.GA15640@secunet.com>
2011-02-14 16:59 ` [PATCHSET RFC] selinux: rework labeled IPsec networking Paul Moore
     [not found]   ` <20110215121900.GA25769@secunet.com>
2011-02-16  0:02     ` Paul Moore
     [not found]       ` <20110221115403.GA20852@secunet.com>
2011-02-21 15:28         ` Paul Moore
     [not found] ` <20110214131739.GB15640@secunet.com>
2011-02-16 19:18   ` [PATCH 01/10] selinux: Fix check for xfrm selinux context algorithm Paul Moore
     [not found] ` <20110214131815.GC15640@secunet.com>
2011-02-16 19:34   ` [PATCH 02/10] selinux: Perform postroute access control checks after IPsec transfomations Paul Moore
     [not found]     ` <20110222112334.GB20852@secunet.com>
2011-02-23 21:02       ` Paul Moore
2011-02-28  7:29         ` Steffen Klassert
     [not found] ` <20110214131855.GD15640@secunet.com>
2011-02-16 19:39   ` [PATCH 03/10] selinux: Remove checks for xfrm transformations from selinux_xfrm_postroute_last Paul Moore
     [not found] ` <20110214131934.GE15640@secunet.com>
2011-02-16 19:46   ` [PATCH 04/10] selinux: Fix wrong checks for selinux_policycap_netpeer Paul Moore
     [not found] ` <20110214132009.GF15640@secunet.com>
2011-02-16 20:11   ` [PATCH 05/10] selinux: selinux_xfrm_decode_session check for socket sid Paul Moore
     [not found]     ` <20110222121143.GC20852@secunet.com>
2011-02-23 21:16       ` Paul Moore [this message]
2011-02-25 19:21         ` Joy Latten
2011-02-28 10:25           ` Steffen Klassert
2011-02-28  8:51         ` Steffen Klassert
     [not found] ` <20110214132049.GG15640@secunet.com>
2011-02-16 20:19   ` [PATCH 06/10] selinux: Fix packet forwarding checks on postrouting Paul Moore
     [not found] ` <20110214132122.GH15640@secunet.com>
2011-02-16 20:32   ` [PATCH 07/10] selinux: Check receiving against sending interface on packet forwarding Paul Moore
     [not found]     ` <20110222130409.GD20852@secunet.com>
2011-02-23 21:34       ` Paul Moore
2011-02-28  9:10         ` Steffen Klassert
     [not found] ` <20110214132157.GI15640@secunet.com>
2011-02-16 20:57   ` [PATCH 08/10] selinux: Fix handling of kernel generated packets on labeled IPsec Paul Moore
     [not found]     ` <20110222133150.GE20852@secunet.com>
2011-02-23 21:45       ` Paul Moore
2011-02-25 20:50         ` Joy Latten
2011-02-28 10:33         ` Steffen Klassert
2011-03-01 18:41           ` Paul Moore
     [not found] ` <20110214132312.GK15640@secunet.com>
2011-02-16 21:08   ` [PATCH 10/10] selinux: Perform xfrm checks for unlabeled access in any case Paul Moore
     [not found]     ` <20110222135217.GF20852@secunet.com>
2011-02-23 21:59       ` Paul Moore
2011-02-28 11:34         ` Steffen Klassert
2011-03-01 18:42           ` Paul Moore
     [not found] ` <20110214132234.GJ15640@secunet.com>
     [not found]   ` <1297889991.25079.46.camel@sifl>
2011-02-16 22:08     ` [PATCH 09/10] selinux: xfrm - notify users on dropped packets James Morris

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=201102231616.39183.paul.moore@hp.com \
    --to=paul.moore@hp.com \
    --cc=linux-security-module@vger.kernel.org \
    --cc=selinux@tycho.nsa.gov \
    --cc=steffen.klassert@secunet.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.