Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp6079291ybe; Tue, 10 Sep 2019 13:11:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFfTzM+kezs67BjaTsRi8gwVl1ssgwd72Gj6PxfmRX8wrxOnouHanYq5r+7mY/zm5KqcgI X-Received: by 2002:a17:906:fcc9:: with SMTP id qx9mr26252925ejb.32.1568146314334; Tue, 10 Sep 2019 13:11:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568146314; cv=none; d=google.com; s=arc-20160816; b=N1MjJWqzY0BDGQKLtppZtdd/biTUDWXk4Nu5hzy1lAhVL/1P1sF4y29PHzKy1LteNF 0Qf5U7GDC4XWsPY8Yl0FQwehsOwmDT6lzxCldky2lgxARC1Tcs7Ydopz0jsIzrOCJD0U vHVowC3g5GnnquGOLxVnCThKDvAK641M/9Cmn6mmXe6+g9eFYhjJiIh4Svi0qykSAyQ4 gF5hdOglkK+N9Jc6WQt6/pI1ZIW0FjXI5zUW64qnvYnxckat5VRDWcuJqjl8WSs3Kxz3 +G1ALnXxjo7fT/uiSTF3DyjazMt/7VoTDw7ze3ub7D5yipSw+Ga20tj/o0NQcN01wpxM o4pw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=vwMMzMvxkQmYU+cgMn7bmQcXsQg2xN/Q4Qk7+zmeX+I=; b=vl89wknxdIuJBAZmEvvA3cQD2tssk5NAZfB3cjCQLUPRudWWiPcz9RRdhGnYFZAnRD FszS6AwdM3Arsf/Tc3BtgecuqU12M8CowPETlO6kudGEFGfoB78QS5efjIek7NKJ5OXY EFrPjXFy29tC8PTLoJlrWtJt990pQQ0tTBTQyQRigdL0e9PWYRNUMekkC7ZANhVDL9k0 dliAakB1e2t058Di1Wfpb2/0iFCHcTYUEcMDo9W7Fwh8uyZWtEJCy+v/EB49Hq7ZOLkU 9z+3uVzXLTbKle8QnxJ/3hhmldDzHV5cfjjGn3zsX6ybJhebnLEfiQ0yTbmjYzTQl2iT 0ivA== ARC-Authentication-Results: i=1; mx.google.com; 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 k23si9827952ejr.329.2019.09.10.13.11.29; Tue, 10 Sep 2019 13:11:54 -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; 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 S1729496AbfIINHt (ORCPT + 99 others); Mon, 9 Sep 2019 09:07:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:39608 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726640AbfIINHs (ORCPT ); Mon, 9 Sep 2019 09:07:48 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 737C5ADDD; Mon, 9 Sep 2019 13:07:46 +0000 (UTC) Subject: Re: [PATCH v2 0/2] mm/kasan: dump alloc/free stack for page allocator To: walter-zh.wu@mediatek.com, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Matthias Brugger , Andrew Morton , Martin Schwidefsky , Will Deacon , Andrey Konovalov , Arnd Bergmann , Thomas Gleixner , Michal Hocko , Qian Cai Cc: linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, wsd_upstream@mediatek.com References: <20190909082412.24356-1-walter-zh.wu@mediatek.com> From: Vlastimil Babka Message-ID: Date: Mon, 9 Sep 2019 15:07:45 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190909082412.24356-1-walter-zh.wu@mediatek.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/9/19 10:24 AM, walter-zh.wu@mediatek.com wrote: > From: Walter Wu > > This patch is KASAN report adds the alloc/free stacks for page allocator > in order to help programmer to see memory corruption caused by page. > > By default, KASAN doesn't record alloc and free stack for page allocator. > It is difficult to fix up page use-after-free or dobule-free issue. > > Our patchsets will record the last stack of pages. > It is very helpful for solving the page use-after-free or double-free. > > KASAN report will show the last stack of page, it may be: > a) If page is in-use state, then it prints alloc stack. > It is useful to fix up page out-of-bound issue. I still disagree with duplicating most of page_owner functionality for the sake of using a single stack handle for both alloc and free (while page_owner + debug_pagealloc with patches in mmotm uses two handles). It reduces the amount of potentially important debugging information, and I really doubt the u32-per-page savings are significant, given the rest of KASAN overhead. > BUG: KASAN: slab-out-of-bounds in kmalloc_pagealloc_oob_right+0x88/0x90 > Write of size 1 at addr ffffffc0d64ea00a by task cat/115 > ... > Allocation stack of page: > set_page_stack.constprop.1+0x30/0xc8 > kasan_alloc_pages+0x18/0x38 > prep_new_page+0x5c/0x150 > get_page_from_freelist+0xb8c/0x17c8 > __alloc_pages_nodemask+0x1a0/0x11b0 > kmalloc_order+0x28/0x58 > kmalloc_order_trace+0x28/0xe0 > kmalloc_pagealloc_oob_right+0x2c/0x68 > > b) If page is freed state, then it prints free stack. > It is useful to fix up page use-after-free or double-free issue. > > BUG: KASAN: use-after-free in kmalloc_pagealloc_uaf+0x70/0x80 > Write of size 1 at addr ffffffc0d651c000 by task cat/115 > ... > Free stack of page: > kasan_free_pages+0x68/0x70 > __free_pages_ok+0x3c0/0x1328 > __free_pages+0x50/0x78 > kfree+0x1c4/0x250 > kmalloc_pagealloc_uaf+0x38/0x80 > > This has been discussed, please refer below link. > https://bugzilla.kernel.org/show_bug.cgi?id=203967 That's not a discussion, but a single comment from Dmitry, which btw contains "provide alloc *and* free stacks for it" ("it" refers to page, emphasis mine). It would be nice if he or other KASAN guys could clarify. > Changes since v1: > - slim page_owner and move it into kasan > - enable the feature by default > > Signed-off-by: Walter Wu > --- > include/linux/kasan.h | 1 + > lib/Kconfig.kasan | 2 ++ > mm/kasan/common.c | 32 ++++++++++++++++++++++++++++++++ > mm/kasan/kasan.h | 5 +++++ > mm/kasan/report.c | 27 +++++++++++++++++++++++++++ > 5 files changed, 67 insertions(+)