From: Chuck Lever <chuck.lever@oracle.com>
To: Trond Myklebust <trond.myklebust@fys.uio.no>
Cc: nfs@lists.sourceforge.net, "Talpey, Thomas" <Thomas.Talpey@netapp.com>
Subject: Re: [PATCH] SUNRPC: Fix xdr_decode_string_inplace() mixed sign comparison
Date: Thu, 01 Nov 2007 11:37:06 -0400 [thread overview]
Message-ID: <4729F2A2.4030505@oracle.com> (raw)
In-Reply-To: <1193889489.7511.17.camel@heimdal.trondhjem.org>
[-- Attachment #1: Type: text/plain, Size: 3015 bytes --]
Trond Myklebust wrote:
> On Wed, 2007-10-31 at 21:53 -0400, Chuck Lever wrote:
>> On Oct 31, 2007, at 3:00 PM, Trond Myklebust wrote:
>>> On Wed, 2007-10-31 at 13:06 -0400, Talpey, Thomas wrote:
>>>> This is a serious vunerability! A huge string length will always be
>>>> accepted by this code, right? Security/integrity bug, not a minor
>>>> sign cleanup IOW.
>>> Wrong! The current code is quite correct.
>>>
>>> It trusts that the caller is setting a reasonable value for maxlen,
>>> and
>>> assumes that 'len' is the untrusted value (since it comes from the
>>> network).
>>>
>>> in the comparison
>>>
>>> ((len = ntohl(*p++)) < maxlen)
>>>
>>> then the trusted value maxlen is the one that gets cast to an unsigned
>>> value since 'len' and 'maxlen' are both integers of the same rank (see
>>> the description of the usual binary conversions in section 6.3.4 in
>>> Harbison and Steele).
>> Whatever H&S says, the compiler flags this as a mixed sign
>> comparison. Thus something is not working the way you assume it is.
>>
>> [cel@ingres NFS_ALL]$ make net/sunrpc/xdr.o
>> Using /home/cel/src/linux/NFS_ALL as source for kernel
>> GEN /u/cel/obj/Makefile
>> CHK include/linux/version.h
>> CHK include/linux/utsrelease.h
>> UPD include/linux/utsrelease.h
>> CALL /home/cel/src/linux/NFS_ALL/scripts/checksyscalls.sh
>> CC net/sunrpc/xdr.o
>> /home/cel/src/linux/NFS_ALL/net/sunrpc/xdr.c: In function
>> xdr_decode_string_inplace:
>> /home/cel/src/linux/NFS_ALL/net/sunrpc/xdr.c:100: warning: comparison
>> between signed and unsigned
>> [cel@ingres NFS_ALL]$
>>
>> Line 100 is precisely:
>>
>> if ((len = ntohl(*p++)) > maxlen)
>
> Which is still correct according to both the old and new C standards. I
> know you've got that book at home...
>
>> My gcc is the latest available for Fedora 7:
>>
>> gcc version 4.1.2 20070925 (Red Hat 4.1.2-27)
>>
>> I rather prefer spelling this out completely so that neither the
>> compiler nor humans can mistake the intent of this logic.
>
> That's fine, but please do not change the logic. The correct change is
> to replace the maxlen parameter with an unsigned int.
That's what I sent you originally. You rejected it:
On October 26, 2007 at 14:24 -0400, Trond Myklebust said:
>> diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
>> index 3d1f7cd..ff16bab 100644
>> --- a/net/sunrpc/xdr.c
>> +++ b/net/sunrpc/xdr.c
>> @@ -93,7 +93,7 @@ xdr_encode_string(__be32 *p, const char *string)
>> }
>>
>> __be32 *
>> -xdr_decode_string_inplace(__be32 *p, char **sp, int *lenp, int maxlen)
>> +xdr_decode_string_inplace(__be32 *p, char **sp, int *lenp, unsigned int maxlen)
>> {
>> unsigned int len;
>
> Nope. maxlen should be of the same type as *lenp.
>
> Trond
Thus I now argue that both *lenp and maxlen should either be unsigned
integers or size_t. Negative string lengths make no sense whatsoever.
If we change both arguments, then we should also change the callers, at
least to be consistent.
[-- Attachment #2: chuck.lever.vcf --]
[-- Type: text/x-vcard, Size: 259 bytes --]
begin:vcard
fn:Chuck Lever
n:Lever;Chuck
org:Oracle Corporation;Corporate Architecture: Linux Projects Group
adr:;;1015 Granger Avenue;Ann Arbor;MI;48104;USA
title:Principal Member of Staff
tel;work:+1 248 614 5091
x-mozilla-html:FALSE
version:2.1
end:vcard
[-- Attachment #3: Type: text/plain, Size: 314 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
[-- Attachment #4: Type: text/plain, Size: 140 bytes --]
_______________________________________________
NFS maillist - NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs
next prev parent reply other threads:[~2007-11-01 15:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-31 16:50 [PATCH] SUNRPC: Fix xdr_decode_string_inplace() mixed sign comparison Chuck Lever
2007-10-31 17:06 ` Talpey, Thomas
2007-10-31 17:29 ` Chuck Lever
2007-10-31 17:41 ` Talpey, Thomas
2007-10-31 17:56 ` Chuck Lever
2007-10-31 18:06 ` Talpey, Thomas
2007-10-31 19:00 ` Trond Myklebust
2007-10-31 19:14 ` Talpey, Thomas
2007-11-01 1:53 ` Chuck Lever
2007-11-01 3:58 ` Trond Myklebust
2007-11-01 15:37 ` Chuck Lever [this message]
2007-11-01 15:45 ` Trond Myklebust
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=4729F2A2.4030505@oracle.com \
--to=chuck.lever@oracle.com \
--cc=Thomas.Talpey@netapp.com \
--cc=nfs@lists.sourceforge.net \
--cc=trond.myklebust@fys.uio.no \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.