From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 512D517C21B for ; Thu, 22 May 2025 17:40:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747935649; cv=none; b=e39AN+gQVKZsnHn4p/fO1OTEntmhMDJKGKQg4XobL8N+zv7AAuq7Rlb5OsSPnHuSexieNUgDXd02D+FTEGmm5LQD+BynE/7O9KPg4aK7RweUZaVXogEO0ikwTo2jZ1vqSm6FsQ4K51O/+x1Ka/chBxTFYgW+Wv3u9o+ZJjAIrPs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747935649; c=relaxed/simple; bh=2q+nvK98glNS1OrImQ40LpGSURdNbFHXEYA7zULYzG4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=uo5AB/KqNmIPoiW/WNap5q3w68bDBvIfZdrcxl2Ku+l5hRtkThK9u5n3uRjQp2QYC8hQunjbG9KqjJ1Vb6rUkyfSVI/a+QOFuohQwQSGEj7WqhKiInWh+TMGr6RlnIUgF9R7uT/8VY11iRxuVELESLbN1ajZzpU5nRyM3nDYNFI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YbkBSbb1; arc=none smtp.client-ip=209.85.221.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YbkBSbb1" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-3a4bafbb1abso772075f8f.1 for ; Thu, 22 May 2025 10:40:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1747935645; x=1748540445; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RztcMjTLHfY23vLuGORKKnjudgJGslj+PjsonErxbkQ=; b=YbkBSbb1mEzi6aqU6gllICn+Fyw9MC9XtTaannSOalUilo+1B3IppTq4AsXtAN5BrP bL5aaJJn1eWVQA/cRTBq2FQ5ngJ82ySUyrd/2QsR0Ubs7dEl3drmsdcy7evEK4ojMr1N LPCu5B9Gj0DlW4hCXRv1a0QDurNAWnD6sk9NTSNQTMEFAkJ+rFkASow85obMwoQgvINS sKgwpzLfoMroztM5h0bCiFzzlMY4TyDGKJGAv+33UlRwNUz3xQcBen1w7bfXPici2exb SsNaAIZXS71cyJ/uALvODrgkr+wwFDM18MHe19dVxM1zckcNPuyeq66QtXrd1vo3viA2 bTWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747935645; x=1748540445; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RztcMjTLHfY23vLuGORKKnjudgJGslj+PjsonErxbkQ=; b=UIeqnwqsv41TLpvKK5B20rFkp/DMzNmDORMaHiGzfDLvDASdja5wBkhn25lfOKNp4e o+xIDJ7XHp+puvPve7H8RbQekSQ07ZfzUSRafa0vB6laC0MWQEMML0edLaQJKG6473My Qa4+1+aZvUL9XYGczBjcScgkOT/RYX1VxCedUBlU+wxoBXS5E1L6D6HHPIZcVjolghzR 7OsqaRV57Cl34qeJEBTV6Hht2I3Lez8rCkj+e9ncUqwwW+K1+FXvOatWvjB2ifQ+x15D FsMP315w77Re/dnGRrHaokvSHjbdYCI4F7RbjVFyJeTpUve1DznkIYR+ka28Tw5Ri5G5 o82A== X-Forwarded-Encrypted: i=1; AJvYcCUKg68KE8HIytSOwut1H4wj3ChrhqKkdYNb+sfeE3Y7rB1GQv3YfxH0CSQMQ9tq3PnnavHRHCYqihbTqhZRvQ==@vger.kernel.org X-Gm-Message-State: AOJu0YwFF3sT5bIB4WgysXvwnHMClcbyRt68Skb/5SsCHRsN0JGi7iLb 65zlMVtB9QuwwVN3hklMHMTI5IaXzw11jROxgQKqz9dsc4mHsD7w92GP8DMS4HznuWcQB7ry3Aq 7H9ydHWVrDEJL1ShjqA== X-Google-Smtp-Source: AGHT+IF9OwV6oxhkvb6hFcvf8W+yXowqsFL3Y+t3gINXRCXBioOEg1RYheJvI1SMPeCdKIHlD7kguFPVoKDHOUE= X-Received: from wmbhj14.prod.google.com ([2002:a05:600c:528e:b0:442:f9ef:e460]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:37cf:b0:442:f485:6fa4 with SMTP id 5b1f17b1804b1-442ff03c45amr286843375e9.31.1747935645775; Thu, 22 May 2025 10:40:45 -0700 (PDT) Date: Thu, 22 May 2025 17:40:43 +0000 In-Reply-To: <2025052201-return-reprogram-add9@gregkh> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <2025051524-festival-afterglow-8483@gregkh> <2025052201-return-reprogram-add9@gregkh> Message-ID: Subject: Re: [PATCH v5 4/4] rust: samples: Add debugfs sample From: Alice Ryhl To: Greg Kroah-Hartman Cc: Danilo Krummrich , Benno Lossin , Matthew Maurer , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Andreas Hindborg , Trevor Gross , "Rafael J. Wysocki" , Sami Tolvanen , Timur Tabi , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="utf-8" On Thu, May 22, 2025 at 04:15:46PM +0200, Greg Kroah-Hartman wrote: > > > Well, take the case I described above, where the debugfs "root" is created in > > > the module scope, but subsequent entries are created by driver instances. If a > > > driver would use keep() in such a case, we'd effectively the file / directory > > > (and subsequently also the corresponding memory) everytime a device is unplugged > > > (or unbound in general)." > > > > > > If the module is built-in the directory from the module scope is *never* > > > removed, but the entries the driver e.g. creates in probe() for a particular > > > device with keep() will pile up endlessly, especially for hot-pluggable devices. > > > > > > (It's getting even worse when there's data bound to such a leaked file, that > > > might even contain a vtable that is entered from any of the fops of the file.) > > > > > > That'd be clearly a bug, but for the driver author calling keep() seems like a > > > valid thing to do -- to me that's clearly a built-in footgun. > > > > I mean, for cases such as this, I could imagine that you use `keep()` on > > the files stored inside of the driver directory, but don't use it on the > > directory. That way, you only have to keep a single reference to an > > entire directory around, which may be more convenient. > > No, sorry, but debugfs files are "create and forget" type of things. > The caller has NO reference back to the file at all in the C version, > let's not add that functionality back to the rust side after I spent a > long time removing it from the C code :) > > If you really want to delete a debugfs file that you have created in the > past, then look it up and delete it with the call that is present for > that. > > The only thing I think that might be worth "keeping" in some form, as an > object reference as discussed, is a debugfs directory. That could work if we don't have any Rust value for files at all. The problem is that if we do have such values, then code like this: let my_file = dir.create_file("my_file_name"); dir.delete_file("my_file_name"); my_file.do_something(); would be a UAF on the last line. We have to design the Rust API to avoid such UAF, which is why I suggested the ghost objects; the delete_file() call leaves my_file in a valid but useless state. And as a ghost object, the .do_something() call becomes a no-op since the file is now missing from the filesystem. Alice