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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F9B1C433F5 for ; Wed, 17 Nov 2021 13:00:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B999961BE3 for ; Wed, 17 Nov 2021 13:00:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B999961BE3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 192B46B0072; Wed, 17 Nov 2021 07:59:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 142706B0073; Wed, 17 Nov 2021 07:59:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 009406B0074; Wed, 17 Nov 2021 07:59:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E29BB6B0072 for ; Wed, 17 Nov 2021 07:59:52 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A34AA800BA for ; Wed, 17 Nov 2021 12:59:42 +0000 (UTC) X-FDA: 78818429004.24.94365C8 Received: from mail-il1-f180.google.com (mail-il1-f180.google.com [209.85.166.180]) by imf24.hostedemail.com (Postfix) with ESMTP id C71E2B0000B5 for ; Wed, 17 Nov 2021 12:59:40 +0000 (UTC) Received: by mail-il1-f180.google.com with SMTP id w15so2666048ill.2 for ; Wed, 17 Nov 2021 04:59:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FT+WTgntcUcOhdQh68NQbpJcx5eGcrjyuCTdifDbfTc=; b=T0SLV5Vak0BHlp3lNiwOfwLSjFJCkWriKOSMmmIlbrUM1s2gKo16l5j4nXES0zNUvP qEylCxSqiEXL9J+tsl6PvttSItH+Z3idq5ZXKiqIMzuV+JPT0twEucq23yghkSOZ6hpT y7aP26txPNx09jao6zjvsgFLtsJcnnF8fKoifS7187mSv36Aqc0bs54lVUzVaARH/Dbp fXH7MwdZAP2x1ZqY7UEajsH4Oe7V96TXqwDV9rxZRiKmRhmRDIbNNQ5wKxAYO6xFZIYy psF6nC8032YQAYl/XDc8Kq+F0wdusS0AynCu1wtbPTkA1U/vI+oNGlm+MN9QN5hDosE7 b8Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FT+WTgntcUcOhdQh68NQbpJcx5eGcrjyuCTdifDbfTc=; b=Gy+WX2nHT1HzwkVsh3zqb9lfdEdB/YYJcabCVpv9R+2ihjBjflf2KS0nm8iS7xbXUP Y/uDPEm1ibGgbAYFPB4XxEFA5/21cUhcHc55j5Ui15z4i9RQTHoRNEFSy6eMHFd1TrUD ghX576Xy8APueRu9YfoE30EOEceZO9Jv6b2TfrCloqVGTSeCXdvAF4srzo/+cALcQ5W5 QlMs7Rp4tqtF2hbdl+kF/RiTEZyVdE3tpmOh+nDKcFvzf8IDHiDF9FbF2TP45V/gKz8B 0LAjJV8p+DddmBdbmcCidqslIwSrrXD0V69VfZeVFU+3I/4JvJlAbKLntqjfXQbGUHOx wRsA== X-Gm-Message-State: AOAM530H6/EATKQSjioXImC+w+v0OgJZYo1Vn4wPnjuTg0iRdF9oz2SZ WTDLmMSN5SruYTHvgbpv/oaRPqLSZ1unQsTzuP8= X-Google-Smtp-Source: ABdhPJx8YHxYHux/ZSqYkkNgl/dqm48tf7DGiPYZ/9RP5WbW6fvAtvkfIAGLT+gOfzhv83ogUUjrW0TH9lnpP7pap64= X-Received: by 2002:a05:6e02:1525:: with SMTP id i5mr10012820ilu.81.1637153981523; Wed, 17 Nov 2021 04:59:41 -0800 (PST) MIME-Version: 1.0 References: <20211117110916.97944-1-elver@google.com> In-Reply-To: <20211117110916.97944-1-elver@google.com> From: Andrey Konovalov Date: Wed, 17 Nov 2021 13:59:30 +0100 Message-ID: Subject: Re: [PATCH] kasan: test: add globals left-out-of-bounds test To: Marco Elver Cc: Andrew Morton , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , kasan-dev , LKML , Linux Memory Management List , Kaiwan N Billimoria Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C71E2B0000B5 X-Stat-Signature: rhxn44oqf7rk7i4j33yyi7i6ffck9d5e Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=T0SLV5Va; spf=pass (imf24.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.166.180 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1637153980-363354 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 Wed, Nov 17, 2021 at 12:09 PM Marco Elver wrote: > > Add a test checking that KASAN generic can also detect out-of-bounds > accesses to the left of globals. > > Unfortunately it seems that GCC doesn't catch this (tested GCC 10, 11). > The main difference between GCC's globals redzoning and Clang's is that > GCC relies on using increased alignment to producing padding, where > Clang's redzoning implementation actually adds real data after the > global and doesn't rely on alignment to produce padding. I believe this > is the main reason why GCC can't reliably catch globals out-of-bounds in > this case. > > Given this is now a known issue, to avoid failing the whole test suite, > skip this test case with GCC. > > Reported-by: Kaiwan N Billimoria > Signed-off-by: Marco Elver Hi Marco, > --- > lib/test_kasan.c | 18 ++++++++++++++++-- > 1 file changed, 16 insertions(+), 2 deletions(-) > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > index 67ed689a0b1b..69c32c91420b 100644 > --- a/lib/test_kasan.c > +++ b/lib/test_kasan.c > @@ -700,7 +700,7 @@ static void kmem_cache_bulk(struct kunit *test) > > static char global_array[10]; > > -static void kasan_global_oob(struct kunit *test) > +static void kasan_global_oob_right(struct kunit *test) > { > /* > * Deliberate out-of-bounds access. To prevent CONFIG_UBSAN_LOCAL_BOUNDS > @@ -723,6 +723,19 @@ static void kasan_global_oob(struct kunit *test) > KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); > } > > +static void kasan_global_oob_left(struct kunit *test) > +{ > + char *volatile array = global_array; > + char *p = array - 3; > + > + /* > + * GCC is known to fail this test, skip it. > + */ Please link the KASAN bugzilla issue here. > + KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_CC_IS_CLANG); > + KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); > + KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); > +} > + > /* Check that ksize() makes the whole object accessible. */ > static void ksize_unpoisons_memory(struct kunit *test) > { > @@ -1160,7 +1173,8 @@ static struct kunit_case kasan_kunit_test_cases[] = { > KUNIT_CASE(kmem_cache_oob), > KUNIT_CASE(kmem_cache_accounted), > KUNIT_CASE(kmem_cache_bulk), > - KUNIT_CASE(kasan_global_oob), > + KUNIT_CASE(kasan_global_oob_right), > + KUNIT_CASE(kasan_global_oob_left), > KUNIT_CASE(kasan_stack_oob), > KUNIT_CASE(kasan_alloca_oob_left), > KUNIT_CASE(kasan_alloca_oob_right), > -- > 2.34.0.rc2.393.gf8c9666880-goog > Otherwise: Reviewed-by: Andrey Konovalov Thanks!