From patchwork Wed Aug 9 20:07:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tycho Andersen X-Patchwork-Id: 9891877 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 633E760363 for ; Wed, 9 Aug 2017 20:09:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54FE92898B for ; Wed, 9 Aug 2017 20:09:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48069289E2; Wed, 9 Aug 2017 20:09:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 490E02898B for ; Wed, 9 Aug 2017 20:09:43 +0000 (UTC) Received: (qmail 32325 invoked by uid 550); 9 Aug 2017 20:09:13 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 32146 invoked from network); 9 Aug 2017 20:09:08 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=docker.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=smWs/ioHgWxjGrsgmEs0wxYBrpTHYx0x8RZxDFoLDLc=; b=US+FVf/jGm7I31dQg5Bg+tMKcYpy8rN7/j2vJCqJRrGoL9fb0wgoVfMTZPveN+vaMd RLHeJpuNmcATs5hnfaWO6NO0qL2x/W4nhYow+gkPxj+lUeQU86pb6Ms2S6AQhTLsniCK 4lQ+ySVQrGym+cHN9BZqUcYYmqyxnMS2JoGBk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=smWs/ioHgWxjGrsgmEs0wxYBrpTHYx0x8RZxDFoLDLc=; b=icgzEyUxFa/Ro1BHKKvAJPXmIIKh1lQ24Vse9GVDYcMJa7fJHuIFTtN6hSHomY3N0K SaFzBnbD7N3mDVT0P3b1PIrgi1lmRg2oDery+nGuImyAYOGoywnhUZIszOPcEgIdxlAo 7KNS9p2yhlS+7ywgzu0V3rVmxQ2en4ZYFT9FJ0aILbmIg3FJm6qNNBV98E84jkc+GaBt GNkThUj7uWqaq45yx/Tnpeg23PhzRELaLcRa4DWST+ulGFBWk1fNbRrVWj5e2/50FKI2 rKQi/S+1D5nppZXE21uOjzirOvuYLiIKm6AkuiidIzGRjVEiztbYJBrzXgd7Bjg9Ar6A EdCg== X-Gm-Message-State: AIVw112QCalVPnMpk3BuTJBaQfp40vSqITPcZrUQDIK1KnjupxYQ3Rbn cE2SqzTs8TOcAg2K X-Received: by 10.36.71.135 with SMTP id t129mr7673036itb.141.1502309337338; Wed, 09 Aug 2017 13:08:57 -0700 (PDT) From: Tycho Andersen To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, kernel-hardening@lists.openwall.com, Marco Benatto , Juerg Haefliger , Juerg Haefliger Date: Wed, 9 Aug 2017 14:07:48 -0600 Message-Id: <20170809200755.11234-4-tycho@docker.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170809200755.11234-1-tycho@docker.com> References: <20170809200755.11234-1-tycho@docker.com> Subject: [kernel-hardening] [PATCH v5 03/10] swiotlb: Map the buffer if it was unmapped by XPFO X-Virus-Scanned: ClamAV using ClamSMTP From: Juerg Haefliger Signed-off-by: Juerg Haefliger Tested-by: Tycho Andersen --- include/linux/xpfo.h | 4 ++++ lib/swiotlb.c | 3 ++- mm/xpfo.c | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/linux/xpfo.h b/include/linux/xpfo.h index 1ff2d1976837..6b61f7b820f4 100644 --- a/include/linux/xpfo.h +++ b/include/linux/xpfo.h @@ -27,6 +27,8 @@ void xpfo_kunmap(void *kaddr, struct page *page); void xpfo_alloc_pages(struct page *page, int order, gfp_t gfp); void xpfo_free_pages(struct page *page, int order); +bool xpfo_page_is_unmapped(struct page *page); + #else /* !CONFIG_XPFO */ static inline void xpfo_kmap(void *kaddr, struct page *page) { } @@ -34,6 +36,8 @@ static inline void xpfo_kunmap(void *kaddr, struct page *page) { } static inline void xpfo_alloc_pages(struct page *page, int order, gfp_t gfp) { } static inline void xpfo_free_pages(struct page *page, int order) { } +static inline bool xpfo_page_is_unmapped(struct page *page) { return false; } + #endif /* CONFIG_XPFO */ #endif /* _LINUX_XPFO_H */ diff --git a/lib/swiotlb.c b/lib/swiotlb.c index a8d74a733a38..d4fee5ca2d9e 100644 --- a/lib/swiotlb.c +++ b/lib/swiotlb.c @@ -420,8 +420,9 @@ static void swiotlb_bounce(phys_addr_t orig_addr, phys_addr_t tlb_addr, { unsigned long pfn = PFN_DOWN(orig_addr); unsigned char *vaddr = phys_to_virt(tlb_addr); + struct page *page = pfn_to_page(pfn); - if (PageHighMem(pfn_to_page(pfn))) { + if (PageHighMem(page) || xpfo_page_is_unmapped(page)) { /* The buffer does not have a mapping. Map it in and copy */ unsigned int offset = orig_addr & ~PAGE_MASK; char *buffer; diff --git a/mm/xpfo.c b/mm/xpfo.c index 3cd45f68b5ad..3f305f31a072 100644 --- a/mm/xpfo.c +++ b/mm/xpfo.c @@ -206,3 +206,12 @@ void xpfo_kunmap(void *kaddr, struct page *page) spin_unlock_irqrestore(&xpfo->maplock, flags); } EXPORT_SYMBOL(xpfo_kunmap); + +inline bool xpfo_page_is_unmapped(struct page *page) +{ + if (!static_branch_unlikely(&xpfo_inited)) + return false; + + return test_bit(XPFO_PAGE_UNMAPPED, &lookup_xpfo(page)->flags); +} +EXPORT_SYMBOL(xpfo_page_is_unmapped);