From patchwork Tue Jun 2 20:10:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11584293 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A7E860D for ; Tue, 2 Jun 2020 20:10:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EB814206E2 for ; Tue, 2 Jun 2020 20:10:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="m7DNcrzN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB814206E2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AC1D28000E; Tue, 2 Jun 2020 16:10:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A714F8000D; Tue, 2 Jun 2020 16:10:19 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9882A8000E; Tue, 2 Jun 2020 16:10:19 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0065.hostedemail.com [216.40.44.65]) by kanga.kvack.org (Postfix) with ESMTP id 80ABB8000D for ; Tue, 2 Jun 2020 16:10:19 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3712A180AD802 for ; Tue, 2 Jun 2020 20:10:19 +0000 (UTC) X-FDA: 76885363758.16.step00_5a03748be2e35 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id EE873100B430A for ; Tue, 2 Jun 2020 20:10:18 +0000 (UTC) X-Spam-Summary: 2,0,0,abd4b8ee88609af9,d41d8cd98f00b204,akpm@linux-foundation.org,,RULES_HIT:41:355:379:800:960:967:973:988:989:1260:1263:1345:1359:1381:1431:1437:1535:1543:1711:1730:1747:1777:1792:2198:2199:2393:2525:2553:2559:2566:2682:2685:2859:2902:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:5007:6261:6653:6737:6738:7576:7875:8603:8957:9025:9545:10004:11026:11232:11257:11473:11658:11914:12043:12048:12297:12438:12517:12519:12555:12679:12698:12737:12783:13161:13223:13229:13846:14181:14721:14849:21080:21347:21451:21627:21749:21939:30003:30029:30054:30064:30090,0,RBL:198.145.29.99:@linux-foundation.org:.lbl8.mailshell.net-64.100.201.201 62.2.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: step00_5a03748be2e35 X-Filterd-Recvd-Size: 5222 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Tue, 2 Jun 2020 20:10:18 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (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 7C1962072F; Tue, 2 Jun 2020 20:10:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591128617; bh=9NQbJriEaKXaj4U9Mx0S/g215yIDp/ctZOuN/UuQ4MQ=; h=Date:From:To:Subject:In-Reply-To:From; b=m7DNcrzNJW/JgQ0HBaEHlVWinB0O79RGyiGiW6Vx4TElcsHLGM8qcC2de5BOtncLb fALWSi5uyRlx5hDRUNBaIAU51RCZdYn9KJj6oR9W5pcVEbS8URgZoZnog5kA62lqTQ 7DxE2DH69sp1Smtf1rnMQJXy+QtcCFMAx81rnCII= Date: Tue, 02 Jun 2020 13:10:16 -0700 From: Andrew Morton To: akpm@linux-foundation.org, borntraeger@de.ibm.com, christoffer.dall@linaro.org, cl@linux.com, dave.kleikamp@oracle.com, dave@nullcore.net, davem@davemloft.net, hch@infradead.org, iamjoonsoo.kim@lge.com, jack@suse.cz, jannh@google.com, jslaby@suse.cz, jwi@linux.ibm.com, labbott@redhat.com, linux-mm@kvack.org, luisbg@kernel.org, luto@kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, martin.petersen@oracle.com, mjg59@google.com, mkubecek@suse.cz, mm-commits@vger.kernel.org, pbonzini@redhat.com, penberg@kernel.org, riel@surriel.com, rientjes@google.com, torvalds@linux-foundation.org, ubraun@linux.ibm.com, vbabka@suse.cz, viro@zeniv.linux.org.uk Subject: [patch 007/128] usercopy: mark dma-kmalloc caches as usercopy caches Message-ID: <20200602201016.vTZmVgDb9%akpm@linux-foundation.org> In-Reply-To: <20200602130930.8e8f10fa6f19e3766e70921f@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: EE873100B430A X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Vlastimil Babka Subject: usercopy: mark dma-kmalloc caches as usercopy caches We have seen a "usercopy: Kernel memory overwrite attempt detected to SLUB object 'dma-kmalloc-1 k' (offset 0, size 11)!" error on s390x, as IUCV uses kmalloc() with __GFP_DMA because of memory address restrictions. The issue has been discussed [2] and it has been noted that if all the kmalloc caches are marked as usercopy, there's little reason not to mark dma-kmalloc caches too. The 'dma' part merely means that __GFP_DMA is used to restrict memory address range. As Jann Horn put it [3]: "I think dma-kmalloc slabs should be handled the same way as normal kmalloc slabs. When a dma-kmalloc allocation is freshly created, it is just normal kernel memory - even if it might later be used for DMA -, and it should be perfectly fine to copy_from_user() into such allocations at that point, and to copy_to_user() out of them at the end. If you look at the places where such allocations are created, you can see things like kmemdup(), memcpy() and so on - all normal operations that shouldn't conceptually be different from usercopy in any relevant way." Thus this patch marks the dma-kmalloc-* caches as usercopy. [1] https://bugzilla.suse.com/show_bug.cgi?id=1156053 [2] https://lore.kernel.org/kernel-hardening/bfca96db-bbd0-d958-7732-76e36c667c68@suse.cz/ [3] https://lore.kernel.org/kernel-hardening/CAG48ez1a4waGk9kB0WLaSbs4muSoK0AYAVk8=XYaKj4_+6e6Hg@mail.gmail.com/ Link: http://lkml.kernel.org/r/7d810f6d-8085-ea2f-7805-47ba3842dc50@suse.cz Signed-off-by: Vlastimil Babka Acked-by: Christian Borntraeger Acked-by: Jiri Slaby Cc: Jann Horn Cc: Christoph Hellwig Cc: Christopher Lameter Cc: Julian Wiedmann Cc: Ursula Braun Cc: Alexander Viro Cc: David Windsor Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Cc: Linus Torvalds Cc: Andy Lutomirski Cc: "David S. Miller" Cc: Laura Abbott Cc: Mark Rutland Cc: "Martin K. Petersen" Cc: Paolo Bonzini Cc: Christoffer Dall Cc: Dave Kleikamp Cc: Jan Kara Cc: Luis de Bethencourt Cc: Marc Zyngier Cc: Rik van Riel Cc: Matthew Garrett Cc: Michal Kubecek Signed-off-by: Andrew Morton --- mm/slab_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/mm/slab_common.c~usercopy-mark-dma-kmalloc-caches-as-usercopy-caches +++ a/mm/slab_common.c @@ -1303,7 +1303,8 @@ void __init create_kmalloc_caches(slab_f kmalloc_caches[KMALLOC_DMA][i] = create_kmalloc_cache( kmalloc_info[i].name[KMALLOC_DMA], kmalloc_info[i].size, - SLAB_CACHE_DMA | flags, 0, 0); + SLAB_CACHE_DMA | flags, 0, + kmalloc_info[i].size); } } #endif