From patchwork Wed Mar 29 18:15:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9652265 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 A089F60349 for ; Wed, 29 Mar 2017 18:35:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A2DF28520 for ; Wed, 29 Mar 2017 18:35:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D17828524; Wed, 29 Mar 2017 18:35:50 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C4B8A28520 for ; Wed, 29 Mar 2017 18:35:49 +0000 (UTC) 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=U4pkL3Bvbp8SK9pbErGbwDccDAPUCB3VAdhVqpT6H8s=; b=DO4QESOaswQaX8nJVZp6TYVaQY s4rlUOci5pP10NlQmBqGk5BZ2xu2dAoSm46s+50oiWsE4ZvNHTzyL8YlW3QBZjmAkIgfrrOT1WyPd 2M2T5RzpzqkW4TrkxuOSmUBtjZmfD5uqplgFlQtO8DY0xJCnNQpcFgk2pJ7FHkINd3Ey+KKbZdb3K 7N29qC6c0Ft2HMrHUmgjdKpVxhXQpH66BLJk2Y0Fc8MUOaCcKX2+CPf5KuefPDwSxMV0YNTCZsBGF YTPAPU53qBKHmMxkJIlF1i3ICpNS5rfRUrHYCv5e5frqht98ZjyTheRK4f3RLBzIufaCQdzpI54N9 OilIb++Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ctIRh-0007wG-5Y; Wed, 29 Mar 2017 18:35:49 +0000 Received: from mail-pg0-x22d.google.com ([2607:f8b0:400e:c05::22d]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ctI9F-00058M-10 for linux-arm-kernel@lists.infradead.org; Wed, 29 Mar 2017 18:16:53 +0000 Received: by mail-pg0-x22d.google.com with SMTP id g2so14446701pge.3 for ; Wed, 29 Mar 2017 11:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4op9aTM+6/dH0iK/FcaFxyNOYIDGyrtsD/Qz7/6UK5M=; b=YXl64gzI0J2uBmMXT+37mymhoMagclXG5Dzt4DfomtVsvhoUnn6fR6v6lbNyj4gSaC WTkfgg8Ro2qSChMpL1u6I7djyfp1zBJRdNXFbd1zFaLrx21+iFKhO67Qp2PXV1VABfrE zifcDMOBE4Dq1w9SFhPjpk7PIYjC9T5Q/6Ops= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4op9aTM+6/dH0iK/FcaFxyNOYIDGyrtsD/Qz7/6UK5M=; b=kVfg0PyAG5jxQcvhr9j5F6kbTUqkiBjA0FnXyFIcmpd41f5Kz9Vdcq04GuA/vTOrvr OdT72E/R9V3ljyTwjhV0gJBpHQ7E8xYJsLuNqC/Nxvf8GxMCURyYMslKP82F2PmrX0eq EsU72NdhF5Rb32RiWXnljeLPWqUKDoDzIgKfQaxczvwQ3OsfplyIIjg7nGQonTS+hz12 e8L8GLKMQFXoYnNCMt9rD7uAmESxNRroZinR/loU2U6nIAeZMpa6wvVzIKMuefM6cYrm 0rQ+6UVE+dcJL1cKp3NgRDt5ndgmTrHBltFRXdtPe7q6/6QRv7qBPlOLoDrOWJiuZjYr n+XA== X-Gm-Message-State: AFeK/H2p1LQAmmtA0lid8rTNFLa8i3ym98Vw8EAJ9XiqdbFj8/C8fBq30jj0IcYRpoX/taC4 X-Received: by 10.84.135.34 with SMTP id 31mr2168589pli.50.1490811384158; Wed, 29 Mar 2017 11:16:24 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id r81sm10891271pfj.24.2017.03.29.11.16.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Mar 2017 11:16:22 -0700 (PDT) From: Kees Cook To: kernel-hardening@lists.openwall.com Subject: [RFC v2][PATCH 05/11] ARM: mm: dump: Add domain to output Date: Wed, 29 Mar 2017 11:15:57 -0700 Message-Id: <1490811363-93944-6-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490811363-93944-1-git-send-email-keescook@chromium.org> References: <1490811363-93944-1-git-send-email-keescook@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170329_111645_279476_B21CBF38 X-CRM114-Status: GOOD ( 17.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Hoeun Ryu , Kees Cook , x86@kernel.org, Russell King , linux-kernel@vger.kernel.org, Emese Revfy , Andy Lutomirski , PaX Team , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This adds the memory domain (on non-LPAE) to the PMD and PTE dumps. This isn't in the regular PMD bits because I couldn't find a clean way to fall back to retain some of the PMD bits when reporting PTE. So this is special-cased currently. New output example: ---[ Modules ]--- 0x7f000000-0x7f001000 4K KERNEL ro x SHD MEM/CACHED/WBWA 0x7f001000-0x7f002000 4K KERNEL ro NX SHD MEM/CACHED/WBWA 0x7f002000-0x7f004000 8K KERNEL RW NX SHD MEM/CACHED/WBWA ---[ Kernel Mapping ]--- 0x80000000-0x80100000 1M KERNEL RW NX SHD 0x80100000-0x80800000 7M KERNEL ro x SHD 0x80800000-0x80b00000 3M KERNEL ro NX SHD 0x80b00000-0xa0000000 501M KERNEL RW NX SHD ... ---[ Vectors ]--- 0xffff0000-0xffff1000 4K VECTORS USR ro x SHD MEM/CACHED/WBWA 0xffff1000-0xffff2000 4K VECTORS ro x SHD MEM/CACHED/WBWA Signed-off-by: Kees Cook --- This patch is already queued in the ARM tree, but I'm including it here too since a following patch updates the list of domain names from this patch... --- arch/arm/mm/dump.c | 54 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/arch/arm/mm/dump.c b/arch/arm/mm/dump.c index 21192d6eda40..35ff45470dbf 100644 --- a/arch/arm/mm/dump.c +++ b/arch/arm/mm/dump.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -43,6 +44,7 @@ struct pg_state { unsigned long start_address; unsigned level; u64 current_prot; + const char *current_domain; }; struct prot_bits { @@ -216,7 +218,8 @@ static void dump_prot(struct pg_state *st, const struct prot_bits *bits, size_t } } -static void note_page(struct pg_state *st, unsigned long addr, unsigned level, u64 val) +static void note_page(struct pg_state *st, unsigned long addr, + unsigned int level, u64 val, const char *domain) { static const char units[] = "KMGTPE"; u64 prot = val & pg_level[level].mask; @@ -224,8 +227,10 @@ static void note_page(struct pg_state *st, unsigned long addr, unsigned level, u if (!st->level) { st->level = level; st->current_prot = prot; + st->current_domain = domain; seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); } else if (prot != st->current_prot || level != st->level || + domain != st->current_domain || addr >= st->marker[1].start_address) { const char *unit = units; unsigned long delta; @@ -240,6 +245,8 @@ static void note_page(struct pg_state *st, unsigned long addr, unsigned level, u unit++; } seq_printf(st->seq, "%9lu%c", delta, *unit); + if (st->current_domain) + seq_printf(st->seq, " %s", st->current_domain); if (pg_level[st->level].bits) dump_prot(st, pg_level[st->level].bits, pg_level[st->level].num); seq_printf(st->seq, "\n"); @@ -251,11 +258,13 @@ static void note_page(struct pg_state *st, unsigned long addr, unsigned level, u } st->start_address = addr; st->current_prot = prot; + st->current_domain = domain; st->level = level; } } -static void walk_pte(struct pg_state *st, pmd_t *pmd, unsigned long start) +static void walk_pte(struct pg_state *st, pmd_t *pmd, unsigned long start, + const char *domain) { pte_t *pte = pte_offset_kernel(pmd, 0); unsigned long addr; @@ -263,25 +272,50 @@ static void walk_pte(struct pg_state *st, pmd_t *pmd, unsigned long start) for (i = 0; i < PTRS_PER_PTE; i++, pte++) { addr = start + i * PAGE_SIZE; - note_page(st, addr, 4, pte_val(*pte)); + note_page(st, addr, 4, pte_val(*pte), domain); } } +static const char *get_domain_name(pmd_t *pmd) +{ +#ifndef CONFIG_ARM_LPAE + switch (pmd_val(*pmd) & PMD_DOMAIN_MASK) { + case PMD_DOMAIN(DOMAIN_KERNEL): + return "KERNEL "; + case PMD_DOMAIN(DOMAIN_USER): + return "USER "; + case PMD_DOMAIN(DOMAIN_IO): + return "IO "; + case PMD_DOMAIN(DOMAIN_VECTORS): + return "VECTORS"; + default: + return "unknown"; + } +#endif + return NULL; +} + static void walk_pmd(struct pg_state *st, pud_t *pud, unsigned long start) { pmd_t *pmd = pmd_offset(pud, 0); unsigned long addr; unsigned i; + const char *domain; for (i = 0; i < PTRS_PER_PMD; i++, pmd++) { addr = start + i * PMD_SIZE; + domain = get_domain_name(pmd); if (pmd_none(*pmd) || pmd_large(*pmd) || !pmd_present(*pmd)) - note_page(st, addr, 3, pmd_val(*pmd)); + note_page(st, addr, 3, pmd_val(*pmd), domain); else - walk_pte(st, pmd, addr); + walk_pte(st, pmd, addr, domain); - if (SECTION_SIZE < PMD_SIZE && pmd_large(pmd[1])) - note_page(st, addr + SECTION_SIZE, 3, pmd_val(pmd[1])); + if (SECTION_SIZE < PMD_SIZE && pmd_large(pmd[1])) { + addr += SECTION_SIZE; + pmd++; + domain = get_domain_name(pmd); + note_page(st, addr, 3, pmd_val(*pmd), domain); + } } } @@ -296,7 +330,7 @@ static void walk_pud(struct pg_state *st, pgd_t *pgd, unsigned long start) if (!pud_none(*pud)) { walk_pmd(st, pud, addr); } else { - note_page(st, addr, 2, pud_val(*pud)); + note_page(st, addr, 2, pud_val(*pud), NULL); } } } @@ -317,11 +351,11 @@ static void walk_pgd(struct seq_file *m) if (!pgd_none(*pgd)) { walk_pud(&st, pgd, addr); } else { - note_page(&st, addr, 1, pgd_val(*pgd)); + note_page(&st, addr, 1, pgd_val(*pgd), NULL); } } - note_page(&st, 0, 0, 0); + note_page(&st, 0, 0, 0, NULL); } static int ptdump_show(struct seq_file *m, void *v)