From patchwork Thu Sep 2 21:57:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12473119 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 0A134C433FE for ; Thu, 2 Sep 2021 21:57:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B698660E8B for ; Thu, 2 Sep 2021 21:57:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B698660E8B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 5B66D6B0149; Thu, 2 Sep 2021 17:57:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 565CB8D0001; Thu, 2 Sep 2021 17:57:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47DC36B014B; Thu, 2 Sep 2021 17:57:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0221.hostedemail.com [216.40.44.221]) by kanga.kvack.org (Postfix) with ESMTP id 3AD026B0149 for ; Thu, 2 Sep 2021 17:57:46 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 005551841C1C4 for ; Thu, 2 Sep 2021 21:57:45 +0000 (UTC) X-FDA: 78543996132.18.5464A0E Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf23.hostedemail.com (Postfix) with ESMTP id B0A9A90000A0 for ; Thu, 2 Sep 2021 21:57:45 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id BD3A86056B; Thu, 2 Sep 2021 21:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1630619865; bh=faqvaT+OtWaijztr6/+B5xpjvZVs0AYWxQVp+sdCfz8=; h=Date:From:To:Subject:In-Reply-To:From; b=lsJKYTGKUqXRcVlmpYAHPmysEzKrXiPcT/tVV/f8rQgr1QJZcbpV59XprfOwQdzAG dtFG/mdQ0q6veTZX/0mMFqgEMgUlT17yzVZYqH/Uv6UWVXP7Z1EbE+T3MFfwxNLRWl cbCC9d4uTbp9qtJvTvK2xdZY5+5uJMQ9AdK2DhUs= Date: Thu, 02 Sep 2021 14:57:44 -0700 From: Andrew Morton To: akpm@linux-foundation.org, andreyknvl@gmail.com, aryabinin@virtuozzo.com, dvyukov@google.com, elver@google.com, glider@google.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 146/212] kasan: test: only do kmalloc_uaf_memset for generic mode Message-ID: <20210902215744.wv5bAMZa1%akpm@linux-foundation.org> In-Reply-To: <20210902144820.78957dff93d7bea620d55a89@linux-foundation.org> User-Agent: s-nail v14.8.16 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=lsJKYTGK; dmarc=none; spf=pass (imf23.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B0A9A90000A0 X-Stat-Signature: wwtkdray45rkqkouw1xxpmk9ro1sqbfe X-HE-Tag: 1630619865-916594 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: From: Andrey Konovalov Subject: kasan: test: only do kmalloc_uaf_memset for generic mode kmalloc_uaf_memset() writes to freed memory, which is only safe with the GENERIC mode (as it uses quarantine). For other modes, this test corrupts kernel memory, which might result in a crash. Only enable kmalloc_uaf_memset() for the GENERIC mode. Link: https://lkml.kernel.org/r/2e1c87b607b1292556cde3cab2764f108542b60c.1628779805.git.andreyknvl@gmail.com Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver Cc: Alexander Potapenko Cc: Andrey Ryabinin Cc: Dmitry Vyukov Signed-off-by: Andrew Morton --- lib/test_kasan.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/lib/test_kasan.c~kasan-test-only-do-kmalloc_uaf_memset-for-generic-mode +++ a/lib/test_kasan.c @@ -534,6 +534,12 @@ static void kmalloc_uaf_memset(struct ku char *ptr; size_t size = 33; + /* + * Only generic KASAN uses quarantine, which is required to avoid a + * kernel memory corruption this test causes. + */ + KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); + ptr = kmalloc(size, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);