All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Moore <paul.moore@hp.com>
To: Stephen Smalley <sds@tycho.nsa.gov>
Cc: selinux@tycho.nsa.gov
Subject: Re: [RFC PATCH v1 1/6] selinux: Update socket's label alongside inode's label
Date: Tue, 4 May 2010 11:29:05 -0400	[thread overview]
Message-ID: <201005041129.06051.paul.moore@hp.com> (raw)
In-Reply-To: <1272978238.30175.22.camel@moss-pluto.epoch.ncsc.mil>

On Tuesday 04 May 2010 09:03:53 am Stephen Smalley wrote:
> On Mon, 2010-05-03 at 18:11 -0400, Paul Moore wrote:
> > We have always had a potential disconnect between the label on socket and
> > the label on the associated inode when a user calls fsetxattr() on a
> > socket.  The problem is that the fsetxattr() call would only relabel the
> > inode and not the corresponding socket; the good news is that the
> > mainstream SELinux policies have always prevented this, but better safe
> > than sorry ...
> > 
> > This patch fixes this problem by adding the necessary socket labeling
> > code to selinux_inode_setsecurity() so that if a user did relabel a
> > socket via fsetxattr() both the inode and socket would be relabeled.
> > 
> > Signed-off-by: XXX
> > ---
> > 
> >  security/selinux/hooks.c            |   39
> >  ++++++++++++++++++++++++++++++++++- security/selinux/include/netlabel.h
> >  |    5 ++--
> >  security/selinux/netlabel.c         |    8 +++++--
> >  3 files changed, 46 insertions(+), 6 deletions(-)
> > 
> > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > index 5feecb4..f9545c8 100644
> > --- a/security/selinux/hooks.c
> > +++ b/security/selinux/hooks.c
> > @@ -2920,6 +2920,43 @@ static int selinux_inode_setsecurity(struct inode
> > *inode, const char *name,
> > 
> >  	if (rc)
> >  	
> >  		return rc;
> > 
> > +	if (S_ISSOCK(inode->i_mode)) {
> 
> I think this is the wrong test - it would evaluate to true for both the
> socket inode and for the file inode by which the socket is named, which
> are separate and distinct objects.  I think you want:
> 	if (inode->i_sb->s_magic == SOCKFS_MAGIC)
> which would only be true for the actual socket inode.

Thanks for the review ...

Sounds reasonable, I wasn't sure this was 100% right but it seemed like a 
reasonable place to start.  I haven't had a chance to test this yet as I need 
to write a little dummy app that does a fsetxattr() on a socket - amazing that 
apps like this don't exist ;)


> > +		lock_sock(sk);
> > +		sksec->sid = newsid;
> > +		selinux_netlbl_sk_security_reset(sksec);
> > +		rc = selinux_netlbl_socket_setsid(sk, sk->sk_family);
> > +		release_sock(sk);
> > +		if (rc)
> > +			return rc;
> 
> If the netlabel state change fails, do we want to revert the sksec->sid
> to its original value?

Funny you mention this, I was going over the patches again this morning and 
noticed this; I also moved the SID assignments outside of the socket lock, 
probably not a big deal, but you never know ... Regardless, I've already made 
the changes and they will be in the next version.

-- 
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.

  reply	other threads:[~2010-05-04 15:29 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-03 22:11 [RFC PATCH v1 0/6] UNIX domain socket fixes and other cleanups Paul Moore
2010-05-03 22:11 ` [RFC PATCH v1 1/6] selinux: Update socket's label alongside inode's label Paul Moore
2010-05-04 13:03   ` Stephen Smalley
2010-05-04 15:29     ` Paul Moore [this message]
2010-05-03 22:11 ` [RFC PATCH v1 2/6] selinux: Set the peer label correctly on connected UNIX domain sockets Paul Moore
2010-05-04 14:05   ` Stephen Smalley
2010-05-04 14:27     ` Eric Paris
2010-05-04 15:34       ` Paul Moore
2010-05-04 19:47         ` Stephen Smalley
2010-05-05 15:46           ` Paul Moore
2010-05-03 22:11 ` [RFC PATCH v1 3/6] selinux: Consolidate sockcreate_sid logic Paul Moore
2010-05-04 13:52   ` Stephen Smalley
2010-05-04 15:31     ` Paul Moore
2010-05-04 19:44       ` Stephen Smalley
2010-05-05 15:48         ` Paul Moore
2010-05-03 22:11 ` [RFC PATCH v1 4/6] selinux: Shuffle the sk_security_struct alloc and free routines Paul Moore
2010-05-03 22:11 ` [RFC PATCH v1 5/6] selinux: Convert socket related access controls to use socket labels Paul Moore
2010-05-04 14:30   ` Eric Paris
2010-05-04 15:38     ` Paul Moore
2010-05-03 22:11 ` [RFC PATCH v1 6/6] selinux: Use current_security() when possible Paul Moore

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=201005041129.06051.paul.moore@hp.com \
    --to=paul.moore@hp.com \
    --cc=sds@tycho.nsa.gov \
    --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.