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 A2B77224234; Tue, 8 Apr 2025 11:02:54 +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=1744110174; cv=none; b=ARpUtiXBh6+I71fbI0cOhHYuqWQbdtnQ3B83PPu7wR/RxtYtwchLP2dEoI3loIvJWBLdt2KOZuT3dclAnnLeUCNnyDMbUThcc3CaRJbaRJ5Ra2qfb1/2jBAFXGhRnZfXdIrAlbFIep1OJvcy9vrqbUFRTiB/yUaEqO0B0vl9l64= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744110174; c=relaxed/simple; bh=3syzXNxFx6eOhn1P50HvuwZowTRJ7QaitxB76yORn5I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A0HwzkdWXOaU3UTd+pHB3hv64b4ZuePz/Xfj5hrte/yt6Zu/1xi34kmnk10MXhd5RZC75B4NkJ8W4wgcgCU99e3MIwIbbJW7kIelea+h4H0wVZUKY37Y49v/X+aCvBcHg36b6myNyG0pAFhjlvKTc2iftG6vbuN1KZsCYhKnkDU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lEQisah9; 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="lEQisah9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A4C5C4CEE5; Tue, 8 Apr 2025 11:02:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744110174; bh=3syzXNxFx6eOhn1P50HvuwZowTRJ7QaitxB76yORn5I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lEQisah9S8MAWt18k+UOH5FMN6FAwUumtS6XxeobXFdgzALKhf2HWklB56sFUPIyc ehQqhMKAL8zfJX1VYAoS1gXj7USCi4Owl7GC0jzEX7jopaVxotFEBuK8L0HmBh/dS5 bgZ9fZQ5cPU3n4jhv9AazFtA9pUtm6FMrW+9QaTs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yajun Deng , Logan Gunthorpe , Jon Mason , Sasha Levin Subject: [PATCH 5.10 195/227] ntb_hw_switchtec: Fix shift-out-of-bounds in switchtec_ntb_mw_set_trans Date: Tue, 8 Apr 2025 12:49:33 +0200 Message-ID: <20250408104826.149079020@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408104820.353768086@linuxfoundation.org> References: <20250408104820.353768086@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yajun Deng [ Upstream commit de203da734fae00e75be50220ba5391e7beecdf9 ] There is a kernel API ntb_mw_clear_trans() would pass 0 to both addr and size. This would make xlate_pos negative. [ 23.734156] switchtec switchtec0: MW 0: part 0 addr 0x0000000000000000 size 0x0000000000000000 [ 23.734158] ================================================================================ [ 23.734172] UBSAN: shift-out-of-bounds in drivers/ntb/hw/mscc/ntb_hw_switchtec.c:293:7 [ 23.734418] shift exponent -1 is negative Ensuring xlate_pos is a positive or zero before BIT. Fixes: 1e2fd202f859 ("ntb_hw_switchtec: Check for alignment of the buffer in mw_set_trans()") Signed-off-by: Yajun Deng Reviewed-by: Logan Gunthorpe Signed-off-by: Jon Mason Signed-off-by: Sasha Levin --- drivers/ntb/hw/mscc/ntb_hw_switchtec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c index ad09946100b56..c5c1963c699d9 100644 --- a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c +++ b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c @@ -288,7 +288,7 @@ static int switchtec_ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int widx, if (size != 0 && xlate_pos < 12) return -EINVAL; - if (!IS_ALIGNED(addr, BIT_ULL(xlate_pos))) { + if (xlate_pos >= 0 && !IS_ALIGNED(addr, BIT_ULL(xlate_pos))) { /* * In certain circumstances we can get a buffer that is * not aligned to its size. (Most of the time -- 2.39.5