From patchwork Tue Jan 31 20:24:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9548423 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 D813F60415 for ; Tue, 31 Jan 2017 20:24:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8A462838C for ; Tue, 31 Jan 2017 20:24:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB2602838E; Tue, 31 Jan 2017 20:24:59 +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 B8B412838C for ; Tue, 31 Jan 2017 20:24:57 +0000 (UTC) Received: (qmail 21921 invoked by uid 550); 31 Jan 2017 20:24:53 -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 21820 invoked from network); 31 Jan 2017 20:24:50 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qa1CrFTksuJ5hg2iz3UyG6U7ihShcN+dHGc0ck4XTDU=; b=bptl/VI8uXeRAKuvtylBKcJstLiDau9f/T4vQxZAmOAmtbTx0twPMgfzMhmBKFsbxw /WN7ezybB/KQSgdNovwA3LRDDCN6E4+abVvcKnfvINZtBqLMM8FQ2yKtihcDXpR/B0eD riwhDLSt8XuNudOpsymyRE+vWtfbpl+lRXt1o= 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=qa1CrFTksuJ5hg2iz3UyG6U7ihShcN+dHGc0ck4XTDU=; b=sVCMc1atK547rP7NaMTC3NrXglCJ0zlQn6OIdobQbCyZ3OHVHXebVO442PZUsUQW9J 1sLV6EkfDXJuwLJH8Oeazitd02VdHWLSTUYd/qfShlohsOxHzsSXhdrtA5F01OcdZ6Fn 0PnRmjjejn06H7Sc5yPbSy3RH6Zy+nJWvK3QH26T9/8u//dDptiSE85JRvfcBb9Xsy2v G+xBdqaTfNZGEbeYinkn0tfof9Jz7M0KBU4IlhlNKKy4N62g56J6xA5EDWv5t8xZwAuk BIrxD1VCo6SGCsTRQ+UTcsLwajr9EUSK3JJlMh0UxNZOc0VjziPr61XOjdXpetN2a0qq fzBA== X-Gm-Message-State: AIkVDXIzIn94wZLA6crnM6s2TWmEPgh0c7/FdH+W348uirAHxjx1dwKWjNfrjCqoKBAQRl56 X-Received: by 10.98.112.134 with SMTP id l128mr31321197pfc.81.1485894278175; Tue, 31 Jan 2017 12:24:38 -0800 (PST) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Emese Revfy , Arnd Bergmann , Josh Triplett , pageexec@freemail.hu, yamada.masahiro@socionext.com, minipli@ld-linux.so, linux@armlinux.org.uk, catalin.marinas@arm.com, linux@rasmusvillemoes.dk, david.brown@linaro.org, benh@kernel.crashing.org, tglx@linutronix.de, akpm@linux-foundation.org, jlayton@poochiereds.net, sam@ravnborg.org, kernel-hardening@lists.openwall.com Date: Tue, 31 Jan 2017 12:24:22 -0800 Message-Id: <1485894263-91051-5-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1485894263-91051-1-git-send-email-keescook@chromium.org> References: <1485894263-91051-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH v5 4/4] initify: Mark functions with the __unverified_nocapture attribute X-Virus-Scanned: ClamAV using ClamSMTP From: Emese Revfy The initify plugin attempts to analyze function arguments that have been marked correctly with the __nocapture attribute. However, due to code complexity, this is not always possible to verify. As a result, some __nocapture attributes need to be marked as excluded from the automatic verification. To do this, the __unverified_nocapture attribute is added. It is intedned to only be used on function parameters that are difficult for the plugin to analyze. Signed-off-by: Emese Revfy Signed-off-by: Kees Cook --- include/linux/compiler-gcc.h | 8 ++++++++ include/linux/compiler.h | 4 ++++ lib/vsprintf.c | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index cd4e9ffb00a7..fc0495e849ff 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -204,9 +204,17 @@ * been unmapped from memory. In order to identify functions that are confirmed * to not capture their arguments, the __nocapture() attribute is used so that * initify can better identify candidate variables. + * + * Arguments marked in this way are verified by the plugin, but sometimes + * code complexity and other limitiations will cause initify to not be able + * to check it correctly. For these cases, the __unverified_nocapture + * attribute can be added to disable this checking, overriding the plugin + * logic for cases that have been manually verified. This should not need + * to be used very often. */ #ifdef INITIFY_PLUGIN #define __nocapture(...) __attribute__((nocapture(__VA_ARGS__))) +#define __unverified_nocapture(...) __attribute__((unverified_nocapture(__VA_ARGS__))) #endif /* diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 8b3dcc790bb6..1bde420f07bb 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -437,6 +437,10 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s # define __nocapture(...) #endif +#ifndef __unverified_nocapture +# define __unverified_nocapture(...) +#endif + /* * Tell gcc if a function is cold. The compiler will assume any path * directly leading to the call is unlikely. diff --git a/lib/vsprintf.c b/lib/vsprintf.c index a192761d338a..cb964b51f9f8 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -118,7 +118,7 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base) } EXPORT_SYMBOL(simple_strtoll); -static noinline_for_stack __nocapture(1) +static noinline_for_stack __nocapture(1) __unverified_nocapture(1) int skip_atoi(const char **s) { int i = 0; @@ -1570,7 +1570,7 @@ int kptr_restrict __read_mostly; * function pointers are really function descriptors, which contain a * pointer to the real address. */ -static noinline_for_stack __nocapture(1) +static noinline_for_stack __nocapture(1) __unverified_nocapture(1) char *pointer(const char *fmt, char *buf, char *end, void *ptr, struct printf_spec spec) {