From patchwork Fri Jan 15 17:52:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12023559 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.5 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 3B14BC433E0 for ; Fri, 15 Jan 2021 17:53:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BA6EE221FA for ; Fri, 15 Jan 2021 17:53:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA6EE221FA 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 B40E08D01D4; Fri, 15 Jan 2021 12:53:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AEF208D01D3; Fri, 15 Jan 2021 12:53:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98E928D01D4; Fri, 15 Jan 2021 12:53:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id 7E7408D01D3 for ; Fri, 15 Jan 2021 12:53:25 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 45EAD180163C7 for ; Fri, 15 Jan 2021 17:53:25 +0000 (UTC) X-FDA: 77708756370.10.hook32_1212ceb27531 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id 2596716A4B4 for ; Fri, 15 Jan 2021 17:53:25 +0000 (UTC) X-HE-Tag: hook32_1212ceb27531 X-Filterd-Recvd-Size: 5159 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 Jan 2021 17:53:24 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id k126so8755460qkf.8 for ; Fri, 15 Jan 2021 09:53:24 -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=ifrv61nnbwuahZCEiwjCwkZVX2MKhkqH/HoLspc9PnM=; b=vTETwvGiJABOZThdLEGDvx2ivUu23KL2qBe85GQ2khevnt+UiLKbHEZFfUnOq4GNLk qEQRZu2Rryy9Th2CbAjsJV5MPhk4d4wXovKLQW0Ge60/tF8f7gxVwDEynPo0GSJ8UzXS 76BSdfwWrmYxJc+ReiL5WAUkT6fy0dbh2URGuNq7lMXRza3iXqgLubGYMjGcju2p7GKG 3EKGiT0/Y8Xy02Qkh/YyLa9r+ewB6SHgkKeRMAuUDbP8hCjB+8ndVXAjVh1YZ9ttC9IB ArlvDDJZeldDhBey7DK9pNJdB/cBxSOaj0KonS02EAleUp5JjHggEc+tsnlgOb/DAqVb MPCg== 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=ifrv61nnbwuahZCEiwjCwkZVX2MKhkqH/HoLspc9PnM=; b=lewyOkYeGIj38AYG8ufrGoG0MpxpNxeSIrmgzqkdziGL1A8B83P6SEMtXlUT5tsUhc oKNoOP/CUPOKctUH2RUTuqGKp8lNsQxNuZO1vdLE2DncZuzGW+yHRMPZ041SV7yYLFtd hclJkQ6NTKlbvH/aKHCsm2HNJ/QcVSH/tlq+MDtPpCmM8hvMUfP5r+l3XJwjO6njIbpG h2m7+5X/euw04JPh2ZYk7vgSGkr1rmS/L9ExKPMl3P5yN/0izB26RLx64h/QztGJap1c HrtnZPSLyzTZKOnC2Fmfts6KoVunbK8ytA1r1h7d6hyqMIylpICqP8QxnD2IRgndgQKn AuxA== X-Gm-Message-State: AOAM531fsh+LFhg9tHkPMXIrvlnQcqm9nS1KmREHOLc6FzBgJsKXf297 RXiSLy4dJd51tsdT2OdL74I5C1VI6I+voWag X-Google-Smtp-Source: ABdhPJzBfQb6zE2y+OXiTp9u55l4FMz8PVljaEAfFdsjjaKCaC+5vFZX/LRjW8sQEZKI2STL25NXVivPrT2w5LX2 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:4c44:: with SMTP id cs4mr13129570qvb.25.1610733204089; Fri, 15 Jan 2021 09:53:24 -0800 (PST) Date: Fri, 15 Jan 2021 18:52:47 +0100 In-Reply-To: Message-Id: <7d452ce4ae35bb1988d2c9244dfea56cf2cc9315.1610733117.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH v4 10/15] kasan: fix memory corruption in kasan_bitops_tags test From: Andrey Konovalov To: Andrew Morton , Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: 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 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 0cda4a1ff394..a06e7946f581 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); }