Received: from eggs.gnu.org ([2001:4830:134:3::10]:55449) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecLnO-0002Fp-Hr for qemu-devel@nongnu.org; Thu, 18 Jan 2018 20:48:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecLnL-0005DI-Fe for qemu-devel@nongnu.org; Thu, 18 Jan 2018 20:48:42 -0500 Date: Fri, 19 Jan 2018 02:48:37 +0100 (CET) From: BALATON Zoltan In-Reply-To: Message-ID: References: <20180111045937.2119-1-david@gibson.dropbear.id.au> <20180111045937.2119-7-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Subject: Re: [Qemu-devel] [PULL 06/11] hw/ide: Emulate SiI3112 SATA controller List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: David Gibson , qemu-ppc@nongnu.org, Alexander Graf , QEMU Developers , Greg Kurz , Michael Roth , surajjs@au1.ibm.com On Thu, 18 Jan 2018, Peter Maydell wrote: > On 11 January 2018 at 04:59, David Gibson wrote: >> From: BALATON Zoltan >> >> This is a common generic PCI SATA controller that is also used in PCs >> but more importantly guests running on the Sam460ex board prefer this >> card and have a driver for it (unlike for other SATA controllers >> already emulated). >> >> Signed-off-by: BALATON Zoltan >> Acked-by: John Snow >> Signed-off-by: David Gibson >> --- > >> + case 0x10: >> + val = d->i.bmdma[0].cmd; >> + val |= (d->regs[0].confstat & (1UL << 11) ? (1 << 4) : 0); /*SATAINT0*/ >> + val |= (d->regs[1].confstat & (1UL << 11) ? (1 << 6) : 0); /*SATAINT1*/ >> + val |= (d->i.bmdma[1].status & BM_STATUS_INT ? (1 << 14) : 0); >> + val |= d->i.bmdma[0].status << 16; >> + val |= d->i.bmdma[1].status << 24; >> + break; > > Hi. Coverity points out (CID 1385151) that the << 24 here will > potentially inadvertently set the high 32 bits of val if the top > bit in bmdma[1].status is 1. (This is because in x << 24 where > x is uint8_t x gets promoted to signed int, and then when that > signed int with a high bit set is converted to uint64_t for the > logical or it's done by sign-extending. > > Adding a cast, like > val |= (uint32_t)d->i.bmdma[1].status << 24; > > should fix this. Sent another patch for this. Also adding casts to similar places (some of which might not be needed but should not hurt and there for symmetry). Thank you, BALATON Zoltan