[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241215181557.GBZ18c3QJw8-7HWeSD@fat_crate.local>
Date: Sun, 15 Dec 2024 19:15:57 +0100
From: Borislav Petkov <bp@...en8.de>
To: Yazen Ghannam <yazen.ghannam@....com>
Cc: Karan Sanghavi <karansanghvi98@...il.com>,
Tony Luck <tony.luck@...el.com>, linux-edac@...r.kernel.org,
linux-kernel@...r.kernel.org,
Shuah Khan <skhan@...uxfoundation.org>
Subject: Re: [PATCH v3] RAS/AMD/ATL: Fix unintended sign extension issue from
coverity
On Wed, Dec 11, 2024 at 11:01:13AM -0500, Yazen Ghannam wrote:
> On Wed, Nov 27, 2024 at 06:23:48PM +0000, Karan Sanghavi wrote:
> > This error is reported by coverity scan stating as
> >
> > CID 1593397: (#1 of 1): Unintended sign extension (SIGN_EXTENSION)
> > sign_extension: Suspicious implicit sign extension: pc
> > with type u16 (16 bits, unsigned) is promoted in
> > pc << bit_shifts.pc to type int (32 bits, signed),
> > then sign-extended to type unsigned long (64 bits, unsigned).
> > If pc << bit_shifts.pc is greater than 0x7FFFFFFF,
> > the upper bits of the result will all be 1.
> >
> > Use u32 for bitwise operations to prevent unintentional
> > sign extension by assigning the u16 value to a u32
> > variable before performing the bitwise operation to
> > avoid unintended sign extension and maintain
> > consistency with the existing code style.
> >
> > Reviewed-by: Yazen Ghannam <yazen.ghannam@....com>
> > Signed-off-by: Karan Sanghavi <karansanghvi98@...il.com>
> Boris, can you please take this patch if no objections?
Lemme see:
bit_shifts.pc = 5 + FIELD_GET(ADDR_SEL_2_CHAN, temp);
#define ADDR_SEL_2_CHAN GENMASK(15, 12)
that register field is 4 bits, so 0xf is the highest value it can contain.
Thus, bit_shifts.pc can have 20 as its max value.
So all that coverity OMG OMG sign-extension overflow above cannot actually
really happen, can it?
Because pc is promoted to an int, as the text rightfully points out.
Or am I way off here?
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
Powered by blists - more mailing lists