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=-24.8 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_AGENT_SANE_1,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 534FDC433E0 for ; Tue, 12 Jan 2021 13:55:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DF3FE2310D for ; Tue, 12 Jan 2021 13:55:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF3FE2310D 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 D8CA08D00A9; Tue, 12 Jan 2021 08:55:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D3CFB8D0090; Tue, 12 Jan 2021 08:55:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDDAF8D00A9; Tue, 12 Jan 2021 08:55:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0041.hostedemail.com [216.40.44.41]) by kanga.kvack.org (Postfix) with ESMTP id A65B48D0090 for ; Tue, 12 Jan 2021 08:55:27 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6EF988248047 for ; Tue, 12 Jan 2021 13:55:27 +0000 (UTC) X-FDA: 77697270294.07.songs41_3e128a327515 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 4EFC51803F9A4 for ; Tue, 12 Jan 2021 13:55:27 +0000 (UTC) X-HE-Tag: songs41_3e128a327515 X-Filterd-Recvd-Size: 5556 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 13:55:26 +0000 (UTC) Received: by mail-wm1-f52.google.com with SMTP id n16so1801284wmc.0 for ; Tue, 12 Jan 2021 05:55:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=jU0ycsEdEyG12FaOCf2AucocFaDBPHhikig1gZJxSS0=; b=USJ1WbcWVHmg2KSm7+bUEzehLqCHcu05wPWW5iCMzg1JSkfogd/hwH3PLqgNwxvMG3 Z9eVLK1cbDNbGe8O3NaAPY4txG7GvekAuYF3gyCqpKmDxvnh0Ma2SJ/ZjPdVMrBLp8fw a+LQEEj0dX9Ku/1f3KkSKWN8hCj5iC0Uu+1fUT0m3uUOB7099dNFfFQ1tNuUTryo3+vz DJhboxbrHi81fU7gB641owMu7izhJ/9ZBCcgPQWaHU3bCU/Cx0uIyqCVHSPxPeIOG5Gz +YGtNCVdzNRTuBRMNvTkEX6k5qJIZBQHuKQSgQn+M4xayTc9D/A/OUXAiYhZvVuQLgiP /00Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=jU0ycsEdEyG12FaOCf2AucocFaDBPHhikig1gZJxSS0=; b=FF1CVSaZH6eZXuGBWQhK5bUyIx8vE887iwvZfGppbX9jm090Wzb9UmkBMMwdZjIwmA vX+rJ3gAQSriDbX4NHO6uOQ2JlBr7MlbuRLPX9XMVjrqrT2AgFCiYqdz5DRW25fRxtaj FwysB560Jyb1vRYVLYEvZUU9VYAcHN5L5QMes5GOGIpJNGGA313mml8KkdtPJPurlqV3 aJuXYeMyGFY6VO/bNweWBySV13w4ccUwv/R/Ac6oJNorIlXZkyVXH8S6gYlgVJ9qnDAO AsMLaE7cktIV4D3+qFMDh0/adZ4bWERfalVFQ15vDBRgUZZyhPPuWFCaSSbUWGhUYmj8 joUA== X-Gm-Message-State: AOAM530SqrTB/IDRtR4I/hR7NzQrBCQEm4lXJ2ihwy/txEENS+p6XLCa Eey+97Wscg7k7Ohaj3LBDKZZWg== X-Google-Smtp-Source: ABdhPJyt+xXTspVy3CyA7gxyG4tW/TsByXZ/HU6iwQNJNQ5hYjqVXPCO++la/5WhHGqluSbZl24okw== X-Received: by 2002:a1c:356:: with SMTP id 83mr3856521wmd.31.1610459725577; Tue, 12 Jan 2021 05:55:25 -0800 (PST) Received: from elver.google.com ([2a00:79e0:15:13:f693:9fff:fef4:2449]) by smtp.gmail.com with ESMTPSA id w21sm4052524wmi.45.2021.01.12.05.55.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 05:55:24 -0800 (PST) Date: Tue, 12 Jan 2021 14:55:18 +0100 From: Marco Elver To: Andrey Konovalov Cc: Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Andrew Morton , Will Deacon , Andrey Ryabinin , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 09/11] kasan: fix memory corruption in kasan_bitops_tags test Message-ID: References: <0c51a7266ea851797dc9816405fc40d860a48db1.1609871239.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0c51a7266ea851797dc9816405fc40d860a48db1.1609871239.git.andreyknvl@google.com> User-Agent: Mutt/2.0.2 (2020-11-20) 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 05, 2021 at 07:27PM +0100, 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: Marco Elver > --- > 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); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bits); > > - /* Do the accesses past the 16 allocated bytes. */ > - kasan_bitops_modify(test, BITS_PER_LONG, &bits[1]); > - kasan_bitops_test_and_modify(test, BITS_PER_LONG + BITS_PER_BYTE, &bits[1]); > + /* Do the accesses past the 48 allocated bytes, but within the redone. */ > + kasan_bitops_modify(test, BITS_PER_LONG, (void *)bits + 48); > + kasan_bitops_test_and_modify(test, BITS_PER_LONG + BITS_PER_BYTE, (void *)bits + 48); > > kfree(bits); > } > -- > 2.29.2.729.g45daf8777d-goog >