From nobody Sun Sep 14 22:49:45 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5ABD1C6FA82 for ; Tue, 13 Sep 2022 14:40:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231874AbiIMOk5 (ORCPT ); Tue, 13 Sep 2022 10:40:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234501AbiIMOio (ORCPT ); Tue, 13 Sep 2022 10:38:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1AF86C11D; Tue, 13 Sep 2022 07:20:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E6ED3B80EFC; Tue, 13 Sep 2022 14:20:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 448DDC433D6; Tue, 13 Sep 2022 14:20:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078850; bh=isSUejFmC6YCkWSG1RxhFo0pAIfhZ7nb6G9Uj8+uiaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kaON+QM27G44xnL4/v2JBjtuFmhL3Q9vHBL2fvoJRUQcR2eIHft6skwK+kL+iVC0k Qd4oP0mjjPrY55Wy27fFJCa3oXoR09E4pHuTC6Lcn9rOCVNjRG2Vdlk63GZ/KobEOa tTu9ql+21OjE60gSNPXL0xYHI1tbiGqpSehO6T54= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Gao , Dongli Zhang , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.15 107/121] swiotlb: avoid potential left shift overflow Date: Tue, 13 Sep 2022 16:04:58 +0200 Message-Id: <20220913140401.943247423@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140357.323297659@linuxfoundation.org> References: <20220913140357.323297659@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Chao Gao [ Upstream commit 3f0461613ebcdc8c4073e235053d06d5aa58750f ] The second operand passed to slot_addr() is declared as int or unsigned int in all call sites. The left-shift to get the offset of a slot can overflow if swiotlb size is larger than 4G. Convert the macro to an inline function and declare the second argument as phys_addr_t to avoid the potential overflow. Fixes: 26a7e094783d ("swiotlb: refactor swiotlb_tbl_map_single") Signed-off-by: Chao Gao Reviewed-by: Dongli Zhang Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- kernel/dma/swiotlb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index e62fb7a4da694..018f140aaaf4e 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -435,7 +435,10 @@ static void swiotlb_bounce(struct device *dev, phys_ad= dr_t tlb_addr, size_t size } } =20 -#define slot_addr(start, idx) ((start) + ((idx) << IO_TLB_SHIFT)) +static inline phys_addr_t slot_addr(phys_addr_t start, phys_addr_t idx) +{ + return start + (idx << IO_TLB_SHIFT); +} =20 /* * Carefully handle integer overflow which can occur when boundary_mask = =3D=3D ~0UL. --=20 2.35.1