Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp605371pxb; Tue, 5 Apr 2022 15:42:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuIFZ39h2II78B61Kk4LFbrGwDqeAC58fety608sxnqc68F0eEVL9y5tcGoYDEm5kNpLY2 X-Received: by 2002:a17:90b:38cd:b0:1ca:64dd:4747 with SMTP id nn13-20020a17090b38cd00b001ca64dd4747mr6623661pjb.55.1649198576820; Tue, 05 Apr 2022 15:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649198576; cv=none; d=google.com; s=arc-20160816; b=CNSovEh37m1iOsy5yQTt8AiycA/Gyxyk3IMo3WdYM6Kr+FPlunz+LCEYR445mCnc5C zBjFJeyaTT9o5sLqEv5/YDefwyKIUvndJwVlpx6rpEpwqvYuidJIDOf3vB/yXSBPeHDU Hw7NEu/h7MWmD+licCkis6iT5uGH7zNLvlcqRrMAVoYqjphvtBpHfHiDfrv2nOxpI/zI vZReQB9WYTs8mEO8zebJc0XV5OtRU8IJTdWGapifKpanTamnHTN05m3QwkyLIrS7WT7G cwrHCB3QoKqLI6pnXVXO+G9cRpqH/I9BoKKVkfGzx4qLTLEVLC89sGoKbpehr3jZIXjU u/OQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=B6QGrnIBhnIBlsXGaidhxdcRkopl2afBCG5vru1FCAU=; b=MHVbDAQLvHf54IOFU84Kf2cU32kS2UY0Z6RQ6cZ1PLHQOmoundVSbHK6AHU1dXS4z8 C75GUOQHXgdDlipQz3WzM7Ic3f3efaLSDMnn04UstbdBzIPVV8ApwhVrYzheVlAj32LR OVBS5TI5L3oJ8BV8tDhC7LfdTSHU13afG19ry5FkCy4jUptZ3onZjMjVUcfzRnukmC/W B5v74aGVdbLmA/+LrAfGfV87WkWr7LokbWD45ShMcbLY9U51ODL+XchXTefi0rpdP4XY GE64RjveRbLcwsceiiBibAPbrwcFHP69OBx0dqHOYu+6Eqg45OVXzasFiXS2DJWHlse2 +mMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="e3/TLXsW"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id n6-20020a63ee46000000b003816043ee1fsi14993919pgk.20.2022.04.05.15.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 15:42:56 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="e3/TLXsW"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A9BDD65434; Tue, 5 Apr 2022 15:23:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355495AbiDEOCh (ORCPT + 99 others); Tue, 5 Apr 2022 10:02:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234394AbiDEJae (ORCPT ); Tue, 5 Apr 2022 05:30:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28829E41C0; Tue, 5 Apr 2022 02:17:24 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 913D6615E3; Tue, 5 Apr 2022 09:17:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6EC3C385A3; Tue, 5 Apr 2022 09:17:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150243; bh=2QZcy4ugKnChUB5AG5XphNhvFP3xwzzyQEERB//4VRQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e3/TLXsWHd350aB0f+ccGgNavYcEUgENiXGIMmju3NYbjD1+ezjbYByL8IwZG04Zt Hqv6qQBc7M33rnhc2hY3GpnuVRj+knaHwVnn9PIUz8M8cFfiPr8D2wb1ru6HEbssSv csZUFtuYFfJSpKwyrqUo6FLdRLmkoZ3JzdSxBR1w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Halil Pasic , Oleksandr Natalenko , Christoph Hellwig , Linus Torvalds Subject: [PATCH 5.16 0967/1017] Reinstate some of "swiotlb: rework "fix info leak with DMA_FROM_DEVICE"" Date: Tue, 5 Apr 2022 09:31:20 +0200 Message-Id: <20220405070422.909709892@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Linus Torvalds commit 901c7280ca0d5e2b4a8929fbe0bfb007ac2a6544 upstream. Halil Pasic points out [1] that the full revert of that commit (revert in bddac7c1e02b), and that a partial revert that only reverts the problematic case, but still keeps some of the cleanups is probably better.  And that partial revert [2] had already been verified by Oleksandr Natalenko to also fix the issue, I had just missed that in the long discussion. So let's reinstate the cleanups from commit aa6f8dcbab47 ("swiotlb: rework "fix info leak with DMA_FROM_DEVICE""), and effectively only revert the part that caused problems. Link: https://lore.kernel.org/all/20220328013731.017ae3e3.pasic@linux.ibm.com/ [1] Link: https://lore.kernel.org/all/20220324055732.GB12078@lst.de/ [2] Link: https://lore.kernel.org/all/4386660.LvFx2qVVIh@natalenko.name/ [3] Suggested-by: Halil Pasic Tested-by: Oleksandr Natalenko Cc: Christoph Hellwig Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- Documentation/core-api/dma-attributes.rst | 8 -------- include/linux/dma-mapping.h | 8 -------- kernel/dma/swiotlb.c | 12 ++++++++---- 3 files changed, 8 insertions(+), 20 deletions(-) --- a/Documentation/core-api/dma-attributes.rst +++ b/Documentation/core-api/dma-attributes.rst @@ -130,11 +130,3 @@ accesses to DMA buffers in both privileg subsystem that the buffer is fully accessible at the elevated privilege level (and ideally inaccessible or at least read-only at the lesser-privileged levels). - -DMA_ATTR_OVERWRITE ------------------- - -This is a hint to the DMA-mapping subsystem that the device is expected to -overwrite the entire mapped size, thus the caller does not require any of the -previous buffer contents to be preserved. This allows bounce-buffering -implementations to optimise DMA_FROM_DEVICE transfers. --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -62,14 +62,6 @@ #define DMA_ATTR_PRIVILEGED (1UL << 9) /* - * This is a hint to the DMA-mapping subsystem that the device is expected - * to overwrite the entire mapped size, thus the caller does not require any - * of the previous buffer contents to be preserved. This allows - * bounce-buffering implementations to optimise DMA_FROM_DEVICE transfers. - */ -#define DMA_ATTR_OVERWRITE (1UL << 10) - -/* * A dma_addr_t can hold any valid DMA or bus address for the platform. It can * be given to a device to use as a DMA source or target. It is specific to a * given device and there may be a translation between the CPU physical address --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -581,10 +581,14 @@ phys_addr_t swiotlb_tbl_map_single(struc for (i = 0; i < nr_slots(alloc_size + offset); i++) mem->slots[index + i].orig_addr = slot_addr(orig_addr, i); tlb_addr = slot_addr(mem->start, index) + offset; - if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && - (!(attrs & DMA_ATTR_OVERWRITE) || dir == DMA_TO_DEVICE || - dir == DMA_BIDIRECTIONAL)) - swiotlb_bounce(dev, tlb_addr, mapping_size, DMA_TO_DEVICE); + /* + * When dir == DMA_FROM_DEVICE we could omit the copy from the orig + * to the tlb buffer, if we knew for sure the device will + * overwirte the entire current content. But we don't. Thus + * unconditional bounce may prevent leaking swiotlb content (i.e. + * kernel memory) to user-space. + */ + swiotlb_bounce(dev, tlb_addr, mapping_size, DMA_TO_DEVICE); return tlb_addr; }