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 ABC24C433E0 for ; Tue, 12 Jan 2021 20:07:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2981022202 for ; Tue, 12 Jan 2021 20:07:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2981022202 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 9A4EE6B00BA; Tue, 12 Jan 2021 15:07:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 957026B00C3; Tue, 12 Jan 2021 15:07:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86C6E6B00C5; Tue, 12 Jan 2021 15:07:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0103.hostedemail.com [216.40.44.103]) by kanga.kvack.org (Postfix) with ESMTP id 726EF6B00BA for ; Tue, 12 Jan 2021 15:07:09 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 38AAF180AD830 for ; Tue, 12 Jan 2021 20:07:09 +0000 (UTC) X-FDA: 77698206978.19.stick98_050e2bf27518 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 1281E1AD1B3 for ; Tue, 12 Jan 2021 20:07:09 +0000 (UTC) X-HE-Tag: stick98_050e2bf27518 X-Filterd-Recvd-Size: 5249 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 20:07:08 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id y12so2308701pji.1 for ; Tue, 12 Jan 2021 12:07:08 -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=pMt208i988Aj1RV+YWcUlsqzon7o0ifo6LZ2mK0qEq0=; b=hp5afakNd2d/FQoQpixyj3+dET0KAs/17uAZVG2pt5rAFbU6WZBkW/T0x4f5Gwu0rF zVN+Ck9CcaN4f7yG+3ctQS1OCckqVyxGKNe/NL+mMblv6IdAJ8EYWnioEfhdVoJrb+zg jwPFQR87TwuAPE1J9s9t0JSpwYAvlQE2Z96giLtFUHgqvklZhu3buAnwiINDF6nAqy8r maxUiS6HPd87hiGmj9YyUz23qOlrjdNH/0Ab6y/uGq26aFj4vzS8skOfh5jOLRldoHgs LlDnU/6XEb0LNfs1eKaW9Uj+CGSFM951EH0Qm87MTYfrhqsoTYwXrz1HwydVZqVKVWEG D8zQ== 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=pMt208i988Aj1RV+YWcUlsqzon7o0ifo6LZ2mK0qEq0=; b=IIdMZRLqetLUzlOdPSGZfzM3RqxfSEva+baCweCDcd+t+azfzoJP7kWprLQLrsM3ND 0vBRFi7080QwRmAeYwGemmVAE+bqxid8F7ZuE+LhhjW1w/p9iDSPewNkOwYprWY1zlBy TfHDH9EppuGUpBwmPg0eDMuBRYFC5vscMB7ykgAMZYYP2HX1Wd/GE3SijT6An/u1YLUM qV/5LCI0a/PyN3NR5rrS+sGdVzNZRwBcgEZJuHIoB/K/L8GYJEN87gOKK2sNW2sGXX3V +HNDCOpNcXvmT1Zyntd0ZMS9AqMkE/TLcqIaVPQWZYbsZKB9semTcD8aIRG+HmXbnCuj z4kg== X-Gm-Message-State: AOAM531jyVtRrY10Gb+OzXErmG7f4LfJqGzaUFP96ZKEcUkHowtbetXc fnI/6rSMnyS8UodEGd1MYxoA5NOBOMbOx43VRwaSjw== X-Google-Smtp-Source: ABdhPJxmSGRHqWdnI3a/eD2Zk4MKrqBKhIill+QCO1/HJbdNIc7ksRdpTMI9qx1p9hVBDBv9KOHd7j1iLC0/AYVSsNE= X-Received: by 2002:a17:90b:350b:: with SMTP id ls11mr844230pjb.166.1610482027266; Tue, 12 Jan 2021 12:07:07 -0800 (PST) MIME-Version: 1.0 References: <0c51a7266ea851797dc9816405fc40d860a48db1.1609871239.git.andreyknvl@google.com> In-Reply-To: From: Andrey Konovalov Date: Tue, 12 Jan 2021 21:06:56 +0100 Message-ID: Subject: Re: [PATCH 09/11] kasan: fix memory corruption in kasan_bitops_tags test To: Alexander Potapenko 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: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 > > --- > > 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. 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. Thanks!