From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71931C17441 for ; Tue, 12 Nov 2019 21:21:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2169021925 for ; Tue, 12 Nov 2019 21:21:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ZfNUt0qS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2169021925 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BE6426B0003; Tue, 12 Nov 2019 16:21:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B97556B0005; Tue, 12 Nov 2019 16:21:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A86366B0006; Tue, 12 Nov 2019 16:21:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0018.hostedemail.com [216.40.44.18]) by kanga.kvack.org (Postfix) with ESMTP id 8F3496B0003 for ; Tue, 12 Nov 2019 16:21:58 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 3ABFC181AEF0B for ; Tue, 12 Nov 2019 21:21:58 +0000 (UTC) X-FDA: 76148897916.12.men05_686c4432d2856 X-HE-Tag: men05_686c4432d2856 X-Filterd-Recvd-Size: 8327 Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Nov 2019 21:21:57 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id w11so12656005pga.12 for ; Tue, 12 Nov 2019 13:21:57 -0800 (PST) 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:content-transfer-encoding:in-reply-to; bh=56RmInZgI7Bh5RV3HY6BrZUpnFAVvdE9v++wifdVVbQ=; b=ZfNUt0qSlG/eNpBtAZ0VTYWsyYp45EI1kg059Eym4v5QX0Rd4eJhUdGDHMn6QKbyy7 rAEVCINxRbPGFWvH2zmErPehM9LKyDLyBoDAInAHNKT4/quKkG/EtZO/FhCOkM/nDfkP OwUp5RB5f4lGpDiCQlYFyWhQBMqbf0YFKIWuU= 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:content-transfer-encoding :in-reply-to; bh=56RmInZgI7Bh5RV3HY6BrZUpnFAVvdE9v++wifdVVbQ=; b=cacSAg/EIvXNLZuayHSz2OFR0LS/BywP5VmTIKbRuVaNzlosUtKCCnqtcol5nJNrKn nkGQBIqlgd+16LAce+jDbP6NPZdYj6xKfIhPNEWD7krMWYqpQ8KYzjjgpmr1z1Umt/L8 wXg7A+qNyrqdHph2nvjrvIhQDRRurpZ0ZuHCNgy+HpkJdM7iMLTEp4TW4eNlCVLucvlK Cerha2fAonfIdpuJqUYCpM5vRPpUe3whpNkYEyqEeEOMkz1d9tq4L9d9As8FcmjdzMr5 o9/4JVPupnx3J99+tcGsDiObDdqVKevVzx9/3p4t0m/wR4YuW/01qXJoTsGWXdzETK81 T7rQ== X-Gm-Message-State: APjAAAWby1IQQbxi5AskUynhYPkNoLPy09AK8oMIuxRmVbLIBQ5RF3bn 82XgabiZWDO33IBArl6/L/9EWQ== X-Google-Smtp-Source: APXvYqzdFzu4zPPFnJ9ABSyKsWziEZi4Dk2O2pVHeNcsXTcPeB3CKkazqUJ/8FJ/XZkexPEBBAMb2g== X-Received: by 2002:aa7:8d8b:: with SMTP id i11mr11186741pfr.45.1573593716214; Tue, 12 Nov 2019 13:21:56 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id c21sm19635349pgh.25.2019.11.12.13.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2019 13:21:55 -0800 (PST) Date: Tue, 12 Nov 2019 13:21:54 -0800 From: Kees Cook To: Jiri Slaby , Alexander Viro Cc: linux-kernel@vger.kernel.org, David Windsor , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , linux-mm@kvack.org, linux-xfs@vger.kernel.org, Linus Torvalds , 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 Subject: Re: [kernel-hardening] [PATCH 09/38] usercopy: Mark kmalloc caches as usercopy caches Message-ID: <201911121313.1097D6EE@keescook> References: <1515636190-24061-1-git-send-email-keescook@chromium.org> <1515636190-24061-10-git-send-email-keescook@chromium.org> <9519edb7-456a-a2fa-659e-3e5a1ff89466@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <9519edb7-456a-a2fa-659e-3e5a1ff89466@suse.cz> Content-Transfer-Encoding: quoted-printable 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: On Tue, Nov 12, 2019 at 08:17:57AM +0100, Jiri Slaby wrote: > On 11. 01. 18, 3:02, Kees Cook wrote: > > From: David Windsor > >=20 > > 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. > >=20 > > 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 cod= e are > > mine and don't reflect the original grsecurity/PaX code. > >=20 > > 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(-) > >=20 > > 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(voi= d) > > static void __init new_kmalloc_cache(int idx, slab_flags_t flags) > > { > > kmalloc_caches[idx] =3D create_kmalloc_cache(kmalloc_info[idx].name= , > > - kmalloc_info[idx].size, flags); > > + kmalloc_info[idx].size, flags, 0, > > + kmalloc_info[idx].size); > > } > > =20 > > /* > > @@ -1139,7 +1141,7 @@ void __init create_kmalloc_caches(slab_flags_t = flags) > > =20 > > BUG_ON(!n); > > kmalloc_dma_caches[i] =3D create_kmalloc_cache(n, > > - size, SLAB_CACHE_DMA | flags); > > + size, SLAB_CACHE_DMA | flags, 0, 0); >=20 > Hi, >=20 > was there any (undocumented) reason NOT to mark DMA caches as usercopy? >=20 > We are seeing this on s390x: >=20 > > 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! Interesting! I believe the rationale was that if the region is used for DMA, allowing direct access to it from userspace could be prone to races. > See: > https://bugzilla.suse.com/show_bug.cgi?id=3D1156053 For context from the bug, the trace is: (<0000000000386c5a> usercopy_abort+0xa2/0xa8)=20 <000000000036097a> __check_heap_object+0x11a/0x120 =20 <0000000000386b3a> __check_object_size+0x18a/0x208 =20 <000000000079b4ba> skb_copy_datagram_from_iter+0x62/0x240 =20 <000003ff804edd5c> iucv_sock_sendmsg+0x1fc/0x858 =DDaf_iucv=A8 =20 <0000000000785894> sock_sendmsg+0x54/0x90 =20 <0000000000785944> sock_write_iter+0x74/0xa0 =20 <000000000038a3f0> new_sync_write+0x110/0x180 =20 <000000000038d42e> vfs_write+0xa6/0x1d0 =20 <000000000038d748> ksys_write+0x60/0xe8 =20 <000000000096a660> system_call+0xdc/0x2e0 =20 I know Al worked on fixing up usercopy checking for iters. I wonder if there is redundant checking happening here? i.e. haven't iters already done object size verifications, so they're not needed during iter copy helpers? > 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 fl= ags) > kmalloc_caches[KMALLOC_DMA][i] =3D > 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 How is iucv the only network protocol that has run into this? Do others use a bounce buffer? --=20 Kees Cook