Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2046140rwb; Sat, 24 Sep 2022 01:53:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6EhFwGLAlN3qV0ugBpsgQK5SqxQxg65zWpx3LLvoZ3bJVTS9LslaTQGuESOddSjd131Fds X-Received: by 2002:a17:906:d550:b0:780:cec2:aae1 with SMTP id cr16-20020a170906d55000b00780cec2aae1mr10517652ejc.477.1664009630525; Sat, 24 Sep 2022 01:53:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664009630; cv=none; d=google.com; s=arc-20160816; b=FIF/s0DUy1o3elW5z6IXQx4hCsp4sPykwAMGmMJoLPowimzb66cInOpxFoyCQkC1U8 y2/HYKhT3EwQWpTRKl/V9oJEBUwnHSethVrQkiU5telE3VyjvFRS/HUp9fmSOiIm7fO6 nGUSwd8l2wsop8HvVFq131QvLRfWnxp3BeVi7gcrMnWTiFdOBupTYExAulqsUGF76JGs rO+hfMgwD7bOjNStDEsE+q6KDBb/SAD19658UkA61pJCOsBETDZbt5FDrzrk45wMf/OD KziDMr0wwrtHE2yOdrBzd6rcBXKJ7fEbYgFLwsBYQFSHj9bm9VYFyCnMaKeNgBEcmeQd 0jEw== 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=nQomz4ut+7sjfQrrU1jIFAnyWatFfjECi53D3yczEIE=; b=QxtQTq6bCgJNCvHpeHDyR66w05L4MZcUsBMNhBnzZIeFVbZGCWO+tVTAmi5DamFw/Y YCpOHMe5QJHDBiHCLj0THP/i7cn3jxHLMNkcr51oC2X6idOqf/M3g4RnygvXVn8Qm8+U 8ZbtzByMEogjDFkD6EuI/Xw+IM7vKmWMFlNfZmlHu+PgDSwxsiScvpNF72cvgNscaQ8j 8xSz1YfMzuyybgJQPYQrqkTBs9QGFvLBoIg8kJZjWEhI4Artl+X6CU5qpdHh91AX0Aut uZjmycEotvR8ED5QntDUOJkvx++lroet9y/mIXJfNJlNAVfpnuEJliV7QIbXZSia79T4 tJEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=KI9bvqb1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho9-20020a1709070e8900b0078248dc1d7asi8352310ejc.716.2022.09.24.01.53.22; Sat, 24 Sep 2022 01:53:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=KI9bvqb1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233816AbiIXISM (ORCPT + 99 others); Sat, 24 Sep 2022 04:18:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233781AbiIXIRo (ORCPT ); Sat, 24 Sep 2022 04:17:44 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E014C88B1 for ; Sat, 24 Sep 2022 01:15:31 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id s10so2332394ljp.5 for ; Sat, 24 Sep 2022 01:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=nQomz4ut+7sjfQrrU1jIFAnyWatFfjECi53D3yczEIE=; b=KI9bvqb1+pvOBd4LUHBVRiy4ZY0slRCTRZZlpbG/wkf5BfzAwgC4tzlqpiFF6oyV8H D7v79qgnbhBTO6d2uDyYHRhhdOOhBfa6EEXzsR1OAGK0jLsPlfD7cA9BCk+dEYTkPA3D wWtwWaAoPO0/uTRDdef7+H6/fPQ584Q/+VF22lUeYetTvqY4NLRzWkfcrMuUKAwvI8Ur HORX0nTGI2VWAa2VLCpjSTjWJtDJGVfm/4NoDwUwRQY3sCzLDgDtibX9udsLmyhZz/Ab UsteBe0vnTvVHno/YLL9xbDupvnLo0yMlhWvaVPU8HJaxwp4Vvg2Oz/Cql9apCVP7xpg yn0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=nQomz4ut+7sjfQrrU1jIFAnyWatFfjECi53D3yczEIE=; b=3/z4qesJdUa3zXEg5WWhYOLLiUH7Njfqla7Cu0kNzmdU73Y0Hl077bVR/Sb961UGHt DbFRczDgak3gge4a+o5zXi3+joT5dcqMtexJU1qHWmpjvirf0XTkYZRuYGMo4IerlmQZ 03Eedqsf4UHAJfBn+edJkf6V7ypNLaa22n4MBD3dg6wtyTLSXIIj2XmfHU22c6ohOY3e Ka3RZVyGsmBrGl7RHsXr8ZYLUKREMDhhuBS9RA6ljWBq/U2co87QkaMDhX29fW6x7fH7 UfVh7UqI/wtyJaA+dBzWAu/DCWL4fvrDhQyFWQnUOcssE94zbZspR5fHp8j3+ZwIMctV +J8Q== X-Gm-Message-State: ACrzQf3pnOwBPn+nZ99QfhhiChJ4awIYAzkj3dV1RGLkBBvp503tjNOr IKYfAZSpgajOiBU6XJO4h8NcBt1PinMKLhj7APYJ9A== X-Received: by 2002:a2e:be8d:0:b0:26c:f4b:47a0 with SMTP id a13-20020a2ebe8d000000b0026c0f4b47a0mr4030821ljr.92.1664007329396; Sat, 24 Sep 2022 01:15:29 -0700 (PDT) MIME-Version: 1.0 References: <20220923202822.2667581-1-keescook@chromium.org> <20220923202822.2667581-15-keescook@chromium.org> In-Reply-To: <20220923202822.2667581-15-keescook@chromium.org> From: Dmitry Vyukov Date: Sat, 24 Sep 2022 10:15:18 +0200 Message-ID: Subject: Re: [PATCH v2 14/16] kasan: Remove ksize()-related tests To: Kees Cook Cc: Vlastimil Babka , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Vincenzo Frascino , Andrew Morton , kasan-dev@googlegroups.com, linux-mm@kvack.org, "Ruhl, Michael J" , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Greg Kroah-Hartman , Nick Desaulniers , Alex Elder , Josef Bacik , David Sterba , Sumit Semwal , =?UTF-8?Q?Christian_K=C3=B6nig?= , Jesse Brandeburg , Daniel Micay , Yonghong Song , Marco Elver , Miguel Ojeda , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-fsdevel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, dev@openvswitch.org, x86@kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 23 Sept 2022 at 22:28, Kees Cook wrote: > > In preparation for no longer unpoisoning in ksize(), remove the behavioral > self-tests for ksize(). > > Cc: Andrey Ryabinin > Cc: Alexander Potapenko > Cc: Andrey Konovalov > Cc: Dmitry Vyukov > Cc: Vincenzo Frascino > Cc: Andrew Morton > Cc: kasan-dev@googlegroups.com > Cc: linux-mm@kvack.org > Signed-off-by: Kees Cook > --- > lib/test_kasan.c | 42 ------------------------------------------ > mm/kasan/shadow.c | 4 +--- > 2 files changed, 1 insertion(+), 45 deletions(-) > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > index 58c1b01ccfe2..bdd0ced8f8d7 100644 > --- a/lib/test_kasan.c > +++ b/lib/test_kasan.c > @@ -753,46 +753,6 @@ static void kasan_global_oob_left(struct kunit *test) > KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); > } > > -/* Check that ksize() makes the whole object accessible. */ > -static void ksize_unpoisons_memory(struct kunit *test) > -{ > - char *ptr; > - size_t size = 123, real_size; > - > - ptr = kmalloc(size, GFP_KERNEL); > - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); > - real_size = ksize(ptr); > - > - OPTIMIZER_HIDE_VAR(ptr); > - > - /* This access shouldn't trigger a KASAN report. */ > - ptr[size] = 'x'; I would rather keep the tests and update to the new behavior. We had bugs in ksize, we need test coverage. I assume ptr[size] access must now produce an error even after ksize. > - /* This one must. */ > - KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[real_size]); > - > - kfree(ptr); > -} > - > -/* > - * Check that a use-after-free is detected by ksize() and via normal accesses > - * after it. > - */ > -static void ksize_uaf(struct kunit *test) > -{ > - char *ptr; > - int size = 128 - KASAN_GRANULE_SIZE; > - > - ptr = kmalloc(size, GFP_KERNEL); > - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); > - kfree(ptr); > - > - OPTIMIZER_HIDE_VAR(ptr); > - KUNIT_EXPECT_KASAN_FAIL(test, ksize(ptr)); This is still a bug that should be detected, right? Calling ksize on a freed pointer is a bug. > - KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[0]); > - KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[size]); > -} > - > static void kasan_stack_oob(struct kunit *test) > { > char stack_array[10]; > @@ -1392,8 +1352,6 @@ static struct kunit_case kasan_kunit_test_cases[] = { > KUNIT_CASE(kasan_stack_oob), > KUNIT_CASE(kasan_alloca_oob_left), > KUNIT_CASE(kasan_alloca_oob_right), > - KUNIT_CASE(ksize_unpoisons_memory), > - KUNIT_CASE(ksize_uaf), > KUNIT_CASE(kmem_cache_double_free), > KUNIT_CASE(kmem_cache_invalid_free), > KUNIT_CASE(kmem_cache_double_destroy), > diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c > index 0e3648b603a6..0895c73e9b69 100644 > --- a/mm/kasan/shadow.c > +++ b/mm/kasan/shadow.c > @@ -124,9 +124,7 @@ void kasan_unpoison(const void *addr, size_t size, bool init) > addr = kasan_reset_tag(addr); > > /* > - * Skip KFENCE memory if called explicitly outside of sl*b. Also note > - * that calls to ksize(), where size is not a multiple of machine-word > - * size, would otherwise poison the invalid portion of the word. > + * Skip KFENCE memory if called explicitly outside of sl*b. > */ > if (is_kfence_address(addr)) > return; > -- > 2.34.1