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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,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 EEB2EC433E0 for ; Wed, 13 Jan 2021 12:30:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 54DEC23339 for ; Wed, 13 Jan 2021 12:30:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 54DEC23339 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 881938D004B; Wed, 13 Jan 2021 07:30:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 831388D002E; Wed, 13 Jan 2021 07:30:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 746958D004B; Wed, 13 Jan 2021 07:30:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0091.hostedemail.com [216.40.44.91]) by kanga.kvack.org (Postfix) with ESMTP id 5F58F8D002E for ; Wed, 13 Jan 2021 07:30:35 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1C8A8180AD838 for ; Wed, 13 Jan 2021 12:30:35 +0000 (UTC) X-FDA: 77700685230.21.crown74_23012f32751e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id E1DA9180238B4 for ; Wed, 13 Jan 2021 12:30:34 +0000 (UTC) X-HE-Tag: crown74_23012f32751e X-Filterd-Recvd-Size: 5582 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 12:30:34 +0000 (UTC) Received: by mail-qt1-f170.google.com with SMTP id c1so958825qtc.1 for ; Wed, 13 Jan 2021 04:30:34 -0800 (PST) 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=YHb853OW+nOYLu/IE6QCDFLb71LosLe9lCUBT46DGFo=; b=A4DDeU2VTnUM/WugpeuuSLcq9DsDKZjW0otZi4DeSSn3tJzX8FHHFbhlUurXyQRR4p PiIgYMuNq97TrI5EQsmI1BzT66qkEfU5AuW1i02BlbKZ44VFVxHmLB9rjtDfH7/RK9OJ FS3SOC1fw1P/VWiCX6FK2U1QqrbCQVIGSgqu/KDe+h5MaJ7GTRNQZ+1+0I9k4t6+LOBl PNDRukfZWdk3Ue13Ow6DENqwIhn7TeIkUR0nTSBygPjK6T4TFDqPsVlTpMDWXvjkR9IM /Dsn21BJ3wSZnwOAW9hc1ZXARRdSKj9vniM1aNMeir7rOy4EIsqw3ss75pR+mlAQMC5p K6Sg== 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=YHb853OW+nOYLu/IE6QCDFLb71LosLe9lCUBT46DGFo=; b=L0GB07qfdarowftc6YkX4kXzYmoRKekoUrDIScJ+9JVfDe41Sg9D5WumZz5uDbmw5T EPQf2EPd9eNP7G0DBl2VbrNLlcgv07aJP2vX2vDzKnO/dYDjbKCRyi2KydB2mtuoxkfv 1Y+9kc5ynRdqRaIhUwtfmFx7esRMf/x8NRkpSinLlLyVDNbTp5GCujvV0uPyUmVzmqqk iAkDNgEIlVLe0BzYnQmZIrLjxn5rQ0EkUFU+XQgJt9kNiSDit3/EFSIyWUP2dg0fuJQK cElNX1tdWjvHwtvGZKd+wNmbR37qOAtTdZEROKp9PeZz6Vg6pCZneGLcsv0tSSmL5azh hZ6g== X-Gm-Message-State: AOAM531l4PDIL4sWEhELp+YZqe1o2WwUiASmP9S3VXn9j1opI4ssNxF5 aeniNqb/D8LL2+tLdFTQfPdOWucs3FDPDfLbDH3qBw== X-Google-Smtp-Source: ABdhPJzKGyNdIflFErZkBaYeIIgatGIdJmqQZ/ahgW1INpCbqgO3B6lUZSe/Ve2mjALp83/bCAe0T/tIFtiJL5pfZGs= X-Received: by 2002:ac8:6f32:: with SMTP id i18mr1908368qtv.175.1610541033304; Wed, 13 Jan 2021 04:30:33 -0800 (PST) MIME-Version: 1.0 References: <0c51a7266ea851797dc9816405fc40d860a48db1.1609871239.git.andreyknvl@google.com> In-Reply-To: From: Alexander Potapenko Date: Wed, 13 Jan 2021 13:30:22 +0100 Message-ID: Subject: Re: [PATCH 09/11] kasan: fix memory corruption in kasan_bitops_tags test To: Andrey Konovalov Cc: Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Marco Elver , Andrew Morton , Will Deacon , Andrey Ryabinin , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev , Linux ARM , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" 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 Tue, Jan 12, 2021 at 9:07 PM 'Andrey Konovalov' via kasan-dev wrote: > > On Tue, Jan 12, 2021 at 9:30 AM Alexander Potapenko wrote: > > > > On Tue, Jan 5, 2021 at 7:28 PM Andrey Konovalov wrote: > > > > > > Since the hardware tag-based KASAN mode might not have a redzone that > > > comes after an allocated object (when kasan.mode=prod is enabled), the > > > kasan_bitops_tags() test ends up corrupting the next object in memory. > > > > > > Change the test so it always accesses the redzone that lies within the > > > allocated object's boundaries. > > > > > > Signed-off-by: Andrey Konovalov > > > Link: https://linux-review.googlesource.com/id/I67f51d1ee48f0a8d0fe2658c2a39e4879fe0832a Reviewed-by: Alexander Potapenko > > > --- > > > lib/test_kasan.c | 12 ++++++------ > > > 1 file changed, 6 insertions(+), 6 deletions(-) > > > > > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > > > index b67da7f6e17f..3ea52da52714 100644 > > > --- a/lib/test_kasan.c > > > +++ b/lib/test_kasan.c > > > @@ -771,17 +771,17 @@ static void kasan_bitops_tags(struct kunit *test) > > > > > > /* This test is specifically crafted for the tag-based mode. */ > > > if (IS_ENABLED(CONFIG_KASAN_GENERIC)) { > > > - kunit_info(test, "skipping, CONFIG_KASAN_SW_TAGS required"); > > > + kunit_info(test, "skipping, CONFIG_KASAN_SW/HW_TAGS required"); > > > return; > > > } > > > > > > - /* Allocation size will be rounded to up granule size, which is 16. */ > > > - bits = kzalloc(sizeof(*bits), GFP_KERNEL); > > > + /* kmalloc-64 cache will be used and the last 16 bytes will be the redzone. */ > > > + bits = kzalloc(48, GFP_KERNEL); > > > > I think it might make sense to call ksize() here to ensure we have > > these spare bytes. > > Calling ksize() will unpoison the whole object. Ah, that's right. > I think it's OK to make assumptions about KASAN internals in tests. I > would actually say that we need more tests that check such internal > properties. Agreed.