Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp331527ybl; Fri, 24 Jan 2020 00:59:04 -0800 (PST) X-Google-Smtp-Source: APXvYqyJi5Adv1hFfiME94RVSSD+Ol4X53dwpmdpXpOPyCL/cNJiqF7c8/kewwpppZp82vt84PpU X-Received: by 2002:aca:7244:: with SMTP id p65mr1308183oic.50.1579856344450; Fri, 24 Jan 2020 00:59:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579856344; cv=none; d=google.com; s=arc-20160816; b=jS873nbzQbo2IqCYO6jIiyJyFdpSk5hX5VzlvQMFz6cXxCY2dUypnnjhlrnw8iSy+S qBtrEzc/NuJHbVPWT25MDY6OQztf5CQevuvjhhmsP5HUuoagkjeei17A9YdyVaSpXaY5 bGJTkjQ5EAEVTZwWq00+AxProbzyflLPB2e3DJygHXAR1+NOpS86NU5HMhwsW+i69T32 Kz2KUL/3YvI6T0DEGtvjGZ3T9tTQkeHs0Z/QdpcNHGOHB1DHV2Onrky8G59+d50tG3Gc RqSlzeCLELGNM13n6+DDkN9pcGLZizb/I1wXjS/9LtF3YxIiW0gtKMIUjU/9BJlv6sSp VRmg== 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 :dkim-signature; bh=DEhgcpuygKBQfdVLqMajCQQxAwHmH0xAO89KbEibv0w=; b=wrn/stMXpnB0edxP1kj4zWTb9lmWIqJiDOIa9RN3ErXD/EDfiRg11Ehywy+FWQDtiN AzfV4D4CqN3Od95j1HqateoPDksk8X+1YNsJIYTi3/kMUQZr4n85UVdIU1ARWcfMg8wf OkO4m1C3xpoLZMHJVvxFLbu0UvIy1lvEXQ+LbLdaq9UQhhOxfas2BGsE5qsIxuk3F6cP OcXefDmkZrS7irUubFxDhLh+DVCLxYsf8vrEviJpA8PGtPV0eKpVeEuuqhCdVB1R/YEA hgDDnwcd70xVUImA0Ljo1DMzlFmpXs0mLaWptZhXGA/mutVNMYGym7fh8fPNz1ZuD4OD WOnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LuIt2JgM; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d192si2053261oig.21.2020.01.24.00.58.51; Fri, 24 Jan 2020 00:59:04 -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; dkim=pass header.i=@kernel.org header.s=default header.b=LuIt2JgM; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729789AbgAXIyr (ORCPT + 99 others); Fri, 24 Jan 2020 03:54:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:40090 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729225AbgAXIyr (ORCPT ); Fri, 24 Jan 2020 03:54:47 -0500 Received: from localhost (unknown [145.15.244.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 05D7020709; Fri, 24 Jan 2020 08:54:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579856086; bh=0xY6x9V00TP+QraY/L7nzfuOqHEO6nvqTQwrER0e3Ys=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LuIt2JgMidLItMGSneEjOjLaEAmYbQDtNOSJ77X4jm6dMcS6nNqRhW2jKfOejaUnq XEbKamI2R/rlHE3qvk8NnzcMCKYRCvWaztzt5ZFioGwAHCBMjhHLQ7pC/0uP117+i6 jBZ+Ka6opDx+8LncDFqJh2y964etJCfDYctenPpI= Date: Fri, 24 Jan 2020 09:54:43 +0100 From: Greg Kroah-Hartman To: "Rafael J. Wysocki" Cc: Linux PM , LKML , Chanho Min , Daewoong Kim , Seokjoo Lee , "Rafael J. Wysocki" Subject: Re: [PATCH] PM: core: Fix handling of devices deleted during system-wide resume Message-ID: <20200124085443.GA2936887@kroah.com> References: <2601275.1tEomSadG4@kreacher> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2601275.1tEomSadG4@kreacher> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 23, 2020 at 12:11:24AM +0100, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > If a device is deleted by one of its system-wide resume callbacks > (for example, because it does not appear to be present or accessible > any more) along with its children, the resume of the children may > continue leading to use-after-free errors and other issues > (potentially). > > Namely, if the device's children are resumed asynchronously, their > resume may have been scheduled already before the device's callback > runs and so the device may be deleted while dpm_wait_for_superior() > is being executed for them. The memory taken up by the parent device > object may be freed then while dpm_wait() is waiting for the parent's > resume callback to complete, which leads to a use-after-free. > Moreover, the resume of the children is really not expected to > continue after they have been unregistered, so it must be terminated > right away in that case. > > To address this problem, modify dpm_wait_for_superior() to check > if the target device is still there in the system-wide PM list of > devices and if so, to increment its parent's reference counter, both > under dpm_list_mtx which prevents device_del() running for the child > from dropping the parent's reference counter prematurely. > > If the device is not present in the system-wide PM list of devices > any more, the resume of it cannot continue, so check that again after > dpm_wait() returns, which means that the parent's callback has been > completed, and pass the result of that check to the caller of > dpm_wait_for_superior() to allow it to abort the device's resume > if it is not there any more. > > Link: https://lore.kernel.org/linux-pm/1579568452-27253-1-git-send-email-chanho.min@lge.com > Reported-by: Chanho Min > Signed-off-by: Rafael J. Wysocki > --- > drivers/base/power/main.c | 42 +++++++++++++++++++++++++++++++++++++----- > 1 file changed, 37 insertions(+), 5 deletions(-) Acked-by: Greg Kroah-Hartman