From patchwork Tue Jan 5 18:27:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12000081 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT 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 45D59C433DB for ; Tue, 5 Jan 2021 18:31:52 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D80E722D57 for ; Tue, 5 Jan 2021 18:31:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D80E722D57 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=WckfmMNpNSb8CdBgl4XKkgoCaLwwph21HyIdayY3378=; b=MZgnl8q2wFur5KteUCfOwbXA9 nXqt1tzsyvT+0LiZV8oLPwffGU1rpVl284gIxjK4K2y4y8PQQxcZy7bR4ZCbTGDRLpVnsF51fy5Gb +Q2/sS2t8AI/L+qisGEA7LyUeqzm6aQC6KaFC0Go1vEkxmgAiHHDhvN9gD7ne3fEK2tu9KLFb7yMK EF0N0vMeu+oI8zJpJ/WPwPWbjn+Lpq3Ouv3UWkHRbT9Sg/TezPwibnEw3jefjcZPUULfVx9GWA6bS QtH80vFpb9PAASkdP7uhw/UabzOorpw6NEKC3qrfS/qSqaJRD5KEg7OqV4JRfufOhXBpFHIs+0q2E T6aOCkTrA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kwr4w-0007Md-Qn; Tue, 05 Jan 2021 18:29:10 +0000 Received: from mail-qk1-x749.google.com ([2607:f8b0:4864:20::749]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kwr4H-000756-GY for linux-arm-kernel@lists.infradead.org; Tue, 05 Jan 2021 18:28:32 +0000 Received: by mail-qk1-x749.google.com with SMTP id u9so531064qkk.5 for ; Tue, 05 Jan 2021 10:28:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=iBAofrYhtWdvm45KaDvHp4GorxFru4go+vxs4/2NiTo=; b=KhhzCW5Es0nmSwmYkGHPGV3OGnAcoZc7jwfMbTCbCegBDHXqF5DT8rkvlPE1yIST+o YEVKKkxEvMOk/SLecNzaD6NXqilvTc8a2f2w2cFRB94lDfJSW043ea4L+TWP+h4PTPcm XZaV27X5QjrMJ3W86t6eGFjgcjoIXsOMabPka26suv2tXMMEa4sSd6qp4ZRWu/8rMri4 radLuY707IJUKEWW2iqRvaEB7j0HgxYLHeWZNGvjBPJ4uKDVQ+C3xGF9GGZ5kGPg+0LY fJd9knwm/PQxFTpoq7S/RzOqqxhlzr1ECWNzghOssFSwsr0qcptOTpJnyq4jJAAo5ke6 bfJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=iBAofrYhtWdvm45KaDvHp4GorxFru4go+vxs4/2NiTo=; b=TBhPRdZqy+pbIBVwKCwo3WraaiPSjvaSLPjCO5GMZKDyIYyUeQwCq+7pM5jBNzQvX5 VfwVGwnsOBStuUvhhK0ccU2cYn0tTs179VPQzsMqrmFlGtxfQWRMNYIhpyq1zQAIRj8b Wbjlqso9deieHgdOzLOCuuKsg4xg/HHYWCJqL4h/7GJJS2pGLJJM633uSo6GRO/ea+43 D09V1K1uwlDz83n4WceEvUiwhZkFbvL4Puv8mKc3A+c3qcrcChHqkH8mexam3ZmBzHao RnhIt0YZjqeVSl0TP0khBe3dcnc+4ioqDvA/TJyeLKBCCrPIXyX+Xqn0PmlEXqfUQ32R jPwA== X-Gm-Message-State: AOAM533wH9VB8kAF6Zx2oc5D3pQKhI2XXgL72jSh75UHhl4lEW2jNPpU /63lbLqxiIHbI3cD0euadXjISwABbDE62/vY X-Google-Smtp-Source: ABdhPJz9ZeKojsIaFk7oiCjyflKtBkBDpOWYVQ94sBgXV9c8H5cDJw47Fn8opToDG7AunMFDOU1CSaq1S5pOZ82S X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:e90a:: with SMTP id a10mr863092qvo.38.1609871305814; Tue, 05 Jan 2021 10:28:25 -0800 (PST) Date: Tue, 5 Jan 2021 19:27:53 +0100 In-Reply-To: Message-Id: <0c51a7266ea851797dc9816405fc40d860a48db1.1609871239.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [PATCH 09/11] kasan: fix memory corruption in kasan_bitops_tags test From: Andrey Konovalov To: Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Marco Elver X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210105_132829_646267_E3267FA7 X-CRM114-Status: GOOD ( 14.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Branislav Rankov , Andrey Konovalov , Kevin Brodsky , Will Deacon , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Andrey Ryabinin , Andrew Morton , Evgenii Stepanov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 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); 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); }