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=-13.6 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 1828AC433DF for ; Tue, 23 Jun 2020 07:24:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C8CE02072E for ; Tue, 23 Jun 2020 07:24:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rCYLtS8h" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8CE02072E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 607B86B0008; Tue, 23 Jun 2020 03:24:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B7246B000A; Tue, 23 Jun 2020 03:24:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47E5E6B000C; Tue, 23 Jun 2020 03:24:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0104.hostedemail.com [216.40.44.104]) by kanga.kvack.org (Postfix) with ESMTP id 2BE156B0008 for ; Tue, 23 Jun 2020 03:24:49 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DAD06281F for ; Tue, 23 Jun 2020 07:24:48 +0000 (UTC) X-FDA: 76959639456.20.soda19_570447e26e39 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id B3804180C0382 for ; Tue, 23 Jun 2020 07:24:48 +0000 (UTC) X-HE-Tag: soda19_570447e26e39 X-Filterd-Recvd-Size: 6969 Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Tue, 23 Jun 2020 07:24:48 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id y20so2063582wmi.2 for ; Tue, 23 Jun 2020 00:24:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=uWsUrBI2cF3cgBJXHkC6C40URSuY/BmKIvQNeI/0//E=; b=rCYLtS8hQyCsH2j0Nnre5UABFgshesNOKJNJupPwo9InI2+Qx8qIWauZHCL7YboqXi byvX3aaLcr028Mal3vMOxqm4dL2SNSVbntoDXPgGjDZqrNXNu+ri/nqzRTkfagcJy4TX 3J7Y/7ev3YMc8cYu9BAjq0a/nGDI6IYPuBytAyMjsY4AFa31U5VUDtDUxr9uUwjsvifx 6GkrnC+NnReT0xH+GyWOyepSK85gD07y+uHsYDndxmnzWF1f9uZbr2Zsxne8lV0Jlk+M IXGaDc6LW4LJ5w/XOVUl5KT7N0EpO819LWMUgvBVrDZ/+kt2VtLMO6Z3Xug5K5E9j8PZ df9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=uWsUrBI2cF3cgBJXHkC6C40URSuY/BmKIvQNeI/0//E=; b=Cpq5UNhpxtA+v+qJ78yZKuJyanqlGyl3toHTzDC7vxyWs7/PpK/wx1nKbkYrEi4XoO PXe9Kmljzd75oK3qz4OmwYZDHjKPuzc5u+KJTf64f+0Tj67P09E0Go/vN5S96rZaf/SB O0uqcO4PCeXapQ7GTu8C972zj+czYMA4QO9bGX1xBFzvr53TZJcc6rmv0+TAhD9kDgRY KsUZ2+M5+kPIj6rVsRBe9TcHewKCBjE3vYxF4winf/PFRPZJ+DOLH0sD7+oDhiHnLiCs AaSlBE7HQDVPuBuiOjLivtqRWBvzD5D4LCQLNPUU6EkwRkaBq/sNFbmobAxX6kS+PSbg HF3Q== X-Gm-Message-State: AOAM533RNRHPU26+RzV1bOgekB69iVXFVK2Eo064BkPBocHz/T6ryk3b FsjA/bPmMzE2YZBg7x52caB9Gzz7om/r4fspfU2E0A== X-Google-Smtp-Source: ABdhPJxR4pb+rI1B2efKebvT8rzSugwN1dVgq95Z2YFFPYruoBaJd4VwYIyYknfr3vHk3e/lpEqVSetFxyVZlYODO6E= X-Received: by 2002:a1c:4c16:: with SMTP id z22mr22271690wmf.103.1592897086960; Tue, 23 Jun 2020 00:24:46 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Alexander Potapenko Date: Tue, 23 Jun 2020 09:24:35 +0200 Message-ID: Subject: Re: Kernel hardening project suggestion: Normalizing ->ctor slabs and TYPESAFE_BY_RCU slabs To: Marco Elver Cc: Dmitry Vyukov , Jann Horn , Kernel Hardening , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Linux-MM , Andrey Konovalov , Will Deacon , kasan-dev , Kees Cook Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: B3804180C0382 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: KFENCE also has to ignore both TYPESAFE_BY_RCU and ctors. For ctors it should be pretty straightforward to fix (and won't require any changes to SL[AU]B). Not sure if your proposal for RCU will also work for KFENCE. Another beneficiary of RCU/ctor normalization would be init_on_alloc/init_on_free, which also ignore such slabs. On Tue, Jun 23, 2020 at 9:18 AM Marco Elver wrote: > > On Tue, 23 Jun 2020 at 08:45, Dmitry Vyukov wrote: > > > > On Tue, Jun 23, 2020 at 8:26 AM Jann Horn wrote: > > > > > > Hi! > > > > > > Here's a project idea for the kernel-hardening folks: > > > > > > The slab allocator interface has two features that are problematic fo= r > > > security testing and/or hardening: > > > > > > - constructor slabs: These things come with an object constructor > > > that doesn't run when an object is allocated, but instead when the > > > slab allocator grabs a new page from the page allocator. This is > > > problematic for use-after-free detection mechanisms such as HWASAN an= d > > > Memory Tagging, which can only do their job properly if the address o= f > > > an object is allowed to change every time the object is > > > freed/reallocated. (You can't change the address of an object without > > > reinitializing the entire object because e.g. an empty list_head > > > points to itself.) > > > > > > - RCU slabs: These things basically permit use-after-frees by design= , > > > and stuff like ASAN/HWASAN/Memory Tagging essentially doesn't work on > > > them. > > > > > > > > > It would be nice to have a config flag or so that changes the SLUB > > > allocator's behavior such that these slabs can be instrumented > > > properly. Something like: > > > > > > - Let calculate_sizes() reserve space for an rcu_head on each object > > > in TYPESAFE_BY_RCU slabs, make kmem_cache_free() redirect to > > > call_rcu() for these slabs, and remove most of the other > > > special-casing, so that KASAN can instrument these slabs. > > > - For all constructor slabs, let slab_post_alloc_hook() call the > > > ->ctor() function on each allocated object, so that Memory Tagging an= d > > > HWASAN will work on them. > > > > Hi Jann, > > > > Both things sound good to me. I think we considered doing the ctor's > > change with KASAN, but we did not get anywhere. The only argument > > against it I remember now was "performance", but it's not that > > important if this mode is enabled only with KASAN and other debugging > > tools. Performance is definitely not as important as missing bugs. The > > additional code complexity for ctors change should be minimal. > > The rcu change would also be useful, but I would assume it will be larg= er. > > Please add them to [1], that's KASAN laundry list. > > > > +Alex, Marco, will it be useful for KFENCE [2] as well? Do ctors/rcu > > affect KFENCE? Will we need any special handling for KFENCE? > > I assume it will also be useful for KMSAN b/c we can re-mark objects > > as uninitialized only after they have been reallocated. > > Yes, we definitely need to handle TYPESAFE_BY_RCU. > > > [1] https://bugzilla.kernel.org/buglist.cgi?bug_status=3D__open__&compo= nent=3DSanitizers&list_id=3D1063981&product=3DMemory%20Management > > [2] https://github.com/google/kasan/commits/kfence --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg