Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4765845ima; Tue, 5 Feb 2019 00:37:03 -0800 (PST) X-Google-Smtp-Source: AHgI3IYMAKt73k2ZuuBDiRLIX0BDTKDlM3V5SJSTypaJON/3JFj211JHvAZ8aelQTyCmqkNQMjsB X-Received: by 2002:a17:902:b609:: with SMTP id b9mr3902544pls.57.1549355823109; Tue, 05 Feb 2019 00:37:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549355823; cv=none; d=google.com; s=arc-20160816; b=s7vAJ4YwdyRpnJALD+SZHsWeSfoMrO5jtMIn3WSLmZsT2oEw+hIpolr1c7AUzKQwUX Z/ixtruWfs0X9ahuLCP9W8zAYLEKXjdAVuFhsLMVGumEi02uqIuYTh8HuYaQtyTh5wjd QZEvnpFvtSS3nN3rLLojzvuWXSptRfDpJF0UhAKcx7nTi4H+1pYkwrJLrgXIf3xbOBwP /oBJOeyIw/2pol5Cn10nHfUJ0erODy68afQX2JmZWeUtX2iy7m5dxuAIe9AOIxxNWuxN ELIcjzJ3eG+JCnHSXbD8EJvjkwq7rCYCmJCzVWKRjZuCQEpyv3nLIgFY55XjSUE+b7dD N/Wg== 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=Vr4fVT+hNY5Y7ABVbkztYRm+pgJ5HItCTKaQ9rit0g0=; b=Nbo9laRkKaC8AR8IVoSHfyhE+gc3BUT79Q9nyejZjUQx1WgdPJhUTliPuRckf5VAOs yP7wP+JgV/GyfQXkxZ7opZSL3e4JLivRDRfqm/q8bjeKjrF+4qs/V7MCMuSNvq/dh/Sh ogljyJlTexwpWAKXFENAPTR2E5zNO1RfJlM7yGmeZ96fJ7Rg4nc3g0zWgMkoVfbtQ7U8 1EEW1zb1VA88M9RZo/SFzzfE5l/w97iExoexOzfZp4ctpb98RrodjLnOaJaKatwUX3jG lpqyQPLjx1n/gnSuIXcHqtO+ezAcLxG+gu6A/the83T20y0sFU9HXZG8oTA4WQuV+EAd mjvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rrXR0tGy; 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 d1si1402925pgm.236.2019.02.05.00.36.46; Tue, 05 Feb 2019 00:37:03 -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=rrXR0tGy; 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 S1727039AbfBEIey (ORCPT + 99 others); Tue, 5 Feb 2019 03:34:54 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38661 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725954AbfBEIey (ORCPT ); Tue, 5 Feb 2019 03:34:54 -0500 Received: by mail-pf1-f194.google.com with SMTP id q1so1180103pfi.5 for ; Tue, 05 Feb 2019 00:34:54 -0800 (PST) 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=Vr4fVT+hNY5Y7ABVbkztYRm+pgJ5HItCTKaQ9rit0g0=; b=rrXR0tGyTfHkW7OrBvGKgWNM3nLM4lLsDEzttZ0xhfb2hi7iDDrStn4CR8Zg2QWSY2 2/f9DRZAvNjcbk8kkh5oWRDHnpoMqekprAxZG319tK69nX1qjyppkkIcwNEBN26l49h+ awPE/mT213lWupD+9Ca/uyWW484+OtMYaoN0bHj79wwacEj9l4BYYW+1sCUmTJlTfuku 6nxvzbeIuyLrB5X5U4KkJpYT0FbzIFE72AgcnY5Tt3rUnbDD6/0M6JIy+mlmbdq9AaCD PBixe40CsRyUuqmW5GZy91FqHfq4svkQE82noxTmkr9eXVJuWmH/0ZAzc7hlQABHdx0A pvuA== 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=Vr4fVT+hNY5Y7ABVbkztYRm+pgJ5HItCTKaQ9rit0g0=; b=juRfHPzbwwSYEmtkcejnWqfMqYXwNdS0Ix+0rK20S41J6wiZdUmah2WYAayZ5VJcv5 e5jVAASSkcHj1n920zBkIaz3Ax6HELRtqF6UjgXVHemHZkhmzwbLGp3ifQaTqttpcQut PqI5VQ/L0FsFz3mVNexz/gUMga6DguvgzZjsDPU24p5IY1SgXbeL1Xnei5kouNgfmd4S vcc4Cpj38twNLgP1U48u3Cc0nSUpTbLmMYtSO5ykPh4kLrNlg/yWZ/RNCT3QUdLU6H+r z59jWNdWy0lrjlfQc+80tCmkUbiHOClh+RcH3DGswEFVpOR1PXKzp4lw2Rcm9GVsPAII 4rKw== X-Gm-Message-State: AHQUAubJJMAVwgNP6NiVF3DLP6TXQuOOxp0oe4zh6fIl5z/+45CUpdor 02z5hUw8OUc1F3ud9OOj3zg= X-Received: by 2002:a62:2044:: with SMTP id g65mr3749012pfg.127.1549355693335; Tue, 05 Feb 2019 00:34:53 -0800 (PST) Received: from dtor-ws ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w184sm2754333pgd.34.2019.02.05.00.34.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Feb 2019 00:34:52 -0800 (PST) Date: Tue, 5 Feb 2019 00:34:51 -0800 From: Dmitry Torokhov To: Sven Van Asbroeck , Jacek Anaszewski Cc: Tejun Heo , Lai Jiangshan , linux-kernel@vger.kernel.org, Sebastian Reichel , Kees Cook Subject: Re: [RFC v1 3/3] cap11xx: fix potential user-after-free on module unload Message-ID: <20190205083451.GC118684@dtor-ws> References: <20190204220952.30761-1-TheSven73@googlemail.com> <20190204220952.30761-4-TheSven73@googlemail.com> <20190205081846.GA118684@dtor-ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190205081846.GA118684@dtor-ws> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 05, 2019 at 12:18:46AM -0800, Dmitry Torokhov wrote: > Hi Sven, > > On Mon, Feb 04, 2019 at 05:09:52PM -0500, Sven Van Asbroeck wrote: > > The work which is scheduled by led_classdev->brightness_set() is > > potentially left pending or running until after the driver module > > is unloaded. > > > > Fix by using resource-controlled version of INIT_WORK(). > > I believe this is wrong way of fixing this. The LED classdev objects are > refcounted, and may live beyond the point where we unwibd devm stack, > so we are still left with the same use-after-free that we currently > have. Hmm, I take it back, it looks like the lifetime of the outer structure is limited to the time while driver is bound. I still wonder if using set_brightness_blocking() would be better fix? > > This is a general issue with LED subsystem as it provides no callback > for properly tearing down device structures, but I think in this > particular case we can simply switch from set_brightness() to > set_brightness_blocking() which will use the work item internal to the > LED classdev and that one is being shut down properly. > > Jacek, does the above sound right? > -- Dmitry