From patchwork Fri Dec 16 22:06:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9478571 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 6D2E86047D for ; Fri, 16 Dec 2016 22:08:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E78827F85 for ; Fri, 16 Dec 2016 22:08:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51BF328638; Fri, 16 Dec 2016 22:08:46 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4544427F85 for ; Fri, 16 Dec 2016 22:08:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933136AbcLPWIo (ORCPT ); Fri, 16 Dec 2016 17:08:44 -0500 Received: from mail-pf0-f173.google.com ([209.85.192.173]:36565 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933017AbcLPWIj (ORCPT ); Fri, 16 Dec 2016 17:08:39 -0500 Received: by mail-pf0-f173.google.com with SMTP id 189so15932035pfz.3 for ; Fri, 16 Dec 2016 14:08:39 -0800 (PST) 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=r/Wz0krH0uPfRTDManRFqLR+U0ZDe1b1Va2L463MQCU=; b=Hgmd1dTzXIopeK5Lr0WFYUitQs0W1Zr+AaarQTqZ9a3eBwqVkPXZBflNV9kPC4UGdD Yi6A0c6OSlpPuAwra2FrnwOew03T2bgDQOtx5y2mu1tiR7gzyj8QtIVa8P2ARq7Pz5d8 OXWIkU3Qj/hVaDKUmCb6H9BP9bJNm9YnTCgdg= 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=r/Wz0krH0uPfRTDManRFqLR+U0ZDe1b1Va2L463MQCU=; b=jUaQ7IeTY7rfTM8bMO/QpGlITF8Lup0pHCi/m0Nre/gcVM6DQgCQ0V6/BLivTFGXpy pJDU/EF1vYF+SEkp4xki2djA0p3FxA7PNaFLdjX0YXV4sjsIyHLyiegbHajGDzI9OXvD qfNTfJnbaoMIGGlkCpMVG8c5vDQHhGe8famSkYOGpWnc176sM33MhBpIDK3K3lr9dGT2 Ona59sR6uhNcgpPDJGrgS/nSqmnPeR3UlJUF1vIvj3T9bYUiIjS5bfXeGfPwAU6jJgIT h7crBh+zfZeF6iqCkajco/3Z38a/jmhRRIRNORvj3JwdTUidrkuKoFaZ85Nm+OcKzIXI IxHg== X-Gm-Message-State: AKaTC03S3akymkxNEKV2h4WuCe9+zPyNmIKHxJYcl3L3+LsgBByMlN4DNpPqc54IbIDAUIRb X-Received: by 10.84.216.80 with SMTP id f16mr11266513plj.91.1481926119222; Fri, 16 Dec 2016 14:08:39 -0800 (PST) Received: from www.outflux.net ([2002:ada4:7085:0:8454:20a8:3cd7:bcbf]) by smtp.gmail.com with ESMTPSA id u23sm13982908pfg.86.2016.12.16.14.08.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Dec 2016 14:08:38 -0800 (PST) From: Kees Cook To: kernel-hardening@lists.openwall.com Cc: Kees Cook , Emese Revfy , linux-kernel@vger.kernel.org, Arnd Bergmann , Josh Triplett , pageexec@freemail.hu, spender@grsecurity.net, mmarek@suse.com, yamada.masahiro@socionext.com, linux-kbuild@vger.kernel.org, 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 Subject: [PATCH v4 2/4] util: Move type casts into is_kernel_rodata Date: Fri, 16 Dec 2016 14:06:22 -0800 Message-Id: <1481925984-98605-3-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481925984-98605-1-git-send-email-keescook@chromium.org> References: <1481925984-98605-1-git-send-email-keescook@chromium.org> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org 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 1a41553db866..5606c6b74eee 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);