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 1D52126B084; Tue, 8 Apr 2025 12:00:07 +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=1744113607; cv=none; b=C+PpoVwhEyYaWt6Sf6JL0ocrXPrfD0D3sylA+Dcla7vchjkDWRQxbIq+yIEqCpesbLixOv43c+bItqhc+KECPJyy0nPLq0p7cI2hLYKY9OHmd/lsWjOrhCjlRsOFMnhuMozMWEchQRKifdawUkAhgw51ZFrwiu1AUbLSCtY9CYQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744113607; c=relaxed/simple; bh=/D/30qW9BYPZC/QTdNeL61HsEWSMZVPO8i2Sj4ZluLg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HoTH33c/DsOJ+NkmHrRLRd+BobGwg9Fh2Q/lju9wKGro5pMgW4iTE5ZDAlx8qxHMe/ZQZ8miRuz5RhOCiaiqNNLpC7z+dag9wQYP/f5zSmkXeYPN/7qgLCCkD+qr7UO0nASCRKS5Uh+KlKhuR9BH+I3L1CQviXybiXgM1e25pe8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YZT/aH5T; 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="YZT/aH5T" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2E9EC4CEE5; Tue, 8 Apr 2025 12:00:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744113607; bh=/D/30qW9BYPZC/QTdNeL61HsEWSMZVPO8i2Sj4ZluLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YZT/aH5TUQMKVIq6qeSbzyGWwXPgiTOH2TJhRw6D0p2ogLR85bChMof0pGr52aPJF mx3Nyu+c9EgfL5MTvor+EP3oYMR4Qt8z96RY+Mu8knx9PRc5V1RBGL4GQctcdHgcsB PkwE2udCI3p+sZcH1ZvvZBplIIArlvlCmKxYNZs4= 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.6 195/268] ntb_hw_switchtec: Fix shift-out-of-bounds in switchtec_ntb_mw_set_trans Date: Tue, 8 Apr 2025 12:50:06 +0200 Message-ID: <20250408104833.816599655@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408104828.499967190@linuxfoundation.org> References: <20250408104828.499967190@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.6-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 0a94c634ddc27..b5f93f07e22a4 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