From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04BB684E15; Mon, 15 Apr 2024 14:30:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713191418; cv=none; b=QP/Mmsm6LWuLUv4vc3lwsbon9dmA6vehfR5DXjYSR5uTFvITginOVQQBUHQl1Euk4oqgjCa+3i/sXlqlkUy+E/Nh61HNBWU2Mhq00RqUIYL1wzl9G5C4SLxuTvW4quccOw6C8LeSzZuNtExF/aVKy4UoV6AC4jhXieEMPNbhDxE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713191418; c=relaxed/simple; bh=1Topyq6XIUgs3dIXjfgBsZA/IFuqgFp/6A2Jj5G5FCk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LiaIF1JFRNhOzXszA/n7nCD1vDscRlS4yT+iCmN9iAWyAfDlp8jSjhjsKz7CckkaQclW4GxFTJreBzflZYKpAfOjVSitbcmSNVSHyx9z3GJHQ9IgYMrFLOy1ruK8nXRY3+C5HRF/01gTN9Suppywi9+hIPExXh1YiT7W5TBbXVU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TlKlxKP1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="TlKlxKP1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AFDBC113CC; Mon, 15 Apr 2024 14:30:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1713191417; bh=1Topyq6XIUgs3dIXjfgBsZA/IFuqgFp/6A2Jj5G5FCk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TlKlxKP1TD83tiMNrdT9ynEcvesaa4L0l21thVy9EXuNT9i71tCpYTHXYYwRP7ct+ tqeGv1fJn4vpq0IO0QnBSjerM8gxrzpM1d1+uiyPTxCFsfnM5ItPTqXwBpRsdHrMVH ZHZ+pEU7Et8Zb8god6MVjziDvk4cIJ5KQIRqlvq0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Arthur Kiyanovski , David Arinzon , Shannon Nelson , Paolo Abeni , Sasha Levin Subject: [PATCH 6.8 096/172] net: ena: Fix potential sign extension issue Date: Mon, 15 Apr 2024 16:19:55 +0200 Message-ID: <20240415142003.305828943@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240415141959.976094777@linuxfoundation.org> References: <20240415141959.976094777@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.8-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Arinzon [ Upstream commit 713a85195aad25d8a26786a37b674e3e5ec09e3c ] Small unsigned types are promoted to larger signed types in the case of multiplication, the result of which may overflow. In case the result of such a multiplication has its MSB turned on, it will be sign extended with '1's. This changes the multiplication result. Code example of the phenomenon: ------------------------------- u16 x, y; size_t z1, z2; x = y = 0xffff; printk("x=%x y=%x\n",x,y); z1 = x*y; z2 = (size_t)x*y; printk("z1=%lx z2=%lx\n", z1, z2); Output: ------- x=ffff y=ffff z1=fffffffffffe0001 z2=fffe0001 The expected result of ffff*ffff is fffe0001, and without the explicit casting to avoid the unwanted sign extension we got fffffffffffe0001. This commit adds an explicit casting to avoid the sign extension issue. Fixes: 689b2bdaaa14 ("net: ena: add functions for handling Low Latency Queues in ena_com") Signed-off-by: Arthur Kiyanovski Signed-off-by: David Arinzon Reviewed-by: Shannon Nelson Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- drivers/net/ethernet/amazon/ena/ena_com.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c b/drivers/net/ethernet/amazon/ena/ena_com.c index 633b321d7fdd9..4db689372980e 100644 --- a/drivers/net/ethernet/amazon/ena/ena_com.c +++ b/drivers/net/ethernet/amazon/ena/ena_com.c @@ -362,7 +362,7 @@ static int ena_com_init_io_sq(struct ena_com_dev *ena_dev, ENA_COM_BOUNCE_BUFFER_CNTRL_CNT; io_sq->bounce_buf_ctrl.next_to_use = 0; - size = io_sq->bounce_buf_ctrl.buffer_size * + size = (size_t)io_sq->bounce_buf_ctrl.buffer_size * io_sq->bounce_buf_ctrl.buffers_num; dev_node = dev_to_node(ena_dev->dmadev); -- 2.43.0