Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A8A8C433E7 for ; Fri, 9 Oct 2020 05:08:04 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 320A3215A4 for ; Fri, 9 Oct 2020 05:08:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ellerman.id.au header.i=@ellerman.id.au header.b="UGj9q5W1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 320A3215A4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4C6x0b6tvwzDqZR for ; Fri, 9 Oct 2020 16:07:59 +1100 (AEDT) Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4C6wyx4lrszDqBc for ; Fri, 9 Oct 2020 16:06:33 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ellerman.id.au header.i=@ellerman.id.au header.a=rsa-sha256 header.s=201909 header.b=UGj9q5W1; dkim-atps=neutral Received: by ozlabs.org (Postfix) id 4C6wyx4JYdz9sTK; Fri, 9 Oct 2020 16:06:33 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4C6wyx22WYz9sSC; Fri, 9 Oct 2020 16:06:33 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1602219993; bh=u/tC6kBNuTt1DLx2MDnVvp5ksb9SRbHet77yVS5sp94=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=UGj9q5W1y29ncbaf5d9vHMAsq7u4kBtOrW4Ly3fqLPyMjqPkuI4CI9bCbTJ2yTYtc v5Vj38kfbQlwdWX+cEfbTy0FzovBVHI12wQcWl+9Bp8atKTpnwQpsx22cLaPN4IgeG kWk43Ikxbt3GEWeZ2oF75vXMWB7U5EGd/WXl21ftOesFTwWRL2DaECtSLa8ywjX2sF 7QUEIsw2NEOSICj7lVt8ZfPct3d8qXpDaF/CWkX5LDq80qVWGpuJsvLL16/oyLoeio LXX2t8aUhGz6FeJSsIYxKtO4dxd1disgHrLfkzEaa+jqJXbPAdgHl+5lNiT1xNx/4l 0+8tNmsw0MpMg== From: Michael Ellerman To: Vasant Hegde , linuxppc-dev@ozlabs.org Subject: Re: [PATCH] powerpc/powernv/dump: Fix race while processing OPAL dump In-Reply-To: <20201007101742.40757-1-hegdevasant@linux.vnet.ibm.com> References: <20201007101742.40757-1-hegdevasant@linux.vnet.ibm.com> Date: Fri, 09 Oct 2020 16:06:32 +1100 Message-ID: <87a6ww0yzr.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vasant Hegde , Mahesh Salgaonkar Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Vasant Hegde writes: > diff --git a/arch/powerpc/platforms/powernv/opal-dump.c b/arch/powerpc/platforms/powernv/opal-dump.c > index 543c816fa99e..7e6eeedec32b 100644 > --- a/arch/powerpc/platforms/powernv/opal-dump.c > +++ b/arch/powerpc/platforms/powernv/opal-dump.c > @@ -346,21 +345,39 @@ static struct dump_obj *create_dump_obj(uint32_t id, size_t size, > rc = kobject_add(&dump->kobj, NULL, "0x%x-0x%x", type, id); > if (rc) { > kobject_put(&dump->kobj); > - return NULL; > + return; > } > > + /* > + * As soon as the sysfs file for this dump is created/activated there is > + * a chance the opal_errd daemon (or any userspace) might read and > + * acknowledge the dump before kobject_uevent() is called. If that > + * happens then there is a potential race between > + * dump_ack_store->kobject_put() and kobject_uevent() which leads to a > + * use-after-free of a kernfs object resulting in a kernel crash. > + * > + * To avoid that, we need to take a reference on behalf of the bin file, > + * so that our reference remains valid while we call kobject_uevent(). > + * We then drop our reference before exiting the function, leaving the > + * bin file to drop the last reference (if it hasn't already). > + */ > + > + /* Take a reference for the bin file */ > + kobject_get(&dump->kobj); > rc = sysfs_create_bin_file(&dump->kobj, &dump->dump_attr); > if (rc) { > kobject_put(&dump->kobj); > - return NULL; > + /* Drop reference count taken for bin file */ > + kobject_put(&dump->kobj); > + return; > } > > pr_info("%s: New platform dump. ID = 0x%x Size %u\n", > __func__, dump->id, dump->size); > > kobject_uevent(&dump->kobj, KOBJ_ADD); > - > - return dump; > + /* Drop reference count taken for bin file */ > + kobject_put(&dump->kobj); > } I think this would be better if it was reworked along the lines of: aea948bb80b4 ("powerpc/powernv/elog: Fix race while processing OPAL error log event.") cheers