Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp996306yba; Thu, 4 Apr 2019 02:02:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzh/8bZ1nVtjmfZzmdqzLORSxXMIvKQf2cgPKVinODUy8mGJ9Qj9aoWy+WgHj6JEpJlCb8H X-Received: by 2002:a17:902:822:: with SMTP id 31mr5278271plk.290.1554368559724; Thu, 04 Apr 2019 02:02:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554368559; cv=none; d=google.com; s=arc-20160816; b=Bv9JYfnLtrrwAXZGzn7WFO3Yv0l4imUdrRpVxTj8LVKFV0zZLde/LKrC6ULMpKS21P Vv60FQ9luhKAe8tmwsyZJhGOxgZsMzxIldf5U7QKn1S+cTkcJSAHby7N55B3OjyXIG5o IzNdAEby+0sqXAjVJjrjG3tCYjgisikmJlSQCrnBq2yks0/xc1RQo55miwE2O3x1qVqD ocUW8UhBpBfdQsifA1Fa4NWPCWCQRlWWvTkV+j8KHqTaYzUEbSWH7+hVbAj3yt6qtrYb cLQtc1SUUf0sKanm49fGVTtxXYWGYEAcfPqspDWuNfMyOxvYPlUJaULsHrkA8KC8cFV7 z58A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DDfdrUjJ4c+oy+zHklASGxIDzZ9kll8qpEQy7mhHC64=; b=YAA0AeYLik0kIX6TOVct8tQzC8XlvRORDNB2bLmj5rF/8fsIzLJI9zayvJvdPNanBN sjNOdo0uI/rEbfDW7JEgRvxdica+QqRYE+8/xyw3D5tV0bOsS6TXvN1KCyGLR0fum0DH OXvSdPtRP4idMnF+6V5mOKsHyuF3B5BshEKnSaGZL0z/S3H3cYNKd9oTYVg4RGaq87aM /VryE0Ib93YzlNnpH0dY2G2uXXmts6Q8rbqfAl4QA8KhVahz27+H/2ov50BCFQ0K5Kyx 2bzxG2Slcp5rp5U5NjE29BVbeithREff2bR1TV482Qciio8LfmI3BblFbJlKs4tQfsM0 8msw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fF3e0RUw; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b17si8528055pls.15.2019.04.04.02.02.24; Thu, 04 Apr 2019 02:02:39 -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=fF3e0RUw; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731468AbfDDJBl (ORCPT + 99 others); Thu, 4 Apr 2019 05:01:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:38798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731006AbfDDJBh (ORCPT ); Thu, 4 Apr 2019 05:01:37 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B9D772184B; Thu, 4 Apr 2019 09:01:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368496; bh=VG6+nVD+xW5CxoFq429VEowshVGnrzPArN3789qZBSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fF3e0RUw8lzHYFB7QOCVqimeY70CZfiU8t5jOtl89735KNdG80gtTuAcjT64ytRfF m0zildk2E5JElXaK8xo6IKtLx1gBEbGsAJ7doIl2pI3mU+Ab4tLQYePVdOoC25O2rI A7sSyaOsAFqTxHCt9zSCrs3+bjQojlnMgkMpBfw4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qian Cai , Andrey Ryabinin , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 035/187] page_poison: play nicely with KASAN Date: Thu, 4 Apr 2019 10:46:12 +0200 Message-Id: <20190404084604.723902158@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 ef99971c13dd..8e6932a140b8 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1922,8 +1922,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 aa2b3d34e8ea..6cfa8e7d7213 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; @@ -34,7 +35,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