mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@redhat.com>
To: Jesper Juhl <juhl-lkml@dif.dk>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH][RFC] variable size and signedness issues in ldt.c - potential problem?
Date: Fri, 9 Jan 2004 04:46:46 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.58.0401090440180.27298@devserv.devel.redhat.com> (raw)
In-Reply-To: <8A43C34093B3D5119F7D0004AC56F4BC074AFBC9@difpst1a.dif.dk>


On Thu, 8 Jan 2004, Jesper Juhl wrote:

> I'm hunting the kernel source for any potential problem I can find (and
> hopefully fix), and I've come across something that looks like a
> possible problem in arch/i386/kernel/ldt.c
> 
> First thing that looks suspicious is this bit in read_ldt() :
> 
>         for (i = 0; i < size; i += PAGE_SIZE) {
> 		...
> 	}
> 
> 'i' is a plain int while 'size' is an 'unsigned long' leaving the
> possibility that if size contains a value greater than what a signed int
> can hold then this code won't do the right thing, either 'i' will wrap
> around to zero and the loop will never exit or something "unknown" will
> happen (as far as I know, what happens when an int overflows is
> implementation defined). [...]

but the user does not control 'newsize'. Can you outline a scenario in 
where the value could overflow?

> The second thing is that in the body of the 'for' loop there is this
> comparison :
> 
> if (bytes > PAGE_SIZE)

no, the value of bytes is really limited. Again, can you suggest a
scenario in where this could overflow?

> I know that the only user of read_ldt() and write_ldt() is
> sys_modify_ldt() , and the arguments for read_ldt and write_ldt thus
> have to match sys_modify_ldt, but why is the 'bytecount' argument for
> sys_modify_ldt an 'unsigned long' and the return type an 'int' ? The
> signedness of the return type makes sense given that it't supposed to
> return -1 on error. But on success, in the case where it calls read_ldt,
> it's supposed to return the actual number of bytes read. But if the
> number of bytes to read is given as an unsigned long, and the number
> actually read exceeds the size of a signed int then the return value
> will get truncated upon return - how can that be right? [...]

LDT size is limited by LDT_ENTRY_SIZE*LDT_ENTRIES. We explicitly truncate
bytecount to this range so unsigned vs. signed makes no difference.

> [...] And if the return value can never exceed what a signed int can
> hold, then why is it possible to request an unsigned long amount of
> bytes to read in the first place?

that's quite common for the interface definitions. Since we are on x86
unsigned long == unsigned int.

> and finally a purely style related thing (sure, call me pedantic); in both
> read_ldt() and write_ldt() 'mm' is declared as
> 
> struct mm_struct * mm = current->mm;

yep, you are right, this is the wrong style.

	Ingo

  parent reply	other threads:[~2004-01-09  9:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-07 23:20 Jesper Juhl
2004-01-07 23:28 ` Jesper Juhl
2004-01-09  9:46 ` Ingo Molnar [this message]
2004-01-11  2:30   ` [PATCH(s)][RFC] " Jesper Juhl
2004-01-12 21:53     ` Jesper Juhl
2004-01-12 22:13       ` Andrew Morton
2004-01-12 22:20         ` Jesper Juhl
2004-01-12 22:39           ` Randy.Dunlap
2004-01-12 22:51             ` Jesper Juhl
2004-01-12 22:55               ` Randy.Dunlap

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.LNX.4.58.0401090440180.27298@devserv.devel.redhat.com \
    --to=mingo@redhat.com \
    --cc=juhl-lkml@dif.dk \
    --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®