Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp483556iog; Thu, 30 Jun 2022 04:47:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vOVHWbkes/ENsGj+QVOY0SfRGBamznnJzqq0EAkk2C4CZksfbohRyMzhC//dodqvi2+DUV X-Received: by 2002:a05:6a00:cce:b0:525:5209:c925 with SMTP id b14-20020a056a000cce00b005255209c925mr15224749pfv.59.1656589664196; Thu, 30 Jun 2022 04:47:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656589664; cv=none; d=google.com; s=arc-20160816; b=rzV1pjr08+msHWDDx3ChVk3Cl++LWKa+5jX6N0XCqpkSWoAk3pbQwznQNIJHcXrnJI zEQigxgLiUlAYo566mYnBRJeGoftO1Yf25MPOIt5cg5YoZ8gb6t8KIlv+mdTCkb5U/td ErHU5Ter40ewqrMbv2QRslit7eTQnM3z5j3eBiOVorplrgDKs/1wPEC+gZgKPvsGTSt9 i+NSoH/kKtlHZSP4y9tYUeoxrBiMKYxkuZnPBTaM7h3mSngqPFTVnxPYVYM0Y39oKb3n YjtJKhFsmXaN/MauJbyL48LMT47uA07RMmENfotfalFuq5P8uOQbtDgAVcMzzMH/0OVp CZrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=RKrue2A8BfuvkesGFCfK/urXzajS/zvnV6lMf4Ag4ug=; b=P5OkUhLGplQc3cLc9Q3EPHXGU1QeBumaribjjUi2BuArHMmXv8aQcXDg7axW8hoUBb 44tMwFPM/nILEdEOgWfDdP6JiWwc2vbwR34PH9peMMKezH96g191SBMaWViFEtAZQjwQ S//zLTWuS+yNoaQWja1B41X8DeCqMEuCwPFsbNcik9c+wGsIvwPDp31HAsDUaiYM0LzN BT8QZi4peT0tbGtmRKf81AW81B51NTSlPrP0dYai9n331hNgvdjzYykAl22mCGnE38F4 /F6gX1FeJyHhvSFTcnSW87oQEM7xQIkoW3L/zRKfVUwE7YN5dfI3gwuaLBsEE8PoBJXv TbFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r199-20020a632bd0000000b00411415a2c7dsi12631058pgr.303.2022.06.30.04.47.33; Thu, 30 Jun 2022 04:47:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234082AbiF3K4I (ORCPT + 99 others); Thu, 30 Jun 2022 06:56:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234013AbiF3K4H (ORCPT ); Thu, 30 Jun 2022 06:56:07 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 904BE427CC; Thu, 30 Jun 2022 03:56:02 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LYZvg6FD2zkWdV; Thu, 30 Jun 2022 18:54:07 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 30 Jun 2022 18:56:00 +0800 Received: from huawei.com (10.175.113.32) by dggpemm100009.china.huawei.com (7.185.36.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 30 Jun 2022 18:56:00 +0800 From: Liu Shixin To: Greg Kroah-Hartman , Halil Pasic , Christoph Hellwig , Ovidiu Panait , Ben Hutchings CC: , , Liu Shixin Subject: [PATCH stable 4.9,4.14] swiotlb: skip swiotlb_bounce when orig_addr is zero Date: Thu, 30 Jun 2022 19:32:25 +0800 Message-ID: <20220630113225.1544802-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After patch ddbd89deb7d3 ("swiotlb: fix info leak with DMA_FROM_DEVICE"), swiotlb_bounce will be called in swiotlb_tbl_map_single unconditionally. This requires that the physical address must be valid, which is not always true on stable-4.19 or earlier version. On stable-4.19, swiotlb_alloc_buffer will call swiotlb_tbl_map_single with orig_addr equal to zero, which cause such a panic: Unable to handle kernel paging request at virtual address ffffb77a40000000 ... pc : __memcpy+0x100/0x180 lr : swiotlb_bounce+0x74/0x88 ... Call trace: __memcpy+0x100/0x180 swiotlb_tbl_map_single+0x2c8/0x338 swiotlb_alloc+0xb4/0x198 __dma_alloc+0x84/0x1d8 ... On stable-4.9 and stable-4.14, swiotlb_alloc_coherent wille call map_single with orig_addr equal to zero, which can cause same panic. Fix this by skipping swiotlb_bounce when orig_addr is zero. Fixes: ddbd89deb7d3 ("swiotlb: fix info leak with DMA_FROM_DEVICE") Signed-off-by: Liu Shixin --- lib/swiotlb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/swiotlb.c b/lib/swiotlb.c index bdc2b89870e3..e162cb464ee4 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c @@ -607,7 +607,8 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, * unconditional bounce may prevent leaking swiotlb content (i.e. * kernel memory) to user-space. */ - swiotlb_bounce(orig_addr, tlb_addr, size, DMA_TO_DEVICE); + if (orig_addr) + swiotlb_bounce(orig_addr, tlb_addr, size, DMA_TO_DEVICE); return tlb_addr; } EXPORT_SYMBOL_GPL(swiotlb_tbl_map_single); -- 2.25.1