Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp958176pxf; Wed, 7 Apr 2021 16:07:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyblvkgLURPcJpEpWYIoxRe+ueDKbNkDy4+jQS+DD1cGECSfCqUKMkzXM14DjNCjGp5jSlG X-Received: by 2002:aa7:d759:: with SMTP id a25mr7590936eds.248.1617836825002; Wed, 07 Apr 2021 16:07:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617836824; cv=none; d=google.com; s=arc-20160816; b=yYQZz1FvUcZQm0IxqQBPxDu5MaEiLN1BgbABsoPRCIYvTAp5s45snahJJQ3xI9hw6b AtKIXRZ9/AtFPRdpPgveouxwKAf6POxMfQU9hU4FQsIzoIDTEXmbLmNNF1e5Hdej1XZD pbexRUKi/UhjT8t2pBPk6CcEdR5/SM1PWQwyr9oUVMdjfI8Yd8dyyTru6zpyH2xsz7Jd jgkGsK9EepDO+Hq7e9F8/6iETZabEZ5rlPF6Qm2JIucAz+QB+Sz18BIVypLKmO8te3T0 Aof3KDmzG1js6QN8d99/rcf0o4J/rLeG+O2j9zoL6WzdYuxk5hz9zKeBVRMK/5Dhra+9 ifug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=4WJCngFAEIg/2vxnkxAF48VJJ3H0I/s465GM+/OMe64=; b=M4qDFu+re99j9FuRO1RmYaJfmykDgycYJclwjxhozQa4AM+lZPFhkYt0eKXJM4JcpH H9zgN+uN7IH911WNv5M2i0EE6L7qD8zYHVZoSREG3YXNGaJncwx5wi6hmmBI9DbFoZxH FvAL+4t29IpSrRiJ4Gr9MrM+9zB97aNKA8PQCu9uGEfAIYwAe/TJlqEdWIgP2lXtzRli wNaldQTCRMwUNYs7XPpU0wyD2kouiGz1ORGmyaJycEX1ZbUkPnJBSCJ50H2pYuJig0qH lkH9MwVnxESqGorppeSlOea9pfm3osAOkqDqjIZcLlyi3QfoZ32zgw6nbLrjGPHyCF/w sG5Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=gentoo.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q10si10928405ejb.620.2021.04.07.16.06.42; Wed, 07 Apr 2021 16:07:04 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=gentoo.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229606AbhDGXFx (ORCPT + 99 others); Wed, 7 Apr 2021 19:05:53 -0400 Received: from smtp.gentoo.org ([140.211.166.183]:55574 "EHLO smtp.gentoo.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbhDGXFw (ORCPT ); Wed, 7 Apr 2021 19:05:52 -0400 Received: by sf.home (Postfix, from userid 1000) id 5ABD95A22061; Thu, 8 Apr 2021 00:05:37 +0100 (BST) Date: Thu, 8 Apr 2021 00:05:37 +0100 From: Sergei Trofimovich To: Vlastimil Babka Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] mm: page_poison: print page owner info when corruption is caught Message-ID: References: <20210404141735.2152984-1-slyfox@gentoo.org> <2f0d1127-8868-f8a3-203f-2c3d473bd496@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2f0d1127-8868-f8a3-203f-2c3d473bd496@suse.cz> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 07, 2021 at 02:15:50PM +0200, Vlastimil Babka wrote: > On 4/4/21 4:17 PM, Sergei Trofimovich wrote: > > When page_poison detects page corruption it's useful to see who > > freed a page recently to have a guess where write-after-free > > corruption happens. > > > > After this change corruption report has extra page_owner data. > > Example report from real corruption: > > > > pagealloc: memory corruption > > e00000014cd61d10: 11 00 00 00 00 00 00 00 30 1d d2 ff ff 0f 00 60 > > e00000014cd61d20: b0 1d d2 ff ff 0f 00 60 90 fe 1c 00 08 00 00 20 > > ... > > CPU: 1 PID: 220402 Comm: cc1plus Not tainted 5.12.0-rc5-00107-g9720c6f59ecf #245 > > Hardware name: hp server rx3600, BIOS 04.03 04/08/2008 > > ... > > Call Trace: > > [] show_stack+0x90/0xc0 > > [] dump_stack+0x150/0x1c0 > > [] __kernel_unpoison_pages+0x410/0x440 > > [] get_page_from_freelist+0x1460/0x2ca0 > > [] __alloc_pages_nodemask+0x3c0/0x660 > > [] alloc_pages_vma+0xb0/0x500 > > [] __handle_mm_fault+0x1230/0x1fe0 > > [] handle_mm_fault+0x310/0x4e0 > > [] ia64_do_page_fault+0x1f0/0xb80 > > [] ia64_leave_kernel+0x0/0x270 > > page_owner tracks the page as freed > > page allocated via order 0, migratetype Movable, > > gfp_mask 0x100dca(GFP_HIGHUSER_MOVABLE|__GFP_ZERO), pid 37, ts 8173444098740 > > __reset_page_owner+0x40/0x200 > > free_pcp_prepare+0x4d0/0x600 > > free_unref_page+0x20/0x1c0 > > __put_page+0x110/0x1a0 > > migrate_pages+0x16d0/0x1dc0 > > compact_zone+0xfc0/0x1aa0 > > proactive_compact_node+0xd0/0x1e0 > > kcompactd+0x550/0x600 > > kthread+0x2c0/0x2e0 > > call_payload+0x50/0x80 > > > > Here we can see that page was freed by page migration but something > > managed to write to it afterwards. > > > > CC: Andrew Morton > > CC: linux-mm@kvack.org > > Signed-off-by: Sergei Trofimovich > > --- > > mm/page_poison.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/mm/page_poison.c b/mm/page_poison.c > > index 65cdf844c8ad..ef2a1eab13d7 100644 > > --- a/mm/page_poison.c > > +++ b/mm/page_poison.c > > @@ -4,6 +4,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -45,7 +46,7 @@ static bool single_bit_flip(unsigned char a, unsigned char b) > > return error && !(error & (error - 1)); > > } > > > > -static void check_poison_mem(unsigned char *mem, size_t bytes) > > +static void check_poison_mem(struct page *page, unsigned char *mem, size_t bytes) > > { > > static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 10); > > unsigned char *start; > > @@ -70,6 +71,7 @@ static void check_poison_mem(unsigned char *mem, size_t bytes) > > print_hex_dump(KERN_ERR, "", DUMP_PREFIX_ADDRESS, 16, 1, start, > > end - start + 1, 1); > > dump_stack(); > > + dump_page_owner(page); > > OK but why not a full dump_page()? Oh, I did not know it existed! Looks even better. Will send a v2 with dump_page(). > > } > > > > static void unpoison_page(struct page *page) > > @@ -82,7 +84,7 @@ static void unpoison_page(struct page *page) > > * that is freed to buddy. Thus no extra check is done to > > * see if a page was poisoned. > > */ > > - check_poison_mem(addr, PAGE_SIZE); > > + check_poison_mem(page, addr, PAGE_SIZE); > > kunmap_atomic(addr); > > } > > > > > -- Sergei