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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241123181256.184004-1-alexjlzheng@tencent.com>
Date: Sun, 24 Nov 2024 02:12:56 +0800
From: Jinliang Zheng <alexjlzheng@...il.com>
To: alexjlzheng@...il.com
Cc: adobriyan@...il.com,
	alexjlzheng@...cent.com,
	brauner@...nel.org,
	flyingpeng@...cent.com,
	jack@...e.cz,
	joel.granados@...nel.org,
	kees@...nel.org,
	linux-fsdevel@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	mcgrof@...nel.org,
	viro@...iv.linux.org.uk
Subject: [PATCH 4/6] sysctl: ensure files_stat.max_files is not less than sysctl_nr_open

Introduce proc_doulongvec_maxfiles_minmax(), ensure the value of
files_stat.max_files is not less than sysctl_nr_open.

Signed-off-by: Jinliang Zheng <alexjlzheng@...cent.com>
---
 fs/file_table.c        |  2 +-
 include/linux/sysctl.h |  2 ++
 kernel/sysctl.c        | 17 +++++++++++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/fs/file_table.c b/fs/file_table.c
index db3d3a9cb421..01faa9c2869e 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -119,7 +119,7 @@ static struct ctl_table fs_stat_sysctls[] = {
 		.data		= &files_stat.max_files,
 		.maxlen		= sizeof(files_stat.max_files),
 		.mode		= 0644,
-		.proc_handler	= proc_doulongvec_minmax,
+		.proc_handler	= proc_doulongvec_maxfiles_minmax,
 		.extra1		= SYSCTL_LONG_ZERO,
 		.extra2		= SYSCTL_LONG_MAX,
 	},
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index aa4c6d44aaa0..4ecf945de956 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -82,6 +82,8 @@ int proc_dointvec_userhz_jiffies(const struct ctl_table *, int, void *, size_t *
 int proc_dointvec_ms_jiffies(const struct ctl_table *, int, void *, size_t *,
 		loff_t *);
 int proc_doulongvec_minmax(const struct ctl_table *, int, void *, size_t *, loff_t *);
+int proc_doulongvec_maxfiles_minmax(const struct ctl_table *, int, void *,
+		size_t *, loff_t *);
 int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int, void *,
 		size_t *, loff_t *);
 int proc_do_large_bitmap(const struct ctl_table *, int, void *, size_t *, loff_t *);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 05b48b204ed4..5ee2bfc7fcbe 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1122,6 +1122,23 @@ int proc_doulongvec_minmax(const struct ctl_table *table, int write,
     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
 }
 
+/*
+ * Used for 'sysctl -w fs.file-max', ensuring its value will not be less
+ * than sysctl_nr_open.
+ */
+int proc_doulongvec_maxfiles_minmax(const struct ctl_table *table, int write,
+		void *buffer, size_t *lenp, loff_t *ppos)
+{
+	unsigned long *min = table->extra1;
+	unsigned long *max = table->extra2;
+	unsigned long nr_open = sysctl_nr_open;
+
+	if (write)
+		min = &nr_open;
+	return __do_proc_doulongvec_minmax(table->data, table, write,
+			buffer, lenp, ppos, 1l, 1l, min, max);
+}
+
 /**
  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
  * @table: the sysctl table
-- 
2.41.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ