Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2813198ybh; Mon, 9 Mar 2020 13:37:10 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsBGgVM4ofvUBwfXjQ/Rfbo6JYUWAV2VNchBVPE0fPVAxIZGab6m+gYcyOGAnn12vLRW1Cw X-Received: by 2002:a9d:6ad1:: with SMTP id m17mr15185432otq.198.1583786230725; Mon, 09 Mar 2020 13:37:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583786230; cv=none; d=google.com; s=arc-20160816; b=av9L9nDR3INDbGonZeJ41f27a5/R3kbNpg8UY0huPj1sXwq5t2LU/B5HGRlaG5xWpK CshoI1Wy3I2FDtz9TteWyGyee7HjerNxElWccPH0Dtbm5ePLWVGL5raxY3nXBAreq79l Mb6a+iqulpFf8In24JpDHJW79dvqqu5K2+XsIL0tUiAMsuwJtbwbZdnXMTWVoNIIsChf WJLD9LppUJmIemH7lT9pEJY2uHNb1VhDkyAXE0Vt/ZiF1NWW2/GJM9HwKyQKbByDAcTs 4uQ/z81wO84HUT3kOd46z7Tpqc6uVLsg7Wzi92g2q9se1em73yINhxENTa4z0mu9yvPn AM7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=sRk1pke9YTA7cKz/JhbTTwHB3/WLWvrK7Ig2WxoYgI8=; b=Tb5psqSQgApIGoH84za2xm4zmGgrVEb6fa6wrdcq0caVkhLd744/4Ng94tWlEbYNId 8/mHGztKdQZSpVV4ZWBtRHfvGxwp7oq5cGzQv5+rCCGD7dJy/DYaoFGy1lmLW/g9T9PI ZYs9wSRWDjKorElkztzeoxwlN5UegPv5StO1b+Ytjwn0QXsn4xSM2NtO5v0jc1cTd9+E xlqJRozraEo45gF2/Wu0sMvVfNMXm47oRuVvENb/dFQV85NCmiHbii793cf4WgeiF2Yw dxAWhL1aT1YC7RkV/OHUH+s/TpO9U2PDxPohxdOV9mkb2mWXaZcOBtWCqUdeADIyHVm2 MGPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="X/Ye0ndi"; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h26si7759894otg.152.2020.03.09.13.36.57; Mon, 09 Mar 2020 13:37:10 -0700 (PDT) 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; dkim=pass header.i=@google.com header.s=20161025 header.b="X/Ye0ndi"; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726193AbgCIUff (ORCPT + 99 others); Mon, 9 Mar 2020 16:35:35 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:34805 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725992AbgCIUff (ORCPT ); Mon, 9 Mar 2020 16:35:35 -0400 Received: by mail-pl1-f195.google.com with SMTP id a23so1766153plm.1 for ; Mon, 09 Mar 2020 13:35:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sRk1pke9YTA7cKz/JhbTTwHB3/WLWvrK7Ig2WxoYgI8=; b=X/Ye0ndiT6/vRdYfa8lbznwxNncY7a4bxQhLjQFBDxsxTu/rRPSzWcz2h0sI9lmNuA hAsOCgP2jlB34NAGbuTpEtDK9cLWgSY9FunbCNYCgu8l5nhUPNcItCXxOQzONgIHkgQ2 upyb1xJRUv/E1Kt80Uz0oG90aTJ09KRL6VP2NjwdgAnDeVoDBq/vrkkfFU2z3rOqbPjZ RqCX7nXl/mFiViARqSjbJdGsL2EY1L2h1SFwLo8ZXmUEC3LKMaD6Vg7bzWKZLW2QQNaM 6hM23O96i1X7VrHAQpQQc2EfrTC0Hpfxx7BnPqPzjdJyvixCT1GTHKx0xlO5MFARX2gj VHFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sRk1pke9YTA7cKz/JhbTTwHB3/WLWvrK7Ig2WxoYgI8=; b=MsZ09BAuG6bQaeLOpt/vjFBWKkpz6+MP8gqbAQ6p9EYF+H5xHk04/tWmDJHDDYTmQO v6Rqpp4Ypd23Kc9+qKYJCc+J4eXUKyBZ9CLYGYRfjWrOhYyA9PEPo8BwItodSQksM/aa Z5sEN/WflzulCC+5qIupj6IeYBQCyw/JroFfVwbr693NkEt7Ebf6dfrHQ5N+BZ+uFaz7 Z2kwI5Z9cphEvCClZi/ClXflgZpLiQ5LKzZV00LOFVpR2eLhZ84bV4FZbJfGgrgNX4Li ZiMQV1amGLM3ruONjgFLEIguz/CZ0anf1o9S83y2ZLWAulbYpHEJ3ezMtsllmEHyrA2X O7Jw== X-Gm-Message-State: ANhLgQ1P1M9m0ePUG+AURnjcS+OoJGESOzT078VCg+bDcDfCXbv9gPsw G0587Mib0MKK9UWpI/S4XFSkJ2xsBamASwzaj69Bkg== X-Received: by 2002:a17:902:74cc:: with SMTP id f12mr9045912plt.232.1583786132922; Mon, 09 Mar 2020 13:35:32 -0700 (PDT) MIME-Version: 1.0 References: <20200305223350.GA2852@mara.localdomain> <20200306120525.GC68079@kuha.fi.intel.com> In-Reply-To: <20200306120525.GC68079@kuha.fi.intel.com> From: Brendan Higgins Date: Mon, 9 Mar 2020 13:35:22 -0700 Message-ID: Subject: Re: BUG: kernel NULL pointer dereference, address: 00 - ida_free+0x76/0x140 To: Heikki Krogerus Cc: Sakari Ailus , 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 6, 2020 at 4:05 AM Heikki Krogerus wrote: > > 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 Either way, isn't it wrong to release the node ID before deleting the sysfs entry? I am not sure that my fix was the correct one, but I believe the bug that Heidi and I found is actually a bug. > the core with something like this (warning, I did not even try to > compile that): I will try it out. > 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!