From patchwork Wed Jan 13 16:21:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12017321 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, URIBL_BLOCKED,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 53065C433E0 for ; Wed, 13 Jan 2021 16:26:15 +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 DED7023370 for ; Wed, 13 Jan 2021 16:26:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DED7023370 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=cqKfeaPpBAyzttQH9GnUpIgFYZiiLoovBSloDjZXlZ8=; b=D+cYHRxk3DNVkoZKOMr5wMFmv 1bMUI5pM9gtDd6Qt0VVcIfC6zsUWDmIuKJ9tQc9NQaHEnKtmXjSigzplUywobqvq8zFpKQT+543kl +OXq6ShTfnI+HKGmuGt2/TwRmepTw9z4vMyb9Y1f3Dnt2hlhOk0anIDZPCzE+M5npOvn5CFEGQTR/ jNOYbURRR8SMATEHczY/664sNnzSHj6MVHI9jEtYs88EwBvEGfAuPqdWJaOugc6B/vgAiq0scg3Cw y2udUZnffcvy/I4IoRngRNSyN+bWosldhFBS+jpBEC7gRI3KRhxkw/7K/jayDjcqSlhfSx7o+Jo/x 2oBCOD+Ag==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzivk-0007lX-Q0; Wed, 13 Jan 2021 16:23:32 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kziuT-0007Hg-MB for linux-arm-kernel@lists.infradead.org; Wed, 13 Jan 2021 16:22:36 +0000 Received: by mail-wr1-x449.google.com with SMTP id l10so770433wry.16 for ; Wed, 13 Jan 2021 08:22:11 -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=L1Lauf2F6M7nowmjOy2kFR6Fh9wMsHUDYRnyLelpHLk=; b=YLqNMyj7CQklsJS87J6H8yeUQkZgOfU7G3lS/Mpds9lAgxLAaIIilaTdab465iE4pV r4K5VWiNZ6YehcB6XsRpj+i/5JzIesafSzAu/f7aS6i2pFhb0vHtPV2Qvj5aPFEZl0SB KtQAWfnJUt++5AVjgai6aKkkafwuPu7tpacheJvcvpdcfsKrgAarJyxxXOaUFBpVniKL pjEJ2AXkZrecOmZs0mVXnGG9ux9jN0M6HmUiY5VOs71uv2Sh3hiNtIXBTomvwUbsRth/ 6Muo7xLqiJfcoGSSHtdnRUivaKaHGpeyJ2nVAP1bS+4VqSMpEH8WUxL656p9rwUeG8QZ jKJg== 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=L1Lauf2F6M7nowmjOy2kFR6Fh9wMsHUDYRnyLelpHLk=; b=gW+Zj3N0zwqI/ICoPa7RF2YzIhiPB+8NLARWGVZGyC4Lsi8kwTdpiKcpGM10PIwK9A SjO+bUKw35rxNhHoJQrUyob1YQnm65fi4HMBBrLWRYBg11gDzwYONd0R2D/X0z2jFXwC dEkMqbXQgnc8DGl1r3ARKnDyUdISnjiBHWD44J3AN4c/v6IvYxOJE2w/F/VNT7VZ3gRJ 66xGFoarS91X6t1DdfuV/PU483joYGBU2SeBpdKV7NUGBWeWvyG116HoAnGLmH4Mt+NV cAJ+Vi/VXUTteSdP+Py8CZKMt8EbqjwZRulFIf5hXZvx9TJ1wARsVwxPnWYcY0t6kbMA AUig== X-Gm-Message-State: AOAM530BTncJIAr8rdY94k3aNYG07zS2LI3mWToJ5gdBu/PcXpRvNDOX oMaFh5eBAHaSUMt2gc/PdXFRsq6hjlF2IHVi X-Google-Smtp-Source: ABdhPJwuVUXUbA1bjgSkMWKa0K4gmDv1FuNW+RgWp1wk2T7Y5zN8m0zyfj5oYjho00jOolHgCjqK85kdGQ5YbXgt X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:c044:: with SMTP id u4mr20900wmc.1.1610554929901; Wed, 13 Jan 2021 08:22:09 -0800 (PST) Date: Wed, 13 Jan 2021 17:21:37 +0100 In-Reply-To: Message-Id: <0dfffb5c0b13f1a150223863490638e8f462f635.1610554432.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH v2 10/14] 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-20210113_112213_834994_DD289647 X-CRM114-Status: GOOD ( 15.43 ) 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 , Peter Collingbourne , 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. Link: https://linux-review.googlesource.com/id/I67f51d1ee48f0a8d0fe2658c2a39e4879fe0832a Reviewed-by: Marco Elver Reviewed-by: Alexander Potapenko Signed-off-by: Andrey Konovalov --- lib/test_kasan.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/test_kasan.c b/lib/test_kasan.c index a1a35d75ee1e..63252d1fd58c 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -749,13 +749,13 @@ static void kasan_bitops_tags(struct kunit *test) /* This test is specifically crafted for tag-based modes. */ KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); - /* 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); }