From: Yu Kuai <yukuai3(a)huawei.com>
hulk inclusion
category: bugfix
bugzilla: 38268
CVE: NA
---------------------------
Such switch can only set the accounting of open fds in filescontrol from
enable to disable. If it is disabled arealdy, the switch can't enable it.
The counter is enabled by default, and it can be disabled by:
a. echo 1 > /sys/fs/cgroup/files/files.no_acct
b. add "filescontrol.no_acct=1" to boot cmd
Signed-off-by: Yu Kuai <yukuai3(a)huawei.com>
Reviewed-by: Hou Tao <houtao1(a)huawei.com>
Reviewed-by: zhangyi (F) <yi.zhang(a)huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang(a)huawei.com>
---
fs/filescontrol.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/fs/filescontrol.c b/fs/filescontrol.c
index 5ec5096383c3..32f3a127579c 100644
--- a/fs/filescontrol.c
+++ b/fs/filescontrol.c
@@ -25,14 +25,17 @@
#include <linux/seq_file.h>
#include <linux/fdtable.h>
#include <linux/sched/signal.h>
+#include <linux/module.h>
#define FILES_MAX D_COUNT_MAX
#define FILES_MAX_STR "max"
-
+static bool no_acct;
struct cgroup_subsys files_cgrp_subsys __read_mostly;
EXPORT_SYMBOL(files_cgrp_subsys);
+module_param(no_acct, bool, 0444);
+
struct files_cgroup {
struct cgroup_subsys_state css;
struct page_counter open_handles;
@@ -204,7 +207,7 @@ int files_cgroup_alloc_fd(struct files_struct *files, u64 n)
* we don't charge their fds, only issue is that files.usage
* won't be accurate in root files cgroup.
*/
- if (files != &init_files) {
+ if (!no_acct && files != &init_files) {
struct page_counter *fail_res;
struct files_cgroup *files_cgroup =
files_cgroup_from_files(files);
@@ -222,7 +225,7 @@ void files_cgroup_unalloc_fd(struct files_struct *files, u64 n)
* It's not charged so no need to uncharge, see comments in
* files_cgroup_alloc_fd.
*/
- if (files != &init_files) {
+ if (!no_acct && files != &init_files) {
struct files_cgroup *files_cgroup =
files_cgroup_from_files(files);
page_counter_uncharge(&files_cgroup->open_handles, n);
@@ -230,6 +233,21 @@ void files_cgroup_unalloc_fd(struct files_struct *files, u64 n)
}
EXPORT_SYMBOL(files_cgroup_unalloc_fd);
+static u64 files_disabled_read(struct cgroup_subsys_state *css,
+ struct cftype *cft)
+{
+ return no_acct;
+}
+
+static int files_disabled_write(struct cgroup_subsys_state *css,
+ struct cftype *cft, u64 val)
+{
+ if (!val)
+ return -EINVAL;
+ no_acct = true;
+
+ return 0;
+}
static int files_limit_read(struct seq_file *sf, void *v)
{
@@ -291,6 +309,12 @@ static struct cftype files[] = {
.name = "usage",
.read_u64 = files_usage_read,
},
+ {
+ .name = "no_acct",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .read_u64 = files_disabled_read,
+ .write_u64 = files_disabled_write,
+ },
{ }
};
--
2.25.1