Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1290692pxx; Fri, 30 Oct 2020 06:50:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaFZg85EhyzpuHW0wdCnUVZU/yfXQHS7yh6LBEJdMMC83dXcL16xrKKRgOC0E6V7irmxM4 X-Received: by 2002:aa7:d1d5:: with SMTP id g21mr2360840edp.388.1604065801981; Fri, 30 Oct 2020 06:50:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604065801; cv=none; d=google.com; s=arc-20160816; b=GGlaGx0TkEO7hS1gJoHwrVgZRx6fRWvPFkTS5eb5QiciQ7rXiYuQ1AbsYkSdC8F4WP A7CLwqQEZ+//hDtnqRsLTZAKRnaQrtRZB2MqDhgQaoyJD8XLEEyQigYUUpsgV6juRTre /GIQM3lizQD2RgrQCLfd3xlNJ1Ye6F4zlDpRp+MVRG1eHF9wW8oR/lj3MiwC3BCwyueg zlOzdd0GOuOn9TANcqaRdBNijnXnZZSxiu40jjxCASds/N0EDodB8SEYYh5WqCqoHpO4 r1E6vtzfQAn9cbRlWsiyd2TJFsBsoch1edNBOtRHWMjaQkKclhaWy0icVbzbgYQZBkSt B7cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=L9KsQ649Ydk+F62S7OnKir8xMXm76fswU9q4GRYaxwA=; b=XMWQqlCivWdIeS168gq8IUou84L9PaLgioGAyyTyDDhtL1gOS6Z5UTP3C+9WZ9431g zWPU3rkrrea7BLZTpKs6iCa9eSnLFlAK9B/0dhUxQHUCXfR7o09JtaSQq0yIY7PXwtAD qlLscPypRqF1kv0wanS0xD+qAX4YifBH4rf7h9zC79rx28U0a7/vYBd6Z2tDiPu8wrX5 ih/uSugAnCzvcg7TPTlZS44kFDwQjVn/Ksc0cSmUHt5A7ZbhaD+NDbEi5S8UV6K3wofW Qe5DDClCjKl+GLUvSW3P1fk/QGNJSaPDR5/25nl7ibluJsfYvZ3GFMABpQIKmztnT3zQ oiJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ADogkMye; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id om24si4254195ejb.610.2020.10.30.06.49.38; Fri, 30 Oct 2020 06:50:01 -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=@google.com header.s=20161025 header.b=ADogkMye; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726491AbgJ3NrB (ORCPT + 99 others); Fri, 30 Oct 2020 09:47:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726307AbgJ3NrA (ORCPT ); Fri, 30 Oct 2020 09:47:00 -0400 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D6B1C0613D4 for ; Fri, 30 Oct 2020 06:46:53 -0700 (PDT) Received: by mail-oi1-x244.google.com with SMTP id x1so6647665oic.13 for ; Fri, 30 Oct 2020 06:46:53 -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; bh=L9KsQ649Ydk+F62S7OnKir8xMXm76fswU9q4GRYaxwA=; b=ADogkMyeqzMi65mLW89eeqxIGlmWBYfTZ3bx3nTmGY2wkQ6ew8sNjqD3uCULVKqUBx onwBT2ZjgdJeC+Ep0EzvoTvRnAW+7Iiyz/5yg7sD3QireG2CCRHS4HyyFb0a9sVm4Gkx oK82pyK24ABm86duxNdYoH4hRNUNuqmxLkaaFdx57gQBJ1bVnIgROlYmlYkkJWUifom+ jVyfyKxvVyc1QRuPHf7ZI42FxPpsi/MDAFg5vR+O2aNlLtDCXRhTiwTAI53bIKW7tEOt sxaK6rXBYliu3y15wi8dcdrb3eape6+JDJFEJWvX3eZs2nbse3syqEqt/L1LVuSMUunF HVTQ== 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; bh=L9KsQ649Ydk+F62S7OnKir8xMXm76fswU9q4GRYaxwA=; b=jP6XzFtRBwTOpjnugWfDJDCCL0uxtAUzCTmjhBgaKFLcv7PQ0192jvSoigy6KFLqLp C+UYrjidQYsb3wHfYYCFfjSBp0+z8nOMuwmn/31mcE6MG2drKMdlLoVw3W/mf4a/CmAd B6zJ+Xc3jSTFUK9iTyDT4DXwjjt0K1BsZ7wcDG2sGW8v9y/1hr92T6Gg54jveZUUWDG2 gYqRhZKCWRPrcjTFcwCTCzLYngGoVlJsYYIwgy5yTi0ECrws8RBgSDm/AqaqRw8oBb2l Wkip2Hee9mC4YdIsFi4ORNN8oOw5wpWA4cAi/5yP7GChBwVlvHBDquGdI4Jd7Ai2DTjQ c3dw== X-Gm-Message-State: AOAM531VkhuqEplxmaEA/GS7PynXc+ZxjjsFICDqthOxUAkXRNz+/f2d x0n2EWk4aa3n3npJWZNxyDeSxGCLKUjdNBhmvaZP0g== X-Received: by 2002:a54:4812:: with SMTP id j18mr1740133oij.70.1604065612340; Fri, 30 Oct 2020 06:46:52 -0700 (PDT) MIME-Version: 1.0 References: <20201029131649.182037-1-elver@google.com> <20201029131649.182037-7-elver@google.com> In-Reply-To: From: Marco Elver Date: Fri, 30 Oct 2020 14:46:40 +0100 Message-ID: Subject: Re: [PATCH v6 6/9] kfence, kasan: make KFENCE compatible with KASAN To: Jann Horn Cc: Andrew Morton , Alexander Potapenko , "H . Peter Anvin" , "Paul E . McKenney" , Andrey Konovalov , Andrey Ryabinin , Andy Lutomirski , Borislav Petkov , Catalin Marinas , Christoph Lameter , Dave Hansen , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Hillf Danton , Ingo Molnar , Jonathan Cameron , Jonathan Corbet , Joonsoo Kim , =?UTF-8?Q?J=C3=B6rn_Engel?= , Kees Cook , Mark Rutland , Pekka Enberg , Peter Zijlstra , SeongJae Park , Thomas Gleixner , Vlastimil Babka , Will Deacon , "the arch/x86 maintainers" , "open list:DOCUMENTATION" , kernel list , kasan-dev , Linux ARM , Linux-MM Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 30 Oct 2020 at 03:50, Jann Horn wrote: > > On Thu, Oct 29, 2020 at 2:17 PM Marco Elver wrote: > > We make KFENCE compatible with KASAN for testing KFENCE itself. In > > particular, KASAN helps to catch any potential corruptions to KFENCE > > state, or other corruptions that may be a result of freepointer > > corruptions in the main allocators. > > > > To indicate that the combination of the two is generally discouraged, > > CONFIG_EXPERT=y should be set. It also gives us the nice property that > > KFENCE will be build-tested by allyesconfig builds. > > > > Reviewed-by: Dmitry Vyukov > > Co-developed-by: Marco Elver > > Signed-off-by: Marco Elver > > Signed-off-by: Alexander Potapenko > > Reviewed-by: Jann Horn Thanks! > with one nit: > > [...] > > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > [...] > > @@ -141,6 +142,14 @@ void kasan_unpoison_shadow(const void *address, size_t size) > > */ > > address = reset_tag(address); > > > > + /* > > + * We may be called from SL*B internals, such as ksize(): with a size > > + * not a multiple of machine-word size, avoid poisoning the invalid > > + * portion of the word for KFENCE memory. > > + */ > > + if (is_kfence_address(address)) > > + return; > > It might be helpful if you could add a comment that explains that > kasan_poison_object_data() does not need a similar guard because > kasan_poison_object_data() is always paired with > kasan_unpoison_object_data() - that threw me off a bit at first. Well, KFENCE objects should never be poisoned/unpoisoned because the kasan_alloc and free hooks have a kfence guard, and none of the code in sl*b.c that does kasan_{poison,unpoison}_object_data() should be executed for KFENCE objects. But I just noticed that kernel/scs.c seems to kasan_poison and unpoison objects, and keeps them poisoned for most of the object lifetime. I think we better add a kfence guard to kasan_poison_shadow() as well. Thanks, -- Marco