lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240812075659.1399447-1-mjguzik@gmail.com>
Date: Mon, 12 Aug 2024 09:56:58 +0200
From: Mateusz Guzik <mjguzik@...il.com>
To: viro@...iv.linux.org.uk
Cc: brauner@...nel.org,
	jack@...e.cz,
	linux-kernel@...r.kernel.org,
	linux-fsdevel@...r.kernel.org,
	Mateusz Guzik <mjguzik@...il.com>
Subject: [PATCH] close_files(): reimplement based on do_close_on_exec()

While here take more advantage of the fact nobody should be messing with
the table anymore and don't clear the fd slot.

Signed-off-by: Mateusz Guzik <mjguzik@...il.com>
---

how about this instead, I think it's a nicer clean up.

It's literally do_close_on_exec except locking and put fd are deleted.

boots & does not blow up, but admittedly I did not bother with ltp or
any serious testing

 fs/file.c | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/fs/file.c b/fs/file.c
index 74d7ad676579..3ff2e8265156 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -389,33 +389,38 @@ struct files_struct *dup_fd(struct files_struct *oldf, unsigned int max_fds)
 	return newf;
 }
 
-static struct fdtable *close_files(struct files_struct * files)
+static struct fdtable *close_files(struct files_struct *files)
 {
 	/*
 	 * It is safe to dereference the fd table without RCU or
 	 * ->file_lock because this is the last reference to the
 	 * files structure.
+	 *
+	 * For the same reason we can skip locking.
 	 */
 	struct fdtable *fdt = rcu_dereference_raw(files->fdt);
-	unsigned int i, j = 0;
+	unsigned i;
 
-	for (;;) {
+	for (i = 0; ; i++) {
 		unsigned long set;
-		i = j * BITS_PER_LONG;
-		if (i >= fdt->max_fds)
+		unsigned fd = i * BITS_PER_LONG;
+		fdt = files_fdtable(files);
+		if (fd >= fdt->max_fds)
 			break;
-		set = fdt->open_fds[j++];
-		while (set) {
-			if (set & 1) {
-				struct file * file = xchg(&fdt->fd[i], NULL);
-				if (file) {
-					filp_close(file, files);
-					cond_resched();
-				}
-			}
-			i++;
-			set >>= 1;
+		set = fdt->open_fds[i];
+		if (!set)
+			continue;
+		for ( ; set ; fd++, set >>= 1) {
+			struct file *file;
+			if (!(set & 1))
+				continue;
+			file = fdt->fd[fd];
+			if (!file)
+				continue;
+			filp_close(file, files);
+			cond_resched();
 		}
+
 	}
 
 	return fdt;
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ