From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42BC9C3A5A7 for ; Wed, 4 Sep 2019 13:44:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 136602339E for ; Wed, 4 Sep 2019 13:44:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="luGclcN1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730166AbfIDNou (ORCPT ); Wed, 4 Sep 2019 09:44:50 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38281 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726943AbfIDNot (ORCPT ); Wed, 4 Sep 2019 09:44:49 -0400 Received: by mail-pf1-f194.google.com with SMTP id h195so6726840pfe.5 for ; Wed, 04 Sep 2019 06:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=W721XQEkMG8bC4j2PepgMeY0jTQOErIpXztyfiJXOs8=; b=luGclcN1dcSuuNyjEd4iVSQhaZ7/plNnDTMPxi9rQNhfhWvSUm52SKtinf2rFBYvXv WkUY7zrmOKflAgtEFgIlDdwxNSqASf+eYZIMIOZno6R0+F2WyGjFJAgjSZ4QIsynr/s2 ODnVlH9pQ8nvqktBpgfoOyAIHBEzgNZe6LLo0mlO0LIalIP8unm77acWwKiMIholXtcx rd0SUmY8p+MkPEaF4kb8sFqd7nNFprQXHr3npmQIDeaSJ+orCGo3gH4fjy6lV6eRrABT 5nNtXJDgdAgHI4Yz0CI2RrNJFbyLrMht5vS5C2Qv1NthNoz3ozyI4WZorI/8tpI2Ehs9 flxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=W721XQEkMG8bC4j2PepgMeY0jTQOErIpXztyfiJXOs8=; b=DdyfijP4/BLUp6cwPthT33WzfvjdYyUj2N9ZB4ZZZiBrDm0FEkEuiz5rcAY7j1fuH/ ItmvppydhuvVPzKIo8sHxY5EHNV8TPk4ylm21NBK9JALoNCxoSI+ZL46hXNPwrh1ZoDw 8AoIV9ecslfzKjQGpS1rChtN92En7xvURPYUyz49rNUsqUMkKXInXvnY/5+UWPCBO/O3 96wO3nXI5PNACjWRXhmDzmkJalhGrtId4sl8ermFBRNiwWrQ7JhaD7XFgWwM0xtRVlMk Oq37oFh8STUL81+4PFMz5t+gIWV/4TRNKb8uRpJ/9KNPMizLU1lP86DY5KfyMHQRZAUs ja5w== X-Gm-Message-State: APjAAAW729G8vwsTVzdj9uxvWUxNwEdBNR2rQDLhUM78iMUOrdRuROkC LLTHDc2ZjvIAu3KybQGVYOORhyM7Av6qRADmqlEXXQ== X-Google-Smtp-Source: APXvYqzCww2lW0PtxSg3odpkkA5VJF/XxD5kKaqrmZ1KDA7CF0CBSRDpFDrvufwyLOctz33+u6vqBpksBAlWIGv+72Q= X-Received: by 2002:a17:90a:ff08:: with SMTP id ce8mr4950627pjb.123.1567604688325; Wed, 04 Sep 2019 06:44:48 -0700 (PDT) MIME-Version: 1.0 References: <20190904065133.20268-1-walter-zh.wu@mediatek.com> In-Reply-To: <20190904065133.20268-1-walter-zh.wu@mediatek.com> From: Andrey Konovalov Date: Wed, 4 Sep 2019 15:44:37 +0200 Message-ID: Subject: Re: [PATCH 1/2] mm/kasan: dump alloc/free stack for page allocator To: Walter Wu Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Matthias Brugger , Andrew Morton , Martin Schwidefsky , Arnd Bergmann , kasan-dev , Linux Memory Management List , LKML , Linux ARM , linux-mediatek@lists.infradead.org, wsd_upstream@mediatek.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 4, 2019 at 8:51 AM Walter Wu wrote: > > 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/free stack for page allocator. > It is difficult to fix up page use-after-free issue. > > This feature depends on page owner to record the last stack of pages. > It is very helpful for solving the page use-after-free or out-of-bound. > > 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. > > 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: > prep_new_page+0x1a0/0x1d8 > get_page_from_freelist+0xd78/0x2748 > __alloc_pages_nodemask+0x1d4/0x1978 > kmalloc_order+0x28/0x58 > kmalloc_order_trace+0x28/0xe0 > kmalloc_pagealloc_oob_right+0x2c/0x90 > > b) If page is freed state, then it prints free stack. > It is useful to fix up page use-after-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 > > Signed-off-by: Walter Wu > --- > lib/Kconfig.kasan | 9 +++++++++ > mm/kasan/common.c | 6 ++++++ > 2 files changed, 15 insertions(+) > > diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan > index 4fafba1a923b..ba17f706b5f8 100644 > --- a/lib/Kconfig.kasan > +++ b/lib/Kconfig.kasan > @@ -135,6 +135,15 @@ config KASAN_S390_4_LEVEL_PAGING > to 3TB of RAM with KASan enabled). This options allows to force > 4-level paging instead. > > +config KASAN_DUMP_PAGE > + bool "Dump the page last stack information" > + depends on KASAN && PAGE_OWNER > + help > + By default, KASAN doesn't record alloc/free stack for page allocator. > + It is difficult to fix up page use-after-free issue. > + This feature depends on page owner to record the last stack of page. > + It is very helpful for solving the page use-after-free or out-of-bound. I'm not sure if we need a separate config for this. Is there any reason to not have this enabled by default? > + > config TEST_KASAN > tristate "Module for testing KASAN for bug detection" > depends on m && KASAN > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index 2277b82902d8..2a32474efa74 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -35,6 +35,7 @@ > #include > #include > #include > +#include > > #include "kasan.h" > #include "../slab.h" > @@ -227,6 +228,11 @@ void kasan_alloc_pages(struct page *page, unsigned int order) > > void kasan_free_pages(struct page *page, unsigned int order) > { > +#ifdef CONFIG_KASAN_DUMP_PAGE > + gfp_t gfp_flags = GFP_KERNEL; > + > + set_page_owner(page, order, gfp_flags); > +#endif > if (likely(!PageHighMem(page))) > kasan_poison_shadow(page_address(page), > PAGE_SIZE << order, > -- > 2.18.0 > > -- > You received this message because you are subscribed to the Google Groups "kasan-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20190904065133.20268-1-walter-zh.wu%40mediatek.com. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 882D4C3A5A8 for ; Wed, 4 Sep 2019 13:44:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 318D22339D for ; Wed, 4 Sep 2019 13:44:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="luGclcN1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 318D22339D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5699C6B0003; Wed, 4 Sep 2019 09:44:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 51A9B6B0006; Wed, 4 Sep 2019 09:44:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4080C6B0007; Wed, 4 Sep 2019 09:44:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id 1B34D6B0003 for ; Wed, 4 Sep 2019 09:44:51 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 9110D181AC9B6 for ; Wed, 4 Sep 2019 13:44:50 +0000 (UTC) X-FDA: 75897358740.16.star42_646be428c1a0a X-HE-Tag: star42_646be428c1a0a X-Filterd-Recvd-Size: 7067 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Wed, 4 Sep 2019 13:44:49 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id s12so6282167pfe.6 for ; Wed, 04 Sep 2019 06:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=W721XQEkMG8bC4j2PepgMeY0jTQOErIpXztyfiJXOs8=; b=luGclcN1dcSuuNyjEd4iVSQhaZ7/plNnDTMPxi9rQNhfhWvSUm52SKtinf2rFBYvXv WkUY7zrmOKflAgtEFgIlDdwxNSqASf+eYZIMIOZno6R0+F2WyGjFJAgjSZ4QIsynr/s2 ODnVlH9pQ8nvqktBpgfoOyAIHBEzgNZe6LLo0mlO0LIalIP8unm77acWwKiMIholXtcx rd0SUmY8p+MkPEaF4kb8sFqd7nNFprQXHr3npmQIDeaSJ+orCGo3gH4fjy6lV6eRrABT 5nNtXJDgdAgHI4Yz0CI2RrNJFbyLrMht5vS5C2Qv1NthNoz3ozyI4WZorI/8tpI2Ehs9 flxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=W721XQEkMG8bC4j2PepgMeY0jTQOErIpXztyfiJXOs8=; b=F6vsvrY7nrZNSSxBRSTVOdN+aVy6/y7gJcNoEwEhsD0zgSsCIkrw1A5MRW4dyPJhZ8 k1xVqsJwhrnFLrKNm+kIQ4bvWfgLRKtv4NmToYjAgDfZPSaQVzynle3UkVitACeLUEv1 YZqgOPDZmqGeQDN8IVgumidN4rYW7bZsbPsQYVhjYQZ6lENSe7scq8RXXoXUWO2YXx9q GoUpGkVMwf87VqQhduL6IISCh3Hw3KHPlDteHzOMWLLvtXtsSpg4yPnMDKzjKLqcK8gY EdyjmvSP12FTJlGEwoQAu90DClbNl4X+RYSJgOVw2br9rCse+ADOyBC+Wz1nez0Y9BV6 cgtw== X-Gm-Message-State: APjAAAVEQjJsdln+/UhNiLocSaE5ikC69sRkBHejXVy9BEE2kRoPG4+C XOBq0FLvNMy74DVrdAUUQnEPEs62rphSb/WLX/c+PA== X-Google-Smtp-Source: APXvYqzCww2lW0PtxSg3odpkkA5VJF/XxD5kKaqrmZ1KDA7CF0CBSRDpFDrvufwyLOctz33+u6vqBpksBAlWIGv+72Q= X-Received: by 2002:a17:90a:ff08:: with SMTP id ce8mr4950627pjb.123.1567604688325; Wed, 04 Sep 2019 06:44:48 -0700 (PDT) MIME-Version: 1.0 References: <20190904065133.20268-1-walter-zh.wu@mediatek.com> In-Reply-To: <20190904065133.20268-1-walter-zh.wu@mediatek.com> From: Andrey Konovalov Date: Wed, 4 Sep 2019 15:44:37 +0200 Message-ID: Subject: Re: [PATCH 1/2] mm/kasan: dump alloc/free stack for page allocator To: Walter Wu Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Matthias Brugger , Andrew Morton , Martin Schwidefsky , Arnd Bergmann , kasan-dev , Linux Memory Management List , LKML , Linux ARM , linux-mediatek@lists.infradead.org, wsd_upstream@mediatek.com Content-Type: text/plain; charset="UTF-8" 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: On Wed, Sep 4, 2019 at 8:51 AM Walter Wu wrote: > > 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/free stack for page allocator. > It is difficult to fix up page use-after-free issue. > > This feature depends on page owner to record the last stack of pages. > It is very helpful for solving the page use-after-free or out-of-bound. > > 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. > > 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: > prep_new_page+0x1a0/0x1d8 > get_page_from_freelist+0xd78/0x2748 > __alloc_pages_nodemask+0x1d4/0x1978 > kmalloc_order+0x28/0x58 > kmalloc_order_trace+0x28/0xe0 > kmalloc_pagealloc_oob_right+0x2c/0x90 > > b) If page is freed state, then it prints free stack. > It is useful to fix up page use-after-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 > > Signed-off-by: Walter Wu > --- > lib/Kconfig.kasan | 9 +++++++++ > mm/kasan/common.c | 6 ++++++ > 2 files changed, 15 insertions(+) > > diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan > index 4fafba1a923b..ba17f706b5f8 100644 > --- a/lib/Kconfig.kasan > +++ b/lib/Kconfig.kasan > @@ -135,6 +135,15 @@ config KASAN_S390_4_LEVEL_PAGING > to 3TB of RAM with KASan enabled). This options allows to force > 4-level paging instead. > > +config KASAN_DUMP_PAGE > + bool "Dump the page last stack information" > + depends on KASAN && PAGE_OWNER > + help > + By default, KASAN doesn't record alloc/free stack for page allocator. > + It is difficult to fix up page use-after-free issue. > + This feature depends on page owner to record the last stack of page. > + It is very helpful for solving the page use-after-free or out-of-bound. I'm not sure if we need a separate config for this. Is there any reason to not have this enabled by default? > + > config TEST_KASAN > tristate "Module for testing KASAN for bug detection" > depends on m && KASAN > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index 2277b82902d8..2a32474efa74 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -35,6 +35,7 @@ > #include > #include > #include > +#include > > #include "kasan.h" > #include "../slab.h" > @@ -227,6 +228,11 @@ void kasan_alloc_pages(struct page *page, unsigned int order) > > void kasan_free_pages(struct page *page, unsigned int order) > { > +#ifdef CONFIG_KASAN_DUMP_PAGE > + gfp_t gfp_flags = GFP_KERNEL; > + > + set_page_owner(page, order, gfp_flags); > +#endif > if (likely(!PageHighMem(page))) > kasan_poison_shadow(page_address(page), > PAGE_SIZE << order, > -- > 2.18.0 > > -- > You received this message because you are subscribed to the Google Groups "kasan-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20190904065133.20268-1-walter-zh.wu%40mediatek.com. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B5E4C3A5A7 for ; Wed, 4 Sep 2019 13:44:59 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0D55D2339D for ; Wed, 4 Sep 2019 13:44:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="iXFfCJMk"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="luGclcN1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0D55D2339D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Xd2fKtrlTvyRyQGelt0S+wUzVdNrxFUQGA9bKHyXC4c=; b=iXFfCJMkc8tDZx kV6BXuoEr4Y7izsxmt4qBMYLoSS8zQRD7hgwQ2u7n1lrEoXyrSBVwMqZptWhd7Sd6WRRQygxW6nMg TjCfF1/QwfmmFhXJQt9xAhQSQ3JxBM+yuZ80WZww9GfH9NmrPT9jgychtPu7xDl6DGYQ+mRQMMZKg fSXzoT1bL2HiDR+w3DvCHs2Lv43ieH8hUaWFQJt4xGJuzXqfr+KLQ/YrNrOL3vGVLdXBUqARslcLg Oiz7Sp/BX5LBTGx+Lyc2a3lFSSo7/1E092wcq52OTg9avZ+qNKCw9dVhRs5QVMrbCeIhlhMM++QMk h18lodUx8hnEVcGuS6ew==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i5Vaj-0005Ds-1b; Wed, 04 Sep 2019 13:44:57 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i5Vae-0005C8-Tl for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2019 13:44:54 +0000 Received: by mail-pg1-x543.google.com with SMTP id 4so7733092pgm.12 for ; Wed, 04 Sep 2019 06:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=W721XQEkMG8bC4j2PepgMeY0jTQOErIpXztyfiJXOs8=; b=luGclcN1dcSuuNyjEd4iVSQhaZ7/plNnDTMPxi9rQNhfhWvSUm52SKtinf2rFBYvXv WkUY7zrmOKflAgtEFgIlDdwxNSqASf+eYZIMIOZno6R0+F2WyGjFJAgjSZ4QIsynr/s2 ODnVlH9pQ8nvqktBpgfoOyAIHBEzgNZe6LLo0mlO0LIalIP8unm77acWwKiMIholXtcx rd0SUmY8p+MkPEaF4kb8sFqd7nNFprQXHr3npmQIDeaSJ+orCGo3gH4fjy6lV6eRrABT 5nNtXJDgdAgHI4Yz0CI2RrNJFbyLrMht5vS5C2Qv1NthNoz3ozyI4WZorI/8tpI2Ehs9 flxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=W721XQEkMG8bC4j2PepgMeY0jTQOErIpXztyfiJXOs8=; b=Uemhhkj5/mbMyPGL786X9028dF7AbQTu5JzF7q0ZtqqVELqyDLNNzyuBpoll/D8MS8 5mpTqMbTDs+9tWyUxJbQ2HvzRNlu2gLOIklnKLkNGTibuo/HPvWvVg522r5AnpNjp1SS eA/dWrE9ewHnUuXxBKkBRlVH3doDUXe++5jrUZopqv7pbTkTwtko+bxgMV3SXbC8vVp/ bH+CiO/LOFcNVrCfXjjYnA29pFg/1Xs6BTKNLyFLfDiz6gR/YD4F+YHbJycd9p5/8q86 fVIxXVWKPlmK0UOqvBAQxUKJ2qQ4L7I1AznYHpKabwrz3J9vWMy005TcjNKCAxlAtah2 Kn9g== X-Gm-Message-State: APjAAAVFS0oxUAsE4uQKrtUIDvfZM0GJCyB+IA2MlGHfzTDX0dBi8Dlp SRre/VPUsbTYOTvgNyH0UFLeY/Uml3zkfp2tVkrI8Q== X-Google-Smtp-Source: APXvYqzCww2lW0PtxSg3odpkkA5VJF/XxD5kKaqrmZ1KDA7CF0CBSRDpFDrvufwyLOctz33+u6vqBpksBAlWIGv+72Q= X-Received: by 2002:a17:90a:ff08:: with SMTP id ce8mr4950627pjb.123.1567604688325; Wed, 04 Sep 2019 06:44:48 -0700 (PDT) MIME-Version: 1.0 References: <20190904065133.20268-1-walter-zh.wu@mediatek.com> In-Reply-To: <20190904065133.20268-1-walter-zh.wu@mediatek.com> From: Andrey Konovalov Date: Wed, 4 Sep 2019 15:44:37 +0200 Message-ID: Subject: Re: [PATCH 1/2] mm/kasan: dump alloc/free stack for page allocator To: Walter Wu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190904_064452_965885_E5BC8BD7 X-CRM114-Status: GOOD ( 26.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wsd_upstream@mediatek.com, Arnd Bergmann , Linux Memory Management List , linux-mediatek@lists.infradead.org, LKML , kasan-dev , Martin Schwidefsky , Alexander Potapenko , Linux ARM , Matthias Brugger , Andrey Ryabinin , Andrew Morton , Dmitry Vyukov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Sep 4, 2019 at 8:51 AM Walter Wu wrote: > > 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/free stack for page allocator. > It is difficult to fix up page use-after-free issue. > > This feature depends on page owner to record the last stack of pages. > It is very helpful for solving the page use-after-free or out-of-bound. > > 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. > > 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: > prep_new_page+0x1a0/0x1d8 > get_page_from_freelist+0xd78/0x2748 > __alloc_pages_nodemask+0x1d4/0x1978 > kmalloc_order+0x28/0x58 > kmalloc_order_trace+0x28/0xe0 > kmalloc_pagealloc_oob_right+0x2c/0x90 > > b) If page is freed state, then it prints free stack. > It is useful to fix up page use-after-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 > > Signed-off-by: Walter Wu > --- > lib/Kconfig.kasan | 9 +++++++++ > mm/kasan/common.c | 6 ++++++ > 2 files changed, 15 insertions(+) > > diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan > index 4fafba1a923b..ba17f706b5f8 100644 > --- a/lib/Kconfig.kasan > +++ b/lib/Kconfig.kasan > @@ -135,6 +135,15 @@ config KASAN_S390_4_LEVEL_PAGING > to 3TB of RAM with KASan enabled). This options allows to force > 4-level paging instead. > > +config KASAN_DUMP_PAGE > + bool "Dump the page last stack information" > + depends on KASAN && PAGE_OWNER > + help > + By default, KASAN doesn't record alloc/free stack for page allocator. > + It is difficult to fix up page use-after-free issue. > + This feature depends on page owner to record the last stack of page. > + It is very helpful for solving the page use-after-free or out-of-bound. I'm not sure if we need a separate config for this. Is there any reason to not have this enabled by default? > + > config TEST_KASAN > tristate "Module for testing KASAN for bug detection" > depends on m && KASAN > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index 2277b82902d8..2a32474efa74 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -35,6 +35,7 @@ > #include > #include > #include > +#include > > #include "kasan.h" > #include "../slab.h" > @@ -227,6 +228,11 @@ void kasan_alloc_pages(struct page *page, unsigned int order) > > void kasan_free_pages(struct page *page, unsigned int order) > { > +#ifdef CONFIG_KASAN_DUMP_PAGE > + gfp_t gfp_flags = GFP_KERNEL; > + > + set_page_owner(page, order, gfp_flags); > +#endif > if (likely(!PageHighMem(page))) > kasan_poison_shadow(page_address(page), > PAGE_SIZE << order, > -- > 2.18.0 > > -- > You received this message because you are subscribed to the Google Groups "kasan-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20190904065133.20268-1-walter-zh.wu%40mediatek.com. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel