Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp3077843pxb; Tue, 12 Jan 2021 05:57:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzcS7eJFnTP9NRXtNeTinpnHaNfRk4vGLUbui6/ZF2UIgMdtkRyN1xIvC19vHlLOgSFu8x9 X-Received: by 2002:a05:6402:318f:: with SMTP id di15mr3532961edb.237.1610459872893; Tue, 12 Jan 2021 05:57:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610459872; cv=none; d=google.com; s=arc-20160816; b=XJ/pZTc7U8M7VHtuIf0Yptklkycpu4W/UEKiWSoJv5PuddFXi9qp2wHP4eY7RsFfS2 PUI7LEHPfzHQC/mYfg3kyd+tlbSOl2Klx/rfJdxX0UUFzfS+uDTSxWvuC+GVB5Jus2G0 d6zXIOMQDl7Os6ocQ0ikD3Kzp+vu5qJTyTkoqSNbZ2BXvCFZpH2TAlVzezT57AxhPyUu +VZlpnabfCrb/dI60grbA5xeXoAWvPK+QO7JZyLAAu3VtAunKdRoFileUcHVfzcg9LyZ Iewh4PL7QyvyQdp2DKx+NoLjsFKD47iuFCAV8wMSDKezz/LtLZ6jlgBIcBEUQNmNWwA0 B4Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=jU0ycsEdEyG12FaOCf2AucocFaDBPHhikig1gZJxSS0=; b=GQU8Wo2POSKQIIn06kV7xjGAMdFjYKmXp89qBEHPxiDG9nm5y8JqsMv/GJG+6V2av/ oacvYpm81Gs2KhGPjYtEpAiqAw6IMRqkm5jnGmOKAZIOdAeG8R6L3inywa2L42uwG6+X sCRPwre2mVcoER4ptfyaw89nhQNuUWPM1f0YJDz9DiZRHJVdvxj9LWhdc3s5IdbcSTlZ f/nlJsMgZ+4Lo7cn3+EMBQf6NALTo/wUBKtCpOcKOaEC8uxGMuPTInlj2O85/0qo2aB3 TXOG2BxHXMsUxuwzE83OjIpamneG1e6X818xIMig7EaCj84zPX7brjhTSn+o/v+dHTMu u4Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=USJ1WbcW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q22si1308625edr.578.2021.01.12.05.57.29; Tue, 12 Jan 2021 05:57:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=USJ1WbcW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730765AbhALN4N (ORCPT + 99 others); Tue, 12 Jan 2021 08:56:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbhALN4H (ORCPT ); Tue, 12 Jan 2021 08:56:07 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E30DAC061786 for ; Tue, 12 Jan 2021 05:55:26 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id n16so1801281wmc.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=gRdYokLY83WCqdXjh8kOA1RiRA+WzH3r72JVjVHxR4J5Nnl/rzST1R0A78whUCZY7E aenx40tEOGXzpNi+AP+peYfCPBRCmuqw+6135Jp8S76B+FO7t7i/SBaOlyulnVm4RDWi N6fOtNlsSwRuicDa0dc8H0jGQbM3bJBBKjcHaCvusnDittExRl6w+LaofuOdyb2SsMUp awkVeR/pJmqUuiHhEqj98kGOEbQe0obsHl+P+zxoFlzzAcafFWjzfl97M+5q2VWZhMzb Ac4RbBZpY0Vh1uxjTHXFXIzMBLkQ/d2c1NijJ9PuOuJIuFDvejpZ4DkZfjDGZjxi3lgJ 4tWA== X-Gm-Message-State: AOAM531dQKv4Ngc2ZuF/lD+gq1q/i0QcdNAjXIX+NBTONZ2R/OkG7Puo 8mgMh9esuvUJcLfwmDhZgUDKSg== 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) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >