Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3859435ybz; Mon, 20 Apr 2020 10:45:12 -0700 (PDT) X-Google-Smtp-Source: APiQypJ3ZJCCOuu45TSK1iBPQvYXpnUJ5U0c/LTXmFqfiYsoMf2EiY53oubR8Ukxnxc3jMwFRtCE X-Received: by 2002:a17:906:1804:: with SMTP id v4mr17788588eje.104.1587404711925; Mon, 20 Apr 2020 10:45:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587404711; cv=none; d=google.com; s=arc-20160816; b=RkghpgxJVhXngami0kWxhijOS68nVD29mfgkw375Y5gVuag6OJOFoGn5Od459EqRNK qZT88Sf32jFBcEPYzvuBCjIeojTY2J70KlxBUmYbEetjGS7KlsBmC/gQYL2omOLubAJx 25hlu4soB7XQwU8nfQI7jCVjeX9H5ASY/eUCNhpFs0X0730ZR9zShTa7ZNhUX3BcbBB2 Y9X9MdiQATnmZA7exSlc1J4FRorOweByJRlMbKXeZV9DD7I+Lzzv4z4irJY3sMqcq64s H1hlub98ar0rJAY6cgT2D8k9QzKH0LBaQ2YR9hw8pxm2TCLWpmoW41XthfZDTXkw2vMn Lw2Q== 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=UbWvOzsjdwKmCuURzqakr712Hwz970Vkw5PGIrntIJg=; b=g35516Wt+h6NrNqgJjgDgXu8xeJJUrGLvA5ykpcqU5gqVjkmWn84of59xyRz3SI+9+ TnSaKn5p42qTbIN7cXqYw/sKkOLrqHh9ZCf/TzrxgNt4eqsTzd1YCDkiJyvC8v36EUsH p/tF32mwMqMTLHNBIBNzNYYKC7an4tgLuMPhVV8T1/q4lb3nHJ+XZuyFOiSMG2w5blrR NDAbUWTIdrWJmZrvcMB0mloeK7VCBv/mJ4/Jgp7d4AUprwOOcSsYgZo3t/I3e5pxsaQo NS3sl4nzy0Acb/gVbJxw/vgz073JK8kaJxZKxDKCuTG72VyshTsX570Y1hqEJsv1No6O IhkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jQBTeSx5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw21si946848ejb.158.2020.04.20.10.44.42; Mon, 20 Apr 2020 10:45:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jQBTeSx5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726013AbgDTRnl (ORCPT + 99 others); Mon, 20 Apr 2020 13:43:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726752AbgDTRnk (ORCPT ); Mon, 20 Apr 2020 13:43:40 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 712F5C061A41 for ; Mon, 20 Apr 2020 10:43:40 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id my1so214980pjb.1 for ; Mon, 20 Apr 2020 10:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=UbWvOzsjdwKmCuURzqakr712Hwz970Vkw5PGIrntIJg=; b=jQBTeSx5RVM7KT1U22GJEb3DH2uZPfcy8Q8n8Z4yMQbR4xX77sT7UNorH68BHXQklv iqyP+lyhtbiw1Z8E6mrIAOVUfrKDbExPTw1eCNreicq7+fmKaKDC0t3L5Z68emnhhiQY F68qqIHfXsfIWhK8AMTQ6lJSl/wFSmFVqe+Fs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=UbWvOzsjdwKmCuURzqakr712Hwz970Vkw5PGIrntIJg=; b=ijRfv/DGeUW0uBuMhM7vGZuud0FQVBUofQhWQSYpHOppsOmSBVGeXgV+LRjYuDZ4f3 x8u/PS9u3KN3v33fkQ0BppsZobfP+aY/JnWUdPSodc8VZxWx/oL1Vd5ICy7q/rwz99vR xP8ANDAqMOdHxWc26kO36yvDUt5CdB2QOy/gM9kvfU0mAMa8O5N8iO725ijOhLF+Y0/R UEPpv2EFq4U3oFRioU38OFZn/YsoDyHqgafFKi5ih2RnpZN0asLGVOi3sK/DMKSWObdT vJ7nginNvK7oFRG/5HNhunbbEJ0q7c3osnNqg9wFSRwFRkNhlR9RV83yILaciLHjj9lq ywLQ== X-Gm-Message-State: AGi0PubkxoI1MpBAvoPLbMV/xskdA7ZytdnEFTm3Fhe2u8ZWBEpjRy9l 6rFbc4w4GJv4rs6dAjHLDdVK4w== X-Received: by 2002:a17:902:6b01:: with SMTP id o1mr18181334plk.100.1587404619781; Mon, 20 Apr 2020 10:43:39 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id v26sm106522pff.45.2020.04.20.10.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2020 10:43:38 -0700 (PDT) Date: Mon, 20 Apr 2020 10:43:37 -0700 From: Kees Cook To: Jiri Slaby Cc: Vlastimil Babka , Jann Horn , Christian Borntraeger , Christoph Hellwig , Christopher Lameter , 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 , Christoffer Dall , Dave Kleikamp , Jan Kara , Luis de Bethencourt , Marc Zyngier , Rik van Riel , Matthew Garrett , linux-fsdevel , linux-arch , Network Development , Kernel Hardening , Michal Kubecek Subject: Re: [kernel-hardening] [PATCH 09/38] usercopy: Mark kmalloc caches as usercopy caches Message-ID: <202004201043.538A7B3F2@keescook> 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> <7d810f6d-8085-ea2f-7805-47ba3842dc50@suse.cz> <548e6212-7b3c-5925-19f2-699af451fd16@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <548e6212-7b3c-5925-19f2-699af451fd16@suse.cz> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 20, 2020 at 09:53:20AM +0200, Jiri Slaby wrote: > On 07. 04. 20, 10:00, Vlastimil Babka wrote: > > From d5190e4e871689a530da3c3fd327be45a88f006a Mon Sep 17 00:00:00 2001 > > From: Vlastimil Babka > > Date: Tue, 7 Apr 2020 09:58:00 +0200 > > Subject: [PATCH] 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/ > > > > Signed-off-by: Vlastimil Babka > > Friendly ping. > > Acked-by: Jiri Slaby Should this go via -mm? -Kees > > > --- > > mm/slab_common.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/mm/slab_common.c b/mm/slab_common.c > > index 5282f881d2f5..ae9486160594 100644 > > --- a/mm/slab_common.c > > +++ b/mm/slab_common.c > > @@ -1303,7 +1303,8 @@ void __init create_kmalloc_caches(slab_flags_t flags) > > 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 > > > > thanks, > -- > js > suse labs -- Kees Cook