public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] getsockopt() early argument sanity checking
@ 2006-08-19 23:05 Solar Designer
  2006-08-19 23:48 ` Willy Tarreau
                   ` (3 more replies)
  0 siblings, 4 replies; 22+ messages in thread
From: Solar Designer @ 2006-08-19 23:05 UTC (permalink / raw)
  To: Willy Tarreau; +Cc: linux-kernel, netdev

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

Willy,

I propose the attached patch (extracted from 2.4.33-ow1) for inclusion
into 2.4.34-pre.

(2.6 kernels could benefit from the same change, too, but at the moment
I am dealing with proper submission of generic changes like this that
are a part of 2.4.33-ow1.)

The patch makes getsockopt(2) sanity-check the value pointed to by
the optlen argument early on.  This is a security hardening measure
intended to prevent exploitation of certain potential vulnerabilities in
socket type specific getsockopt() code on UP systems.

This change has been a part of -ow patches for some years.

Thanks,

-- 
Alexander Peslyak <solar at openwall.com>
GPG key ID: B35D3598  fp: 6429 0D7E F130 C13E C929  6447 73C3 A290 B35D 3598
http://www.openwall.com - bringing security into open computing environments

[-- Attachment #2: linux-2.4.33-ow1-getsockopt-early-arg-sanity.diff --]
[-- Type: text/plain, Size: 686 bytes --]

diff -urpPX nopatch linux-2.4.33/net/socket.c linux/net/socket.c
--- linux-2.4.33/net/socket.c	Wed Jan 19 17:10:14 2005
+++ linux/net/socket.c	Sat Aug 12 08:51:47 2006
@@ -1307,10 +1307,18 @@ asmlinkage long sys_setsockopt(int fd, i
 asmlinkage long sys_getsockopt(int fd, int level, int optname, char *optval, int *optlen)
 {
 	int err;
+	int len;
 	struct socket *sock;
 
 	if ((sock = sockfd_lookup(fd, &err))!=NULL)
 	{
+		/* XXX: insufficient for SMP, but should be redundant anyway */
+		if (get_user(len, optlen))
+			err = -EFAULT;
+		else
+		if (len < 0)
+			err = -EINVAL;
+		else
 		if (level == SOL_SOCKET)
 			err=sock_getsockopt(sock,level,optname,optval,optlen);
 		else

^ permalink raw reply	[flat|nested] 22+ messages in thread
* Re: [PATCH] getsockopt() early argument sanity checking
@ 2006-08-20 18:57 Manfred Spraul
  0 siblings, 0 replies; 22+ messages in thread
From: Manfred Spraul @ 2006-08-20 18:57 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: linux-kernel, Netdev, Solar Designer

Arjan wrote:

>> We're on UP.  sys_getsockopt() does get_user() (due to the patch) and
>> makes sure that the passed *optlen is sane.  Even if this get_user()
>> sleeps, the value it returns in "len" is what's currently in memory at
>> the time of the get_user() return (correct?)  Then an underlying
>> *getsockopt() function does another get_user() on optlen (same address),
>> without doing any other user-space data accesses or anything else that
>> could sleep first.  Is it possible that this second get_user()
>> invocation would sleep?  I think not since it's the same address that
>> we've just read a value from, we did not leave kernel space, and we're
>> on UP (so no other processor could have changed the mapping).  So the
>> patch appears to be sufficient for this special case (which is not
>> unlikely).
>
>this reasoning goes out the window with kernel preemption of course ;)
>  
>
Or O_DIRECT? I'm not sure what's easier to time, a kernel preemption or 
a DMA to the user address.

--
    Manfred


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

end of thread, other threads:[~2006-08-21 12:10 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-19 23:05 [PATCH] getsockopt() early argument sanity checking Solar Designer
2006-08-19 23:48 ` Willy Tarreau
2006-08-20  0:05   ` Michael Buesch
2006-08-20  0:43     ` Willy Tarreau
2006-08-20 19:44       ` David Miller
2006-08-20 20:35         ` Willy Tarreau
2006-08-20 21:12           ` Arjan van de Ven
2006-08-21 12:09       ` Eugene Teo
2006-08-20  8:34 ` Andi Kleen
2006-08-20 10:15   ` Willy Tarreau
2006-08-20 10:50     ` YOSHIFUJI Hideaki / 吉藤英明
2006-08-20 19:46     ` David Miller
2006-08-20 16:16   ` Solar Designer
2006-08-20 16:30     ` Arjan van de Ven
2006-08-20 19:47       ` David Miller
2006-08-20 18:38     ` Andi Kleen
2006-08-20 19:45       ` Solar Designer
2006-08-20 19:45   ` David Miller
2006-08-20 18:15 ` Alan Cox
2006-08-21  3:00 ` David Wagner
2006-08-21  8:24   ` Solar Designer
  -- strict thread matches above, loose matches on Subject: below --
2006-08-20 18:57 Manfred Spraul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox