Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp301013pxf; Thu, 8 Apr 2021 03:28:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrqwkCUbxztT+BDCbshjUd3sfq/cKeZrNyjv/atWeFgqOuYsuBrd34rAJ4+E5rqqvmoXRg X-Received: by 2002:a17:906:4544:: with SMTP id s4mr9640185ejq.474.1617877738763; Thu, 08 Apr 2021 03:28:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617877738; cv=none; d=google.com; s=arc-20160816; b=I8Z1CC4RlZJgWbm2O0jxRYswh1Nb38bbM9NE8G7/mR3g5iq+wnVjak/U38yko88Dzs R/ZxsnCprfR4TxOimJROpbKQj/5c3EUexxkSEYLPqrtZtTGR0dtrxBnWbaU5Gfj5Zv/D KCQ0pDP8FJjxHt3TDIn0dIGFJVAcktC+G2MtT6EeeVkENIrRFn/1trHGgpJjH7yDR3ek Kz9btcAfB7OHqhfFnXgfuJN8b9EqSEFK8DI7i+i2AkdCXZS+YX5AmMoeId70DXPvJoh8 79ADbPoHodoi3IJrV31LkRQe/vIAMG5Fvhg8J7RPrJe6Ny/gLsLUrOK6+fsm4A8WDmT/ Fhjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=YWNPBLoT/7eJDEzhxyM0fg6KltG5DLWhdJV/f7ACk5o=; b=r+C4JJK2H2oN6ZnPmnPtUoDWbx6TEkE+xZ0fNvugoaeCZADLUKXil1eLJzD+MuhRAd cBTWndXxOJFIs5wZKcVe6OA/ebOjE8sLABZq4YMWLzgOWpqPWONxXMtwRDyzCbQ9MubQ hp+ZQnnYYsz1kfhAqnS76o2UFkXZq9Nn22TS7iUyfSZ0m8Hk0LXVFVzDwUWloMK33Kui g5aCHJuR7KhAdv4LZhXewUGmAMSe01+JrO7UpF0DIvUFiSQo+HSqauH7Bp0VctEZSy44 hgjWgxsP8uC7pTI+GzXVSNwiMmrIeqgRF1KjEyS7FmrxjHZSMJ/avyO2XJO7xzwgB1d8 ZQoA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f1si21215284ejz.585.2021.04.08.03.28.35; Thu, 08 Apr 2021 03:28:58 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230476AbhDHK1Y (ORCPT + 99 others); Thu, 8 Apr 2021 06:27:24 -0400 Received: from mx2.suse.de ([195.135.220.15]:37272 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbhDHK1Y (ORCPT ); Thu, 8 Apr 2021 06:27:24 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DD145AF0C; Thu, 8 Apr 2021 10:27:11 +0000 (UTC) Subject: Re: [PATCH v2] mm: page_poison: print page info when corruption is caught To: Sergei Trofimovich , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20210407230800.1086854-1-slyfox@gentoo.org> From: Vlastimil Babka Message-ID: Date: Thu, 8 Apr 2021 12:27:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210407230800.1086854-1-slyfox@gentoo.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/8/21 1:08 AM, 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 data. > Example report from real corruption (includes only page_pwner part): > > pagealloc: memory corruption > e00000014cd61d10: 11 00 00 00 00 00 00 00 30 1d d2 ff ff 0f 00 60 ........0......` > 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: Vlastimil Babka > CC: Andrew Morton > CC: linux-mm@kvack.org > Signed-off-by: Sergei Trofimovich Acked-by: Vlastimil Babka > --- > Change since v1: use more generic 'dump_page()' suggested by Vlastimil > Should supersede existing mm-page_poison-print-page-owner-info-when-corruption-is-caught.patch > > 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..df03126f3b2b 100644 > --- a/mm/page_poison.c > +++ b/mm/page_poison.c > @@ -2,6 +2,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(page, "pagealloc: corrupted page details"); > } > > 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); > } > >