From patchwork Mon Mar 6 19:09:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9607365 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 AD406601D2 for ; Mon, 6 Mar 2017 19:10:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B764D26BE9 for ; Mon, 6 Mar 2017 19:10:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABF0127B2F; Mon, 6 Mar 2017 19:10: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=-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 DA72E26BE9 for ; Mon, 6 Mar 2017 19:10:45 +0000 (UTC) Received: (qmail 9558 invoked by uid 550); 6 Mar 2017 19:10:13 -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 9354 invoked from network); 6 Mar 2017 19:10:07 -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=5MdYn8L3wcLK8lnuA8Y7NnOAjeKwY7MdKm0Eg5kmb10=; b=Bssk5rv1/XrTNPliK6/hm+bB0NJN9ND/OqJxf9JmmGYQ8O1IC2vrzVeTCuHylGORya mFq4VvpmWN72jna0+OW8ANt5V4MyLC7F3X215Na1tJKa3Qg4e5SfvMP5TjpBTUdmlZjK qJWOSKnCY/RD0K2Wn5AJUAsMLLrK+lZan9Q1Y= 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=5MdYn8L3wcLK8lnuA8Y7NnOAjeKwY7MdKm0Eg5kmb10=; b=aVFb9eL/pDcBCSfarOxZIkj5OlGpTJNEreElpVLgV3/VGcZyUFpVJHImUfUpM+raeb sJyVJqHW6nysDhcZipQIGNt38pTTRcu0oeKNRtgIS9+wZU0fC1y7pAI9Rk/q+vj88LXD qDXj9TU/IUrieulfrVchVFjQZUnjgxXOtMghY+jkBSFBEaIbJdeIukcE3bWDbiCIIEUo rNDgJBgEfn/KQhZjc8LRRHk/KFPdOHFlcM7I9CtUMTjGiFhZSCn+Zm3rUtYHvjnRHDzU V/CXZCVvnGHZqoU56Ng/e/sJ6QM928P9iGIhT5u1DRFIEVRv6EkDtAdee6jra5hscblj pyXQ== X-Gm-Message-State: AMke39mcT3Z32i5CcFLX1IiqN/Kv+8YL045iXPYPv8roS5pt9leFzGGLG2G1xRBnX8XxIAMz X-Received: by 10.99.54.140 with SMTP id d134mr22042023pga.91.1488827396072; Mon, 06 Mar 2017 11:09:56 -0800 (PST) From: Kees Cook To: kernel-hardening@lists.openwall.com Cc: Kees Cook , Andrew Morton , Rik van Riel , "Paul E. McKenney" , Jakub Kicinski , Viresh Kumar , Ingo Molnar , Thomas Gleixner , Dmitry Vyukov , Olof Johansson , Peter Zijlstra , Josh Poimboeuf , linux-kernel@vger.kernel.org Date: Mon, 6 Mar 2017 11:09:42 -0800 Message-Id: <1488827386-87193-3-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488827386-87193-1-git-send-email-keescook@chromium.org> References: <1488827386-87193-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH 2/6] 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 5828489309bb..5ef65dc2ed8b 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -129,15 +129,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 */