Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2960703imu; Mon, 19 Nov 2018 08:39:34 -0800 (PST) X-Google-Smtp-Source: AJdET5di1sCVsHQelFLEBE02Tie/Y61xq4RqQEkPzxnj0a/mGQYcRY7Aaln+4GzHKpoxInBCV9Kt X-Received: by 2002:a17:902:d03:: with SMTP id 3-v6mr21061074plu.66.1542645574138; Mon, 19 Nov 2018 08:39:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542645574; cv=none; d=google.com; s=arc-20160816; b=IOhvFHMaQhy/cZ5ckpDefuXBbOY5todrazrbF3VAhMz4Ln0Cm1DsQm7QLbzz28B1HA HWcP9rfdhTlYoQ6/Nb8hI8Ahk+hyUsALQdl3Gu7vYpcBpKpo/OMmOpMmkwwxDmy4hN32 xhUkmeqU1hGGsFShNAatjCYnFZbwfN4GtTJFb7dGHWWhvdaE9p5d8l2HM5OkuLKAznQq 7Pdv1zx2jK36ERd/XDduL741NI8jm0IzO3/wAR+sibOEH7u6Q0GKXYSTgOkxhA4Gjne0 eYsWVYSzbCu6tODR7vuKIomkV30Zpn7copxccsCRRj/luQClcTnWBEpc9QfmGH+iCj/M iQcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EfvFCNXnBYyVUQECO6rOHDvgS1Ou9B4sJq5xadFQ6JM=; b=ebZzaPndRJ+ab2O+27rwtkzNX3piUdtF18iTcOmq3GydFi+NHZiNvhQewnx4BHNdW3 OKsMvUyTnzN4cKxZmYvAGRUSN/vi07RX8oh4O7smcJfdJdWr3Z7NwkKZostX2qC6Bgz0 VZEdKzqo13ieCHWi6bRvXjJaelZEbGbq0GyJFdXeyatOrXeCSN6/H7n7lC6HegKNhsz8 Y12mlEq/QY41L2b0q0e4DxqpukgylmLOjSVZ2idL1VzYN96qgq7sK04jGQi16WMZfglL C2UhmOniQtMBO+9dQjEz575Qauxarlk79EGdtrJCcK8ZArXm2SS6ABm3B+O4HmDyEGbi CneQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XWx+H268; 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 y5si37480973pgk.49.2018.11.19.08.39.18; Mon, 19 Nov 2018 08:39:34 -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=XWx+H268; 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 S1731999AbeKTDAy (ORCPT + 99 others); Mon, 19 Nov 2018 22:00:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:60820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730931AbeKTDAx (ORCPT ); Mon, 19 Nov 2018 22:00:53 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 C5327213A2; Mon, 19 Nov 2018 16:36:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542645404; bh=eqF+jPeBAleF2AFxeUye/yLScoJopQXnJPL8uyVg3o8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XWx+H268Fsn275FygBJBZhutw1rIMzv6F8oem25KsyuhWUreNPuYqAYXtDdXBwltT cztfQHyc2fzQorY8h+BeWk/VkZf0pUx8l64Vjd+Z+um4S5Mz0Gjzy0FGFGV2PDEs74 GPse+5UZTIN01b53cJY2Hy6SKRMXe/35zC2p71TY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Osipenko , Guenter Roeck Subject: [PATCH 4.19 111/205] hwmon: (core) Fix double-free in __hwmon_device_register() Date: Mon, 19 Nov 2018 17:26:58 +0100 Message-Id: <20181119162634.671421328@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162616.586062722@linuxfoundation.org> References: <20181119162616.586062722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dmitry Osipenko commit 74e3512731bd5c9673176425a76a7cc5efa8ddb6 upstream. Fix double-free that happens when thermal zone setup fails, see KASAN log below. ================================================================== BUG: KASAN: double-free or invalid-free in __hwmon_device_register+0x5dc/0xa7c CPU: 0 PID: 132 Comm: kworker/0:2 Tainted: G B 4.19.0-rc8-next-20181016-00042-gb52cd80401e9-dirty #41 Hardware name: NVIDIA Tegra SoC (Flattened Device Tree) Workqueue: events deferred_probe_work_func Backtrace: [] (dump_backtrace) from [] (show_stack+0x20/0x24) [] (show_stack) from [] (dump_stack+0x9c/0xb0) [] (dump_stack) from [] (print_address_description+0x68/0x250) [] (print_address_description) from [] (kasan_report_invalid_free+0x68/0x88) [] (kasan_report_invalid_free) from [] (__kasan_slab_free+0x1f4/0x200) [] (__kasan_slab_free) from [] (kasan_slab_free+0x14/0x18) [] (kasan_slab_free) from [] (kfree+0x90/0x294) [] (kfree) from [] (__hwmon_device_register+0x5dc/0xa7c) [] (__hwmon_device_register) from [] (hwmon_device_register_with_info+0xa0/0xa8) [] (hwmon_device_register_with_info) from [] (devm_hwmon_device_register_with_info+0x74/0xb4) [] (devm_hwmon_device_register_with_info) from [] (lm90_probe+0x414/0x578) [] (lm90_probe) from [] (i2c_device_probe+0x35c/0x384) [] (i2c_device_probe) from [] (really_probe+0x290/0x3e4) [] (really_probe) from [] (driver_probe_device+0x80/0x1c4) [] (driver_probe_device) from [] (__device_attach_driver+0x104/0x11c) [] (__device_attach_driver) from [] (bus_for_each_drv+0xa4/0xc8) [] (bus_for_each_drv) from [] (__device_attach+0xf0/0x15c) [] (__device_attach) from [] (device_initial_probe+0x1c/0x20) [] (device_initial_probe) from [] (bus_probe_device+0xdc/0xec) [] (bus_probe_device) from [] (deferred_probe_work_func+0xa8/0xd4) [] (deferred_probe_work_func) from [] (process_one_work+0x3dc/0x96c) [] (process_one_work) from [] (worker_thread+0x4ec/0x8bc) [] (worker_thread) from [] (kthread+0x230/0x240) [] (kthread) from [] (ret_from_fork+0x14/0x38) Exception stack(0xcf743fb0 to 0xcf743ff8) 3fa0: 00000000 00000000 00000000 00000000 3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 3fe0: 00000000 00000000 00000000 00000000 00000013 00000000 Allocated by task 132: kasan_kmalloc.part.1+0x58/0xf4 kasan_kmalloc+0x90/0xa4 kmem_cache_alloc_trace+0x90/0x2a0 __hwmon_device_register+0xbc/0xa7c hwmon_device_register_with_info+0xa0/0xa8 devm_hwmon_device_register_with_info+0x74/0xb4 lm90_probe+0x414/0x578 i2c_device_probe+0x35c/0x384 really_probe+0x290/0x3e4 driver_probe_device+0x80/0x1c4 __device_attach_driver+0x104/0x11c bus_for_each_drv+0xa4/0xc8 __device_attach+0xf0/0x15c device_initial_probe+0x1c/0x20 bus_probe_device+0xdc/0xec deferred_probe_work_func+0xa8/0xd4 process_one_work+0x3dc/0x96c worker_thread+0x4ec/0x8bc kthread+0x230/0x240 ret_from_fork+0x14/0x38 (null) Freed by task 132: __kasan_slab_free+0x12c/0x200 kasan_slab_free+0x14/0x18 kfree+0x90/0x294 hwmon_dev_release+0x1c/0x20 device_release+0x4c/0xe8 kobject_put+0xac/0x11c device_unregister+0x2c/0x30 __hwmon_device_register+0xa58/0xa7c hwmon_device_register_with_info+0xa0/0xa8 devm_hwmon_device_register_with_info+0x74/0xb4 lm90_probe+0x414/0x578 i2c_device_probe+0x35c/0x384 really_probe+0x290/0x3e4 driver_probe_device+0x80/0x1c4 __device_attach_driver+0x104/0x11c bus_for_each_drv+0xa4/0xc8 __device_attach+0xf0/0x15c device_initial_probe+0x1c/0x20 bus_probe_device+0xdc/0xec deferred_probe_work_func+0xa8/0xd4 process_one_work+0x3dc/0x96c worker_thread+0x4ec/0x8bc kthread+0x230/0x240 ret_from_fork+0x14/0x38 (null) Cc: # v4.15+ Fixes: 47c332deb8e8 ("hwmon: Deal with errors from the thermal subsystem") Signed-off-by: Dmitry Osipenko Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/hwmon.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -635,8 +635,10 @@ __hwmon_device_register(struct device *d if (info[i]->config[j] & HWMON_T_INPUT) { err = hwmon_thermal_add_sensor(dev, hwdev, j); - if (err) - goto free_device; + if (err) { + device_unregister(hdev); + goto ida_remove; + } } } } @@ -644,8 +646,6 @@ __hwmon_device_register(struct device *d return hdev; -free_device: - device_unregister(hdev); free_hwmon: kfree(hwdev); ida_remove: