Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp250937ybi; Wed, 29 May 2019 20:39:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPW1RXM5bP8p6/Mm6Fghz6uFz3CVTuKoXPb5MRcdt8VTLC43prNqV1oXuzL0gq/JywEws2 X-Received: by 2002:a62:65c7:: with SMTP id z190mr1541182pfb.73.1559187589216; Wed, 29 May 2019 20:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559187589; cv=none; d=google.com; s=arc-20160816; b=loYQONeORFLOCYl9NdrfzWvFq1xMti6DSo93DIh98iyJRAz73dGdCX0U9m7d/eAR70 IBqeZTcaAz2K0bB7rspKrNIltar2/DI3krvk2KxB5Zw76U8SVBxsSAnGH/sr5gX/bkq5 8YT1bhI2PQkKrZW/ypEcvi3G4RLbW2hTWCbsEL2huTomPYsnNPE9wA+5CE/inUWlTd2n WQPmabMzlNoPOMoM82Ly79r7zFB8GItahoPPJsQ9iUVKmxyIHMnw9tDDJ0lCoVNoAf7/ /tZBEKo/cAdQfyZlhWuWPYORIK5dMdW2R0fuX9+vfXtaz+MDcRbGc+9qCitAdPvkQ9eQ vXhA== 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=AntB6JFt0ROe12SOMrOIcITswwEVlv+T2WI8HtcZUi4=; b=axkwQN1jXoOTWcy9TI7zFyIy873HI0hxXC3gFZxy+ff7bYwAB2aJOsfIIR7wzI87dg ulA9QMX70a4E9STHLmqPQfQWvLKfIUhSx0ElH5egKAvc7ptMCAwYu+9NdbJa+Ma/H7l7 w5Vyx6cxL5HVMimX7VcDS53GDwR2FKIExhOrEvLnST4d+1b+rHXumdEOoblmGWPzXb+s uGtEe4FPtJNT5l+Xn/wDZihrCldeGljj9CxdzlUQrvpBq38s0GMkFRbz1sP8wpEg5S2w gNWluDB/5pjW3XJ7BkM1B6lEyvBzXEv2R6i7By7c6EVNYDkesm8CRQ8eXkAHnmoxm2ls 7Uuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=X4mw2Yr1; 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 e6si1912601pgj.590.2019.05.29.20.39.31; Wed, 29 May 2019 20:39:49 -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=@kernel.org header.s=default header.b=X4mw2Yr1; 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 S1732972AbfE3DWz (ORCPT + 99 others); Wed, 29 May 2019 23:22:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:45222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729965AbfE3DRJ (ORCPT ); Wed, 29 May 2019 23:17:09 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (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 CCF1124673; Thu, 30 May 2019 03:17:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186228; bh=i1Vi4hGrEFyWzIxeGsWxePBBNB1HBqFssvmMcgk/xcg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X4mw2Yr14/g2jm1YKPtjxoJtYfXjAwfwyKkvHNkqI0bNLCG+moKIFlQq7xnFn62Z1 zHHybq7fDWxUKAQEzRpplr4g0RhxKJ95FRA2WpP5PCbts/DArgw9J7IetwxITb4T9h MWdWQJdpuB7y44Yq1zz8Ei9O5RS4dg7ZkQmjgmoI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sven Van Asbroeck , Alexandre Belloni , Sasha Levin Subject: [PATCH 4.19 084/276] rtc: 88pm860x: prevent use-after-free on device remove Date: Wed, 29 May 2019 20:04:02 -0700 Message-Id: <20190530030531.555933764@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@linuxfoundation.org> User-Agent: quilt/0.66 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 [ Upstream commit f22b1ba15ee5785aa028384ebf77dd39e8e47b70 ] The device's remove() attempts to shut down the delayed_work scheduled on the kernel-global workqueue by calling flush_scheduled_work(). Unfortunately, flush_scheduled_work() does not prevent the delayed_work from re-scheduling itself. The delayed_work might run after the device has been removed, and touch the already de-allocated info structure. This is a potential use-after-free. Fix by calling cancel_delayed_work_sync() during remove(): this ensures that the delayed work is properly cancelled, is no longer running, and is not able to re-schedule itself. This issue was detected with the help of Coccinelle. Signed-off-by: Sven Van Asbroeck Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin --- drivers/rtc/rtc-88pm860x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c index 01ffc0ef8033f..fbcf13bbbd8d1 100644 --- a/drivers/rtc/rtc-88pm860x.c +++ b/drivers/rtc/rtc-88pm860x.c @@ -414,7 +414,7 @@ static int pm860x_rtc_remove(struct platform_device *pdev) struct pm860x_rtc_info *info = platform_get_drvdata(pdev); #ifdef VRTC_CALIBRATION - flush_scheduled_work(); + cancel_delayed_work_sync(&info->calib_work); /* disable measurement */ pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0); #endif /* VRTC_CALIBRATION */ -- 2.20.1