From patchwork Fri Dec 8 11:01:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinbum Park X-Patchwork-Id: 10102329 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 2FDB6602A0 for ; Fri, 8 Dec 2017 11:01:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06CD628B37 for ; Fri, 8 Dec 2017 11:01:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFB9728B3C; Fri, 8 Dec 2017 11:01:49 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 2799828B37 for ; Fri, 8 Dec 2017 11:01:48 +0000 (UTC) Received: (qmail 7879 invoked by uid 550); 8 Dec 2017 11:01:47 -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: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 7856 invoked from network); 8 Dec 2017 11:01:46 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=Ox5GhZCMnjhSAXVI61bFS0dJ7PoBQ0sDfyV+1MrvyjA=; b=H93FIRsgyE/ry1vh6sxNcVitvYkwZ5XEZYdTcRUjerJrnzS9resmBGjnGZHMtVra++ N0K0/J2j5V2ZhhPEItEHVUKcRmZCFIAMw6Ecei1BfuNGMF0upcB7DoJXeoXVSKsYKm4I QsdpLrVg3taOqcta9e5pM4UFO33yufeKTJYhZ6W8Xq6o19DVCC30M1FYUoy6dAYB1Zc/ PyzGN6z5vJXrzUWJi8Kx9g/p2kdaWQCJHkZOFftgy3JAUHBkDIy/pC0E8/8CD4tNdUVx O8vjZBTqXrgezG1P0N/U1cwE37AAz3XeLV3iaHcgWjYpEak+tAnpidBnfC8rqA6V5am4 VCNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=Ox5GhZCMnjhSAXVI61bFS0dJ7PoBQ0sDfyV+1MrvyjA=; b=b8z/nvxEs8LbgpOreT+ByBVFRinqtSVAXKk/JenJ3q+k6sHmM6E04f7KX7uzJ5dNcM tYYiPqKotDxi5d5ei9N6qrYcOXFnt83U1Lpl0xHtss16ZuRbYq62QL3FsBXLrqYlTNqn mclJfKWo0RBRb0tV9dlPNKpL2FrMq7A7zFC5XbonBUqsU2kYyymRZEYC/n7uC65ltgXI 2PEZsHBhLsWSIkq0zRAA1BzeXJciFRCUBB46n/F5s9jhoeextVQz+rV79qLnjLsodmX0 76mGtlh+vbjxpvhwyfnrVX0Ce6GsBdJS/+DZotaUs9N3M+iq6rbp9tNAInhbasAixbbj vbvg== X-Gm-Message-State: AJaThX4uQifiI6eORGeXOpNrHKILXfmFiiFcw0Y0VwbNh5IdluNKvfRp a3F7Pw9nuJOye0tCchGAob0= X-Google-Smtp-Source: AGs4zMaX4leeBeSDPYcN/t9cgRwD7WWy93YqWKjbLQ7+VukFriL5gqxNor2FfqCKGfw02I5eOdh1tA== X-Received: by 10.84.248.148 with SMTP id q20mr30387171pll.110.1512730894676; Fri, 08 Dec 2017 03:01:34 -0800 (PST) Date: Fri, 8 Dec 2017 20:01:27 +0900 From: Jinbum Park To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Cc: afzal.mohd.ma@gmail.com, mark.rutland@arm.com, labbott@redhat.com, linux@armlinux.org.uk, gregkh@linuxfoundation.org, keescook@chromium.org, vladimir.murzin@arm.com, arnd@arndb.de, pombredanne@nexb.com Message-ID: <20171208110127.GA12139@pjb1027-Latitude-E5410> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Subject: [kernel-hardening][PATCH v6 2/3] arm: mm: dump: make the page table dumping seq_file optional X-Virus-Scanned: ClamAV using ClamSMTP This patch makes the page table dumping seq_file optional. It makes the page table dumping code usable for other cases. This patch refers below commit of arm64. (ae5d1cf358a5 ("arm64: dump: Make the page table dumping seq_file optional")) Reviewed-by: Kees Cook Tested-by: Laura Abbott Reviewed-by: Laura Abbott Acked-by: Kees Cook Signed-off-by: Jinbum Park --- v6: No changes (Just add Reviewed-by from Kees Cook) --- arch/arm/mm/dump.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/arch/arm/mm/dump.c b/arch/arm/mm/dump.c index 8dfe7c3..43a2bee 100644 --- a/arch/arm/mm/dump.c +++ b/arch/arm/mm/dump.c @@ -34,6 +34,18 @@ { -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); \ +}) + struct pg_state { struct seq_file *seq; const struct addr_marker *marker; @@ -210,7 +222,7 @@ static void dump_prot(struct pg_state *st, const struct prot_bits *bits, size_t s = bits->clear; if (s) - seq_printf(st->seq, " %s", s); + pt_dump_seq_printf(st->seq, " %s", s); } } @@ -224,7 +236,7 @@ static void note_page(struct pg_state *st, unsigned long addr, st->level = level; st->current_prot = prot; st->current_domain = domain; - 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 || domain != st->current_domain || addr >= st->marker[1].start_address) { @@ -232,7 +244,7 @@ static void note_page(struct pg_state *st, unsigned long addr, unsigned long delta; if (st->current_prot) { - seq_printf(st->seq, "0x%08lx-0x%08lx ", + pt_dump_seq_printf(st->seq, "0x%08lx-0x%08lx ", st->start_address, addr); delta = (addr - st->start_address) >> 10; @@ -240,17 +252,19 @@ static void note_page(struct pg_state *st, unsigned long addr, delta >>= 10; unit++; } - seq_printf(st->seq, "%9lu%c", delta, *unit); + pt_dump_seq_printf(st->seq, "%9lu%c", delta, *unit); if (st->current_domain) - seq_printf(st->seq, " %s", st->current_domain); + pt_dump_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"); + pt_dump_seq_printf(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; st->current_prot = prot;