Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp891089ima; Wed, 6 Feb 2019 10:00:53 -0800 (PST) X-Google-Smtp-Source: AHgI3IZqUKFkXo9oZWS9hJve1Cncf3bsu4ofAj+nfl8Uwvr6tVbP7m4KEYmGFmNRwjleYl5s10cG X-Received: by 2002:aa7:81d0:: with SMTP id c16mr11637472pfn.153.1549476053126; Wed, 06 Feb 2019 10:00:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549476053; cv=none; d=google.com; s=arc-20160816; b=pqnhsPOjQbOac0uAlxODLny93BNytNwS2y38WLh7GfHcPesBENPteCXGtc1vaz3P7+ lEIAq3TKdjYlEFEn1pAYXJbBijO6JgkbFG/JCHdeJNmy0lPMXiN2by2qB7lDoU9MqiLL 6LCoOQN2oT2hONA1yHD447MKErlU7K720zT4e7EK3Ta3GspKxeLDRv9/wRWa6mQEAddK VT31qnzH3xA513z2lPecohfDIXF3fUNeeUWUekoKsENRwYmr67VziHXCY1s+UBSIdJer l1Ibc4TgZ8M5kZj0AYJenlFr+ZGmw8c2SDQHsPHswoe+Xed6w+7JiQhLRzypJSqvI0hp k3Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=5MD26BBKvAItyYxLe+zAjYHyLxzZQedEnSOItHVT1ew=; b=09dLElsHG2FA2C2dHyM3435efif/gbEHa+jhkavIvpC1FIS0zGPE8DocvHoJESg/fJ DprdtM0Kqm9MbxybfWkSw+n1VJZrX7NvviqAqCtYBlG2aCl4wnqcf1CzB7SG/5NOqt5L BLjDh61CWpPIKxfSB5GBqvlOSD5IKm7j6r5HxllXuiMhjOYC9p8AOQsqeTLAYLZS+12q rSjFdYGl6j0cxzSHZIc6ca/6kjD0/LSuz5708xqGIf5VJ8sEL9jpPdznPkKjLN80FXF0 Ov9xbdjdtHwZF2JTgD2Te31Fxhizb/S25l5asBw4wDKcJbxFjwtrmMcpmZGzB5FC/hTO duKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=crc5LZWX; 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 i35si6845423plg.396.2019.02.06.10.00.36; Wed, 06 Feb 2019 10:00:53 -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=crc5LZWX; 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 S1728994AbfBFRam (ORCPT + 99 others); Wed, 6 Feb 2019 12:30:42 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:36910 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbfBFRam (ORCPT ); Wed, 6 Feb 2019 12:30:42 -0500 Received: by mail-it1-f196.google.com with SMTP id b5so8098126iti.2 for ; Wed, 06 Feb 2019 09:30:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5MD26BBKvAItyYxLe+zAjYHyLxzZQedEnSOItHVT1ew=; b=crc5LZWXXlWsEeUtNyA18m6xlrjoODFf+h4/pc/E0+AQvngZOUuXPiEpGGU646IVDF LL+iX/r4JF3e23tul6OG/D1fZgwm3JZ0q3DWm157q3PUonAyiQhSH1YDcTQTPnwU8yK8 Wmj0K/gnOJgIK4pzi1Z0ufRiSkVUrkdroiGKec4tJCVhO+uMeTrjJHst9LNi8ITt9TDu YxQPfS5q9iWIaHo2oX3bFWqhFQ3TpF3JcnmrYi7q32UDLXFJb3NCEBHB3KvyFqKSogDG x/o/hD7971KCj431PKt2fs6KcbUVxeZiiEAdT1UorRcg3irVkVIK4TJgSz+x+w47kUts /+vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5MD26BBKvAItyYxLe+zAjYHyLxzZQedEnSOItHVT1ew=; b=DAC8SzdCv7NusuFOkmVmirPqa2NUqNFr8CGMhiQbH4syaOq+466tzSSXTMttCxfvRU ID14ImB+S3qDD4nEc4fbbH05j4E/yFqN0rpR7M4gnhX1/Ztc49iPeQidOvfgsmP7CIZo skPY9adxdyhgSj6ih1FQS4+T7ls1u5w/X3rGOlyruoqvWSWX28yTlgVs2DxiPaghGPoo mK6+p5W96hUgwP8hEjyaJxzB+LVXBeT+x5RdvOGm2xnc38T3J3FlBbEVBQ3b3R321l05 pXm9VZlCFt1jOMP0aVNFaN/pdzeiBauU7mrhwfz7CN80p7EuA6SFnpaqBqe+IRvijwSp lbbQ== X-Gm-Message-State: AHQUAuZBDwQPG9VawPrPLbP7WnZblHqjWumSVt5MO0yF/5oRGfYcwZp6 4SsecyGk+3GOkixRnStAFPb259t7NnfEzDvmOHuuIA== X-Received: by 2002:a02:1217:: with SMTP id i23mr6447098jad.53.1549474240746; Wed, 06 Feb 2019 09:30:40 -0800 (PST) MIME-Version: 1.0 References: <20190204220952.30761-1-TheSven73@googlemail.com> <20190205184355.GC22198@kroah.com> <20190206164657.GC8466@kroah.com> In-Reply-To: <20190206164657.GC8466@kroah.com> From: Dmitry Torokhov Date: Wed, 6 Feb 2019 09:30:29 -0800 Message-ID: Subject: Re: [RFC v1 0/3] Address potential user-after-free on module unload To: Greg KH Cc: Sven Van Asbroeck , Kees Cook , Tejun Heo , Lai Jiangshan , LKML , Sebastian Reichel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 6, 2019 at 8:47 AM Greg KH wrote: > > On Tue, Feb 05, 2019 at 02:12:31PM -0500, Sven Van Asbroeck wrote: > > On Tue, Feb 5, 2019 at 1:43 PM Greg KH wrote: > > > > > > > > > It really should happen when the device is removed (if it is a driver > > > that binds to a device.) > > > > Absolutely. That's why I'm advocating adding a devm_init_work(), > > which will take care of this automatically. > > > > But it's of course not universally applicable. Not all drivers use devm. > > Ick, no, watch out for devm() calls. Odds are this is _NOT_ what you > want to do for a device. Remember when devm calls get freed (hint, not > at driver unbind/unload, but at device structure removal. ??? We unwind devm on probe() failure and after remove() is called. The device can live on. > > > By creating a work queue, you are suddenly tying module code to a device > memory structure lifespan, both of which are totally independant. > > It's the same issue with the devm irq call, that has been nothing but a > nightmare as everyone gets it wrong. Try to learn from our past > mistakes please :) Yeah. But devm irq gave most trouble because we did not have enough devm APIs so we often ended up with mixed devm/non-devm usage and that is what was causing most of the issues. If we can switch everything to devm then devm irq is not that troublesome. I have 2+ drivers that currently use devm_add_action_or_reset() to install action canceling work, they could be switched to devm_init_work(). Thanks, -- Dmitry