From patchwork Wed Nov 8 22:30:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10049589 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 2278B6032D for ; Wed, 8 Nov 2017 22:32:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15D922999C for ; Wed, 8 Nov 2017 22:32:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AA062A652; Wed, 8 Nov 2017 22:32:03 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 2101A2A662 for ; Wed, 8 Nov 2017 22:32:01 +0000 (UTC) Received: (qmail 17868 invoked by uid 550); 8 Nov 2017 22:31:05 -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 17618 invoked from network); 8 Nov 2017 22:31:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7TFAkpo6AI6yuIkuN6oKv5Jj6SGuH2V0fT4xVMMbIE0=; b=YjbWaCX23ggN1CMF434v+WCoTNE+CMNaI54Q44bmGOFZI5X/anCLlM2naohhotWki9 lSvaRJPJflSR4+buvcvj9jP0sqrEAk7pekcfKDF2sBvsZJYbCAUuOyh5//3vAsz6mVH3 uNCLub8ZPBtv8giCnkKCkpLijpZoPXp1G+n5g= 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=7TFAkpo6AI6yuIkuN6oKv5Jj6SGuH2V0fT4xVMMbIE0=; b=oH2f1H0mxXFd2CmF68vxILCc0ApTM/jyZtKJr8ZZB8neF6NB9iJkoJ3SM5GOGvv/Ax dalLMy2QIckI/5+wS3y9r/PqVMowxB82OrnUyInaWMLhn3GDednX1D9rTeKFz3m/wsu1 UfkA6E+CfCgwcZRvNZrktowKnEiu1O0RNukF/aMm9v/83GRZ/BmXkUWQLZcYO6PL6SoC CMxXEX7Ajx0hHw1y+lsZqRecCVKzXlE48tsqLQOiNUvnyjyXKY7FHmdrtQKCJxxhRc3f 55AKI8l2VLzx4iqD1Xe/GnF934vSEvlyqHIB7ARrFJiFK/TbqlFBs0RzMi78O0cM/sua ucVw== X-Gm-Message-State: AJaThX6R7QnYCYGpzZBu6Yvqsp8uAYWfG8a2wQVaLL6MM0hZFzMb9u3a MG0A33AGfbrzXu4/jRSqilnvE/9Q X-Google-Smtp-Source: AGs4zMZ07y1fAiLirdeYLHdrAvQ2ysESASC6DMVYgR2/J2hqRKcs0FzNPEQ7VLT9RHTq8mGCthkn8w== X-Received: by 10.28.128.138 with SMTP id b132mr78254wmd.82.1510180248881; Wed, 08 Nov 2017 14:30:48 -0800 (PST) From: Rasmus Villemoes To: kernel-hardening@lists.openwall.com Cc: linux-kernel@vger.kernel.org, Andrew Morton , Kees Cook , Rasmus Villemoes Date: Wed, 8 Nov 2017 23:30:20 +0100 Message-Id: <20171108223020.24487-7-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171108223020.24487-1-linux@rasmusvillemoes.dk> References: <20171108223020.24487-1-linux@rasmusvillemoes.dk> Subject: [kernel-hardening] [RFC 6/6] lib/test_printf.c: add a few fmtcheck() test cases X-Virus-Scanned: ClamAV using ClamSMTP It should be trivial to add more test cases, once we figure out the exact rules for being compatible or not. Perhaps we'll have to extend the struct test with a flags element if we add flags that affect the return value. Signed-off-by: Rasmus Villemoes --- lib/test_printf.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/lib/test_printf.c b/lib/test_printf.c index 563f10e6876a..0c8490f3a9b3 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -483,6 +483,45 @@ test_pointer(void) flags(); } +static void __init +test_fmtcheck(void) +{ + struct test { const char *fmt; const char *tmpl; }; + static const struct test compatible[] __initconst = { + {"", ""}, + {"wlan%d", "%d"}, + {"aa%llxbb", "cc%Lxdd%%"}, + }; + static const struct test incompatible[] __initconst = { + {"a %d b %lx", "%d %x"}, + {"%llo", "%Lx"}, + }; + unsigned i; + const struct test *t; + const char *ret; + + for (i = 0; i < ARRAY_SIZE(compatible); ++i) { + total_tests++; + t = &compatible[i]; + ret = _fmtcheck(t->fmt, t->tmpl, FMTCHECK_SILENT); + if (ret != t->fmt) { + failed_tests++; + pr_warn("'%s' and '%s' deemed incompatible by fmtcheck()", + t->fmt, t->tmpl); + } + } + for (i = 0; i < ARRAY_SIZE(incompatible); ++i) { + total_tests++; + t = &incompatible[i]; + ret = _fmtcheck(t->fmt, t->tmpl, FMTCHECK_SILENT); + if (ret != t->tmpl) { + failed_tests++; + pr_warn("'%s' and '%s' deemed compatible by fmtcheck()", + t->fmt, t->tmpl); + } + } +} + static int __init test_printf_init(void) { @@ -496,6 +535,8 @@ test_printf_init(void) test_string(); test_pointer(); + test_fmtcheck(); + kfree(alloced_buffer); if (failed_tests == 0)