From patchwork Tue Jan 31 20:24:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9548427 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 924AC60415 for ; Tue, 31 Jan 2017 20:25:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82DE22838C for ; Tue, 31 Jan 2017 20:25:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 772532838E; Tue, 31 Jan 2017 20:25:12 +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 96C312838C for ; Tue, 31 Jan 2017 20:25:11 +0000 (UTC) Received: (qmail 22068 invoked by uid 550); 31 Jan 2017 20:24:55 -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 21853 invoked from network); 31 Jan 2017 20:24:51 -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=3ghz7HbYbqD+TXWB1sFwU/Md9icO+nQQ0hXpkZjERBU=; b=TYkz8OEBW4OdNWAw91lHRt9RBeuk9pDWCPFP+IoxhI3WHHrMJIyhbRRYSi0hX6I0zH uKHQ1sLkLBucNxIpC1aY6/XgnIP4r4KbA6hrnUJ/1aSTqcS6pZPHPb8sIlF3eixSEo6h guuTjSmldJ4uRoAVpzdeIja0YHcvarpnNmklE= 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=3ghz7HbYbqD+TXWB1sFwU/Md9icO+nQQ0hXpkZjERBU=; b=M968oASOvUlhay71ULh1OXbhHLTO9d9kp/A7aAC2JuXOjHSbYIjY1BQLqMSH+YlaGE bUMfaK9u3AY6lvOt7v9ph1krPf959IWRIJ7srHIGjmIV5J8V2UQDfR3eUywaVCxpY/gA LhbNtFv3e23GFn3THvpdnvwvKB/Q/aBnPmeivPmxFXoedwVOAooFXqUFc8Dwgl2M9TqD 09FtVJQJJe1LkrhO+i6w5WnffSP4aQpWfX9NNuT1Ggh/Ldlt09j98Jxsdg0B7UXy024I u/vTZRVjwm4ZzUariPxgNl4e/cwCy6tmRs0sTDoPIBXUX2tMA+7hDKOYSPywuoZ6eFOi dsvw== X-Gm-Message-State: AIkVDXIYYrL3LmnonQQujyhaFM0ON2EBjyrKrKNxGhGQWvpjrCsbmkxj5DsTziZG46EM+aGQ X-Received: by 10.84.217.7 with SMTP id o7mr42588685pli.166.1485894279790; Tue, 31 Jan 2017 12:24:39 -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:20 -0800 Message-Id: <1485894263-91051-3-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 2/4] util: Move type casts into is_kernel_rodata X-Virus-Scanned: ClamAV using ClamSMTP From: Emese Revfy This moves type casts into the is_kernel_rodata() function itself so that parameters can be marked as "nocapture" in the coming initify gcc plugin. Signed-off-by: Emese Revfy [kees: expanded commit message] Signed-off-by: Kees Cook --- mm/util.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/util.c b/mm/util.c index 3cb2164f4099..a700e3fb1587 100644 --- a/mm/util.c +++ b/mm/util.c @@ -17,10 +17,10 @@ #include "internal.h" -static inline int is_kernel_rodata(unsigned long addr) +static inline int is_kernel_rodata(const void *addr) { - return addr >= (unsigned long)__start_rodata && - addr < (unsigned long)__end_rodata; + return (unsigned long)addr >= (unsigned long)__start_rodata && + (unsigned long)addr < (unsigned long)__end_rodata; } /** @@ -31,7 +31,7 @@ static inline int is_kernel_rodata(unsigned long addr) */ void kfree_const(const void *x) { - if (!is_kernel_rodata((unsigned long)x)) + if (!is_kernel_rodata(x)) kfree(x); } EXPORT_SYMBOL(kfree_const); @@ -68,7 +68,7 @@ EXPORT_SYMBOL(kstrdup); */ const char *kstrdup_const(const char *s, gfp_t gfp) { - if (is_kernel_rodata((unsigned long)s)) + if (is_kernel_rodata(s)) return s; return kstrdup(s, gfp);