From patchwork Thu Sep 29 21:32:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 9357127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E05BC60757 for ; Thu, 29 Sep 2016 21:33:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D119C29C58 for ; Thu, 29 Sep 2016 21:33:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C59A729C68; Thu, 29 Sep 2016 21:33:32 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id ADDEE29C58 for ; Thu, 29 Sep 2016 21:33:31 +0000 (UTC) Received: (qmail 3639 invoked by uid 550); 29 Sep 2016 21:33:29 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: kernel-hardening@lists.openwall.com Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 3614 invoked from network); 29 Sep 2016 21:33:28 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RQ3RKAATzLvAwKxfb/D2tk2O8uUrjokk9xa6iyAPxW8=; b=JtSro28FlwoCA2U89M35Mzg8IeUJA7NHVRC1mrncGA34GX3ItYQkW03w0g7yiz4+zd NigO3Ttz7wJPcEgT0brKZMvBS1yb7tHlcSviq8C7Auq/OGEUZ7TGIFDEUx3MoPNAV8hl 21muRy/53/D3szIv+DY2XDQNk49AdAYX5dA3lG/ZEl3usjh8mIexkA3/ihlxtbDgq/0i gZfxyRg2sUzRkZnpBdi3CbZJDRcwgpNFv7NyLl3VVpoHJXcEZRRNpEQA+yRsg0fV9zWY /SVT5n6gqfZ+ZN8lk3JCT1k8hq9djVT22nRgx7RZJgmJqvdxvElmlIZ0qfmJdnyCEmyn 53Lw== X-Gm-Message-State: AA6/9RlGD5xu1dLq9I4Sup716cTcpsmrPMxJO7QKZU6gOgovnuL1XLHosVQpzDLZ32aLoip4 X-Received: by 10.66.235.100 with SMTP id ul4mr6067171pac.50.1475184796696; Thu, 29 Sep 2016 14:33:16 -0700 (PDT) From: Laura Abbott To: AKASHI Takahiro , Mark Rutland , Ard Biesheuvel , David Brown , Will Deacon , Catalin Marinas Cc: Laura Abbott , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Kees Cook , kernel-hardening@lists.openwall.com Date: Thu, 29 Sep 2016 14:32:55 -0700 Message-Id: <20160929213257.30505-2-labbott@redhat.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20160929213257.30505-1-labbott@redhat.com> References: <20160929213257.30505-1-labbott@redhat.com> Subject: [kernel-hardening] [PATCH 1/3] arm64: dump: Make ptdump debugfs a separate option X-Virus-Scanned: ClamAV using ClamSMTP ptdump_register currently initializes a set of page table information and registers debugfs. There are uses for the ptdump option without wanting the debugfs options. Split this out to make it a separate option. Signed-off-by: Laura Abbott --- arch/arm64/Kconfig.debug | 6 +++++- arch/arm64/include/asm/ptdump.h | 15 +++++++++++++-- arch/arm64/mm/Makefile | 3 ++- arch/arm64/mm/dump.c | 30 +++++++++--------------------- arch/arm64/mm/ptdump_debugfs.c | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 25 deletions(-) create mode 100644 arch/arm64/mm/ptdump_debugfs.c diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug index 0cc758c..9015f02 100644 --- a/arch/arm64/Kconfig.debug +++ b/arch/arm64/Kconfig.debug @@ -2,9 +2,13 @@ menu "Kernel hacking" source "lib/Kconfig.debug" -config ARM64_PTDUMP +config ARM64_PTDUMP_CORE + def_bool n + +config ARM64_PTDUMP_DEBUGFS bool "Export kernel pagetable layout to userspace via debugfs" depends on DEBUG_KERNEL + select ARM64_PTDUMP_CORE select DEBUG_FS help Say Y here if you want to show the kernel pagetable layout in a diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 07b8ed0..b18a62c 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -16,8 +16,9 @@ #ifndef __ASM_PTDUMP_H #define __ASM_PTDUMP_H -#ifdef CONFIG_ARM64_PTDUMP +#ifdef CONFIG_ARM64_PTDUMP_CORE +#include #include struct addr_marker { @@ -33,12 +34,22 @@ struct ptdump_info { }; int ptdump_register(struct ptdump_info *info, const char *name); +void ptdump_walk_pgd(struct seq_file *s, struct ptdump_info *info); +#ifdef CONFIG_ARM64_PTDUMP_DEBUGFS +int ptdump_debugfs_create(struct ptdump_info *info, const char *name); +#else +static inline int ptdump_debugfs_create(struct ptdump_info *info, + const char *name) +{ + return 0; +} +#endif #else static inline int ptdump_register(struct ptdump_info *info, const char *name) { return 0; } -#endif /* CONFIG_ARM64_PTDUMP */ +#endif /* CONFIG_ARM64_PTDUMP_CORE */ #endif /* __ASM_PTDUMP_H */ diff --git a/arch/arm64/mm/Makefile b/arch/arm64/mm/Makefile index 54bb209..e703fb9 100644 --- a/arch/arm64/mm/Makefile +++ b/arch/arm64/mm/Makefile @@ -3,7 +3,8 @@ obj-y := dma-mapping.o extable.o fault.o init.o \ ioremap.o mmap.o pgd.o mmu.o \ context.o proc.o pageattr.o obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o -obj-$(CONFIG_ARM64_PTDUMP) += dump.o +obj-$(CONFIG_ARM64_PTDUMP_CORE) += dump.o +obj-$(CONFIG_ARM64_PTDUMP_DEBUGFS) += ptdump_debugfs.o obj-$(CONFIG_NUMA) += numa.o obj-$(CONFIG_KASAN) += kasan_init.o diff --git a/arch/arm64/mm/dump.c b/arch/arm64/mm/dump.c index 9c3e75d..29e0838 100644 --- a/arch/arm64/mm/dump.c +++ b/arch/arm64/mm/dump.c @@ -286,7 +286,7 @@ static void walk_pud(struct pg_state *st, pgd_t *pgd, unsigned long start) } } -static void walk_pgd(struct pg_state *st, struct mm_struct *mm, +static void __walk_pgd(struct pg_state *st, struct mm_struct *mm, unsigned long start) { pgd_t *pgd = pgd_offset(mm, 0UL); @@ -304,44 +304,32 @@ static void walk_pgd(struct pg_state *st, struct mm_struct *mm, } } -static int ptdump_show(struct seq_file *m, void *v) +void ptdump_walk_pgd(struct seq_file *m, struct ptdump_info *info) { - struct ptdump_info *info = m->private; struct pg_state st = { .seq = m, .marker = info->markers, }; - walk_pgd(&st, info->mm, info->base_addr); + __walk_pgd(&st, info->mm, info->base_addr); note_page(&st, 0, 0, 0); - return 0; } -static int ptdump_open(struct inode *inode, struct file *file) +static void ptdump_initialize(struct ptdump_info *info) { - return single_open(file, ptdump_show, inode->i_private); -} - -static const struct file_operations ptdump_fops = { - .open = ptdump_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -int ptdump_register(struct ptdump_info *info, const char *name) -{ - struct dentry *pe; unsigned i, j; for (i = 0; i < ARRAY_SIZE(pg_level); i++) if (pg_level[i].bits) for (j = 0; j < pg_level[i].num; j++) pg_level[i].mask |= pg_level[i].bits[j].mask; +} - pe = debugfs_create_file(name, 0400, NULL, info, &ptdump_fops); - return pe ? 0 : -ENOMEM; +int ptdump_register(struct ptdump_info *info, const char *name) +{ + ptdump_initialize(info); + return ptdump_debugfs_create(info, name); } static struct ptdump_info kernel_ptdump_info = { diff --git a/arch/arm64/mm/ptdump_debugfs.c b/arch/arm64/mm/ptdump_debugfs.c new file mode 100644 index 0000000..03e161f --- /dev/null +++ b/arch/arm64/mm/ptdump_debugfs.c @@ -0,0 +1,33 @@ +#include +#include + +#include + +static int ptdump_show(struct seq_file *m, void *v) +{ + struct ptdump_info *info = m->private; + ptdump_walk_pgd(m, info); + return 0; +} + +static int ptdump_open(struct inode *inode, struct file *file) +{ + return single_open(file, ptdump_show, inode->i_private); +} + +static const struct file_operations ptdump_fops = { + .open = ptdump_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +int ptdump_debugfs_create(struct ptdump_info *info, const char *name) +{ + struct dentry *pe; + pe = debugfs_create_file(name, 0400, NULL, info, &ptdump_fops); + return pe ? 0 : -ENOMEM; + +} + +