linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* kernel bug in socketpair()
@ 2003-07-23 13:32 David Korn
  2003-07-23 14:04 ` David S. Miller
  2003-07-23 14:20 ` Alan Cox
  0 siblings, 2 replies; 23+ messages in thread
From: David Korn @ 2003-07-23 13:32 UTC (permalink / raw)
  To: linux-kernel; +Cc: gsf


I am not sure what the procedure for reporting bugs, but here
is a description of two bugs and a program that can can be used
to produce them.

$ uname -a 
Linux fror.research.att.com 2.4.18-18.7.xsmp #1 SMP Wed Nov 13 19:01:42 EST 2002


The first problem is that files created with socketpair() are not accessible
via /dev/fd/n or /proc/$$/fd/n where n is the file descriptor returned
by socketpair().  Note that this is not a problem with pipe().

The second problem is that if fchmod(fd,S_IWUSR) is applied to the write end
of a pipe(),  it causes the read() end to also be write only so that
opening  /dev/fd/n for read fails.

The following program demonstrates these problems.  If invoked without
arguments, socketpair() is used to create to files.  Later the
open /dev/fd/n and /proc/$$/fd/n fail.

With one argument, pipe() is used instead of socketpair() and the
program works.  With two arguments, pipe() is used bug fchmod()
is also called, and then it fails.

==================cut here======================
#include	<sys/socket.h>
#include	<sys/stat.h>
#include	<stdio.h>
#include	<errno.h>


int main(int argc, char *argv[])
{
	char buff[256];
	int pv[2], fd;
	if(argc>1)
		fd = pipe(pv);
	else
		fd = socketpair(PF_UNIX, SOCK_STREAM, 0, pv);
	if(fd<0)
	{
		fprintf(stderr,"socketpar failed err=%d\n",errno);
		exit(1);
	}
	if(argc<2)
	{
		if(shutdown(pv[0],1)< 0)
		{
			fprintf(stderr,"shutdown send failed err=%d\n",errno);
			exit(1);
		}
		if(shutdown(pv[1],0)< 0)
		{
			fprintf(stderr,"shutdown recv failed err=%d\n",errno);
			exit(1);
		}
	}
	if(argc!=2)
	{
		fchmod(pv[0],S_IRUSR);
		fchmod(pv[1],S_IWUSR);
	}
	sprintf(buff,"/dev/fd/%d\0",pv[0]);
	errno = 0;
	fd = open(buff,0);
	fprintf(stderr,"name=%s fd=%d errno=%d\n",buff,fd,errno);
	sprintf(buff,"/proc/%d/fd/%d\0",getpid(),pv[0]);
	fd = open(buff,0);
	fprintf(stderr,"name=%s fd=%d errno=%d\n",buff,fd,errno);
	return(0);
}

==================cut here======================

David Korn
dgk@research.att.com

^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: Re: kernel bug in socketpair()
@ 2003-07-23 14:28 David Korn
  2003-07-23 14:46 ` David S. Miller
  0 siblings, 1 reply; 23+ messages in thread
From: David Korn @ 2003-07-23 14:28 UTC (permalink / raw)
  To: davem; +Cc: gsf, linux-kernel, netdev


> On Wed, 23 Jul 2003 09:32:09 -0400 (EDT)
> David Korn <dgk@research.att.com> wrote:
> 
> [ Added netdev@oss.sgi.com, the proper place to discuss networking kernel issues
> . ]
> 
> > The first problem is that files created with socketpair() are not accessible
> > via /dev/fd/n or /proc/$$/fd/n where n is the file descriptor returned
> > by socketpair().  Note that this is not a problem with pipe().
> 
> Not a bug.
> 
> Sockets are not openable via /proc files under any circumstances,
> not just the circumstances you describe.  This is a policy decision and
> prevents a whole slew of potential security holes.
> 
> 

Thanks for you quick response.

This make sense for INET sockets, but I don't understand the security
considerations for UNIX domain sockets.  Could you please elaborate?
Moreover, /dev/fd/n, (as opposed to /proc/$$/n) is restricted to
the current process and its decendents if close-on-exec is not specified.
Again, I don't understand why this would create a security problem
either since the socket is already accesible via the original
descriptor.

Finally if this is a security problem, why is the errno is set to ENXIO 
rather than EACCESS?

David Korn
dgk@research.att.com

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

end of thread, other threads:[~2003-07-23 23:12 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-23 13:32 kernel bug in socketpair() David Korn
2003-07-23 14:04 ` David S. Miller
2003-07-23 14:20 ` Alan Cox
2003-07-23 15:36   ` David S. Miller
2003-07-23 16:13     ` Alan Cox
2003-07-23 14:28 David Korn
2003-07-23 14:46 ` David S. Miller
2003-07-23 16:56   ` Glenn Fowler
2003-07-23 17:00     ` David S. Miller
2003-07-23 17:24       ` Glenn Fowler
2003-07-23 17:31         ` David S. Miller
2003-07-23 18:14           ` Glenn Fowler
2003-07-23 18:23             ` David S. Miller
2003-07-23 18:54               ` Glenn Fowler
2003-07-23 19:04                 ` David S. Miller
2003-07-23 19:11                   ` Glenn Fowler
2003-07-23 19:14                     ` David S. Miller
2003-07-23 19:29                       ` Glenn Fowler
2003-07-23 19:56                         ` David S. Miller
2003-07-23 22:24                         ` jw schultz
2003-07-23 19:08                 ` Alan Cox
2003-07-23 19:41       ` Andreas Jellinghaus
2003-07-23 17:50     ` Alan Cox
2003-07-23 23:27       ` Bill Rugolsky Jr.

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