From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753572AbcHQA0T (ORCPT ); Tue, 16 Aug 2016 20:26:19 -0400 Received: from smtprelay0072.hostedemail.com ([216.40.44.72]:56757 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752224AbcHQA0R (ORCPT ); Tue, 16 Aug 2016 20:26:17 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::::::::::::::::::::::::::::,RULES_HIT:41:355:379:541:599:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2194:2199:2393:2553:2559:2562:2828:2894:2898:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3871:3874:4037:4321:5007:6742:6743:7903:10004:10400:10848:11026:11232:11473:11658:11783:11914:12043:12294:12296:12438:12517:12519:12740:13069:13160:13229:13311:13357:13439:13894:14659:14721:21080:21451:30054:30064:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: doll17_53325a56b8f05 X-Filterd-Recvd-Size: 3389 Message-ID: <1471393569.4075.187.camel@perches.com> Subject: Re: [PATCH v2 4/5] bug: Provide toggle for BUG on data corruption From: Joe Perches To: Kees Cook , "Paul E . McKenney" Cc: Laura Abbott , Steven Rostedt , Stephen Boyd , Daniel Micay , Arnd Bergmann , Greg Kroah-Hartman , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , "Aneesh Kumar K.V" , "Kirill A. Shutemov" , Michael Ellerman , Dan Williams , Andrew Morton , Ingo Molnar , Thomas Gleixner , Josef Bacik , Andrey Ryabinin , Tejun Heo , Nikolay Aleksandrov , Dmitry Vyukov , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Date: Tue, 16 Aug 2016 17:26:09 -0700 In-Reply-To: <1471393229-27182-5-git-send-email-keescook@chromium.org> References: <1471393229-27182-1-git-send-email-keescook@chromium.org> <1471393229-27182-5-git-send-email-keescook@chromium.org> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.5.2-0ubuntu3 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2016-08-16 at 17:20 -0700, Kees Cook wrote: > The kernel checks for cases of data structure corruption under some > CONFIGs (e.g. CONFIG_DEBUG_LIST). When corruption is detected, some > systems may want to BUG() immediately instead of letting the system run > with known corruption.  Usually these kinds of manipulation primitives can > be used by security flaws to gain arbitrary memory write control. This > provides a new config CONFIG_BUG_ON_DATA_CORRUPTION and a corresponding > macro CHECK_DATA_CORRUPTION for handling these situations. Notably, even > if not BUGing, the kernel should not continue processing the corrupted > structure. [] > diff --git a/include/linux/bug.h b/include/linux/bug.h [] > @@ -118,4 +118,21 @@ static inline enum bug_trap_type report_bug(unsigned long bug_addr, >  } >   >  #endif /* CONFIG_GENERIC_BUG */ > + > +/* > + * 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, format...)  \ My preference would be to use (condition, fmt, ...) > + do {  \ > + if (unlikely(condition)) {  \ > + if (IS_ENABLED(CONFIG_BUG_ON_DATA_CORRUPTION)) { \ > + printk(KERN_ERR format);  \ and pr_err(fmt, ##__VA_ARGS__); so that any use would also get any local pr_fmt applied as well. > + BUG();  \ > + } else  \ > + WARN(1, format);  \ > + return false;  \ > + }  \ > + } while (0) > + >  #endif /* _LINUX_BUG_H */