All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ross Kendall Axe <ross.axe@blueyonder.co.uk>
To: James Morris <jmorris@redhat.com>
Cc: 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 07:25:38 +0000	[thread overview]
Message-ID: <419C4E72.5050307@blueyonder.co.uk> (raw)
In-Reply-To: <Xine.LNX.4.44.0411172222160.2531-100000@thoron.boston.redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3630 bytes --]

James Morris wrote:
> On Thu, 18 Nov 2004, Ross Kendall Axe wrote:
> 
> 
>>Ross Kendall Axe wrote:
>>
>>>A possibility that hadn't occurred to me was using sendto to send packets
>>>without connecting. Is this supposed to work? If so, then my patch is
>>>indeed inappropriate. If not, then that needs fixing also.
>>>
>>
>>Well, my reading of socket(2) suggests that it's _not_ supposed to work.
> 
> 
> sendto() on a non connected socket should fail with ENOTCONN.
> 
> 
>>This patch causes sendmsg on SOCK_SEQPACKET unix domain sockets to return
>>EISCONN or ENOTSUPP as appropriate if the 'to' address is specified.
> 
> 
> For sendto():
> 
> The address must be ignored on a connected mode socket (i.e. in this 
> case).
> 
> According to the send(2) man page, we may return EISCONN if the address
> and addr length are not NULL and zero.  I think that the man page is
> incorrect.  Posix says that EISCONN means "A destination address was
> specified and the socket is already connected", not "A destination address
> was specified and the socket is connected mode".  i.e. we should only 
> return EISCONN if the socket is in a connected state.
> 

The man page then goes on to say "the error ENOTCONN is returned when the 
socket was not actually connected". Admittedly, this is not what my patch 
does; it returns ENOTSUPP, as do SOCK_STREAM sockets.

> I'm not sure if we should return any error at all if an address is 
> supplied to sendto() on SOCK_SEQPACKET.  We're only required to ignore it.
> 
> I would say that we should return an error as it is likely a progamming 
> mistake in the application and we should let them know.

This was, after all, the point of the patch. Well, that and closing the 
security hole opened by my earlier patch :-)

> 
> However, as mentioned above, I don't think EISCONN is appropriate in this 
> case.  EINVAL might be better.
> 

I would say that ENOTSUPP all the time would be more sensible. However, my
choice of error codes was determined by the ones used by SOCK_STREAM.
SOCK_SEQPACKET and SOCK_STREAM should use the same error codes, I would 
say. Further, they should use the codes specified by POSIX.

> 
>>It also causes recvmsg to return EINVAL on unconnected sockets. This
>>behaviour is consistent with SOCK_STREAM sockets.
> 
> 
> This seems incorrect too, Posix says to use ENOTCONN.

That seems eminently sensible. Again, I was just cut-n'-pasting from
SOCK_STREAM. If these error codes are wrong, then SOCK_STREAM also needs
fixing.

> 
> There is a non SELinux-related bug lurking in this code.

IMHO, there never was an SELinux bug here. SELinux merely exposed an 
existing bug.

> I got this oops
> when trying to kill a modified version of seqpacket-crash which keeps
> sending in a loop and uses sendto() and an address with SOCK_SEQPACKET.
> 

I'm unable to reproduce that, or the bug you mention in your other 
message. Care to send us your code?

> 
> - James


I think that af_unix.c needs a bit of cleaning up. All of the functions 
are named as being stream vs dgram, even when the issue is connectionless 
vs connection-oriented. For example, unix_connectionless_connect would 
make a lot more sense than unix_dgram_connect. sendmsg and recvmsg are the 
worst since they require a mixture of SOCK_STREAM and SOCK_DGRAM 
semantics. It would be nice to rewite unix_dgram_recvmsg and 
unix_stream_recvmsg as four helper functions dealing with the 
connectionless, connection-oriented, datagram and stream operations and 
then have 3 wrapper functions (one for each socket type) calling the 
appropriate helpers. This is all strictly IMHO, of course.

Ross


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 256 bytes --]

  parent reply	other threads:[~2004-11-18  7:26 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 [this message]
2004-11-18  7:59             ` James Morris
2004-11-18  8:27               ` James Morris
2004-11-18 16:44                 ` Chris Wright
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=419C4E72.5050307@blueyonder.co.uk \
    --to=ross.axe@blueyonder.co.uk \
    --cc=chrisw@osdl.org \
    --cc=davem@davemloft.net \
    --cc=jmorris@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@oss.sgi.com \
    --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 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.