çå: Re: [PATCH] Fix an overflow in range_to_mtrr func

From: Zhenzhong Duan
Date: Tue May 29 2012 - 21:26:39 EST



----- yinghai@xxxxxxxxxx åéï

> On Mon, May 28, 2012 at 5:29 AM, Zhenzhong Duan
> <zhenzhong.duan@xxxxxxxxxx> wrote:
> > When boot x86_64 kernel on sun G5+ with 4T mem, see an overflow in
> mtrr cleanup as below.
> >
> > *BAD*gran_size: 2G Â Â Âchunk_size: 2G Ânum_reg: 10 Â Â lose cover
> RAM:
> > -18014398505283592M
> >
> > This is because 1<<31 sign extended.
> > Use explicit type conversion to force a 64bit constant to fix it.
> > Useful for mem larger than or equal to 4T.
> >
> > Signed-off-by: Zhenzhong Duan <zhenzhong.duan@xxxxxxxxxx>
> > ---
> > Âarch/x86/kernel/cpu/mtrr/cleanup.c | Â Â2 +-
> > Â1 files changed, 1 insertions(+), 1 deletions(-)
> >
> > diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c
> b/arch/x86/kernel/cpu/mtrr/cleanup.c
> > index ac140c7..853a4c6 100644
> > --- a/arch/x86/kernel/cpu/mtrr/cleanup.c
> > +++ b/arch/x86/kernel/cpu/mtrr/cleanup.c
> > @@ -266,7 +266,7 @@ range_to_mtrr(unsigned int reg, unsigned long
> range_startk,
> > Â Â Â Â Â Â Â Âif (align > max_align)
> > Â Â Â Â Â Â Â Â Â Â Â Âalign = max_align;
> >
> > - Â Â Â Â Â Â Â sizek = 1 << align;
> > + Â Â Â Â Â Â Â sizek = (unsigned long)1 << align;
>
> how about
>
> sizek = 1UL << align;
>
>
> > Â Â Â Â Â Â Â Âif (debug_print) {
> > Â Â Â Â Â Â Â Â Â Â Â Âchar start_factor = 'K', size_factor = 'K';
> > Â Â Â Â Â Â Â Â Â Â Â Âunsigned long start_base, size_base;
> > --
> > 1.7.3
> >
Yes, this looks more clean although same compiling result. Should i resend it?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/