From: "David S. Miller" <davem@redhat.com>
To: Chris Evans <chris@scary.beasts.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: Re: Minor net/core/sock.c security issue?
Date: Mon, 23 Jul 2001 16:14:20 -0700 (PDT) [thread overview]
Message-ID: <15196.45004.237634.928656@pizda.ninka.net> (raw)
In-Reply-To: <Pine.LNX.4.33.0107232321120.19755-100000@ferret.lmh.ox.ac.uk>
In-Reply-To: <Pine.LNX.4.33.0107232321120.19755-100000@ferret.lmh.ox.ac.uk>
Chris Evans writes:
> int val;
> ...
> case SO_SNDBUF:
> if (val > sysctl_wmem_max)
> val = sysctl_wmem_max;
> sk->sndbuf = max(val*2,2048);
>
> If val is negative, then sk->sndbuf ends up negative. This is because the
> arguments to max are passed as _unsigned_ ints. SO_RCVBUF has similar
> issues. Maybe a nasty local user could use this to chew up memory?
Indeed, you have only hit the tip of the iceberg on the larger
problems lurking in this area.
In short, min/max usage is pretty broken. And it is broken for
several reasons:
1) Signedness, what you have discovered.
2) Arg evaluation.
3) Multiple definitions
#3 is what really makes this look gross. Watch this:
include/net/sock.h declares two inline functions, min and
max
net/core/sock.c defines "min" as a macro, overriding the
function in sock.h
egrep "define max" include/linux/*.h shows at least three
other headers which want to define their own max macro.
There is even commentary about this in include/linux/netfilter.h along
with Rusty's attempt to make reasonable macros. I personally disagree
with keeping them as macros because of the arg multiple evaluation
issues.
I think the way to fix this is to either:
1) have standard inline functions with names that suggest the
signedness, much like Rusty's netfilter macros.
2) Just open code all instances of min/max, there will be no
mistaking what the code does in such a case.
In both cases, min/max simply die and nobody can therefore misuse them
anymore.
Later,
David S. Miller
davem@redhat.com
next prev parent reply other threads:[~2001-07-23 23:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-07-23 22:24 Chris Evans
2001-07-23 23:14 ` David S. Miller [this message]
2001-07-24 3:02 ` Albert D. Cahalan
2001-07-24 3:41 ` David S. Miller
2001-07-24 4:55 ` Albert D. Cahalan
2001-07-24 22:24 ` Alexey Kuznetsov
2001-07-27 9:56 ` David S. Miller
2001-07-27 16:44 ` kuznet
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=15196.45004.237634.928656@pizda.ninka.net \
--to=davem@redhat.com \
--cc=chris@scary.beasts.org \
--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®