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 7E9A3C433EF for ; Wed, 17 Nov 2021 13:04:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0C09961BB6 for ; Wed, 17 Nov 2021 13:04:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0C09961BB6 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 81D506B0072; Wed, 17 Nov 2021 08:04:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A5406B0073; Wed, 17 Nov 2021 08:04:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 645EE6B0074; Wed, 17 Nov 2021 08:04:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0101.hostedemail.com [216.40.44.101]) by kanga.kvack.org (Postfix) with ESMTP id 4F2486B0072 for ; Wed, 17 Nov 2021 08:04:40 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 0FD5B1814556A for ; Wed, 17 Nov 2021 13:04:30 +0000 (UTC) X-FDA: 78818441100.16.53CFB4C Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) by imf10.hostedemail.com (Postfix) with ESMTP id 93356600199E for ; Wed, 17 Nov 2021 13:04:29 +0000 (UTC) Received: by mail-oi1-f176.google.com with SMTP id bj13so6288336oib.4 for ; Wed, 17 Nov 2021 05:04:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GQVwuxwEF7Twnep+EJ7g8xvuzr4jtUj3SWg3Cfbdhis=; b=liGg1iEPPGLbG4DDHieBsW7IY/rbPGxGqZEmBNhHtDmvF9w/ZZg2JGeimCDddk+omR tIJG/vpRh/HOVBAwy5T0IpVl6YOS8BJi62j5nEuMlCrnSxfxXhxlkam7jf1B2LlHf8h3 ja+x3kmRJleXut4dCQN1rg3xV8pWcNkTNuXVKG2clvoUYxp9Qfqh+wSPdwChGsNS0I71 9V85IKmLnXsteechcFeE+lWZRVTjJxwJE+FLHaQZa8Put2tHsnaPNPKSSddfhooy7xkX qtYwL+kCjJWO4t7oHR0lY6Wm4znk4v84qAk/bg4RXXVG67BKb1L79DwjvRkb6vepamFK REuA== 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=GQVwuxwEF7Twnep+EJ7g8xvuzr4jtUj3SWg3Cfbdhis=; b=i4342lVvL9A6PcvbMvp0cJ/1LsKa56BweiRHcY1PITomWDxQKqzJpKe3hFDhsaqjBX ggUbg8G5+WfnLYk7/gOerZcj4sb5LgSVQU1E/08gI37ZsgYq1tmBehIfweinUHj2cDO/ fVZoi12uE1nIPkLIZuIX/sWpkAN04PeSnfBJSg7+Rp/9LoTZvVTNeYJFPFbzX4o4/ttS fbfQhTEF8om3bUtZCmp/RjSIpSWlYhZd/3jZdI1tzTQy21aBMfFt/JlC3SdVY8qfPg5v 3UoqEwKSajyWdQrTyvggdZpR60PF1BMIj7oYn0IohSHYq1r04DRGvBWfXcMZ9XVMcU4J 25PA== X-Gm-Message-State: AOAM533tnw2NR9I7B41R2LZv1m36eubC9WE/he+NgaBquALCEQwrAZRx 7pniEXojIIo2JQahHSF1+Hp7dabmGryJvk5MXKYzPg== X-Google-Smtp-Source: ABdhPJw5kPCatNefewbxl2yN47Yk2Dxdh+s8FDIPYQfhcAQ6/Csum6NFTKMpxnABqhZYHhdQX9z31pCmKDgqsS+jKK0= X-Received: by 2002:a05:6808:1903:: with SMTP id bf3mr49706426oib.7.1637154268831; Wed, 17 Nov 2021 05:04:28 -0800 (PST) MIME-Version: 1.0 References: <20211117110916.97944-1-elver@google.com> In-Reply-To: From: Marco Elver Date: Wed, 17 Nov 2021 14:04:17 +0100 Message-ID: Subject: Re: [PATCH] kasan: test: add globals left-out-of-bounds test To: Andrey Konovalov 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: rspam01 X-Rspamd-Queue-Id: 93356600199E X-Stat-Signature: r7qtohwfggchbk847zad1n8qipu3crnc Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=liGg1iEP; spf=pass (imf10.hostedemail.com: domain of elver@google.com designates 209.85.167.176 as permitted sender) smtp.mailfrom=elver@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1637154269-335870 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, 17 Nov 2021 at 13:59, Andrey Konovalov wrote: > > 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. I was wondering how to solve the cyclic dependency, because I wanted to link this patch from the bugzilla. Now that the bugzilla entry exists, I guess I can add it and then update bugzilla with link to this patch closing the cycle. :-) > > + 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! > > -- > You received this message because you are subscribed to the Google Groups "kasan-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/CA%2BfCnZcp3dFd3rwpLx6VUi2Yv9uqsWQyQNB6d3X-A7VgTjXUpw%40mail.gmail.com.