Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp166056pxb; Fri, 15 Jan 2021 09:55:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVZ0Gyv9i42nxwKX9gxj+7EahHKGJVXoCOPQkRBmsRJ9+IYuyhQ5StsxzO0U3rX1ncoJpG X-Received: by 2002:a17:906:1308:: with SMTP id w8mr9449056ejb.396.1610733331109; Fri, 15 Jan 2021 09:55:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610733331; cv=none; d=google.com; s=arc-20160816; b=OGQ+990lr+cC9G0Ph4XJsp8EGfPnTHdhF00l0a+e+8baxNXF8rWqR5xLNdk2mU8RoO L2PJ14/mJp6Pcf1oWPkOQC5lhBP4LW+wzRlSOLRs5R9hrV5uylPoM3/iVYJ+zepUde98 mhXvYOWLb3aoNSbG1v7B8HA/TqY2QW5THl7EL3S9Fp6A8WbAGkL/gGNgeuDu74FlT6Tr k3VZ/XXziTf9xErsZ/we8BRygJBe0JZorGKUmUCO4vf93JOSkeu8rlB4pIuBId8mN3UE EJQ7Vrvdq+wn6NtSjIsP0EUoRyjEwbklSu3i3dNMj+ycDowD/ea2zJRPuK4iZdMFOaLi zdYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=ifrv61nnbwuahZCEiwjCwkZVX2MKhkqH/HoLspc9PnM=; b=hVCbVd/qlHhCygQMJtZuGuH7FVEYtRkU2f+yzshAPsBWf/wL8Lri3Vx8RppYFSnKDo CfxBg++X/9h1xheg5ihal65JAYfgy8AaHnC7WM7sPRvIwPa7wImtKYTH0LmEK30PiYzp twCie8oyNmdOt/CbOseskUZXiGo9K2GFse/Lizog6j5hFxOCfxQSmnB+6AI0i5iEu4aP wdvttBGgu6Xe8SBiDXh01WoBuUefBnfQy5OGNDa2BadjIGexBmyG9z93K55FKuwrep2W jmC7EgY9r0khaO3ZYwMZhshJMNgdmoUrV6TUDEjccf2vownw5qTfVoxggBSINDJO1uSO 3qbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vTETwvGi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a5si3994835ejc.573.2021.01.15.09.55.07; Fri, 15 Jan 2021 09:55:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vTETwvGi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733286AbhAORy2 (ORCPT + 99 others); Fri, 15 Jan 2021 12:54:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733220AbhAORy0 (ORCPT ); Fri, 15 Jan 2021 12:54:26 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02F8BC06179C for ; Fri, 15 Jan 2021 09:53:25 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id 189so8760348qko.1 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=WeA95tjaTpcUyBvg6nx+qGhRk+8MeSMhK2+SAMOVYJx5/2wzqcAb97fSzl25BGdNop 7zGWcXAgcLEDb8A9zEE38EEYg8cY/v6Bjdi+HREJvH02DysntR018CKmMfFlWbpjIG6D MKDo9d+KySfzIC3Bxn/29hL0PmHltQKJRbnQAuM2w9E+nTpIDrP813YGVQrQ0/NYKJ2n CLPh3e9yjvXuj8Q0vITGOlZYwSA9dvQrm+ZL/BhwMVMb4+yBp1e1jaKg8Nls+7dy6x83 +hSfCuN+q0Xcxt4V9s5KbVpZw3RXVIlckAmhG5XmoQBfLhoTdw4IDyo8F7V3UH8U4SLC MURA== X-Gm-Message-State: AOAM530G4XaKjm0tqfyUt+tylS4XFzhwcGE4sYZDnje3CMQ5+fPElWZA Ykt5H2JVlwa+bcfL2FjDqHgwqyazO7ZkVkos Sender: "andreyknvl via sendgmr" 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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); } -- 2.30.0.284.gd98b1dd5eaa7-goog