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, 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 392E3C433E9 for ; Tue, 12 Jan 2021 08:30:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BAC9522D58 for ; Tue, 12 Jan 2021 08:30:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BAC9522D58 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 106988D0074; Tue, 12 Jan 2021 03:30:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DE888D0051; Tue, 12 Jan 2021 03:30:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE9668D0074; Tue, 12 Jan 2021 03:30:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0057.hostedemail.com [216.40.44.57]) by kanga.kvack.org (Postfix) with ESMTP id D91F68D0051 for ; Tue, 12 Jan 2021 03:30:29 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9A6983626 for ; Tue, 12 Jan 2021 08:30:29 +0000 (UTC) X-FDA: 77696451378.28.cause37_440be7827514 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 680666C33 for ; Tue, 12 Jan 2021 08:30:29 +0000 (UTC) X-HE-Tag: cause37_440be7827514 X-Filterd-Recvd-Size: 4824 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 08:30:28 +0000 (UTC) Received: by mail-qk1-f173.google.com with SMTP id h4so1207911qkk.4 for ; Tue, 12 Jan 2021 00:30:28 -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=0wLcHsg2X/4z8PrpV9akJDkZzB5hyg40jt+7shI/gTg=; b=H7l/xBsokZWxuOFzTvS7+hoJXKkGNX+QxRbLwuakj+IdGe//P9o1E5TN3/ENCRlaWg +AJQbWcTsANDN0rj16yKPd98Cc5CUH5ram5r0nunqyWgyzBLENpBXaxO6YwkndltHCvx 9/bLKtn8Oe+7NJ2+HcQFM/ZhpVCi2hlfj8zaVT7J5f7TdQ67PYRgx6+AZgRctanQBAKN jWLT/q2+liDdD6foacf7Ge0XEcZQTRAdxih1bMdmgN1optpDDA/L7pfZKgI8qMx/CO8U o0Rt+iVuYnvePEIVGWz7OezS2iwIKHYgUMXbwNSwOjkHn4bHNuD81jPhVfx2qHjWg4Oe NviA== 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=0wLcHsg2X/4z8PrpV9akJDkZzB5hyg40jt+7shI/gTg=; b=WDkG1o+bLRg53kyDwLI3gRpXjywhtoLoezCA1+ARf2QEm9qjdK3hbNpjq3UNujXCdw 5JIQdJCdm0kuJfvWRdbqiI5D55EJ2rBMbnjErrLATuZOybxH5N2Q7ChTtmOeDT6frdB2 5mA6sU6i8oAZN5PIlG2VTbpAaLzJmctmn7tmQhAu6VREhgizF+qoM2y9aMvT/owl2KQb 8Im5YvROCvJfy0c+fOfWJJfEpEpHu1/n4kwvQ2JgYwlponWY9zgQImW6+hpIqHvTzcg1 xe08pujYrqB2dn449osynrqAPGvL7t8Koo7lukpZyvsIh0Hmp5Mnt/tIy8HSwkumzqMa dFvA== X-Gm-Message-State: AOAM531LCfz+3+bBxmLCqAC1cx/3nq9u3ko9IXlG9viRsUi1QJM32m8j 9OD4+bjG5zzXkzuzj/xcNEnJXAVSsO4qrpHt3Is96g== X-Google-Smtp-Source: ABdhPJzX9ZKlxgtpdQZv9xSZdDB8NQvTnIoH5PwigJDwvVh6x5siBFDoV6HC12Np9+IpbIi/oAruZI7lTvLDSsb8sig= X-Received: by 2002:a05:620a:2051:: with SMTP id d17mr3304130qka.403.1610440228161; Tue, 12 Jan 2021 00:30:28 -0800 (PST) MIME-Version: 1.0 References: <0c51a7266ea851797dc9816405fc40d860a48db1.1609871239.git.andreyknvl@google.com> In-Reply-To: <0c51a7266ea851797dc9816405fc40d860a48db1.1609871239.git.andreyknvl@google.com> From: Alexander Potapenko Date: Tue, 12 Jan 2021 09:30:16 +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 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.