Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1425461imm; Sun, 2 Sep 2018 23:25:21 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYa3WhB17uI43Rd93XFwJMdXy9YAYvzZdUOMKXFuhOa6QGO16vFYChgCnlUdljR16b8ceZd X-Received: by 2002:a63:e318:: with SMTP id f24-v6mr23200691pgh.175.1535955921228; Sun, 02 Sep 2018 23:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535955921; cv=none; d=google.com; s=arc-20160816; b=W3PHbZm9ZqCtW6afKehRf0hWSAyj8RmnKwmrdfBJwRx3c9robni8zUE8EavJcQd84z rd6Wx5n+Pa1pMF0mhSlokiRlcGVxjsm43H3sT3B7TNgZrVJQUuV2k28gEyGZW5R7IFw6 AKOvjS7WgJssgBhV7bW5N+dlTNUODmuQMRXG1JSXHmqs+rKgiILHrQoe50YRUXFTaJGc FEEuQlNwb9OuVYtgpIvgb3a6IEoAWWnL+ZmKxKR2TzDpIsgNQZmvs5eJtoZaGgY6ZXKq FzzyeS2Sip2Plf3NVDVOFfJbbbz8Uohr2bnI59aFkAg/+jHv5kwi/R1rIBPL64VaIsMI LgeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=MaDjgc3GK/Kc/7d3E4rKbwOeV9W2wEl2YtI9tWjgF8k=; b=muYCekoXYsWeLrYXks5dZpKeWqdrX0M6noCPamJZ/FBq0EiBuEXueDT0XIw49pTa0q p6kg2Qs4M99Dg5T7h5yMhCUQr7Hb7d3XKsftHdJzxw9f2hrlVldxiCKIzRLe3gLslY5L kBMqtjjxChl/eOix76H7ZcqMtNq7JypJT+0kD+PdaGsch4a7ElPA8eFTo5jKgD3YYMkE pZAL4qxYh9BePG4i9nfhe7dQUs9r1jNICsY3tUByUE9HRBsQ3paU7EuPykcnEBwDPHvV Y+QsjPvZKhQr6iMqn7mYNXTIfJpx8fzSSjvfYgLpjPpsBr1BPjs8dpMX87b169Lggapk TIRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d3zMe6zg; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o18-v6si16890757pll.344.2018.09.02.23.25.03; Sun, 02 Sep 2018 23:25:21 -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=@linaro.org header.s=google header.b=d3zMe6zg; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726157AbeICKmc (ORCPT + 99 others); Mon, 3 Sep 2018 06:42:32 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:43436 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725947AbeICKmc (ORCPT ); Mon, 3 Sep 2018 06:42:32 -0400 Received: by mail-pf1-f193.google.com with SMTP id j26-v6so8210675pfi.10 for ; Sun, 02 Sep 2018 23:23:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=MaDjgc3GK/Kc/7d3E4rKbwOeV9W2wEl2YtI9tWjgF8k=; b=d3zMe6zgZK6WrJP4eHYQnTAjhDKvMDCk5JJm3OSdY7v2DP6CWFOcZi1tDvlSKjTPAF LokCDdvvbrH6JS4cDl+mGzoK3JQtByLqZLdQM5ZkcudXRNU92Cf/t6TecbFAdQH4nUcr tLdPi2S6CIgPxQggrPhuhMna+mhCr/fVTM8Ks= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=MaDjgc3GK/Kc/7d3E4rKbwOeV9W2wEl2YtI9tWjgF8k=; b=TGWcGLT+/NOLKZ6ODzXR5MW+GJ4813p+cjNDO+7aMXqCAPTwaGCHRGzagefnUQPatO 226xRPeoLUILCya0oyzt1vTu076PT9g+2HC37hgLQ0vyyLIo6FXqvN1MbSzA/LAtkiVH X2S5A6+naU5DlXGbk9Cehu2tPpP+2PWMiU/hZvKHfHWRqeLlinsf2+/8dyjTaCVdkkXN VbLfTamIANGkL/fJxDRa7AAnh3Rfb/3spweZzOW0PleyoFkMPlJbYkcrNls+OYc0QCtj Q+OHDMF0ROS0vE2BrzmPb7YOvjWs9UlXaXh/sucKGT/dBTB2j3LgrEfwFUaTbgG1Mu0E VAzA== X-Gm-Message-State: APzg51Dsbb/isM8qhWmHxogoEsozS2xpCBWVVUZ6F3FGmJf5VvjvAWtS mzfu2KdWVhh/WaA5ccupN5y9DQ== X-Received: by 2002:a63:4b1f:: with SMTP id y31-v6mr24685723pga.14.1535955831268; Sun, 02 Sep 2018 23:23:51 -0700 (PDT) Received: from localhost ([122.171.76.41]) by smtp.gmail.com with ESMTPSA id v2-v6sm19859995pgf.58.2018.09.02.23.23.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Sep 2018 23:23:50 -0700 (PDT) Date: Mon, 3 Sep 2018 11:53:48 +0530 From: Viresh Kumar To: Dmitry Osipenko Cc: Zhang Rui , Eduardo Valentin , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1] thermal: core: Fix use-after-free in thermal_cooling_device_destroy_sysfs Message-ID: <20180903062348.e3qadikukr7d4yi7@vireshk-i7> References: <20180813171400.15345-1-digetx@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180813171400.15345-1-digetx@gmail.com> User-Agent: NeoMutt/20180323-120-3dd1ac Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13-08-18, 20:14, Dmitry Osipenko wrote: > This patch fixes use-after-free that was detected by KASAN. The bug is > triggered on a CPUFreq driver module unload by freeing 'cdev' on device > unregister and then using the freed structure during of the cdev's sysfs > data destruction. The solution is to unregister the sysfs at first, then > destroy sysfs data and finally release the cooling device. > > Cc: # v4.17+ > Fixes: 8ea229511e06 ("thermal: Add cooling device's statistics in sysfs") > Signed-off-by: Dmitry Osipenko > --- > drivers/thermal/thermal_core.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index 6ab982309e6a..441778100887 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -1102,8 +1102,9 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev) > mutex_unlock(&thermal_list_lock); > > ida_simple_remove(&thermal_cdev_ida, cdev->id); > - device_unregister(&cdev->device); > + device_del(&cdev->device); > thermal_cooling_device_destroy_sysfs(cdev); > + put_device(&cdev->device); > } > EXPORT_SYMBOL_GPL(thermal_cooling_device_unregister); Acked-by: Viresh Kumar -- viresh