Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp4718738pxt; Wed, 11 Aug 2021 12:25:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygvDHT8j8Rcg2VIHe5p7syrfqE9LyzIp3cqQ8AgyQASwM03QMbfaqn6fZxzr/ZoXWcbCtN X-Received: by 2002:a02:968f:: with SMTP id w15mr385513jai.21.1628709919784; Wed, 11 Aug 2021 12:25:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628709919; cv=none; d=google.com; s=arc-20160816; b=MMnUrCnlpmIPl6OitcUkzXnKwYhwZ7mIJLSP0n5b5l8BdFNgKtw77qpeOCnNpB5DPA OkTP1bjmxbrU3d6ctcenteTLlhV+vrG4XeAeQQRupW8eirgT8BZ88EotLCPuMASVsnbc OLmrp8Hp4qO4+eeRuxuBi8dPFWMtIJp6jO3g6/8j6PX3RK+PCYH0We8B8LsOl9sJxJ/v Um43ttmn2aPBlqJxgNG4Sm6+xSx125CGVJYclUid3PDHcyxOQ9OccEELcOj0sr8dfL1M rPwyhsFlhTVdyBHiHl9lGEIm/KfAdvsCyXQlJ9JctJMCExP8Nb8sHyNFT4Bo6SfQ7Aqk 6U1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=weuZVW/Ysc7M7eQ1iHh/6bngJdzeOf6q/ORvgfr+R4s=; b=PJjFIvQMzHdHZFuE49oxU1xKDhK3lUjmFNc4b6h8Ao2aKdG9zKXwGkxc38yPgjCs3S 8wOlK95gFbTyahKNUoXj1OBmOHEEadQUvWqLm7/AwzkwjNEgdJr/HZhJSD9nNNJV/7Ys BKSKHXqoza+9PKymoN9Shc4avfcf8AgANwDZ303V9ulC6Nlh5Hhks+vxmUqSozpWD9Bk 9C65/2LjtBNrPMZG+EvUX62GTUm3C/QH7RJKAJKJvNUE2zDZDRzc786hnT7MQti6jHsJ oo9W2zJ/rgMC/PreWbpS0EBr8qGMUc6L8jSDYwvpUufFnYshb+HEkmLnRyzpLpVMMvh5 GFhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=XO8QCcYF; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i20si369225jaj.74.2021.08.11.12.25.08; Wed, 11 Aug 2021 12:25:19 -0700 (PDT) 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=@linux.dev header.s=key1 header.b=XO8QCcYF; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231571AbhHKTWR (ORCPT + 99 others); Wed, 11 Aug 2021 15:22:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbhHKTWK (ORCPT ); Wed, 11 Aug 2021 15:22:10 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 236E0C061765 for ; Wed, 11 Aug 2021 12:21:46 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1628709703; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=weuZVW/Ysc7M7eQ1iHh/6bngJdzeOf6q/ORvgfr+R4s=; b=XO8QCcYFDJ2MHdaAQPXDvcKAFeYXPP0VgmGgx84cl5OM2Fg618wUtnRX+NQ+t4gecn8rJs ZKbV3BBoSSRBJYrNVjV/w3jBSVybAbwxpn9AEvNQ8VZIBeEdoxcby2867I/qefvKtoH/oq /jichHZdhMrUYMCelNPZzjowE8WthXI= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Andrey Ryabinin , Marco Elver , Dmitry Vyukov , Alexander Potapenko , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/8] kasan: test: only do kmalloc_uaf_memset for generic mode Date: Wed, 11 Aug 2021 21:21:21 +0200 Message-Id: <6e0ddf32ce140b9e8aaf127e9e40cbfff4430995.1628709663.git.andreyknvl@gmail.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: andrey.konovalov@linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Konovalov 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. Signed-off-by: Andrey Konovalov --- lib/test_kasan.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/test_kasan.c b/lib/test_kasan.c index 0b5698cd7d1d..efd0da5c750f 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -528,6 +528,12 @@ static void kmalloc_uaf_memset(struct kunit *test) 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); -- 2.25.1