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: 12020739 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 DE137C433DB for ; Thu, 14 Jan 2021 19:40:34 +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 6712D2343B for ; Thu, 14 Jan 2021 19:40:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6712D2343B 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=Rt2tGe/LvYeFkjYnaLlNj8aSHf3UGTIWYTCGK1k/LLI=; b=oJsKRsmsome6oUyMt63vN8Ean ICY0JBXwav1VGKJNSu+MtaYYQH1Lq4oBPmeFQOAz7n44AUimeysjfweManyz/56vMxLdyc9hB5vkI U77oa2aV41QEQ1rypnfI+12O9QQgNr6EzMQLHA8b50gQQDI904VTzBL5IUs6TGDK7XvPanSqfh4k/ uEojFrfmpyv3PU3N2MP5+aCbPz4zuxt+0GAxr2OZbWeYRcpb6zdtO0BORlwApTyMHntZJ7avX0jEB 1Fqi/IRYf8dCp8M8cKGmsuJJ0rrPO/A844mgaTkfmMkj/mb61HpUlp7rltqH6VYMgiCDwPLUdHjdu cnx7ehJlQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l08Rz-0004s7-LV; Thu, 14 Jan 2021 19:38:31 +0000 Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l08QY-0004H4-Hz for linux-arm-kernel@lists.infradead.org; Thu, 14 Jan 2021 19:37:10 +0000 Received: by mail-qt1-x849.google.com with SMTP id i1so5321597qtw.4 for ; Thu, 14 Jan 2021 11:36:59 -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=LJY34e99N6IfBcjUNcSH5hFWPS92BatX2ebv5z53Bwug+ZFR6XjlzcZyE2fLMuFOp2 /kYIA3kce3I2FgbOhtzYmLXK4z1AkMqDIWVTz1czeIqwgguKDEa9VGXzPcAagyw8IB/W RpYQb7PPi1TVwe6DheYuw/xDiMf2JvHInzBIwuPDXMqtzWkWCj2jVF9voc9otwe4pIjY gx4CHlp76eflVjfuwuKHJ6ZddZuJpauumbG95LyvXl+YkvEH2atLeTmZuAfEC4TIumEX tNSTsI8zEBoOinL8RGG9NqUNS7CO83YweGmXjYY4eCjK5RkHNIXZ/PnMcfo3Q/h/zjrh uI2g== X-Gm-Message-State: AOAM532lYBHFCSe7hmoxG+2uDpBs16wEhrIZInID+iJmZXvPayzJynOq jsHSiwgH9QHlzNf7lMxzktkGxWTiF8P3cg8l 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210114_143702_761818_1E94458A X-CRM114-Status: GOOD ( 15.32 ) 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 , 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 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); }