From patchwork Thu Oct 27 16:27:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 9399883 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 B65F660231 for ; Thu, 27 Oct 2016 16:28:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A60512A35C for ; Thu, 27 Oct 2016 16:28:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AB132A364; Thu, 27 Oct 2016 16:28:21 +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 A863E2A35C for ; Thu, 27 Oct 2016 16:28:20 +0000 (UTC) Received: (qmail 11273 invoked by uid 550); 27 Oct 2016 16:28:01 -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 10148 invoked from network); 27 Oct 2016 16:28:00 -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=JBQjKDYJroeLDpzbn0FC837G0Sr0FOS2ZBHg7UBkJpU=; b=So/UQnbiN1Keke6wlsrcMXKH7nfcovtoH5PdK3/HsSzSu0+cE7IF7OnNeHNqseGQQX Hh4jSt5ZFyVZn8fgZfO8qSzsKNxEk0rsfS544gtFkW2jTmO7LjfED9i/DxSYX2sjJc+o 72leCvCndd3lOgM3UbxBHlaPTCXldBQJYYSMQAlitsdDKup+SfpJsVICrta12ebTsGJ/ nD6maZGwKgHHA5O140ZbqJeCKmxHvYEhrz4Fqp5U2xlgD1muZNPDAWeQE0oXKf5BYYc1 3nrxeNsNI/3QV6BN7c6xc1ukfpC1v5IrBzj/dJ9Y6Ig6TPE93R0RWH6ZMAcRgTVZLtxy oPNA== X-Gm-Message-State: ABUngvf9UcTvZ6+MfI/ZV2aFs4zHYbsXFqcC7R2JhAosNJvj0eAZvq9YdaPCZppDNT1aaZpl X-Received: by 10.55.129.1 with SMTP id c1mr6691852qkd.53.1477585668486; Thu, 27 Oct 2016 09:27:48 -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, Matt Fleming , linux-efi@vger.kernel.org Date: Thu, 27 Oct 2016 09:27:32 -0700 Message-Id: <1477585654-8908-3-git-send-email-labbott@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477585654-8908-1-git-send-email-labbott@redhat.com> References: <1477585654-8908-1-git-send-email-labbott@redhat.com> Subject: [kernel-hardening] [PATCHv4 2/4] arm64: dump: Make the page table dumping seq_file optional X-Virus-Scanned: ClamAV using ClamSMTP The page table dumping code always assumes it will be dumping to a seq_file to userspace. Future code will be taking advantage of the page table dumping code but will not need the seq_file. Make the seq_file optional for these cases. Reviewed-by: Kees Cook Reviewed-by: Mark Rutland Tested-by: Mark Rutland Acked-by: Mark Rutland Signed-off-by: Laura Abbott --- v4: No changes --- arch/arm64/mm/dump.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/arch/arm64/mm/dump.c b/arch/arm64/mm/dump.c index f0f0be7..bb36649 100644 --- a/arch/arm64/mm/dump.c +++ b/arch/arm64/mm/dump.c @@ -50,6 +50,18 @@ static const struct addr_marker address_markers[] = { { -1, NULL }, }; +#define pt_dump_seq_printf(m, fmt, args...) \ +({ \ + if (m) \ + seq_printf(m, fmt, ##args); \ +}) + +#define pt_dump_seq_puts(m, fmt) \ +({ \ + if (m) \ + seq_printf(m, fmt); \ +}) + /* * The page dumper groups page table entries of the same type into a single * description. It uses pg_state to track the range information while @@ -186,7 +198,7 @@ static void dump_prot(struct pg_state *st, const struct prot_bits *bits, s = bits->clear; if (s) - seq_printf(st->seq, " %s", s); + pt_dump_seq_printf(st->seq, " %s", s); } } @@ -200,14 +212,14 @@ static void note_page(struct pg_state *st, unsigned long addr, unsigned level, st->level = level; st->current_prot = prot; st->start_address = addr; - seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); + pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); } else if (prot != st->current_prot || level != st->level || addr >= st->marker[1].start_address) { const char *unit = units; unsigned long delta; if (st->current_prot) { - seq_printf(st->seq, "0x%016lx-0x%016lx ", + pt_dump_seq_printf(st->seq, "0x%016lx-0x%016lx ", st->start_address, addr); delta = (addr - st->start_address) >> 10; @@ -215,17 +227,17 @@ static void note_page(struct pg_state *st, unsigned long addr, unsigned level, delta >>= 10; unit++; } - seq_printf(st->seq, "%9lu%c %s", delta, *unit, + pt_dump_seq_printf(st->seq, "%9lu%c %s", delta, *unit, pg_level[st->level].name); if (pg_level[st->level].bits) dump_prot(st, pg_level[st->level].bits, pg_level[st->level].num); - seq_puts(st->seq, "\n"); + pt_dump_seq_puts(st->seq, "\n"); } if (addr >= st->marker[1].start_address) { st->marker++; - seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); + pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); } st->start_address = addr; @@ -235,7 +247,7 @@ static void note_page(struct pg_state *st, unsigned long addr, unsigned level, if (addr >= st->marker[1].start_address) { st->marker++; - seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); + pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); } }