Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp6760437ybf; Fri, 6 Mar 2020 04:06:27 -0800 (PST) X-Google-Smtp-Source: ADFU+vvenakcR+GlAL/KlhttfTie682g5eMK8jjudJwxF8/EvqkuOUgFYPJVS+sJxnJp/iguYXEr X-Received: by 2002:a9d:7696:: with SMTP id j22mr2287608otl.188.1583496386944; Fri, 06 Mar 2020 04:06:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583496386; cv=none; d=google.com; s=arc-20160816; b=kPPGNJp1wgjZ6A2mfk4CEd0R5P4lYZx+V5f8vc3/+PZB+Om5tVHiX6Zt3tdsjK/Z6R QwG7QC3Fo1wpJZI4BJOg2z86+tFvuGIcObD/KeuhlYnCTOBmH/eJBQZtBJ/OHGtfklan sst9Xr9g8V/kjWoFyqILy5mTm53YJtvdBrEXZgmyJ8ruewiH15Yz311kPFV8isw3W3+7 4qA6L/OO/GgZaTLLiNragZBLWtQe6F5M3yBza5qmT71k5jgGXsAHDt2tTAuyiim9g4ZI Rfm4iFXwXzZc+sJlLTG7ZeBWM6RRnXAkNauW2SZmcqUg1E1Y1Qqdv9Mo4+ztYmY5S4hA cwKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=tMR4gG4rym92BeBib/Q1ycXBeIzpS6LRvmnpjrX2U+k=; b=nKYgLNgSL7deT42HIqXP2Sl6cerq1oj/Ixf6/IA6vpBj824qBAfSGmtneDWu4KV45s Xr/pCM4vaj65r1KFPPiccTb7FzZFWjuOR1TRBL1yFHq4j7LkeKwOeKl3qHtYVTQmfdkv E08WAYG4xfWQq4TSJLpxtzquPfFS3MVYzN+juHMjzcLxe9sg5zz1fubia4JMijglOD3l Dp6txLzrA0qTT+A1F/4reKjx6Mxtr+a9XKRJ/SWHGeIqbt3NippOxze7J5NUS7rNZgwa dzkY4K909kCK6Ls+VSYdn/dcKDmv7hrEThCqzaN5PPeYkt18SsxRjSoa1VW+hLiTmQuo 2PLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q26si1202132otc.254.2020.03.06.04.06.14; Fri, 06 Mar 2020 04:06:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726299AbgCFMFb (ORCPT + 99 others); Fri, 6 Mar 2020 07:05:31 -0500 Received: from mga12.intel.com ([192.55.52.136]:62982 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726054AbgCFMFa (ORCPT ); Fri, 6 Mar 2020 07:05:30 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2020 04:05:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,522,1574150400"; d="scan'208";a="352729401" Received: from kuha.fi.intel.com ([10.237.72.162]) by fmsmga001.fm.intel.com with SMTP; 06 Mar 2020 04:05:26 -0800 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Fri, 06 Mar 2020 14:05:25 +0200 Date: Fri, 6 Mar 2020 14:05:25 +0200 From: Heikki Krogerus To: Sakari Ailus Cc: Brendan Higgins , Andy Shevchenko , hdegoede@redhat.com, "rafael.j.wysocki" , Naresh Kamboju , open list , "open list:KERNEL SELFTEST FRAMEWORK" , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Shuah Khan , Anders Roxell , lkft-triage@lists.linaro.org, Rasmus Villemoes Subject: Re: BUG: kernel NULL pointer dereference, address: 00 - ida_free+0x76/0x140 Message-ID: <20200306120525.GC68079@kuha.fi.intel.com> References: <20200305223350.GA2852@mara.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200305223350.GA2852@mara.localdomain> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 06, 2020 at 12:33:50AM +0200, Sakari Ailus wrote: > Hi Brendan, > > On Thu, Mar 05, 2020 at 11:51:20AM -0800, Brendan Higgins wrote: > > On Thu, Mar 5, 2020 at 11:40 AM Brendan Higgins > > wrote: > > > > > > On Thu, Mar 5, 2020 at 11:18 AM Andy Shevchenko > > > wrote: > > > > > > > > +Cc: Sakari > > > > > > > > On Thu, Mar 5, 2020 at 6:00 PM Naresh Kamboju wrote: > > > > > > > > > > Regression reported on Linux next 5.6.0-rc4-next-20200305 on x86_64, > > > > > i386, arm and arm64. The steps to reproduce is running kselftests lib > > > > > printf.sh test case. > > > > > Which is doing modprobe operations. > > > > > > > > > > BTW, there are few RCU warnings from the boot log. > > > > > Please refer below link for more details. > > > > > > > > > > Steps reproduce by using kselftests, > > > > > > > > > > - lsmod || true > > > > > - cd /opt/kselftests/default-in-kernel/lib/ > > > > > - export PATH=/opt/kselftests/default-in-kernel/kselftest:$PATH > > > > > - ./printf.sh || true > > > > > - ./bitmap.sh || true > > > > > - ./prime_numbers.sh || true > > > > > - ./strscpy.sh || true > > > > > > > > > > x86_64 kernel BUG dump. > > > > > + ./printf.sh > > > > > > Oops, I am wondering if I broke this with my change "Revert "software > > > node: Simplify software_node_release() function"": > > > > > > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=d1c19322388d6935b534b494a2c223dd089e30dd > > > > > > I am still investigating, will update later. > > > > Okay, yeah, I am pretty sure I caused the breakage. I got an email > > from kernel test robot a couple days ago that I didn't see: > > > > https://lists.01.org/hyperkitty/list/lkp@lists.01.org/thread/N3ZN5XH7HK24JVEJ5WSQD2SK6YCDRILR/ > > > > It shows the same breakage after applying this change. > > > > I am still investigating how my change broke it, nevertheless. > > As nodes in the tree are being removed, the code before the patch that > "simplified" the software_node_release() function accessed the node's parent > in its release function. > > And if CONFIG_DEBUG_KOBJECT_RELEASE is defined, the release functions are no > longer necessarily called in order, leading to referencing released memory. > Oops! > > So Heikki's patch actually fixed a bug. :-) Well, I think it just hid the problem. It looks like the core (lib/kobject.c) allows the parent kobject to be released before the last child kobject is released. To be honest, that does not sound right to me... I think we can workaround this problem by taking reference to the parent when the child is added, and then releasing it when the child is released, and in that way be guaranteed that the parent will not disappear before the child is fully released, but that still does not feel right. It feels more like the core is not doing it's job to me. The parent just should not be released before its children. Either I'm wrong about that, and we still should take the reference on the parent, or we revert my patch like Brendan proposed and then fix the core with something like this (warning, I did not even try to compile that): diff --git a/lib/kobject.c b/lib/kobject.c index 83198cb37d8d..ec5774992337 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -680,6 +680,12 @@ static void kobject_cleanup(struct kobject *kobj) kobject_uevent(kobj, KOBJ_REMOVE); } + if (t && t->release) { + pr_debug("kobject: '%s' (%p): calling ktype release\n", + kobject_name(kobj), kobj); + t->release(kobj); + } + /* remove from sysfs if the caller did not do it */ if (kobj->state_in_sysfs) { pr_debug("kobject: '%s' (%p): auto cleanup kobject_del\n", @@ -687,12 +693,6 @@ static void kobject_cleanup(struct kobject *kobj) kobject_del(kobj); } - if (t && t->release) { - pr_debug("kobject: '%s' (%p): calling ktype release\n", - kobject_name(kobj), kobj); - t->release(kobj); - } - /* free name if we allocated it */ if (name) { pr_debug("kobject: '%s': free name\n", name); thanks, -- heikki