From patchwork Wed Nov 8 22:30:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10049587 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 32AD56032D for ; Wed, 8 Nov 2017 22:31:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25F6929996 for ; Wed, 8 Nov 2017 22:31:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AC3B299A3; Wed, 8 Nov 2017 22:31:53 +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 5FD0C2999C for ; Wed, 8 Nov 2017 22:31:52 +0000 (UTC) Received: (qmail 17802 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 17567 invoked from network); 8 Nov 2017 22:30:59 -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=WqQibg7RCM8+xGZzVb3t7L0pLWwZL1X9p+Lt5r1p8zA=; b=Yoyl6SroJZDIxyLSYqxhqNOO54yKOOB8iJ4vk4T9QW+Miftz7efqV12o+sYc9fSoso CNCRqRiJ184UwzdHaBAd2Q2dD9f2K6BL2L6AhMHLFCk5CCdEUUGQYC1TYxh8zsUmeijJ XDhTdpQ2SouOMGLhwLKPjEIn6+uql+8Oxa9Mg= 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=WqQibg7RCM8+xGZzVb3t7L0pLWwZL1X9p+Lt5r1p8zA=; b=DUcY7l0XNS9E+f2zSgReEz9ROfxUmuUHP8eAYMbn6Zn8rP1paA5LnGlYNJFOcWRIO8 jyWNLH1hNxQYx0a0sCNOYHj4qe5f0IDzQrmeC2a5C2utDVBoCnFs8Qh2euG8baqwbR+g PdOdGqmsVVaP1RAotAbKa4RRBJ6dINq9RlNO8c9GbiZd2JUS/fwPFd3bqAjKNyPxjV6B Lzbj/fzmkb/7WA3Ns/XBpV5VFjatShH+rZ4gt5IEK+OfCn1enzSBw/kIvDCMSl2i7I4T azCrwlNOUACBcInKNPHERXPD0Zyvsr1bl6qi3sD0OAPS+z3XAjLxloU7QDME24Au5EJF w1dA== X-Gm-Message-State: AJaThX44gZdamuxivA+AZ68qI+aD7K/4QTyyaU/pHIH6JWjv3Z2aF2re PstlV6cFM7WVfz3Ls9y54LkYWhe8 X-Google-Smtp-Source: ABhQp+QXSvjcJi7B7pM0wBx6yR55q6pKUQ6ayBGqnnyAp24vTg8pszeCb95zu/HvLZFZHS3FRezpkg== X-Received: by 10.223.149.5 with SMTP id 5mr1604322wrs.135.1510180247919; Wed, 08 Nov 2017 14:30:47 -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:19 +0100 Message-Id: <20171108223020.24487-6-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 5/6] kernel.h: implement fmtmatch() wrapper around fmtcheck() X-Virus-Scanned: ClamAV using ClamSMTP I couldn't come up with a better name, suggestions welcome. Some users may prefer to EINVAL rather than using the the template as a fallback for printf'ing. fmtmatch() is simply a shorthand for fmtcheck(a, b, c) == a. Signed-off-by: Rasmus Villemoes --- include/linux/kernel.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index d7c6f9a9c024..5eae5ecb590d 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -466,6 +466,13 @@ const char *_fmtcheck(const char *fmt, const char *tmpl, unsigned flags); #define FMTCHECK_SILENT 0x01 #define FMTCHECK_NO_EXTRA_ARGS 0x02 +#define fmtmatch(fmt, tmpl, flags) _fmtmatch(fmt, "" tmpl "", flags) +static inline bool +_fmtmatch(const char *fmt, const char *tmpl, unsigned flags) +{ + return _fmtcheck(fmt, tmpl, flags) == fmt; +} + extern __scanf(2, 3) int sscanf(const char *, const char *, ...); extern __scanf(2, 0)