Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2379379ybv; Fri, 21 Feb 2020 14:33:42 -0800 (PST) X-Google-Smtp-Source: APXvYqy9sPvOI+Df04LIeBd6v4cg5zbKKIt4Oh5c5HAPCbHNtDsKZHLoaH7odwH+lrFiPUAyyEUH X-Received: by 2002:aca:ab52:: with SMTP id u79mr3730894oie.145.1582324422171; Fri, 21 Feb 2020 14:33:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582324422; cv=none; d=google.com; s=arc-20160816; b=SEZU4qLwgfXY3AW+AoXaI3fxdnsVYAplO7PF0nk2b1AFRfrvpRsihwQUxsTx8i1NOA l1Wi8Rsw+kiMQgSMEeSBphd3KcbiJ48WhEjE94NxN3TSxZ+JvhPm4J78YQK57VR5a7jb 2Q62Qh5g5q+ei5jeFsFkGabj4pncAfIBruWivlUPbu9htNxIJTS6B4QVemdwB2EdXn2k 7bmbxqYfwuv1nJhXkG6HUQVm0wbv944Z8iPBS536H3IXOrlBMWTcVhdOlKakOVJDDfs0 Gkp3MSYbNk1YYiWvfharjvysNuS5SU+B6y7FcWBfC8XWbTlKXGdK2dfWioZwIY8Rw0KD GbYg== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=/inF5Bzmm1g2cHpLVFGpcCiR1l4vvSPslMa+vfhG/Mk=; b=YHWSKdGjE80zcZiE4zHwjQieCWZ6//fxL9VBvgEP7Pd/FCnZv8T4OWqabblrozT+qi JLQCUC8LgomeP4XSVQD4xFz+jpviXjqc6AeNNR/f96hwNMTd76EgzmUG7f7FR1ybjLYN CJuD5svzWU5BXVcCqGlb2M2MOb/Gr9LUs6OxsFzq0OVawFEbDZi1tuhB4rizbUy0QqxS YQvY9EIwcQiRcrxR/0l1khVHGvxyPoJMWlxwHoFzcEkT6siksfaXyGmARc262dsnzuau wl8ZKxLt3WVL27ChOTEinhh1nx1xMzA2AUFwiZz5W2XxsusvINPfhfLsrKPHdDKdeVbR 1SXg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v23si2003076oto.81.2020.02.21.14.33.30; Fri, 21 Feb 2020 14:33:42 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728792AbgBUWcV (ORCPT + 99 others); Fri, 21 Feb 2020 17:32:21 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:34104 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbgBUWcV (ORCPT ); Fri, 21 Feb 2020 17:32:21 -0500 Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: bbrezillon) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id D6056295BD2; Fri, 21 Feb 2020 22:32:19 +0000 (GMT) Date: Fri, 21 Feb 2020 23:32:16 +0100 From: Boris Brezillon To: Vitor Soares Cc: linux-kernel@vger.kernel.org, linux-i3c@lists.infradead.org, Jose.Abreu@synopsys.com, corbet@lwn.net, Joao.Pinto@synopsys.com, arnd@arndb.de, wsa@the-dreams.de, gregkh@linuxfoundation.org, bbrezillon@kernel.org, broonie@kernel.org Subject: Re: [PATCH v3 4/5] i3c: add i3cdev module to expose i3c dev in /dev Message-ID: <20200221233216.3b2038f8@collabora.com> In-Reply-To: References: Organization: Collabora X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 19 Feb 2020 01:20:42 +0100 Vitor Soares wrote: > +static int i3cdev_detach(struct device *dev, void *dummy) > +{ > + struct i3cdev_data *i3cdev; > + struct i3c_device *i3c; > + > + if (dev->type == &i3c_masterdev_type) > + return 0; > + > + i3c = dev_to_i3cdev(dev); > + > + i3cdev = i3cdev_get_drvdata(i3c); > + if (!i3cdev) > + return 0; > + > + /* Prevent transfers while cdev removal */ > + mutex_lock(&i3cdev->xfer_lock); > + cdev_del(&i3cdev->cdev); When cdev_del() returns there might be opened FDs pointing to your i3cdev [1] ... > + device_destroy(i3cdev_class, MKDEV(MAJOR(i3cdev_number), i3cdev->id)); > + mutex_unlock(&i3cdev->xfer_lock); > + > + ida_simple_remove(&i3cdev_ida, i3cdev->id); > + put_i3cdev(i3cdev); ... and you call put_i3cdev() here which frees the i3cdev object, leading to potential use-after-free if any of the fops (ioctl, read, write) are called on those dangling FDs. That's exactly the kind of nightmare I'd like to avoid. > + > + pr_debug("i3cdev: device [%s] unregistered\n", dev_name(&i3c->dev)); > + > + return 0; > +} > + [1]https://elixir.bootlin.com/linux/latest/source/fs/char_dev.c#L587