Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp900336ima; Wed, 6 Feb 2019 10:08:32 -0800 (PST) X-Google-Smtp-Source: AHgI3IaB1db6V4vk5yklLHjqMPgC+zW1DZhr0QNP39yeK1ytf6AV6DCbzkmmmDpYfQXnQ7FFyM/U X-Received: by 2002:a17:902:4025:: with SMTP id b34mr12083519pld.181.1549476512118; Wed, 06 Feb 2019 10:08:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549476512; cv=none; d=google.com; s=arc-20160816; b=Ez1VIodGu0LFjlth3bs5plyzLnznC8CL+g+khvf3trl/daIHEL/lpjh9pY/mV7XcU/ 3VqacHsCkHHBrrA8/Jk20qhe/1Qq9ueHDnsDVPLOT4q5LSPJicwRfaksg13uvILZB2ae G+hYC527plPYOqrB2PrKMBT+tGthhODYwwErHDCMu38OkfenWonEbhdcXkCwEdfwZSkP Nk84/ELIXTOQm07g96UANbNWPgjiRej3Mm1nrFay8VLlDcbq3xyKIHqZSQEF/vqC9ygS 3bg52QAmkKRw+nfPEdQekrtQttfg6Yjgd1PeP0AZBxPvfEDcm7rD5rFG8TO+LBQa82vG rOdA== 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=+rRMVWcIepJ780DiGU65IJUJ+FeBxKihEfR1/RuIkls=; b=D+pW2n9GXecb5so7MtVVmZCWRM8hGJVVzBTGkyQBn+5J7L/6RptLae2Ab5fQQJKj+w rAxC0fwHllIOXIs73coPEru686bNeMFHtMBME0ftMNTs9YDBATz4dS99z4dV2OogAQ5/ FxC/fVyD2TaWtNdvc+BdhH0pfn0Nj+DWH0CZw5mUbQfGbScU9sAe9FoHRLbUHK+i1IJm GvwCDefJHzlu4ahTIECwtevU2koUPQ4sykHGV7zIRT3ZVVajggnzexU2vl+nsIdeU47O ns8B1ZjHqolMSFEN+ztwWdD5yIMYSw8YHOHQH3yUUjDXW5F6cWo4sZNUIwCw+bPt3GNg aRaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=c0rkUeJX; 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 n21si6106600pgm.456.2019.02.06.10.08.08; Wed, 06 Feb 2019 10:08:32 -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=c0rkUeJX; 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 S1729399AbfBFRtf (ORCPT + 99 others); Wed, 6 Feb 2019 12:49:35 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:41951 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727299AbfBFRte (ORCPT ); Wed, 6 Feb 2019 12:49:34 -0500 Received: by mail-ot1-f66.google.com with SMTP id u16so13373687otk.8 for ; Wed, 06 Feb 2019 09:49:33 -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=+rRMVWcIepJ780DiGU65IJUJ+FeBxKihEfR1/RuIkls=; b=c0rkUeJXHWQAog5OCqvrgIB4oKC94nuDCiTyHdVBmx/Vv7Oi4UVLorFPf1idqeCbbu YeIg0K+LRZLk+1jxWsElcb5WTobQaIKlQTYYXbV3qf3PGIskRCXELaJkRTtiiPT4Vn6T 5Rx+Gtt9VGDA0Em8QY3qRV1E1sUDL0amdLR5QDg1FV1IKxYzq8gdEyFYEsUMDdv8D50m oTdSnK2hpWMBAqMvaQZtXm4cAYGwFvSD6vG45euieSw2ByH8tsYDyvMLWHTjJIaW7p/O fw1wDBXpa5svPIbbd6lI84kcOi9KA6fZFvFSR6PgJZN4t4BmdlGA8K0W37FqjFlZCkP8 VeHw== 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=+rRMVWcIepJ780DiGU65IJUJ+FeBxKihEfR1/RuIkls=; b=EnYfQ5zGOabPJhCcS4vTvRULUXmGUFwaanJJ/GLrgkAWwPt0ntDzmNBpSQCCJqyUde SUHBQ/SFjoz5K7KPEzewJyw498wZu9ZKUD4E08FEAlirbBDtr/V6tNXYACXf4cKN5rw7 i73IHTTYXAvfGCJJxKpSBtHyvbJ+ucMaLSJ0sZVQFPAPn0ramXzIKUNj2xgca+Fu2zgy 5RJ0Gg6inoEpLuQKdFA3Upoj0ioajU3iWalwmH0u2q14xEqtlsf08hRujJXSxzeGiz3e UCt+Tp7I0WsIyyXBStEmVwTz9CxG3r7Pnpqhxi0f0HZlUUyYJfO2EB93vddlsWABrX+X lgPA== X-Gm-Message-State: AHQUAubEwRkngceYAPnQEodnJSQpyCQZYj768K1Nn0hgPy7XucFWyfgw ThDGMR8aVftQmXm4WPHWAdvoUAqNs52air6LOOQ= X-Received: by 2002:a9d:61c8:: with SMTP id h8mr5959942otk.279.1549475373118; Wed, 06 Feb 2019 09:49:33 -0800 (PST) MIME-Version: 1.0 References: <20190204220952.30761-1-TheSven73@googlemail.com> <20190205184355.GC22198@kroah.com> <20190206164657.GC8466@kroah.com> In-Reply-To: From: Sven Van Asbroeck Date: Wed, 6 Feb 2019 12:49:22 -0500 Message-ID: Subject: Re: [RFC v1 0/3] Address potential user-after-free on module unload To: Dmitry Torokhov Cc: Greg KH , 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 12:30 PM Dmitry Torokhov wrote: > > 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. > It sounds to me like _incomplete_ devm_ is worse than no devm at all. Imagine a devm_ resource depends on a non-devm one: int acme_probe(struct device *dev) { ... r = create_something(); d = devm_create_thing(dev, r); } Then remove could get us into some serious trouble: void acme_remove(struct device *dev) { /* r _must_ be released here, we have no other place to do it */ destroy_something(r); /* here, d is still alive because it's devm * which is cleaned up _after_ remove(). * Now we have a live resource using a released resource. * use-after-free anyone? */ } This is a more generalized version of the issue I originally observed, where r => struct work_struct. I'm sure there must be plenty of these around the codebase. I wish we had a Coccinelle script to catch these, because it's one thing to fix them today. More will be added tomorrow. devm_ is so elegant that people frequently use it without thinking it through. I certainly would have, before yesterday :)