Reply-To: kernel-hardening@lists.openwall.com From: Arnd Bergmann Date: Mon, 22 Aug 2016 15:15:35 +0200 Message-ID: <4367840.AWTJIHYqbe@wuerfel> In-Reply-To: <1471470132-29499-5-git-send-email-keescook@chromium.org> References: <1471470132-29499-1-git-send-email-keescook@chromium.org> <1471470132-29499-5-git-send-email-keescook@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Subject: [kernel-hardening] Re: [PATCH v3 4/5] bug: Provide toggle for BUG on data corruption To: Kees Cook Cc: "Paul E . McKenney" , Laura Abbott , Steven Rostedt , Daniel Micay , Joe Perches , Stephen Boyd , Syed Rameez Mustafa , Greg Kroah-Hartman , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , "Aneesh Kumar K.V" , "Kirill A. Shutemov" , Michael Ellerman , Andrew Morton , Dan Williams , Jan Kara , Thomas Gleixner , Josef Bacik , Ingo Molnar , Tejun Heo , Andrey Ryabinin , Nikolay Aleksandrov , Dmitry Vyukov , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com List-ID: On Wednesday, August 17, 2016 2:42:11 PM CEST Kees Cook wrote: > + > +/* > + * Since detected data corruption should stop operation on the affected > + * structures, this returns false if the corruption condition is found. > + */ > +#define CHECK_DATA_CORRUPTION(condition, fmt, ...) \ > + do { \ > + if (unlikely(condition)) { \ > + if (IS_ENABLED(CONFIG_BUG_ON_DATA_CORRUPTION)) { \ > + pr_err(fmt, ##__VA_ARGS__); \ > + BUG(); \ > + } else \ > + WARN(1, fmt, ##__VA_ARGS__); \ > + return false; \ > + } \ > + } while (0) > + I think the "return false" inside of the macro makes it easy to misread what is actually going on. How about making it a macro that returns the condition argument? #define CHECK_DATA_CORRUPTION(condition, fmt, ...) \ ({ \ bool _condition = unlikely(condition); \ if (_condition) { \ ... } \ _condition; \ }) Arnd