All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Hopwood <david.nospam.hopwood@blueyonder.co.uk>
To: xen-devel@lists.xensource.com
Subject: Re: [PATCH] Off-by-one in cpu_gdt_init
Date: Mon, 06 Jun 2005 17:14:15 +0100	[thread overview]
Message-ID: <42A47657.7020107@blueyonder.co.uk> (raw)
In-Reply-To: <Pine.LNX.4.60.0506061132180.3202@stclair.eecs.umich.edu>

George Washington Dunlap III wrote:
> I forget what triggered this bug (it was a long time ago), but 
> cpu_gdt_init() is trying to allocate an array, one per frame, based on 
> gdt_descr->size.  However, the math currently rounds down instead of up! 
> (I'm pretty sure that when I triggered it, (gdt_descr->size>>PAGE_SHIFT) 
> was 0.)
> 
> diff -urN --exclude=SCCS --exclude=BitKeeper xen-unstable.latest/linux-2.6.11-xen-sparse/arch/xen/i386/kernel/cpu/common.c xeno-ft/linux-2.6.11-xen-sparse/arch/xen/i386/kernel/cpu/common.c
> --- xen-unstable.latest/linux-2.6.11-xen-sparse/arch/xen/i386/kernel/cpu/common.c	2005-05-16 13:05:03.000000000 -0400
> +++ xeno-ft/linux-2.6.11-xen-sparse/arch/xen/i386/kernel/cpu/common.c	2005-05-16 13:55:06.000000000 -0400
> @@ -554,7 +554,7 @@
>  
>  void __init cpu_gdt_init(struct Xgt_desc_struct *gdt_descr)
>  {
> -	unsigned long frames[gdt_descr->size >> PAGE_SHIFT];
> +	unsigned long frames[(gdt_descr->size >> PAGE_SHIFT)+1];

Variable-length arrays? Never use variable-length arrays in code that needs
to be robust: you can't guarantee that the stack won't overflow. If it does,
there is no way to detect that situtation (unlike malloc et al where you can
check for NULL), you just get undefined behaviour.

-- 
David Hopwood <david.nospam.hopwood@blueyonder.co.uk>

  reply	other threads:[~2005-06-06 16:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-06 15:35 [PATCH] Off-by-one in cpu_gdt_init George Washington Dunlap III
2005-06-06 16:14 ` David Hopwood [this message]
2005-06-07  0:48   ` Rusty Russell
2005-06-07 22:03     ` David Hopwood

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=42A47657.7020107@blueyonder.co.uk \
    --to=david.nospam.hopwood@blueyonder.co.uk \
    --cc=xen-devel@lists.xensource.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 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.