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 0546A2676FA; Tue, 8 Apr 2025 12:25:32 +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=1744115132; cv=none; b=C4vcSt8mhiMQxHWe1wGJYJP3G/q14YZ11pceU+KNJnwP5xCWFs3VVh4p/A76bLFlRIrNDxg6KYNrTlC3CcUR9u6tB9Qv6ooXrQ8UYqnLlERZld0BCC3j5FBqgE7iGaRgJ2/Oip1puqD5o/zZD/lOhhkw49bNWBvcPxdAe8fQPHc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744115132; c=relaxed/simple; bh=n4qXtnZjSxtWdqoZ/XYejQVCKheR5OtmoOmED3gOnKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BKHMGz7V/XjWBlJO7UXg7/mOYWTPBby/3Wb3+vdGbRX4mcYrg67f1Z4dkrDowuor/Hcl0Zz1fCvK6rQwDcw/Te8m10+4v9poExXV7uGbX641222+WjQrFg3b+16YM4LWQANooNLOWJA7mSpvR/0QddQOeRPEdsEhgRsNuajJ6nk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jy3JZRak; 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="jy3JZRak" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 845F8C4CEE5; Tue, 8 Apr 2025 12:25:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744115131; bh=n4qXtnZjSxtWdqoZ/XYejQVCKheR5OtmoOmED3gOnKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jy3JZRakjaYY4vktQbbw/TxBkyQ23yrJ7vSPczNQb2JNWUzlhiKljPWwGVnbsyil/ aRE8QrO2C5TAphUu+wjMJSVZ534ddz3py0X18FXgux4F/3wILy9PV9/T1b1nUpFNdc zijXnQ4JQbrbWzqlVOgZ3ORLp7wst3fBTEO7MZKk= 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 6.13 361/499] 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: <20250408104900.234592417@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408104851.256868745@linuxfoundation.org> References: <20250408104851.256868745@linuxfoundation.org> User-Agent: quilt/0.68 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.13-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 ad1786be2554b..f851397b65d6e 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