From patchwork Wed Nov 8 22:30:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10049583 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 23CC660381 for ; Wed, 8 Nov 2017 22:31:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 171EB2912F for ; Wed, 8 Nov 2017 22:31:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08C6D29994; Wed, 8 Nov 2017 22:31:45 +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 34E912999C for ; Wed, 8 Nov 2017 22:31:44 +0000 (UTC) Received: (qmail 17755 invoked by uid 550); 8 Nov 2017 22:31:02 -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 17501 invoked from network); 8 Nov 2017 22:30:58 -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=wJnmuizw611SSHKmEA33UKDmEa6sgpBQxALOFQOrteU=; b=FoRcd1474mjmiPwoLdTHDpENBW9y5V872wYe4JZUOzMFaP9ngJJSI4oHe60/RGQyby poJFBIMnHuxsGvOoXp3lv6DxKsS2cPFhuFMMCBocq1NRkhtTv4GL4nE/Ym4wAYvjbrlf KyJsVAraRpbBSRsm6xBf1eJaIh8RLPmKiesHs= 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=wJnmuizw611SSHKmEA33UKDmEa6sgpBQxALOFQOrteU=; b=YkxZDPHhlMDsVKLMT56/yfhFFmOjKo/Ytq04+/OC/8qKvnJOwFTynR5nUnq/TbIlFX 7szqPelIKAmMEslsa6DAtxmKQGVun1tVzd8Gt/U4K5i/YATnPmlHB+UpQ7utRl9ChaZv 018RAwqJYQwn6r/C2rTO+NEyastSNrW71XiMhSqF1bY9xQdjpxysKDfJEFWSsU0N4Ars rjCNxjYg6jSpwpqYPfdbhD0GAh4Nstpozx7Sq8vrFr+3QYaHMv9SF+c2GZkmnEg+gvPF b+DSj3Jq1yYMAqo7x6m57+jQnP718NkNCLqdZS8LOdNzbomd093KG3li2U1IENd7YLag RmUg== X-Gm-Message-State: AJaThX43Inx2W/7UD7gaFCWaaaEo5K7ixin7m9NgKetV4hRJ9P98626+ I4XcdjYNkGGMaVcLfZumyq1gpgdX X-Google-Smtp-Source: ABhQp+SUgac8d0LIx0Nfns3ljpBjMU3rxceBw6U9AjcmmwD4k9ktb2rsqhy2UrIyYDpSqkY0kMz4ZQ== X-Received: by 10.223.134.14 with SMTP id 14mr1687660wrv.148.1510180246391; Wed, 08 Nov 2017 14:30:46 -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:17 +0100 Message-Id: <20171108223020.24487-4-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 3/6] compiler.h: add __attribute__((format_arg)) shorthand X-Virus-Scanned: ClamAV using ClamSMTP The __format_arg attribute tells gcc that it can use a specific argument to the annotated function as the format string for the purpose of type-checking a surrounding __printf function call, e.g. sprintf(buf, fmtcheck(what->ever, "%d %lx", 0), i, m) makes gcc check that i and m are indeed an int and a long; with sprintf(buf, what->ever, i, m) the compiler cannot do any type checking. Signed-off-by: Rasmus Villemoes --- include/linux/compiler-gcc.h | 1 + include/linux/compiler.h | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index bb78e5bdff26..69a233f9fa26 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -128,6 +128,7 @@ #define __maybe_unused __attribute__((unused)) #define __always_unused __attribute__((unused)) #define __mode(x) __attribute__((mode(x))) +#define __format_arg(n) __attribute__((format_arg(n))) /* gcc version specific checks */ diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 478914ad280b..2c8793f72fb0 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -631,4 +631,8 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s #define __format_template(x) #endif +#ifndef __format_arg +#define __format_arg(n) +#endif + #endif /* __LINUX_COMPILER_H */