Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4362772ima; Mon, 4 Feb 2019 15:15:20 -0800 (PST) X-Google-Smtp-Source: AHgI3IY83VHFMHG0lrNPX0Tk0hxPw4iSrcbT+L5QtMXG7+DiDrf/M2Evec6orJLnQz4byOp56Fi6 X-Received: by 2002:a63:902:: with SMTP id 2mr1588168pgj.219.1549322120627; Mon, 04 Feb 2019 15:15:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549322120; cv=none; d=google.com; s=arc-20160816; b=TzKxbREjj1N/d2qJp+Gfbl4ES4DHSVwhudCAY180248VFZIzhSPSnNLFtM7oIYu7Sf ZkLMZWTItLXVotaKF1+9OnteTTYv/JFnCQqX3rOPKfg1MAW6CqJNzrKa/K2DYn3RI5jZ cfJGyhER9HzD1hCShw3GGpSPexWbedbiu8F4X6ckyuB8HNtzU3lOvYxOv584aCGBcrjL zZCgAfHEtqunRGtgXJ1BSo6TCVrr++W1XG/pZtyHg/D2gTfMpgfaZGPgnF1n3azb9Q4c Fs3o8Q35B4vI1OVVJ2cmHmTvkfGRFaht6rZmicRUGSsgiWV14CXzYvvZpS2wB77oC9CM oisQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=bPU4yGp8groZzMsMQG7ObLh9y+ne17hprQCw1G/vo/k=; b=EqCfft5/5gEJZglyBpovlF5M8QbcHrU4w7wBEsZ4EZuuuHe+pkeZfC9MluPM3xzPCb ey6LxmOy9/ZCLzGVjiWzWp22t4gvJdu8BOHGLCFiQUal/OfcmnKIL9SYpM1HsiHXbvmD W/HNyd5B1989WdcmBlaKJRGeaHoPIg6eAVwHk5oQbupLSOHbrPh5BcpEibrsFYod0kcN rJ6jHdEYANDl+hH4e5PpwD/rzx9cvNLlE8gGoA7MAmswcMq9naj6VF4URK9mPtGNg2OX TSQWCZtmUfWH/OUu6Sow+jqO0+0ga6k57dCr1ravcUAGQCV465WIU5fCLi4axVIv8UlX X/zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Psx8d03J; 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 m8si1346132plt.171.2019.02.04.15.15.04; Mon, 04 Feb 2019 15:15:20 -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=@gmail.com header.s=20161025 header.b=Psx8d03J; 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 S1727176AbfBDWKF (ORCPT + 99 others); Mon, 4 Feb 2019 17:10:05 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:32968 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726897AbfBDWJ7 (ORCPT ); Mon, 4 Feb 2019 17:09:59 -0500 Received: by mail-it1-f194.google.com with SMTP id m8so12783959itk.0 for ; Mon, 04 Feb 2019 14:09:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bPU4yGp8groZzMsMQG7ObLh9y+ne17hprQCw1G/vo/k=; b=Psx8d03JsRW6hTGNB7jLBqBocu3HOSbn1YqneJQHtrJcWgk4S0aJ9Fi7TDEOuMtHsw +h8ZRJUMSQ2pOdM4beoifEmnN3OIWjrIMibyrw5dFZVCia1HjZTAz3QOSXz1W/u06kuY FhXNk7bwbSRUne0vQl3zEABX3HKJtCe/gWHvxEVfDpXk9UYVJZ4PcfqeAlaHM3scHHa+ amEc5ZMkDobbXM4YN0N3R0djQ4U+kR6SYqVhseVHm1sQ3cdQqXA2t2EEOJpv6uEO6MUy Jj6wpJ+h5AUdKaAgDZBWsiGaVgknlrcpilPMyBKhgbT5UhhjduyRGelaJEvFVtjKGgAH UUeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bPU4yGp8groZzMsMQG7ObLh9y+ne17hprQCw1G/vo/k=; b=Sj0AzeG6Ifv6edu3+oGpQRhJ8NgaVQIzg9uKle0uJt+qeYi28dmzranRujb2O/qgd7 hg+2PjpjclOxY0rUgPNfcPuPS54AvcKSlWwJoSMUxwmWCqVBDirNffjI7RnVfNZWf0QF o6p1F+Eq5eWR2n6jyePvAeuHdvQXu3Z8vYDcq5308GTEd4Dwk9VUf5rDpUUMCYpOFwf5 cSr1bIbNrXf4uwD9tLwpvpp3UU/vzjoI863UFEP/Wqy2WVX6DE9b4E89k6EHiz53gN2A MihBol+m6YGc7ugIpQH1KA5xknaSAh5goCHlTW9njP0aPztSMDcp+YptbUmSxH70typw hNhw== X-Gm-Message-State: AHQUAuZfNjHzCa/sLmoFp8zoHepIsKRSXkAwxJp4e804CM3t4ujIWY1s rzrCuvwbExBHPuAzyT+W/+k= X-Received: by 2002:a6b:ef02:: with SMTP id k2mr859976ioh.95.1549318198440; Mon, 04 Feb 2019 14:09:58 -0800 (PST) Received: from svens-asus.arcx.com ([184.94.50.30]) by smtp.gmail.com with ESMTPSA id z1sm531602ioi.77.2019.02.04.14.09.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Feb 2019 14:09:57 -0800 (PST) From: Sven Van Asbroeck X-Google-Original-From: Sven Van Asbroeck To: Tejun Heo Cc: Lai Jiangshan , linux-kernel@vger.kernel.org, Sebastian Reichel , Dmitry Torokhov , Kees Cook Subject: [RFC v1 2/3] max17042_battery: fix potential user-after-free on module unload Date: Mon, 4 Feb 2019 17:09:51 -0500 Message-Id: <20190204220952.30761-3-TheSven73@googlemail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190204220952.30761-1-TheSven73@googlemail.com> References: <20190204220952.30761-1-TheSven73@googlemail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The work which is scheduled on a POR boot is potentially left pending or running until after the driver module is unloaded. Fix by using resource-controlled version of INIT_WORK(). Signed-off-by: Sven Van Asbroeck --- drivers/power/supply/max17042_battery.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index 2a8d75e5e930..a61e2b81f68a 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -1100,7 +1100,10 @@ static int max17042_probe(struct i2c_client *client, regmap_read(chip->regmap, MAX17042_STATUS, &val); if (val & STATUS_POR_BIT) { - INIT_WORK(&chip->work, max17042_init_worker); + ret = devm_init_work(&client->dev, &chip->work, + max17042_init_worker); + if (ret) + return ret; schedule_work(&chip->work); } else { chip->init_complete = 1; -- 2.17.1