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=-16.6 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,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 03903C433DB for ; Wed, 13 Jan 2021 16:22:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 878042313C for ; Wed, 13 Jan 2021 16:22:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 878042313C 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 68E3E8D0079; Wed, 13 Jan 2021 11:22:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 63D238D0078; Wed, 13 Jan 2021 11:22:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 553838D0079; Wed, 13 Jan 2021 11:22:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id 3F5728D0078 for ; Wed, 13 Jan 2021 11:22:12 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 10F68824556B for ; Wed, 13 Jan 2021 16:22:12 +0000 (UTC) X-FDA: 77701268904.12.event39_190603d2751f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id E6A5F18055A04 for ; Wed, 13 Jan 2021 16:22:11 +0000 (UTC) X-HE-Tag: event39_190603d2751f X-Filterd-Recvd-Size: 5146 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 16:22:11 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id u18so1010684wmu.4 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=cbjCt8DQeDf5Je4h/Z7R3nxkLu6d4B8lMnL/9jUGM+GIgnXXoM9zpF6o7V6Nyw4jdE pZZaXB7rhglp1XZzRwJQCCHpD0nyZhpZcV6djRC6YeM+f+/qHr1p512VqsKBGNatkFOs R6ynufBs3NN+KR1vSWS/GQJTEz1gi4tKDNkc6j1O6jZ3o+iRkEQ/HlCyLAx7ma8a5kvd K9RRInND8OhGXLoeYdG3/zTLnCVDLzBSRAsTH2oSfRK5UQIOay4p3S5e8R65BNqB9VkT 45rGewiDO3dRO2lUieSYs4d2Z4QbNtwO1xPLJAoPmTnZllQp0AeTs1suyHhiDYIb9Bsb XvGQ== X-Gm-Message-State: AOAM531n3VL2E7nhGGKR8O1PhOSqklgRzz0sMrrBQUegB/oeayvLdaF9 yCzYzORk4IOXVrKNMTScI3URgBVOBj0TldIp 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 Cc: Andrew Morton , Will Deacon , Andrey Ryabinin , Peter Collingbourne , 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, Andrey Konovalov 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: 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); } -- 2.30.0.284.gd98b1dd5eaa7-goog