From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932357AbdDDWM3 (ORCPT ); Tue, 4 Apr 2017 18:12:29 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:33758 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932159AbdDDWMZ (ORCPT ); Tue, 4 Apr 2017 18:12:25 -0400 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 Subject: [PATCH v2 2/7] bug: Improve unlikely() in data corruption check 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> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 */ -- 2.7.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kees Cook Date: Tue, 4 Apr 2017 15:12:13 -0700 Message-Id: <1491343938-75336-3-git-send-email-keescook@chromium.org> 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 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 List-ID: 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 */ -- 2.7.4