Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5654316img; Wed, 27 Mar 2019 12:31:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqyCiW7YjKtIsy8sfKhYAx3gQbk1s0APefQBpq9nXOOM62SBrwSOdWNoIhJ38Q/opVwXhGSt X-Received: by 2002:a65:5049:: with SMTP id k9mr22970905pgo.229.1553715108004; Wed, 27 Mar 2019 12:31:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553715107; cv=none; d=google.com; s=arc-20160816; b=RnEqdHp2IC0AKxU375Q+PaGzMCDds7QR2YLfuPCKc+sVlpEO4sRM/u2z1c4tlZ8CAC HHlnvAF5jUzj0AuhIzfV4KCJ2j+AK11uR+CtP3A/IyEa7/LfDzBaLpANSf2WCk0nivaU S5d85rWlto4418ksJUO9MnVz4+KJGgkK1Xv53HeIUIjKbBq69P/t/AKXW47AgaLCjD1t hlyr0uvP4P/7FlAwQvlhh9GNItYU+u+nfUkn/xU0BxtCJ8MSelmUkHbA6MuV5IJq50XB 6dZmHrTV/QDDahGvILFQ0gK0MwUfgVRELzMcSKuF/Brng6rlBpiP6vnb3uUvXtVIaL18 sD5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Jr+PzPGb0B6CDRISq/SwheQLQ1nMXSDO/cNUisVg5MA=; b=BeZS8nLlRxR2yebEt4J3w9LJkJ7IVzN3Pu7RtDhodgM1BlOPSHp3eSVlPk68yD8szJ NeeJ6ouayhTpRdkR1xX5SfDpiev/f8O6gPS5dMNNCG08BlASAJNvX4onMm1caGHRO279 AtCrsptAfDnsQOScohOqVSMV00PReVBmt8XVDkIftmtuNmxcXStoy8ei7WPQHOuwHV2q vsKM9K4QwCp8YS2a7YYF+mIqe3Ue6OVyOBuDnA7kWa0BGb+kHYQjB/+oWlGF5Izb4vvV KWyLkyJR7vncwODi8GGJ25mi6pxR5F3JB8HvMjwNJdz1mN7ZukXkB5rOjmobvoFcJBNK 9mGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AMv18hDC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n10si18585373pgq.287.2019.03.27.12.31.32; Wed, 27 Mar 2019 12:31:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AMv18hDC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732397AbfC0SDZ (ORCPT + 99 others); Wed, 27 Mar 2019 14:03:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:43564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732295AbfC0SDW (ORCPT ); Wed, 27 Mar 2019 14:03:22 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 792E92147C; Wed, 27 Mar 2019 18:03:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709801; bh=FRAKY1CotUHVxCnDmq5Ek+oJvURhXLmI4VPfroxhSlY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AMv18hDClKoNkxSJW4rz3ZQgQoO79fQhRGIqlyrVYdFChnGnPqjqSzNkYrLxM3HWB a6Z23nvL/Ed9S7W1P0cC8Fi++Bc0/dL9U6n7dOJGaBjd4Php5asdUF66fMNINCTgD2 4QD5B91VT3m/U3Ck2aeqO3vpKE1in4vEfULnUNmM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Qian Cai , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 5.0 044/262] page_poison: play nicely with KASAN Date: Wed, 27 Mar 2019 13:58:19 -0400 Message-Id: <20190327180158.10245-44-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qian Cai [ Upstream commit 4117992df66a26fa33908b4969e04801534baab1 ] KASAN does not play well with the page poisoning (CONFIG_PAGE_POISONING). It triggers false positives in the allocation path: BUG: KASAN: use-after-free in memchr_inv+0x2ea/0x330 Read of size 8 at addr ffff88881f800000 by task swapper/0 CPU: 0 PID: 0 Comm: swapper Not tainted 5.0.0-rc1+ #54 Call Trace: dump_stack+0xe0/0x19a print_address_description.cold.2+0x9/0x28b kasan_report.cold.3+0x7a/0xb5 __asan_report_load8_noabort+0x19/0x20 memchr_inv+0x2ea/0x330 kernel_poison_pages+0x103/0x3d5 get_page_from_freelist+0x15e7/0x4d90 because KASAN has not yet unpoisoned the shadow page for allocation before it checks memchr_inv() but only found a stale poison pattern. Also, false positives in free path, BUG: KASAN: slab-out-of-bounds in kernel_poison_pages+0x29e/0x3d5 Write of size 4096 at addr ffff8888112cc000 by task swapper/0/1 CPU: 5 PID: 1 Comm: swapper/0 Not tainted 5.0.0-rc1+ #55 Call Trace: dump_stack+0xe0/0x19a print_address_description.cold.2+0x9/0x28b kasan_report.cold.3+0x7a/0xb5 check_memory_region+0x22d/0x250 memset+0x28/0x40 kernel_poison_pages+0x29e/0x3d5 __free_pages_ok+0x75f/0x13e0 due to KASAN adds poisoned redzones around slab objects, but the page poisoning needs to poison the whole page. Link: http://lkml.kernel.org/r/20190114233405.67843-1-cai@lca.pw Signed-off-by: Qian Cai Acked-by: Andrey Ryabinin Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/page_alloc.c | 2 +- mm/page_poison.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 0b9f577b1a2a..10d0f2ed9f69 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1945,8 +1945,8 @@ inline void post_alloc_hook(struct page *page, unsigned int order, arch_alloc_page(page, order); kernel_map_pages(page, 1 << order, 1); - kernel_poison_pages(page, 1 << order, 1); kasan_alloc_pages(page, order); + kernel_poison_pages(page, 1 << order, 1); set_page_owner(page, order, gfp_flags); } diff --git a/mm/page_poison.c b/mm/page_poison.c index f0c15e9017c0..21d4f97cb49b 100644 --- a/mm/page_poison.c +++ b/mm/page_poison.c @@ -6,6 +6,7 @@ #include #include #include +#include static bool want_page_poisoning __read_mostly; @@ -40,7 +41,10 @@ static void poison_page(struct page *page) { void *addr = kmap_atomic(page); + /* KASAN still think the page is in-use, so skip it. */ + kasan_disable_current(); memset(addr, PAGE_POISON, PAGE_SIZE); + kasan_enable_current(); kunmap_atomic(addr); } -- 2.19.1