Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp490231pxb; Wed, 13 Jan 2021 08:26:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwOKfFMLxZHfG19pKuiyJk+U+jyEHti+WL+m88Wv+RMugx1dNa+QZLt3cRybFrwjYg5mwVt X-Received: by 2002:a05:6402:3074:: with SMTP id bs20mr2429263edb.365.1610555218227; Wed, 13 Jan 2021 08:26:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610555218; cv=none; d=google.com; s=arc-20160816; b=UXeB/5WTC8x4ATT8iePo1vzyhdoACBQcnThRbI+Caa4UrpbyuL6fTwkyRdjKV/HMvw ZEdd+FPO6AcwKU6mW3rC+KcXpH4oqQu74qvf9TmHid1wgAqeEO8OLWJbiPzyFyv5dS+Y XFf7g64uL5AyB3fMjxYfzC8kH0v7UVE56U9SHkCgVSIw2udYVHySig5LY1GWXQFAS4rv CxptA9t92x6652fy+NoCOeHlv5AiYJoMadt9BXG9FpPFW0/YwtLaSJMs473fS84LnHj9 b2goRio4nEFJKpCGHQqfZ8zZuIzcJrXtQixG+2tl82+zjfHuM0R6IukirVf87tPMJC6H IBIA== 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=L1Lauf2F6M7nowmjOy2kFR6Fh9wMsHUDYRnyLelpHLk=; b=FAMtip/JFvY0Vu2cngP5YeYvWN/dZuJodeN6SWjLewob6bBNIZDHHK+x221Hblbano KzMfefx2o/ifhGsKc+wr8J525iuZiw/4MtX8DUryEzRCrQhoEbQZJJl17qrdvdPGZpFs qzOEhTsxUhK3T1YPo5ecc/lmnWkN7qVYOGcGjKZZdItnZ1CH8EMqn+RhK4W23+/H3xLu KB4vfR0wfXd6CSlQRMH5IxIMY9e7JtECa3BREsW+szHJ7XLHRPvxfoLb2YEBGt8762B5 Oe0PWvqYDyC5s40TaqQhYZ79OCfZfmIaDPY+4U4xFXCHz1y6sCrkhSedWvvv6xSf7d7S N2mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YLqNMyj7; 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 f25si1258912ejh.688.2021.01.13.08.26.34; Wed, 13 Jan 2021 08:26:58 -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=YLqNMyj7; 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 S1727883AbhAMQXn (ORCPT + 99 others); Wed, 13 Jan 2021 11:23:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727759AbhAMQXM (ORCPT ); Wed, 13 Jan 2021 11:23:12 -0500 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4675C0617A7 for ; Wed, 13 Jan 2021 08:22:11 -0800 (PST) Received: by mail-wr1-x449.google.com with SMTP id r11so1174516wrs.23 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=HwxS55SdVJVgKSsAcO0So+qa2PIUGaZH0a58p0QZLu1YnplOOIrEjC91xKjvFjKfjZ dCg7YbGdXvxA/fRWX6ckt9fA8uBqQ4z9ZuAEoDz4S4otwmsd+yRVkOLAkD2TcLoIgTGw 5D9eQaJQ9b2PFP4z+2qZG3zAKL+0FKqW7UqBkZvmnhEpgz8r9vQS5zqYlDOOA5BON7n2 s3XUjPOrRoc3MCvCRaGc4JLWhjlfWbQ/km+syuEc5ROqKT+cSojcBbH8CivtqUc8ofPX Jlg402e2qU0B+BZuokm/25MMbbAbRna2xEi9lq627li/RLHR5Lu8kiBZpU7Px/k6WGI/ nuhg== X-Gm-Message-State: AOAM531Ywb1PnwyKZmtNsH1E1wpuaJlCK1YpjHwh1lB0gMmgaXFLmYiZ xqEUi+1YvK4wscEiJWtvUydiq6FgrDJUXDGW 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: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" 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 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