Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp728655pxt; Thu, 12 Aug 2021 08:20:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXap6m7UleGgtF/Z0nhyEZKUiasBA2ZEhIr06pe5pWsvl4+yUWmF6emZ8DLAYr/GDFCz3D X-Received: by 2002:a17:906:c443:: with SMTP id ck3mr4094897ejb.195.1628781610480; Thu, 12 Aug 2021 08:20:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628781610; cv=none; d=google.com; s=arc-20160816; b=gzfjLM1JCrvIdi30U+l+NKeCuIGKy8ojNVuzF7qDuA3Kd2o9kF0kju9UMJubTHMWLd JkgMxLnrHmqNhliUzGSexQKG9QQpSmX4Fl3+QnMFZkOR7PhQqmRb5V3xkdJkLafmlucG UJ4KO/E6Mdz9foYoEBRcn84dSyhovK3YbZyhNLjHr4TAdYwS99gcdATwZgakmj5fewPD VgOojjvbzNTY4t0P6dKp/Qi82j6+p5Ldz3g0CEy9NSGwunkLGAxcwlzdbM+PMOFtQwpT FQvp4YBrLQEbNWk6ie28snYqUB7zPdEJ081R/zGINdjU9a9mB7ntRjHktp1rGofHqH53 W26g== 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=nFE484nExSDg5Ok/GAjUckuGCTsrDMPO22KkRkoS4wU=; b=oqMYswkkq7KjyCalhii1lkj2A/BgZ+VUbGIl+lSvxZFNjdYBD+pbi8WQt1LzjlqBIM ojenM8GCGVPeNo8qIutLDPd1Hkd+lxczE2YM2s9nrfh9vG6sDhrKzhOuTqqvCMGo9pZR mBAvwbw+210U0obGUfNu5mUlaIm2NtE6VqmzfIRkOSBJM6PwYoGRYWE9cRQPhtFzbIEm YTrCSzcnFhjqc9sDQLa266ckOSU+Dapjopt3cROCJkm0SpzwaxhaAVufwmhFULwtcGfB 6I3nCQP3+JLspy2eTGPBQKZJ3z/vSm30Uexx+P+qJtSWjBKTaAW8rY75ODhgS7eR+16n NmEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=pr6XeKYA; 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 g14si1596390edv.296.2021.08.12.08.19.46; Thu, 12 Aug 2021 08:20:10 -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=pr6XeKYA; 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 S238215AbhHLOyb (ORCPT + 99 others); Thu, 12 Aug 2021 10:54:31 -0400 Received: from out2.migadu.com ([188.165.223.204]:65070 "EHLO out2.migadu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238178AbhHLOyT (ORCPT ); Thu, 12 Aug 2021 10:54:19 -0400 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=1628780033; 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=nFE484nExSDg5Ok/GAjUckuGCTsrDMPO22KkRkoS4wU=; b=pr6XeKYAMprwvuBBdX/lt+F3QwTj3fGUhv4IEAotjC/4BaZkHHf7XeolnzIweVIW6LCyyW EPOKOwqPtC2QGXfPPurU+h1aTQa1PmDAu7Tgj0c3dqunydSrIQDWGL7bYCjuzOVAWNhYsn YcmE+DR0rDAgOM8kUwC5Bk0rGoGw/lg= 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 v2 5/8] kasan: test: only do kmalloc_uaf_memset for generic mode Date: Thu, 12 Aug 2021 16:53:32 +0200 Message-Id: <2e1c87b607b1292556cde3cab2764f108542b60c.1628779805.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 1f533a7346d9..1dcba6dbfc97 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -534,6 +534,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