Skip to contentSkip to conversation

Some socket syscalls fail to return an error on bad file-descriptor# argument

PATCH Tony Griffiths 4 participants 4 messages Jun 1, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Description:

The sockfd_lookup_light() function does not set the return error status on a particular failure mode when the passed-in fd# is erroneous.

Environment:

2.6.16 kernel with the -mm2 patch-set applied. Linux 2.6.17 kernels are also affected. Without the fix, a number of tests in LTP fail! Any program calling one of the syscalls listed below with a bad fd# will not get an error return indicating that the syscall failed.

Fix:

The attached patch correctly sets *err = -EBADF if the attempt to map the fd# to a file pointer returns NULL. The following syscalls are affected-

bind()
listen()
accept()
connect()
getsockname()
getpeername()
setsockopt()
setsockopt()
shutdown()
sendmsg()
recvmsg()

net/socket.c renamed from net/socket.c.orig +2 -0
diff -urpN ./net/socket.c.orig ./net/socket.c
@@ -496,6 +496,8 @@ static struct socket *sockfd_lookup_ligh
 		if (sock)
 			return sock;
 		fput_light(file, *fput_needed);
+	} else {
+		*err = -EBADF;
 	}
 	return NULL;
 }
#1 lore raw

This has been fixed in 2.6.17.

Quoted 45 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Tony Griffiths
Sent: Wednesday, May 31, 2006 8:39 PM
To: [email protected]
Subject: Some socket syscalls fail to return an error on bad file-descriptor# argument

Description:

The sockfd_lookup_light() function does not set the return error status on a particular failure mode when the passed-in fd# is erroneous.

Environment:

2.6.16 kernel with the -mm2 patch-set applied. Linux 2.6.17 kernels are also affected. Without the fix, a number of tests in LTP fail! Any program calling one of the syscalls listed below with a bad fd# will not get an error return indicating that the syscall failed.

Fix:

The attached patch correctly sets *err = -EBADF if the attempt to map the fd# to a file pointer returns NULL. The following syscalls are
affected-

bind()
listen()
accept()
connect()
getsockname()
getpeername()
setsockopt()
setsockopt()
shutdown()
sendmsg()
recvmsg()

#2 lore raw
In reply to Tony Griffiths

net/socket.c static struct socket *sockfd_lookup_ligh · line 503

Quoted 12 lines · On Thu, 01 Jun 2006 13:38:55 +1000 Tony Griffiths <[email protected]> wrote:

diff -urpN ./net/socket.c.orig ./net/socket.c

net/socket.c renamed from net/socket.c.orig +2 -0
@@ -496,6 +496,8 @@ static struct socket *sockfd_lookup_ligh
 		if (sock)
 			return sock;
 		fput_light(file, *fput_needed);
+	} else {
+		*err = -EBADF;
 	}
 	return NULL;
 }

Confused. That patch cannot make any difference to this function:

static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)

{
	struct file *file;
	struct socket *sock;

	*err = -EBADF;
	file = fget_light(fd, fput_needed);
	if (file) {
		sock = sock_from_file(file, err);
		if (sock)
			return sock;
		fput_light(file, *fput_needed);
	}
	return NULL;
}
#3 lore raw
Quoted 1 line · Andrew Morton

Confused. That patch cannot make any difference to this function:

Yep, the code definitely looks correct in current LT git.

Quoted 15 lines

static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)

{
	struct file *file;
	struct socket *sock;

	*err = -EBADF;
	file = fget_light(fd, fput_needed);
	if (file) {
		sock = sock_from_file(file, err);
		if (sock)
			return sock;
		fput_light(file, *fput_needed);
	}
	return NULL;
}

- James

Signature · 2 lines
James Morris
<[email protected]>