netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chris Wright <chrisw@osdl.org>
To: James Morris <jmorris@redhat.com>
Cc: Ross Kendall Axe <ross.axe@blueyonder.co.uk>,
	netdev@oss.sgi.com, Stephen Smalley <sds@epoch.ncsc.mil>,
	lkml <linux-kernel@vger.kernel.org>,
	Chris Wright <chrisw@osdl.org>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH] linux 2.9.10-rc1: Fix oops in unix_dgram_sendmsg when using SELinux and SOCK_SEQPACKET
Date: Thu, 18 Nov 2004 08:44:49 -0800	[thread overview]
Message-ID: <20041118084449.Z14339@build.pdx.osdl.net> (raw)
In-Reply-To: <Xine.LNX.4.44.0411180305060.3192-100000@thoron.boston.redhat.com>; from jmorris@redhat.com on Thu, Nov 18, 2004 at 03:27:42AM -0500

* James Morris (jmorris@redhat.com) wrote:
> What's happening is that mixing stream and dgram ops for SEQPACKET is
> having some unfortunate side effects.

Agreed.

> One of these is that there is a race between client sendmsg() and server
> accept().  The server child socket is attached via sock_graft() after the 
> client has entered unix_dgram_sendmsg() and called 
> 
> 	security_unix_may_send(sk->sk_socket, other->sk_socket);
> 
> other->sk_socket will thus be null, causing the oops in SELinux and any 
> other LSM which tries to dereference the pointer.

Yup.  And it's not much of a race, the window is wide open.  One
malicious app simply has to do:

bind()
listen()
connect()
send() <-- Oops

> The fix is a combination of some of Ross's ideas:
> 
> 1) SOCK_SEQPACKET is connection oriented, and there no need to call 
> security_unix_may_send() for each packet.  security_unix_stream_connect() 
> is sufficient.

Why not make a unix_seq_sendmsg, which is a very small wrapper?
e.g.
static int unix_seq_sendmsg(struct kiocb *kiocb, struct socket *sock,
			    struct msghdr *msg, size_t len)
{
	struct sock *sk = sock->sk;

	if (sk->sk_type == SOCK_SEQPACKET && sk->sk_state != TCP_ESTABLISHED)
		return -ENOTCONN;
	if (msg->msg_name || msg->msg_namelen)
		return -EINVAL;
	return unix_dgram_sendmsg(kiocb, sock, msg, len);
}


Also, I missed how MSG_EOR is honored.

> 2) Ensure that unix_dgram_sendmsg() fails for SOCK_SEQPACKET sockets which
> are not connected, otherwise someone could bypass LSM by sending on an
> unconnected socket.

Agreed, not connected, it should fail IMHO.

> Note that this only solves the problem for the LSM hook.

Does the above stop the other issue?  My laptop died, so I'm not able to
test ATM.

thanks,
-chris
-- 
Linux Security Modules     http://lsm.immunix.org     http://lsm.bkbits.net

  reply	other threads:[~2004-11-18 16:44 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-14 18:13 [PATCH] linux 2.9.10-rc1: Fix oops in unix_dgram_sendmsg when using SELinux and SOCK_SEQPACKET Ross Kendall Axe
2004-11-15 13:31 ` Stephen Smalley
2004-11-16  8:41   ` Chris Wright
2004-11-17 21:29     ` Ross Kendall Axe
2004-11-18  0:09       ` Ross Kendall Axe
2004-11-18  3:42         ` James Morris
2004-11-18  4:25           ` James Morris
2004-11-18  6:07             ` Chris Wright
2004-11-18  7:25           ` Ross Kendall Axe
2004-11-18  7:59             ` James Morris
2004-11-18  8:27               ` James Morris
2004-11-18 16:44                 ` Chris Wright [this message]
2004-11-18 17:01                   ` James Morris
2004-11-18 17:07                     ` Chris Wright
2004-11-18 17:11                       ` James Morris
2004-11-18 17:25                     ` James Morris
2004-11-18 16:58                       ` Alan Cox
2004-11-18 22:34                       ` David S. Miller
2004-11-19  3:23                   ` Ross Kendall Axe
2004-11-19  7:19                     ` Chris Wright
2004-11-19  9:40                       ` Ross Kendall Axe
2004-11-19 13:05                       ` Arnaldo Carvalho de Melo
2004-11-19 13:16                         ` Arnaldo Carvalho de Melo
2004-11-18 16:49                 ` Alan Cox
2004-11-18 18:40                   ` James Morris
2004-11-18 23:39                     ` Alan Cox
2004-11-19  3:12                       ` James Morris
2004-11-19  7:01                         ` Chris Wright
2004-11-19  7:12                           ` James Morris
2004-11-19  7:28                             ` Chris Wright
2004-11-19 11:39                         ` Alan Cox
2004-11-19 16:24                           ` James Morris
2004-11-20  7:11                             ` David S. Miller
2004-11-18 16:45           ` Alan Cox
2004-11-18 18:28             ` James Morris
2004-11-18 18:34             ` Chris Wright

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=20041118084449.Z14339@build.pdx.osdl.net \
    --to=chrisw@osdl.org \
    --cc=davem@davemloft.net \
    --cc=jmorris@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@oss.sgi.com \
    --cc=ross.axe@blueyonder.co.uk \
    --cc=sds@epoch.ncsc.mil \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).