Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4051470imm; Wed, 5 Sep 2018 09:55:57 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaGHKrU4uLfdfOS8/9/x1TSu4Kf4xrTaOZAOxikNvvI7qT3YXlNbSpOMGduqcJAE1rg2n6S X-Received: by 2002:a63:291:: with SMTP id 139-v6mr36418067pgc.365.1536166557012; Wed, 05 Sep 2018 09:55:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536166556; cv=none; d=google.com; s=arc-20160816; b=nqjpdYbQ9O1adEm4toSSqQmtuKWYFKrA+elMDrpXSoxGsphjE+HoyzWLiaXyQRZ3F4 wiQSxVtwOePCJUOXBycz6h+ndtjjXDYuxUV0BGbLCoIaGkUYjt2Px5anCX8IcA2OpKJs rsLWlzKNgetXuMC9vtOBRRrASJh3reCZjxlbmp+7ZZfskEoeR7t9jAp7QYPt4nb7JcH8 TYrfZykJe4URVNQfPhzm6bpW9K7PAXepRQrfVshog9x/w331HGophX5S52EVZr3jiSiJ OuiwZTWAZT6aud3PfUNa81ZHSY0lcshaLtj3dvVc4jEUMn5B7eUjSIplODrOCpU/b/sP Ho/Q== 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; bh=Dlige6MAsXw0Nyf287r/RPmrRs43jIQ+KJ1Cs1Mxj84=; b=mX1FmI7cFZzeX7XuMENghXogC3WNVefxR1HTzf6PVuaqXf/atPGlxm/yaPMtqeN7Mn mouSjkWQdZWnhxZWQv6SEvarQw21ni7jucQ7QaTlelOmHPB/kici01vn87W2mM+YVUe5 SEtHCNTwYnaYUZ7JuqtC86OiROpWkrAEd9rhAgC5FSwlQXkCRJWzyPCYxz8bblJb6baJ FtR/CJ7IoKKtN50bzdxp4Gp+MmeWj8cdXNXFN3PBzVwn+zqOaVmW+zkNLsqfKFSNqfNH 4xgO9scBYRurD2vIVoPGd+0Uy1wSBO0cFK4B5siiTz2tx+HHlb152xB2GH3HHcDs8PH6 VMdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OOOQ9Dgm; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 23-v6si2443300pgr.493.2018.09.05.09.55.41; Wed, 05 Sep 2018 09:55:56 -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=@gmail.com header.s=20161025 header.b=OOOQ9Dgm; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727671AbeIEVYe (ORCPT + 99 others); Wed, 5 Sep 2018 17:24:34 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:35005 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726335AbeIEVYd (ORCPT ); Wed, 5 Sep 2018 17:24:33 -0400 Received: by mail-pg1-f195.google.com with SMTP id 7-v6so3736342pgf.2; Wed, 05 Sep 2018 09:53:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Dlige6MAsXw0Nyf287r/RPmrRs43jIQ+KJ1Cs1Mxj84=; b=OOOQ9Dgm4xQTMwet6NCYfoRkEBMXFx6hNGASsoRgFW/DBbImoOeC/QnBqbJ3sDUxP9 aS5qNguWX6PcVb9dVzbjJXrFP1n+fEMbD7TA1gNLPL8Qp+TpxiTOm866Lv0F5Pu8O1y/ bMacBohGEAJ+MbPjPYvkJ/34VR2F5a8Ee4xVxmOVe3XY572P9+DScUTmPPEO/EW+f5CM jbjLuL3kHu+GCvtil+MOUCJ1Xjiyo1naIhLmrpSIrFCido2Ktk8Cfxmey3X4LGvfQJtd d/OCgV4qMufsSY+3cwCGJDgl8q2NFlBygAq9p+EWwDyBBE0Fn3cXLX2h4stWJ+KC9xIO RJ5g== 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=Dlige6MAsXw0Nyf287r/RPmrRs43jIQ+KJ1Cs1Mxj84=; b=G0wqeo1tLgT2FooeHMZBpWj6OoJXg7Q3erezSllm6Js+Fk9LRGI9qMqlanAFaGYYlM GBD2NwP38mycmWp3/M32cEf6Uvkk5sjaIYOgKSkPAhjtbeQyiRlfchcWl6AbgHwPGnru 0KCtTy/yhWVD9LBfeNuYXuisJyoTkbzVl3R4AJFrm34d9mm1gVtsgXvxE1JirGPFnAu5 zjWZSIvpIFwtJCA/qbcX9SsLJy6VH28rP8TS6JEqhWFJISzTo1ebvBKxy+KbjbgeV4cb TUbw3i08x+ZCGHrVsx1CyoCQsoIaaCjV1axcH+8B/6vW51rzI2aW13lBaNmBuhBf7feT Gzzw== X-Gm-Message-State: APzg51B8t+oGrdOepCq9kEKpLxzvNgBKVeoWvwqSdP88mooyqffEXa6j BZZv//BsYlyTzxuNQd8b7LTF+MLn X-Received: by 2002:a62:1157:: with SMTP id z84-v6mr41566901pfi.66.1536166411895; Wed, 05 Sep 2018 09:53:31 -0700 (PDT) Received: from localhost.localdomain ([2601:644:8201:32e0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id j13-v6sm2844846pgq.56.2018.09.05.09.53.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Sep 2018 09:53:31 -0700 (PDT) Date: Wed, 5 Sep 2018 09:53:29 -0700 From: Eduardo Valentin To: Dmitry Osipenko Cc: Zhang Rui , Viresh Kumar , 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: <20180905165327.GA1841@localhost.localdomain> 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: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 13, 2018 at 08:14:00PM +0300, 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 Acked-by: Eduardo Valentin Rui, can you please queue this one? > --- > 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); > > -- > 2.18.0 >