From patchwork Tue Apr 4 22:12:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9662695 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 0141D6032D for ; Tue, 4 Apr 2017 22:12:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E691227F94 for ; Tue, 4 Apr 2017 22:12:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA9F728587; Tue, 4 Apr 2017 22:12:55 +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 2605A27F94 for ; Tue, 4 Apr 2017 22:12:54 +0000 (UTC) Received: (qmail 26251 invoked by uid 550); 4 Apr 2017 22:12:37 -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 26204 invoked from network); 4 Apr 2017 22:12:36 -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=g8vU3rHkLzlDcs0qM9dpDHjI3QPuPJDBtXKm7cDzRBA=; b=S36AyTaduGRg2vq8ZXxee6XE3JiGhLH8MZIk719VNqfJn0MaJwwyTNXIXrYHS9hBRC SCGIxYfymU+2KzEGoaAMU91i94jsx3YlqpBS26Et+hwLlWikYq48vS1e7V0Yj4qsSU44 Cm8sose0G7b93u5/+ESyTLsiH2/CoPPsJWSsE= 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=g8vU3rHkLzlDcs0qM9dpDHjI3QPuPJDBtXKm7cDzRBA=; b=Qi7VxBnZvSTwB9Zt7czUnJfj8gWOMyu8F6y4DLdbx6xUAvrRIWT9WH3D0crw/GEML6 3E24aBGxTIDJL0/l19R8PkJ/hGRN3mkCGejx+3eAkgRZIP6ep4XBn90PSXjymeFiqh2L qwoo7GU5My01wjyKcHwdpdaXyNyFaHucopbws3gLbGzIzEkCynnA+kqwdlXqL1Bc8W0c PcF6WzvqryhT1U8p1wNLoQ8L4kBe/VwTfEYnhS4PmnW/BBo60J2mNikQBCzodx1xIVSK iIsOak26aG6qMZBhvhwWTqKa+JFo0r0Qf/lsVmk1jpI8pUVbYGH/XYvrV973FqzueAac Dd7w== X-Gm-Message-State: AFeK/H0/bgQ1sdB9XEQKh8MlNFWpiBR545PW2FPCpHLf94RJ8y5l2cTVcAl+Crjcr4zk/+8S X-Received: by 10.99.101.67 with SMTP id z64mr26906506pgb.78.1491343944820; Tue, 04 Apr 2017 15:12:24 -0700 (PDT) From: Kees Cook To: Ingo Molnar Cc: Kees Cook , Peter Zijlstra , "Paul E. McKenney" , Kalle Valo , Andrew Morton , Rik van Riel , Jakub Kicinski , Viresh Kumar , Andy Shevchenko , Geert Uytterhoeven , Olof Johansson , Chris Wilson , George Spelvin , Thomas Gleixner , Josh Poimboeuf , David Windsor , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Date: Tue, 4 Apr 2017 15:12:13 -0700 Message-Id: <1491343938-75336-3-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491343938-75336-1-git-send-email-keescook@chromium.org> References: <1491343938-75336-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH v2 2/7] bug: Improve unlikely() in data corruption check X-Virus-Scanned: ClamAV using ClamSMTP This improves the compiler branch-hinting used in CHECK_DATA_CORRUPTION(), similar to how it is done in WARN_ON() and friends. Signed-off-by: Kees Cook --- include/linux/bug.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/bug.h b/include/linux/bug.h index db1e41c69bac..b6cfcb7f778f 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -130,15 +130,15 @@ static inline enum bug_trap_type report_bug(unsigned long bug_addr, static inline __must_check bool check_data_corruption(bool v) { return v; } #define CHECK_DATA_CORRUPTION(condition, fmt, ...) \ check_data_corruption(({ \ - bool corruption = unlikely(condition); \ - if (corruption) { \ + bool corruption = !!(condition); \ + if (unlikely(corruption)) { \ if (IS_ENABLED(CONFIG_BUG_ON_DATA_CORRUPTION)) { \ pr_err(fmt, ##__VA_ARGS__); \ BUG(); \ } else \ WARN(1, fmt, ##__VA_ARGS__); \ } \ - corruption; \ + unlikely(corruption); \ })) #endif /* _LINUX_BUG_H */