mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Aikens <marka@wpi.edu>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] SO_BINDTODEVICE parameter checking in 2.2.19
Date: Thu, 12 Jul 2001 16:27:52 -0400	[thread overview]
Message-ID: <20010712162752.A690@cactus.desert.cx> (raw)

Hello,

There's a slight problem with the parameter checking in kernel version 2.2.19.
As it is now, if the parameter is less than 4 bytes long, it returns EINVAL.
That means that passing in ("lo", 3) to bind a socket to the loopback device
will never succeed.

There is also another bug where passing NULL as the parameter would unbind
the socket but still return EINVAL. That doesn't seem to be sensible behavior.

I don't know if these two bugs are in 2.4 but I've attached a patch which
fixes these bugs in 2.2.19. If you have any comments, please CC me because
I'm not on the list.

-Mark Aikens


diff -u --new-file --recursive linux-2.2.19.orig/net/core/sock.c linux-2.2.19/net/core/sock.c
--- linux-2.2.19.orig/net/core/sock.c	Sun Mar 25 11:37:41 2001
+++ linux-2.2.19/net/core/sock.c	Wed Jul 11 22:43:29 2001
@@ -174,16 +174,21 @@
 			return 0;
 	}
 #endif	
-		
-  	if(optlen<sizeof(int))
-  		return(-EINVAL);
-  	
-	err = get_user(val, (int *)optval);
-	if (err)
-		return err;
-	
-  	valbool = val?1:0;
-  	
+
+#ifdef CONFIG_NETDEVICES
+	if(optname != SO_BINDTODEVICE)
+#endif
+	{
+ 		if(optlen<sizeof(int))
+ 			return(-EINVAL);
+ 
+		err = get_user(val, (int *)optval);
+		if (err)
+			return err;
+
+		valbool = val?1:0;
+	}
+
   	switch(optname) 
   	{
 		case SO_DEBUG:	
@@ -305,7 +310,7 @@
 			 * is not bound. 
 			 */ 
 
-			if (!valbool) {
+			if (optval == NULL) {
 				sk->bound_dev_if = 0;
 			} else {
 				if (optlen > IFNAMSIZ) 
@@ -326,8 +331,8 @@
 						return -EINVAL;
 					sk->bound_dev_if = dev->ifindex;
 				}
-				return 0;
 			}
+			return 0;
 		}
 #endif
 

                 reply	other threads:[~2001-07-12 20:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20010712162752.A690@cactus.desert.cx \
    --to=marka@wpi.edu \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®