Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17892713ybl; Thu, 2 Jan 2020 14:13:47 -0800 (PST) X-Google-Smtp-Source: APXvYqyeDKC3cIXOyyq/ZlqvcW58Bu9RoVbdrY5pwM9HjZj22ILPPX5HeD5bX8CjInWxQdH/mgmj X-Received: by 2002:a05:6830:1707:: with SMTP id 7mr68848043otk.235.1578003227324; Thu, 02 Jan 2020 14:13:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578003227; cv=none; d=google.com; s=arc-20160816; b=CPyFWJsX3Q/3iEr3SgMQ26Wx/omfmF/1mOUKoPaxtrksijPNMvFRVQvgZWIgE78/aZ kpHRzjBtqWo8KKKlID0yADGUO4a/MzPflD0C7QA8G/WXnTuPmorj0W2rhIV8NouX2Ls2 aD9bL0+JVA6QedvZuNX/1Z/TIkcudy4C8FRjdBw0NZmk2wOoe/Xsfj5fwV21JJG43SSv rmmlVu8VnWSs+66I5qu7PRooS4za6uC4ScTYrq9oMGOjjih2geQkCbUXWmoXYfh7f4qZ KLn9uiA8PeysTKVUB5KalXEiBGmQu4MBiOZjQhScAuBoKsjWpA7hYelgDONrL3Moj32r sY8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=y25fGTifSxPiScHNfXnJbOGGpEnIRGC1d/EO5F8mPg0=; b=W9l+QQUwmoPZheB2LXHf8GsDqR1y9IA2BCzDzFSfaodS4Z8zn8P8aJgu7FtKhlxV/T 7db9AOoSYcGR4wFTy8gfIwXOactmz4COZ7FZfZMiuQBM++JePJ0zFkiI01scDpr0ih+S 9fLhgnrzxbT+yy1NFH9YYxQxZGL9GbJpBNL3VIu5yWsyVB8vwGdRv4B+Z2f4DOGorzZ/ 3M12N273TbohtiH8IvmKAQyD8iddimX5yZsRYti1myVqRiJaFE2+QwrlGqvaFpOa4Xko wiaXVUnfGfnZCy6oiAX0ATw1IX52tLAKR5WLZdiu5ClUvVdEctRKY3Rrcj3Q3byipOxb fKIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VHaqIl2w; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si28303643otz.198.2020.01.02.14.13.35; Thu, 02 Jan 2020 14:13:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VHaqIl2w; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727487AbgABWM3 (ORCPT + 99 others); Thu, 2 Jan 2020 17:12:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:51512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726099AbgABWMY (ORCPT ); Thu, 2 Jan 2020 17:12:24 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4109A21D7D; Thu, 2 Jan 2020 22:12:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003143; bh=YquLg6jkYweR4AX4GUs+bFzHa07A3GIOUgATF3V/FIs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VHaqIl2wu1VA3Q8Vy2iwuUoz18/huzNxL6yuCnuKS0d08IY6y8OkOlYnbD0vdJK7h wTlHC0sbKrCu0Ekjc5EpGXpNwGLHMryEGcDRbn+Ra5a2NW+m9SizraOVu1Ze8QlneY T6JLH1m2Yu8KrqX5Un9C0OsshFN096qkfQrRLXCE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Laura Abbott , Kees Cook , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.4 030/191] dma-mapping: Add vmap checks to dma_map_single() Date: Thu, 2 Jan 2020 23:05:12 +0100 Message-Id: <20200102215833.205799110@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102215829.911231638@linuxfoundation.org> References: <20200102215829.911231638@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook [ Upstream commit 4544b9f25e70eae9f70a243de0cc802aa5c8cb69 ] As we've seen from USB and other areas[1], we need to always do runtime checks for DMA operating on memory regions that might be remapped. This adds vmap checks (similar to those already in USB but missing in other places) into dma_map_single() so all callers benefit from the checking. [1] https://git.kernel.org/linus/3840c5b78803b2b6cc1ff820100a74a092c40cbb Suggested-by: Laura Abbott Signed-off-by: Kees Cook [hch: fixed the printk message] Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- include/linux/dma-mapping.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 4a1c4fca475a..0aad641d662c 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -583,6 +583,10 @@ static inline unsigned long dma_get_merge_boundary(struct device *dev) static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr, size_t size, enum dma_data_direction dir, unsigned long attrs) { + /* DMA must never operate on areas that might be remapped. */ + if (dev_WARN_ONCE(dev, is_vmalloc_addr(ptr), + "rejecting DMA map of vmalloc memory\n")) + return DMA_MAPPING_ERROR; debug_dma_map_single(dev, ptr, size); return dma_map_page_attrs(dev, virt_to_page(ptr), offset_in_page(ptr), size, dir, attrs); -- 2.20.1