From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752878AbdKHWav (ORCPT ); Wed, 8 Nov 2017 17:30:51 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:48267 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752835AbdKHWar (ORCPT ); Wed, 8 Nov 2017 17:30:47 -0500 X-Google-Smtp-Source: ABhQp+SUgac8d0LIx0Nfns3ljpBjMU3rxceBw6U9AjcmmwD4k9ktb2rsqhy2UrIyYDpSqkY0kMz4ZQ== From: Rasmus Villemoes To: kernel-hardening@lists.openwall.com Cc: linux-kernel@vger.kernel.org, Andrew Morton , Kees Cook , Rasmus Villemoes Subject: [RFC 3/6] compiler.h: add __attribute__((format_arg)) shorthand 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> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 */ -- 2.11.0