From patchwork Thu Feb 24 00:20:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 12757747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31C3FC433F5 for ; Thu, 24 Feb 2022 00:20:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B1B68D0002; Wed, 23 Feb 2022 19:20:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 961998D0001; Wed, 23 Feb 2022 19:20:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 802678D0002; Wed, 23 Feb 2022 19:20:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 5E6908D0001 for ; Wed, 23 Feb 2022 19:20:46 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 11263205CD for ; Thu, 24 Feb 2022 00:20:46 +0000 (UTC) X-FDA: 79175767692.07.43AB452 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf10.hostedemail.com (Postfix) with ESMTP id 6E2A9C0003 for ; Thu, 24 Feb 2022 00:20:45 +0000 (UTC) Received: by mail-yb1-f202.google.com with SMTP id o5-20020a25d705000000b0062499d760easo318693ybg.7 for ; Wed, 23 Feb 2022 16:20:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=d5dLzGHZ/03S2GwnSJZ7atIUIHBRbtyGlBVTRxvEnP4=; b=PGhrk29E4gaPK0VSM9m4SYYFNB8byuIYTyilg6iL8qEgAy+DUiTuwXd7DwWukyrYDH HODoiwtt41htHibpJCxw2SNj3gA/5wHQTPpT3FY7jUCgzKZFwnrFWiRL9etRFbbYwpfp ZDbOwmboFlG6R+8FIOeJ+SE1/iyRV9rtgNBcHSrJGs6nNbTJUdiNe3po+yiRM7lowpcT h4COXZ3g1PUUgIYa8UfcVw94kUnoARZHjSwXwBsmjFdxYXGPhHIdAPIgF6sIsUycN28Y 10boTttMhEfGpNXIS6ZYFYT/yS3orWUjXjSdB4rQGZ32OgUftqMZwsu3cfw6kgEzQSKD G3iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=d5dLzGHZ/03S2GwnSJZ7atIUIHBRbtyGlBVTRxvEnP4=; b=wZW5G5qpCZDoow3pDAAj3orhM5FUHLFRZG1iuEN51LLjZNAwN8SyQe1KnCMsHFlXwl E4xamKTlAM4C0bLJ0lZnowtpwnM1kCP/AkteGIZ4mp6kEaWkO1OP+NtQlr16wglTWiLb /OAOGP0/uNcYqt1mh2E66+3sFewfrmaIUoOBuCp/3rpUiPYzUFHVpePnG9NausUfwJqR gujpNJI8n6lrfwMeqyQB5HFu7SV7/wxVJnXO9Hf1erQTAdkWEB2VnL8j3p68YWwIARQK 5zjk2GJpGuDbSyIdFPsDJeOMiyY3xKc2O3jwCVHTB+9Oq6mEYOYt5oN2fnG8rZ4w5uNy +DeA== X-Gm-Message-State: AOAM5319TdMYcHG8T7NocMztTGtY7Etl8hbkvXI2RZr1pyVdmDKmuUWQ 5l17EIO+ihI/CjxrLYyoM6HRgJw= X-Google-Smtp-Source: ABdhPJzHJzd8T2fG9kRGkhwLudz98Mmh+GT6Rb7XdX1haa3CGWXiOCcOvzUyS8xw4PF3T70uQA4HBkA= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2ce:200:ef38:18a6:8640:7dc1]) (user=pcc job=sendgmr) by 2002:a25:7:0:b0:623:abbe:e6e9 with SMTP id 7-20020a250007000000b00623abbee6e9mr200654yba.547.1645662044312; Wed, 23 Feb 2022 16:20:44 -0800 (PST) Date: Wed, 23 Feb 2022 16:20:24 -0800 Message-Id: <20220224002024.429707-1-pcc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.473.g83b2b277ed-goog Subject: [PATCH v2] kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled From: Peter Collingbourne To: Andrey Konovalov , Marco Elver Cc: Peter Collingbourne , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Nick Desaulniers , Daniel Micay , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org X-Rspamd-Queue-Id: 6E2A9C0003 X-Stat-Signature: 36h8fkaxpqjfx4froxc7wm4opspb4ooy X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=PGhrk29E; spf=pass (imf10.hostedemail.com: domain of 3XM8WYgMKCG0aNNRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3XM8WYgMKCG0aNNRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam05 X-HE-Tag: 1645662045-98975 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: This is a followup to commit f649dc0e0d7b ("kasan: fix unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled") that fixes tests that fail as a result of __alloc_size annotations being added to the kernel allocator functions. Link: https://linux-review.googlesource.com/id/I4334cafc5db600fda5cebb851b2ee9fd09fb46cc Signed-off-by: Peter Collingbourne Cc: # 5.16.x Fixes: c37495d6254c ("slab: add __alloc_size attributes for better bounds checking") Reviewed-by: Marco Elver Acked-by: Andrey Konovalov --- v2: - use OPTIMIZER_HIDE_VAR instead of volatile lib/test_kasan.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/test_kasan.c b/lib/test_kasan.c index 26a5c9007653..7c3dfb569445 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -185,6 +185,7 @@ static void kmalloc_pagealloc_oob_right(struct kunit *test) ptr = kmalloc(size, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); + OPTIMIZER_HIDE_VAR(ptr); KUNIT_EXPECT_KASAN_FAIL(test, ptr[size + OOB_TAG_OFF] = 0); kfree(ptr); @@ -295,6 +296,7 @@ static void krealloc_more_oob_helper(struct kunit *test, KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x'); /* For all modes first aligned offset after size2 must be inaccessible. */ + OPTIMIZER_HIDE_VAR(ptr2); KUNIT_EXPECT_KASAN_FAIL(test, ptr2[round_up(size2, KASAN_GRANULE_SIZE)] = 'x'); @@ -319,6 +321,8 @@ static void krealloc_less_oob_helper(struct kunit *test, /* Must be accessible for all modes. */ ptr2[size2 - 1] = 'x'; + OPTIMIZER_HIDE_VAR(ptr2); + /* Generic mode is precise, so unaligned size2 must be inaccessible. */ if (IS_ENABLED(CONFIG_KASAN_GENERIC)) KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x');