Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp192764ybc; Mon, 11 Nov 2019 23:19:18 -0800 (PST) X-Google-Smtp-Source: APXvYqxtmL2h73P3dNKEK1HzNo3B8LcjmybKiFnkPXjNYMk1JaK4+m1/KeXKQ53JXXaVAXCQhogr X-Received: by 2002:a50:f058:: with SMTP id u24mr31615638edl.288.1573543158269; Mon, 11 Nov 2019 23:19:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573543158; cv=none; d=google.com; s=arc-20160816; b=EteSso6iAqPs53L5K8xt+zCLO/cmkHuABAg8Xf5segsI5KRhlA+v7kntLcheM60yga jJKXf/9zH8FxeXVxt6r/VpXyqEsq8ImBrUCTc3X+C8uh1py7Jis1NuQpFFgTKRAMAUAW fH21B+tBm57Ykvlr4tca3NfVZkRiQCoCrIE+UAqWMxnXF6wPrx0pZp6OYHN4AAVKaBrN lNT6ZaTxelF4SAjGILnAKIN2iizNlgj+xdgZo/GwLu6RxgX0fxAdt5vvYf7sOnf7RTxV ELr1fp4vnA1yqBosS/6ltY6+wmh8vHyhacr6Z4H1TZjhX4wfG7M4t/8Jl183frEptHZg 14dg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:from:references:cc:to:subject; bh=am10xx8IfJqOSuDyYTDQaz4P8Dm7qQG6az4OEVbOtdA=; b=fKrOJEEyVuUa2ehSXM7BjxkSEWMjdCno8Vi7ONLy3Da2HVvuGueuT27hgU9/eQyIqw j92590HM8T6rqQfUfMYlZUdnbZAVOwVF/W050PTC0Ntj9ET5xFTYNzHE5IV3uoycpnGX sKA7pz86fPFWJzQXKPI8xjGB6X4KJDVpjKuozyKeAQ8tCXNyWq71OuiFWsXr2jsFUGK/ HPCLP85Q/xfMXcJZ/OxVS/kRMrh9U0jfGfEtQ+tHmv3gXHgUpB8x8gq1nsk8sn/CnUFs C6rBylZ20QlBgKxfddRQo6a80jAWsalnsyiWETwyBeu6oVUCWxC5smjsNT5V/vzvJVnZ Zy2A== ARC-Authentication-Results: i=1; mx.google.com; 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 cb6si10624959ejb.359.2019.11.11.23.18.54; Mon, 11 Nov 2019 23:19:18 -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; 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 S1727041AbfKLHSG (ORCPT + 99 others); Tue, 12 Nov 2019 02:18:06 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:33885 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725283AbfKLHSG (ORCPT ); Tue, 12 Nov 2019 02:18:06 -0500 Received: by mail-wm1-f68.google.com with SMTP id j18so1581515wmk.1; Mon, 11 Nov 2019 23:18:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=am10xx8IfJqOSuDyYTDQaz4P8Dm7qQG6az4OEVbOtdA=; b=gwiD25hiiuPlpvpN0IXaAAaddlDtA8oy9GHpWprcSsiemO45qrdjPsuYlwp7KpZZsG a4vQjJjfDHfgXPmoq6YeJB9qf5wsXif/zROUNbmOntRMKreJjjz54YMQpBKlR9xwt5C+ hSScrc8zRQSONiqCjSb+uRH3TfPbR38Is8geNC1lq/LVqgsfVIEtkVQD9ONXH78CqCbI WBreGkAjwML4OAtcvmZsCAiYCPoS5YI2/yO16BtnD97DoaAK8Dto6SbGaraFqa0D/Bpj 8AlQkCdnXRm6SalwRPmDg/W8JvBmOb7NtNvKoFvUBlsYe63Aq7jd/Xj6QOB9SDF9abyw 6DKQ== X-Gm-Message-State: APjAAAXnBAr05UsCewhv9QKz11dO0tnbnJqsbDHyyBD8pOWEkJJskOdd GBqkVxDPDFzQP3CXscc7mYY= X-Received: by 2002:a05:600c:210b:: with SMTP id u11mr2576008wml.170.1573543080951; Mon, 11 Nov 2019 23:18:00 -0800 (PST) Received: from ?IPv6:2a0b:e7c0:0:107::49? ([2a0b:e7c0:0:107::49]) by smtp.gmail.com with ESMTPSA id l10sm32454860wrg.90.2019.11.11.23.17.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 Nov 2019 23:18:00 -0800 (PST) Subject: Re: [kernel-hardening] [PATCH 09/38] usercopy: Mark kmalloc caches as usercopy caches To: Kees Cook , linux-kernel@vger.kernel.org Cc: David Windsor , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , linux-mm@kvack.org, linux-xfs@vger.kernel.org, Linus Torvalds , Alexander Viro , Andy Lutomirski , Christoph Hellwig , Christoph Lameter , "David S. Miller" , Laura Abbott , Mark Rutland , "Martin K. Petersen" , Paolo Bonzini , Christian Borntraeger , Christoffer Dall , Dave Kleikamp , Jan Kara , Luis de Bethencourt , Marc Zyngier , Rik van Riel , Matthew Garrett , linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org, kernel-hardening@lists.openwall.com, Vlastimil Babka , Michal Kubecek References: <1515636190-24061-1-git-send-email-keescook@chromium.org> <1515636190-24061-10-git-send-email-keescook@chromium.org> From: Jiri Slaby Autocrypt: addr=jslaby@suse.cz; prefer-encrypt=mutual; keydata= mQINBE6S54YBEACzz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x9 B42WbV4xrtiiydfBtO6tH6c9mT5Ng+d1sN/VTSPyfQARAQABiQIfBBgBAgAJBQJOkueGAhsM AAoJEL0lsQQGtHBJN7UQAIDvgxaW8iGuEZZ36XFtewH56WYvVUefs6+Pep9ox/9ZXcETv0vk DUgPKnQAajG/ViOATWqADYHINAEuNvTKtLWmlipAI5JBgE+5g9UOT4i69OmP/is3a/dHlFZ3 qjNk1EEGyvioeycJhla0RjakKw5PoETbypxsBTXk5EyrSdD/I2Hez9YGW/RcI/WC8Y4Z/7FS ITZhASwaCOzy/vX2yC6iTx4AMFt+a6Z6uH/xGE8pG5NbGtd02r+m7SfuEDoG3Hs1iMGecPyV XxCVvSV6dwRQFc0UOZ1a6ywwCWfGOYqFnJvfSbUiCMV8bfRSWhnNQYLIuSv/nckyi8CzCYIg c21cfBvnwiSfWLZTTj1oWyj5a0PPgGOdgGoIvVjYXul3yXYeYOqbYjiC5t99JpEeIFupxIGV ciMk6t3pDrq7n7Vi/faqT+c4vnjazJi0UMfYnnAzYBa9+NkfW0w5W9Uy7kW/v7SffH/2yFiK 9HKkJqkN9xYEYaxtfl5pelF8idoxMZpTvCZY7jhnl2IemZCBMs6s338wS12Qro5WEAxV6cjD VSdmcD5l9plhKGLmgVNCTe8DPv81oDn9s0cIRLg9wNnDtj8aIiH8lBHwfUkpn32iv0uMV6Ae sLxhDWfOR4N+wu1gzXWgLel4drkCJcuYK5IL1qaZDcuGR8RPo3jbFO7Y Message-ID: <9519edb7-456a-a2fa-659e-3e5a1ff89466@suse.cz> Date: Tue, 12 Nov 2019 08:17:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 In-Reply-To: <1515636190-24061-10-git-send-email-keescook@chromium.org> Content-Type: text/plain; charset=iso-8859-2 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11. 01. 18, 3:02, Kees Cook wrote: > From: David Windsor > > Mark the kmalloc slab caches as entirely whitelisted. These caches > are frequently used to fulfill kernel allocations that contain data > to be copied to/from userspace. Internal-only uses are also common, > but are scattered in the kernel. For now, mark all the kmalloc caches > as whitelisted. > > This patch is modified from Brad Spengler/PaX Team's PAX_USERCOPY > whitelisting code in the last public patch of grsecurity/PaX based on my > understanding of the code. Changes or omissions from the original code are > mine and don't reflect the original grsecurity/PaX code. > > Signed-off-by: David Windsor > [kees: merged in moved kmalloc hunks, adjust commit log] > Cc: Pekka Enberg > Cc: David Rientjes > Cc: Joonsoo Kim > Cc: Andrew Morton > Cc: linux-mm@kvack.org > Cc: linux-xfs@vger.kernel.org > Signed-off-by: Kees Cook > Acked-by: Christoph Lameter > --- > mm/slab.c | 3 ++- > mm/slab.h | 3 ++- > mm/slab_common.c | 10 ++++++---- > 3 files changed, 10 insertions(+), 6 deletions(-) > > diff --git a/mm/slab.c b/mm/slab.c > index b9b0df620bb9..dd367fe17a4e 100644 > --- a/mm/slab.c > +++ b/mm/slab.c ... > @@ -1098,7 +1099,8 @@ void __init setup_kmalloc_cache_index_table(void) > static void __init new_kmalloc_cache(int idx, slab_flags_t flags) > { > kmalloc_caches[idx] = create_kmalloc_cache(kmalloc_info[idx].name, > - kmalloc_info[idx].size, flags); > + kmalloc_info[idx].size, flags, 0, > + kmalloc_info[idx].size); > } > > /* > @@ -1139,7 +1141,7 @@ void __init create_kmalloc_caches(slab_flags_t flags) > > BUG_ON(!n); > kmalloc_dma_caches[i] = create_kmalloc_cache(n, > - size, SLAB_CACHE_DMA | flags); > + size, SLAB_CACHE_DMA | flags, 0, 0); Hi, was there any (undocumented) reason NOT to mark DMA caches as usercopy? We are seeing this on s390x: > usercopy: Kernel memory overwrite attempt detected to SLUB object 'dma-kmalloc-1k' (offset 0, size 11)! > ------------[ cut here ]------------ > kernel BUG at mm/usercopy.c:99! See: https://bugzilla.suse.com/show_bug.cgi?id=1156053 This indeed fixes it: --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1290,7 +1290,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