Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3515688ybl; Mon, 3 Feb 2020 01:38:45 -0800 (PST) X-Google-Smtp-Source: APXvYqzH8my/3jvU7jq/Zgiya3w7ykN1uprbJQT4rn4Fa5Xj0bhyhb50/Nr0dWvJibHdUgqjiMSA X-Received: by 2002:a9d:7:: with SMTP id 7mr16328584ota.26.1580722724885; Mon, 03 Feb 2020 01:38:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580722724; cv=none; d=google.com; s=arc-20160816; b=Psz3sUA7T8nzhUD9DH9KlbBSn2WmKyW1Vxn3nXp3FdN3ZxKF14UY2HX/OgVTmUyB7Z E2J86EHrUrw/bz6+jl/zc1/o8hKqxgx0rDB24NNb/AGUbNQLUZoe+WH+uwAqUO71g+eS sfu+rQ/kXHDKZEzk4F9KoDCw+1/wYWAe2dtqbhiEsGpmavuC5RlvDzcvE0KCI+C6Wa4f CESROOQl/fi/sBtSTU+9Ms3IWpMeqnGc9Hfvjs1liReRtB7bjULfpQpYd9TYW5M0QW3C pox8K7Lxosm8//0Yf64tuv3uhFXQ9PjWBfhQwWimuA8iZrUkiGpkrEZ/Qxgiz7ePSqOH YK/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=1OnLUtccVxzRGy3H6tEuURVA5Cw1eDsrX9HvO+XJeD4=; b=R8mYnzCygRuXk+9nH0oGpa2Bted/iK93pSjhK9KqTbsTMPKDXgUXjaLdJQKrWad7ou ULIZKBIUtc6ISpDTscZOg5foDtBs1fg4MOT+2qmpAxnCvr+Qfk0BbTq3JzAKhGIq2uda yVGEfZrpQIdigJCKwhIahUd/ysjHVVu+2cw6ViBSG+SoqxiZpbCG+ll8FMEWhi+32lmS 2j8/zu2L9pUiXTiyEBrwS/6pwLdaoJghJC5J7ATgv4h8oYZR6a+M09ei+phlG1+zbvGR SB1bdhmr30PgBQHIBn/kPdrvOqkceNNNVgkk7dJ7A+cNDxPTuK4AY1zQXstWSrmdVUkz 6nVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=tIPQmbMB; 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 h18si8145444otr.265.2020.02.03.01.38.32; Mon, 03 Feb 2020 01:38:44 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=tIPQmbMB; 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 S1727658AbgBCHqw (ORCPT + 99 others); Mon, 3 Feb 2020 02:46:52 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:58872 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727652AbgBCHqw (ORCPT ); Mon, 3 Feb 2020 02:46:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=1OnLUtccVxzRGy3H6tEuURVA5Cw1eDsrX9HvO+XJeD4=; b=tIPQmbMBJJkyM1EUffKpQ6t8+ 6fwTSe6r4ihL5NqNlss4BtnMRFyaJcEPiVZ64i/7LitZrfYs81oZ1L69NyPjMREv3zXAuPxvS0bI2 eMLUSHfCDe+Uhbh/03f2I/93N1FOLazKz82/5pZp0ZjY/ieytY6YhoUGFolkmaBRB9ehsBDiIZHK+ bkuV60ig9MmsNyEVGt8E0ZhQVk6ERJlJE/YSTpSCBFbCtPNtYKIiwbs9X9JfUX2DCkFMoZJyTbNcM L+Sm7T5i2/9zTP8/s+1LrDkKFqoSf7iPfX+6fv7NwwWoLbf8UowsIMPpObCqY5IZs9aWtvn+JjE0x uAmUP6+mA==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1iyWRQ-0001Y1-VE; Mon, 03 Feb 2020 07:46:44 +0000 Date: Sun, 2 Feb 2020 23:46:44 -0800 From: Matthew Wilcox To: Jann Horn Cc: Kees Cook , Christian Borntraeger , Christoph Hellwig , Christopher Lameter , Jiri Slaby , Julian Wiedmann , Ursula Braun , Alexander Viro , kernel list , David Windsor , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Linux-MM , linux-xfs@vger.kernel.org, Linus Torvalds , Andy Lutomirski , "David S. Miller" , Laura Abbott , Mark Rutland , "Martin K. Petersen" , Paolo Bonzini , Dave Kleikamp , Jan Kara , Marc Zyngier , Matthew Garrett , linux-fsdevel , linux-arch , Network Development , Kernel Hardening , Vlastimil Babka , Michal Kubecek Subject: Re: [kernel-hardening] [PATCH 09/38] usercopy: Mark kmalloc caches as usercopy caches Message-ID: <20200203074644.GD8731@bombadil.infradead.org> References: <5861936c-1fe1-4c44-d012-26efa0c8b6e7@de.ibm.com> <202001281457.FA11CC313A@keescook> <6844ea47-8e0e-4fb7-d86f-68046995a749@de.ibm.com> <20200129170939.GA4277@infradead.org> <771c5511-c5ab-3dd1-d938-5dbc40396daa@de.ibm.com> <202001300945.7D465B5F5@keescook> <202002010952.ACDA7A81@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 01, 2020 at 08:27:49PM +0100, Jann Horn wrote: > FWIW, as far as I understand, usercopy doesn't actually have any > effect on drivers that use the modern, proper APIs, since those don't > use the slab allocator at all - as I pointed out in my last mail, the > dma-kmalloc* slabs are used very rarely. (Which is good, because > putting objects from less-than-page-size slabs into iommu entries is a > terrible idea from a security and reliability perspective because it > gives the hardware access to completely unrelated memory.) Instead, > they get pages from the page allocator, and these pages may e.g. be > allocated from the DMA, DMA32 or NORMAL zones depending on the > restrictions imposed by hardware. So I think the usercopy restriction > only affects a few oddball drivers (like this s390 stuff), which is > why you're not seeing more bug reports caused by this. Getting pages from the page allocator is true for dma_alloc_coherent() and friends. But it's not true for streaming DMA mappings (dma_map_*) for which the memory usually comes from kmalloc(). If this is something we want to fix (and I have an awful feeling we're going to regret it if we say "no, we trust the hardware"), we're going to have to come up with a new memory allocation API for these cases. Or bounce bugger the memory for devices we don't trust. The problem with the dma_map_* API is that memory might end up being allocated once and then used multiple times by different drivers. eg if I allocate an NFS packet, it might get sent first to eth0, then (when the route fails) sent to eth1. Similarly in storage, a RAID-5 driver might map the same memory several times to send to different disk controllers.