From patchwork Thu Jan 14 19:36:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12020763 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 D8B06C433E0 for ; Thu, 14 Jan 2021 19:37:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8A0102399C for ; Thu, 14 Jan 2021 19:37:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A0102399C 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 B5D508D012A; Thu, 14 Jan 2021 14:36:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AE3B68D0129; Thu, 14 Jan 2021 14:36:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E8118D012A; Thu, 14 Jan 2021 14:36:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0069.hostedemail.com [216.40.44.69]) by kanga.kvack.org (Postfix) with ESMTP id 7227D8D0129 for ; Thu, 14 Jan 2021 14:36:59 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 33558181AF5C1 for ; Thu, 14 Jan 2021 19:36:59 +0000 (UTC) X-FDA: 77705388558.19.cork27_0105de127529 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id F12711ACC2B for ; Thu, 14 Jan 2021 19:36:58 +0000 (UTC) X-HE-Tag: cork27_0105de127529 X-Filterd-Recvd-Size: 5157 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Thu, 14 Jan 2021 19:36:58 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id c14so5331856qtn.5 for ; Thu, 14 Jan 2021 11:36:58 -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=svvurHrHAcNYd/CQpQXSFQuHa9Ng8oBiXsZOqVosLsBBpuko4Af8P7jmQDjInyf/fM DVIWn495lGvWTbxs+rpvrFbIHurmf+B/mdK1L18doOeUSBrUSD0brU/9kX/U1vm9qhJp kAs3xT0lWdqqiAiB5sVUJRyWfszLq7mO6QKFsTd+Xr0wyHtJBEs1Q/EsEtKybR9gotZ8 fjvT4ue9G6yBvYVXQR2ZABb8kp4QUr/3SMVaLi2E2Gy5DAeBAVyEav6RLmYpuLVm39iH eF8aJCJfYsIXVRHUQvFWd76xKwZHT8LIdDjWrMcFRwQSPDyVhguE8MAnZaOzY5p5g985 PCHg== 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=U5E1DcPXmf+IRd12ga8bU5saVDZmGHNBQ1KS+Ugq49V98s8x57WfHX79m44QO/1lYV TZiS/gtrEnSn7iDgQPbJzI9GkObpv16EreHmGosRNbaECZScnKs0jlfrcf6wczSAWgSf /Y8qmCp8ybxdzcDqkJIjJUfMedP1gpTPzHiy0Ya1IxU4eAQGsc/AuarMzf7mFeQKqPJR ga4rB/v/1s1GN4cZ9VZAGq5oyOJ6ETvbwDP6zTZCMT41n3pmmWcqRfHAg0HTR8MaB6UK oOAMk/BVSMBplL4UJZo7mSlIBItxQdtULoKLQ0QDcBweaFfjfrwBgnpITCds5MXrMcz0 o/lw== X-Gm-Message-State: AOAM532vklIhe+9GFY+U+/vRNrggKYS4FPvZf2u3Il0jwV86FGhUCaON DBrraATZwseUSpRS+CmbflvrKKx3vsMKjJ9y X-Google-Smtp-Source: ABdhPJxsaB8DotGQxWble5pFmykfdTGG5ArjTFhmCqcwhqBIGlk7Tsyswg8ZcoX/blfWQVd4MH1EYIJAGkRqexxn 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 cs4mr8625788qvb.25.1610653017877; Thu, 14 Jan 2021 11:36:57 -0800 (PST) Date: Thu, 14 Jan 2021 20:36:26 +0100 In-Reply-To: Message-Id: <5232775c82fe249ef3ec0a1e8470ec54eceb5002.1610652890.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH v3 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); }