From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753619AbcHPVyE (ORCPT ); Tue, 16 Aug 2016 17:54:04 -0400 Received: from smtprelay0182.hostedemail.com ([216.40.44.182]:56068 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753563AbcHPVyC (ORCPT ); Tue, 16 Aug 2016 17:54:02 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::::::::::::::::::::::::::::::::::::::::,RULES_HIT:2:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1535:1593:1594:1605:1730:1747:1777:1792:1801:2194:2199:2393:2553:2559:2562:2693:3138:3139:3140:3141:3142:3622:3865:3866:3867:3868:3870:3871:3872:3873:3874:4049:4119:4250:4321:4605:5007:6119:6261:6742:6743:7875:7903:9149:10004:10848:10967:11026:11232:11233:11473:11658:11914:12043:12296:12438:12517:12519:12555:12740:13161:13229:13439:14093:14097:14659:21080:21451:30029:30054:30056:30062:30064: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:2,LUA_SUMMARY:none X-HE-Tag: fan86_3f969f7851061 X-Filterd-Recvd-Size: 8907 Date: Tue, 16 Aug 2016 17:53:54 -0400 From: Steven Rostedt To: Kees Cook Cc: Paul McKenney , Stephen Boyd , Daniel Micay , Arnd Bergmann , Greg Kroah-Hartman , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , Peter Zijlstra , Ingo Molnar , Tejun Heo , Michael Ellerman , "Aneesh Kumar K.V" , "Kirill A. Shutemov" , Andrew Morton , Dan Williams , Jan Kara , Josef Bacik , Thomas Gleixner , Andrey Ryabinin , Nikolay Aleksandrov , Dmitry Vyukov , LKML , "kernel-hardening@lists.openwall.com" , Joe Perches Subject: Re: [PATCH 4/5] bug: Provide toggle for BUG on data corruption Message-ID: <20160816175354.0b58d5f3@gandalf.local.home> In-Reply-To: References: <1471381865-25724-1-git-send-email-keescook@chromium.org> <1471381865-25724-5-git-send-email-keescook@chromium.org> <20160816212605.GY3482@linux.vnet.ibm.com> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 16 Aug 2016 14:42:28 -0700 Kees Cook wrote: > > OK, I will bite... Why both the WARN() and the BUG_ON()? > > Mostly because not every case of BUG(CORRUPTED_DATA_STRUCTURE) is > cleanly paired with a WARN (see the workqueue addition that wants to > dump locks too). I could rearrange things a bit, though, and create > something like: > > #ifdef CONFIG_BUG_ON_CORRUPTION > # define CORRUPTED(format...) { \ > printk(KERN_ERR format); \ > BUG(); \ > } > #else > # define CORRUPTED(format...) WARN(1, format) > #endif > > What do you think? I prefer what you currently have. WARN(1, "list_del corruption. next->prev should be %p, but was %p\n", entry, next->prev); BUG_ON(CORRUPTED_DATA_STRUCTURE); Will always warn (as stated by "1") and and the BUG_ON() will bug if CORRUPTED_DATA_STRUCTURE is set. Although, I don't like that name. Can we have a: BUG_ON(BUG_ON_CORRUPTED_DATA_STRUCTURES); Or maybe have that as a macro: #ifdef CONFIG_BUG_ON_CORRUPTION # define BUG_ON_CORRUPTED_DATA_STRUCTURE() BUG_ON(1) #else # define BUG_ON_CORRUPTED_DATA_STRUCTURE() do {} while (0) #endif Then we can have: WARN(1, "list_del corruption. next->prev should be %p, but was %p\n", entry, next->prev); BUG_ON_CORRUPTED_DATA_STRUCTURE(); ?? -- Steve > > -Kees > > > > > Thanx, Paul > > > >> --- > >> include/linux/bug.h | 7 +++++++ > >> kernel/locking/spinlock_debug.c | 1 + > >> kernel/workqueue.c | 2 ++ > >> lib/Kconfig.debug | 10 ++++++++++ > >> lib/list_debug.c | 7 +++++++ > >> 5 files changed, 27 insertions(+) > >> > >> diff --git a/include/linux/bug.h b/include/linux/bug.h > >> index e51b0709e78d..7e69758dd798 100644 > >> --- a/include/linux/bug.h > >> +++ b/include/linux/bug.h > >> @@ -118,4 +118,11 @@ static inline enum bug_trap_type report_bug(unsigned long bug_addr, > >> } > >> > >> #endif /* CONFIG_GENERIC_BUG */ > >> + > >> +#ifdef CONFIG_BUG_ON_CORRUPTION > >> +# define CORRUPTED_DATA_STRUCTURE true > >> +#else > >> +# define CORRUPTED_DATA_STRUCTURE false > >> +#endif > >> + > >> #endif /* _LINUX_BUG_H */ > >> diff --git a/kernel/locking/spinlock_debug.c b/kernel/locking/spinlock_debug.c > >> index 0374a596cffa..d5f833769feb 100644 > >> --- a/kernel/locking/spinlock_debug.c > >> +++ b/kernel/locking/spinlock_debug.c > >> @@ -64,6 +64,7 @@ static void spin_dump(raw_spinlock_t *lock, const char *msg) > >> owner ? owner->comm : "", > >> owner ? task_pid_nr(owner) : -1, > >> lock->owner_cpu); > >> + BUG_ON(CORRUPTED_DATA_STRUCTURE); > >> dump_stack(); > >> } > >> > >> diff --git a/kernel/workqueue.c b/kernel/workqueue.c > >> index ef071ca73fc3..ea0132b55eca 100644 > >> --- a/kernel/workqueue.c > >> +++ b/kernel/workqueue.c > >> @@ -48,6 +48,7 @@ > >> #include > >> #include > >> #include > >> +#include > >> > >> #include "workqueue_internal.h" > >> > >> @@ -2108,6 +2109,7 @@ __acquires(&pool->lock) > >> current->comm, preempt_count(), task_pid_nr(current), > >> worker->current_func); > >> debug_show_held_locks(current); > >> + BUG_ON(CORRUPTED_DATA_STRUCTURE); > >> dump_stack(); > >> } > >> > >> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug > >> index 2307d7c89dac..d64bd6b6fd45 100644 > >> --- a/lib/Kconfig.debug > >> +++ b/lib/Kconfig.debug > >> @@ -1987,6 +1987,16 @@ config TEST_STATIC_KEYS > >> > >> If unsure, say N. > >> > >> +config BUG_ON_CORRUPTION > >> + bool "Trigger a BUG when data corruption is detected" > >> + help > >> + Select this option if the kernel should BUG when it encounters > >> + data corruption in various kernel memory structures during checks > >> + added by options like CONFIG_DEBUG_LIST, CONFIG_DEBUG_SPINLOCK, > >> + etc. > >> + > >> + If unsure, say N. > >> + > >> source "samples/Kconfig" > >> > >> source "lib/Kconfig.kgdb" > >> diff --git a/lib/list_debug.c b/lib/list_debug.c > >> index 80e2e40a6a4e..161c7e7d3478 100644 > >> --- a/lib/list_debug.c > >> +++ b/lib/list_debug.c > >> @@ -26,16 +26,19 @@ bool __list_add_debug(struct list_head *new, > >> if (unlikely(next->prev != prev)) { > >> WARN(1, "list_add corruption. next->prev should be prev (%p), but was %p. (next=%p).\n", > >> prev, next->prev, next); > >> + BUG_ON(CORRUPTED_DATA_STRUCTURE); > >> return false; > >> } > >> if (unlikely(prev->next != next)) { > >> WARN(1, "list_add corruption. prev->next should be next (%p), but was %p. (prev=%p).\n", > >> next, prev->next, prev); > >> + BUG_ON(CORRUPTED_DATA_STRUCTURE); > >> return false; > >> } > >> if (unlikely(new == prev || new == next)) { > >> WARN(1, "list_add double add: new=%p, prev=%p, next=%p.\n", > >> new, prev, next); > >> + BUG_ON(CORRUPTED_DATA_STRUCTURE); > >> return false; > >> } > >> return true; > >> @@ -52,21 +55,25 @@ bool __list_del_entry_debug(struct list_head *entry) > >> if (unlikely(next == LIST_POISON1)) { > >> WARN(1, "list_del corruption, %p->next is LIST_POISON1 (%p)\n", > >> entry, LIST_POISON1); > >> + BUG_ON(CORRUPTED_DATA_STRUCTURE); > >> return false; > >> } > >> if (unlikely(prev == LIST_POISON2)) { > >> WARN(1, "list_del corruption, %p->prev is LIST_POISON2 (%p)\n", > >> entry, LIST_POISON2); > >> + BUG_ON(CORRUPTED_DATA_STRUCTURE); > >> return false; > >> } > >> if (unlikely(prev->next != entry)) { > >> WARN(1, "list_del corruption. prev->next should be %p, but was %p\n", > >> entry, prev->next); > >> + BUG_ON(CORRUPTED_DATA_STRUCTURE); > >> return false; > >> } > >> if (unlikely(next->prev != entry)) { > >> WARN(1, "list_del corruption. next->prev should be %p, but was %p\n", > >> entry, next->prev); > >> + BUG_ON(CORRUPTED_DATA_STRUCTURE); > >> return false; > >> } > >> return true; > >> -- > >> 2.7.4 > >> > > > > >