From patchwork Mon Jan 14 23:34:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qian Cai X-Patchwork-Id: 10763593 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA1426C2 for ; Mon, 14 Jan 2019 23:34:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C82F2C142 for ; Mon, 14 Jan 2019 23:34:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 911362C163; Mon, 14 Jan 2019 23:34:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F9E92C142 for ; Mon, 14 Jan 2019 23:34:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E0698E0006; Mon, 14 Jan 2019 18:34:21 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 18F868E0002; Mon, 14 Jan 2019 18:34:21 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07E228E0006; Mon, 14 Jan 2019 18:34:21 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id CE7538E0002 for ; Mon, 14 Jan 2019 18:34:20 -0500 (EST) Received: by mail-qk1-f198.google.com with SMTP id c84so745668qkb.13 for ; Mon, 14 Jan 2019 15:34:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=7jl5/RRo1w1Y4Nd6Af7IGPCqHR+Ha/rAu0Vgu3aHMTg=; b=DzQXzA+n54Xzuta3Y1E0jW1KL6B/155O4+KNMy6Eo0Fb4b2/2+yR4xJUcn1evCEZ7u r0Rkl6R4hhUnrmtbYv2JHx8LPRfm76nONpn4qS0kBfIo68+N/eHE8i9N08MSKsDp8ll8 HfMt0BulvbPkox+d9cJ3PAlA3OBks05TjbhG5y8UO/v2r/d6cBcCwTy1V4iKM3NVN1pn +opzTUXbU/eSPQWjVLG2fdvEuzowkLnrgfhUI1c8vYEW52npjKTDBE/U6f+86aNQTAUJ 7ZE4QbGu/Osenk4QwW2imwrKnSUDRkWDSZaNRSSZqBv58cuOY3iN42BpO6LoWs7tT9Xq 6hlw== X-Gm-Message-State: AJcUukeEICFlADnVueDjYKyMS7YQrAqIDwimgS4X//+OU8AJd78BkH5I /oN5GuZ85580j7SpFve024rNFhS9dZVyWyf6ZvoEVtIpGVgcgVxBIzPVGurpPEBrnPgxHuz64fb VgebZguSx1xz6XA2cq5IVNrC5TNyYPUClrI7ACKTgObg6PF2fWhUAzL1xUa7NgjPwLm4utme+Y9 1jaEUUz49Sya4/8KVIGQ5fbk78jho592qCW0tl2Q9UuHV4v/g+Gc3Cax8NFLFND5cJhgslAt9qd Q5varRSIf5kdMY351HwSRmpDarJj3i6VETGQQnISIrMl8RmYOsnwJnNDfe/J1Difb2+ES7TAqB0 YyTZZqOT2iPneZHL0Hq5Xk3PGS2l1tTux/n/wyBpC6kNTRffQjwXu4PKNiIv0mAyDYalFE5FZ9K z X-Received: by 2002:ac8:738e:: with SMTP id t14mr728134qtp.283.1547508860563; Mon, 14 Jan 2019 15:34:20 -0800 (PST) X-Received: by 2002:ac8:738e:: with SMTP id t14mr728108qtp.283.1547508859909; Mon, 14 Jan 2019 15:34:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547508859; cv=none; d=google.com; s=arc-20160816; b=Q9xOwm2LH5Zb5lYL/I6jyvDxomFMemy6QBudylU3djbEGAI2INLyTDknBae7/5oTL5 JMx8kaLPIOzaLmtNRnQSxMrNZOzQ6uSgJv8YQlAfNP1FevltPRXuNHb7LHrcxy5pSMWa D6kn2mr9mXZvr0RnYOWDktIL3v9IxJs7boP1sC8vL5EJB+kg+WbLyCefMtcNxGw6bPLn YhGUvPhSmkeJeVKMh3DmFjuJvjBRJ7hh2YAZk2tEFXV6wP0ZpBAedbL/m4oPqiXO7BLx ds/LPyKEiSJDIYrkGxEgF15cZ08/mo3tsbjjil1n7ZQ4fniF4WnWwJeweoJAmXsRzkAQ MmYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7jl5/RRo1w1Y4Nd6Af7IGPCqHR+Ha/rAu0Vgu3aHMTg=; b=A05VO16x1A7EAf7r27h/SzFi63p+xNOuy3bJVXempPLT849foXTSnkGuTwJNTn3bGO Wk535F61mkBjlMV/rDcfqf3fD2cS1WdDAB4MOOh0LRPmHtq8t1xV7vbJHyIG6/3gHhXX vutmc1KJqP+bqCYdoaEOUqr06tMBpVA7R5d5gVWZPD+/yaTOk/y8uwQSDafKHeWiQ4Wg 0rQiL8MeO0fnFWDRbo78deDf0SVcCrhD603PlxH1usOpIm7cnq9QqOcmak4HvE/Ab3TT N9CLX3wp1hPxKg7rHOmSV/xItdc5VTtkz18IMNykvlrc9Gk1iu36XpIbwK618lpEtNen t3Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=Ql4tJfDT; spf=pass (google.com: domain of cai@lca.pw designates 209.85.220.65 as permitted sender) smtp.mailfrom=cai@lca.pw Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id e5sor34632502qkj.13.2019.01.14.15.34.19 for (Google Transport Security); Mon, 14 Jan 2019 15:34:19 -0800 (PST) Received-SPF: pass (google.com: domain of cai@lca.pw designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=Ql4tJfDT; spf=pass (google.com: domain of cai@lca.pw designates 209.85.220.65 as permitted sender) smtp.mailfrom=cai@lca.pw DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7jl5/RRo1w1Y4Nd6Af7IGPCqHR+Ha/rAu0Vgu3aHMTg=; b=Ql4tJfDTtlb6EDAsuDNFGINDtL5qX6GChGwKFK3jj9kEcHwzGOEIWrGe+6jquIJXvh N26ScuiY3qn/F1geFtDQ7FRzbPGesbb7g+1hdjkakCGc5UZL4ZZ5ognKC7RUQR++wfi3 A6PxF6UBftX+oRZdb876fQRoppCYNixnC41CkejANvHWSfIDV1i1xcprQ6Bfgc3xwWM/ 5hpKThYDgyztLc4Gv12pjMKzDHeLGA7pAQPmeP09iFz7EvV8y9wzqSsuRmNwjIlah/wY 8A29d7zs7hY5NknEi26O7T154Nt1WxNk6VSgMNlAGo/c3+7ftwvMU6Jdh0dmzZvkZ2Pw UNgg== X-Google-Smtp-Source: ALg8bN5r+OoD47PEGyeI7sDIwhgVMbqEUDysk6yF1OhT5QxPA9ejMeCrCdLFJngBYbHgqMtwZ+rkEA== X-Received: by 2002:a37:34f:: with SMTP id 76mr688462qkd.347.1547508859628; Mon, 14 Jan 2019 15:34:19 -0800 (PST) Received: from ovpn-120-55.rdu2.redhat.com (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id o49sm51752874qtf.60.2019.01.14.15.34.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Jan 2019 15:34:19 -0800 (PST) From: Qian Cai To: akpm@linux-foundation.org Cc: aryabinin@virtuozzo.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH v2] page_poison: play nicely with KASAN Date: Mon, 14 Jan 2019 18:34:05 -0500 Message-Id: <20190114233405.67843-1-cai@lca.pw> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <2e46c139-70d3-dc86-28c9-a9f263651b57@virtuozzo.com> References: <2e46c139-70d3-dc86-28c9-a9f263651b57@virtuozzo.com> 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: X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Qian Cai Acked-by: Andrey Ryabinin --- v2: use kasan_disable/enable_current() instead. 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 d295c9bc01a8..906250a9b89c 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); }