Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754816Ab2F3MBm (ORCPT ); Sat, 30 Jun 2012 08:01:42 -0400 Received: from mga14.intel.com ([143.182.124.37]:27224 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754404Ab2F3MBk (ORCPT ); Sat, 30 Jun 2012 08:01:40 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.71,315,1320652800"; d="scan'208";a="117642656" From: Octavian Purdila To: "H. Peter Anvin" Cc: linux-kernel@vger.kernel.org, Octavian Purdila , Ram Pai , Jesse Barnes Subject: [PATCH] resource: make sure requested range intersects root range Date: Sat, 30 Jun 2012 15:00:57 +0300 Message-Id: <1341057657-7823-1-git-send-email-octavian.purdila@intel.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3955 Lines: 86 When the requested and root ranges do not intersect the logic in __reserve_region_with_split will cause an infinite recursion which will overflow the stack as seen in the warning bellow. This particular stack overflow was caused by requesting the (100000000-107ffffff) range while the root range was (0-ffffffff). In this case __request_resource would return the whole root range as conflict range (i.e. 0-ffffffff). Then, the logic in __reserve_region_with_split would continue the recursion requesting the new range as (conflict->end+1, end) which incidentally in this case equals the originally requested range. This patch aborts looking for a usable range when the requested one is completely outside the root range to avoid the infinite recursion, and since this indicates a problem in the layers above, it also prints an error message indicating the requested and root range in order to make the problem more easily traceable. [ 5.968374] WARNING: at kernel/sched.c:4129 sub_preempt_count+0x63/0x89() [ 5.975150] Modules linked in: [ 5.978184] Pid: 1, comm: swapper Not tainted 3.0.22-mid27-00004-gb72c817 #46 [ 5.985324] Call Trace: [ 5.987759] [] ? console_unlock+0x17b/0x18d [ 5.992891] [] warn_slowpath_common+0x48/0x5d [ 5.998194] [] ? sub_preempt_count+0x63/0x89 [ 6.003412] [] warn_slowpath_null+0xf/0x13 [ 6.008453] [] sub_preempt_count+0x63/0x89 [ 6.013499] [] _raw_spin_unlock+0x27/0x3f [ 6.018453] [] add_partial+0x36/0x3b [ 6.022973] [] deactivate_slab+0x96/0xb4 [ 6.027842] [] __slab_alloc.isra.54.constprop.63+0x204/0x241 [ 6.034456] [] ? kzalloc.constprop.5+0x29/0x38 [ 6.039842] [] ? kzalloc.constprop.5+0x29/0x38 [ 6.045232] [] kmem_cache_alloc_trace+0x51/0xb0 [ 6.050710] [] ? kzalloc.constprop.5+0x29/0x38 [ 6.056100] [] kzalloc.constprop.5+0x29/0x38 [ 6.061320] [] __reserve_region_with_split+0x1c/0xd1 [ 6.067230] [] __reserve_region_with_split+0xc6/0xd1 ... [ 7.179057] [] __reserve_region_with_split+0xc6/0xd1 [ 7.184970] [] reserve_region_with_split+0x30/0x42 [ 7.190709] [] e820_reserve_resources_late+0xd1/0xe9 [ 7.196623] [] pcibios_resource_survey+0x23/0x2a [ 7.202184] [] pcibios_init+0x23/0x35 [ 7.206789] [] pci_subsys_init+0x3f/0x44 [ 7.211659] [] do_one_initcall+0x72/0x122 [ 7.216615] [] ? pci_legacy_init+0x3d/0x3d [ 7.221659] [] kernel_init+0xa6/0x118 [ 7.226265] [] ? start_kernel+0x334/0x334 [ 7.231223] [] kernel_thread_helper+0x6/0x10 Cc: Ram Pai Cc: Jesse Barnes Signed-off-by: Octavian Purdila --- kernel/resource.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/resource.c b/kernel/resource.c index e1d2b8e..54402be 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -789,7 +789,13 @@ void __init reserve_region_with_split(struct resource *root, const char *name) { write_lock(&resource_lock); - __reserve_region_with_split(root, start, end, name); + if (start > root->end || end < root->start) + pr_err("Requested range (0x%llx-0x%llx) not in root range (0x%llx-0x%llx)\n", + (unsigned long long)start, (unsigned long long)end, + (unsigned long long)root->start, + (unsigned long long)root->end); + else + __reserve_region_with_split(root, start, end, name); write_unlock(&resource_lock); } -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/