mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexey Toptygin <alexeyt@freeshell.org>
To: Andi Kleen <ak@suse.de>
Cc: linux-kernel@vger.kernel.org, tony.luck@intel.com
Subject: Re: [PATCH] sendfile compat functions on x86_64 and ia64
Date: Fri, 5 May 2006 22:19:32 +0000 (UTC)	[thread overview]
Message-ID: <Pine.NEB.4.62.0605052145140.25706@ukato.freeshell.org> (raw)
In-Reply-To: <200605052328.21370.ak@suse.de>

On Fri, 5 May 2006, Andi Kleen wrote:

>> On a 32 bit kernel (and on a 64 bit kernel using the native interface),
>> count is passed to sendfile as unsigned. rw_verify_area explicitly casts
>> to signed
>
> To a 64bit signed.
>
>> before checking for negativeness. The only place anywhere in the
>> kernel that count is signed (other than where rw_verify area explicitly
>> casts it for one test) is in the declaration of sys32_sendfile in the
>> x86_64 compat code. I'm pretty sure it's supposed to be unsigned there
>> too, and the current code is a typo.
>
> It's a 32bit signed.
>
> Somehow the 32bit signed has to become a 64bit signed to be caught
> by rw_verify_area(). The only place that can do that is the compat
> layer.

I still think you misunderstand.

According to 32 bit libc, count is an unsigned 32 bit value. This unsigned 
32 bit value is given to x86_64's sys32_sendfile, which _thinks_ it's a 
signed 32 bit value. sys32_sendfile is passing it to sys_sendfile, which 
expects an unsigned 64 bit value, so the compiler sign-extends it to 64 
bits, then gives it to sys_sendfile as unsigned 64 bits. sys_sendfile 
passes it to do_sendfile with the same type, so it goes there unchanged. 
do_sendfile passes it to rw_verify_area with the same type, so it goes 
there unchanged. rw_verify_area then does this:

         if (unlikely((ssize_t) count < 0))
                 goto Einval;

I agree that this test will pass if we change the declaration of count to 
u32 in sys32_sendfile, but it should pass: this test isn't meant to catch 
values that shouldn't be passed by a 32 bit program, it is only protecting 
against math involving count wrapping later on in rw_verify_area. The test 
agains MAX_NON_LFS (passed via max from sys_sendfile) later in do_sendfile 
will still fail and reject values greater than ((1<<31)-1) passed in from 
32 bit libc.

The ia64 compat path declares count to be unsigned, and presumably this is 
working fine. That path is identical to the above, except sign extension 
doesn't happen: a u32 value is just placed in a u64 variable.

As a result, the x86_64 and ia64 compat paths are inconsistent, so I think 
one of them needs to change. Since every other path from userland into a 
sendfile function has an unsigned count (and none of them appear to be 
broken), I think the change needs to be in x86_64 sys32_sendfile. I think 
the sign extension that is going on there now is completely unnecessary 
and confusing; I think it's a happy accident that it didn't break 
anything.

The only thing my patch does other than changing the signedness of count 
in the declaration of x86_64 sys32_sendfile is relabelling the types of 
offset and count to compat_off_t and compat_size_t. The underlying types 
shouldn't change as a result, but I think this way what is going on is 
much clearer: the compat_ types were defined for exactly this scenario of 
64 bit kernel functions getting off_t and size_t values from a 32 bit 
userland, no?

 			Alexey

  reply	other threads:[~2006-05-05 22:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-05  0:45 Alexey Toptygin
2006-05-05 20:38 ` Andi Kleen
2006-05-05 20:44   ` Alexey Toptygin
2006-05-05 21:28     ` Andi Kleen
2006-05-05 22:19       ` Alexey Toptygin [this message]
2006-05-06  8:46         ` Andi Kleen
2006-05-06 22:43           ` Alexey Toptygin

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=Pine.NEB.4.62.0605052145140.25706@ukato.freeshell.org \
    --to=alexeyt@freeshell.org \
    --cc=ak@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tony.luck@intel.com \
    /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

Powered by JetHome