public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Philippe Troin <phil@fifi.org>
To: "David S. Miller" <davem@redhat.com>
Cc: linux-kernel@vger.kernel.org, alan@lxorguk.ukuu.org.uk
Subject: Re: 2.2.x BUG & PATCH: recvmsg() does not check msg_controllen correctly
Date: 04 Nov 2000 18:40:30 -0800	[thread overview]
Message-ID: <87snp7gmzl.fsf@tantale.fifi.org> (raw)
In-Reply-To: <87n1fgvl7a.fsf@tantale.fifi.org> <200011032218.OAA12790@pizda.ninka.net> <878zr0vbda.fsf@tantale.fifi.org> <200011040038.QAA13178@pizda.ninka.net> <87u29oz93z.fsf@tantale.fifi.org> <200011040451.UAA13833@pizda.ninka.net>
In-Reply-To: <200011040451.UAA13833@pizda.ninka.net> ("David S. Miller"'s message of "Fri, 3 Nov 2000 20:51:55 -0800")

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

"David S. Miller" <davem@redhat.com> writes:

>    From: Philippe Troin <phil@fifi.org>
>    Date: 03 Nov 2000 19:53:04 -0800
> 
>    Yes I agree, mixing signed and unsigned arithmetic is evil... Doesn't
>    gcc have a flag for unsafe signed/unsigned mixtures ?
> 
>    Would you consider this patch (or a variant) for inclusion ?
> 
> I would accept a patch which made the code set fdmax <= 0 when
> (msg->msg_controllen < (sizeof(struct cmsghdr) + sizeof(int)))
> because it is the sole reason this bug exists at all.

How about this one ?

Phil.

[-- Attachment #2: linux-2.2.17-scmrights.patch --]
[-- Type: application/octet-stream, Size: 800 bytes --]

diff -ruN linux.orig/net/core/scm.c linux/net/core/scm.c
--- linux.orig/net/core/scm.c	Thu Apr 22 19:45:19 1999
+++ linux/net/core/scm.c	Sat Nov  4 17:19:34 2000
@@ -210,12 +210,16 @@
 {
 	struct cmsghdr *cm = (struct cmsghdr*)msg->msg_control;
 
-	int fdmax = (msg->msg_controllen - sizeof(struct cmsghdr))/sizeof(int);
+	int fdmax = 0;
 	int fdnum = scm->fp->count;
 	struct file **fp = scm->fp->fp;
 	int *cmfptr;
 	int err = 0, i;
 
+	if (msg->msg_controllen > sizeof(struct cmsghdr))
+		fdmax = (msg->msg_controllen - sizeof(struct cmsghdr))
+			/sizeof(int);
+
 	if (fdnum < fdmax)
 		fdmax = fdnum;
 
@@ -251,7 +255,7 @@
 			msg->msg_controllen -= cmlen;
 		}
 	}
-	if (i < fdnum)
+	if (i < fdnum || (fdnum && fdmax == 0))
 		msg->msg_flags |= MSG_CTRUNC;
 
 	/*

  reply	other threads:[~2000-11-05  2:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-03 20:45 2.2.x BUG & PATCH: recvmsg() does not check msg_controllen correctly Philippe Troin
2000-11-03 22:18 ` David S. Miller
2000-11-04  0:17   ` Philippe Troin
2000-11-04  0:38     ` David S. Miller
2000-11-04  3:53       ` Philippe Troin
2000-11-04  4:51         ` David S. Miller
2000-11-05  2:40           ` Philippe Troin [this message]
2000-11-06  3:32             ` David S. Miller
2000-11-06  4:07               ` Philippe Troin
2000-11-06  3:57                 ` David S. Miller

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=87snp7gmzl.fsf@tantale.fifi.org \
    --to=phil@fifi.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=davem@redhat.com \
    --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