Skip to content

Commit b502273

Browse files
thestingeranthraxx
authored andcommitted
make sysctl constants read-only
Most of this is extracted from the last publicly available version of the PaX patches where it's part of KERNEXEC as __read_only. It has been extended to a few more of these constants.
1 parent e1b543b commit b502273

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

kernel/sysctl.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,41 +117,41 @@ extern int sysctl_nr_trim_pages;
117117

118118
/* Constants used for minimum and maximum */
119119
#ifdef CONFIG_LOCKUP_DETECTOR
120-
static int sixty = 60;
120+
static int sixty __read_only = 60;
121121
#endif
122122

123-
static int __maybe_unused neg_one = -1;
123+
static int __maybe_unused neg_one __read_only = -1;
124124

125125
static int zero;
126-
static int __maybe_unused one = 1;
127-
static int __maybe_unused two = 2;
128-
static int __maybe_unused four = 4;
129-
static unsigned long one_ul = 1;
130-
static int one_hundred = 100;
131-
static int one_thousand = 1000;
126+
static int __maybe_unused one __read_only = 1;
127+
static int __maybe_unused two __read_only = 2;
128+
static int __maybe_unused four __read_only = 4;
129+
static unsigned long one_ul __read_only = 1;
130+
static int one_hundred __read_only = 100;
131+
static int one_thousand __read_only = 1000;
132132
#ifdef CONFIG_PRINTK
133-
static int ten_thousand = 10000;
133+
static int ten_thousand __read_only = 10000;
134134
#endif
135135
#ifdef CONFIG_PERF_EVENTS
136-
static int six_hundred_forty_kb = 640 * 1024;
136+
static int six_hundred_forty_kb __read_only = 640 * 1024;
137137
#endif
138138

139139
/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
140-
static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
140+
static unsigned long dirty_bytes_min __read_only = 2 * PAGE_SIZE;
141141

142142
/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
143-
static int maxolduid = 65535;
144-
static int minolduid;
143+
static int maxolduid __read_only = 65535;
144+
static int minolduid __read_only;
145145

146-
static int ngroups_max = NGROUPS_MAX;
146+
static int ngroups_max __read_only = NGROUPS_MAX;
147147
static const int cap_last_cap = CAP_LAST_CAP;
148148

149149
/*
150150
* This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
151151
* and hung_task_check_interval_secs
152152
*/
153153
#ifdef CONFIG_DETECT_HUNG_TASK
154-
static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
154+
static unsigned long hung_task_timeout_max __read_only = (LONG_MAX/HZ);
155155
#endif
156156

157157
#ifdef CONFIG_INOTIFY_USER
@@ -297,19 +297,19 @@ static struct ctl_table sysctl_base_table[] = {
297297
};
298298

299299
#ifdef CONFIG_SCHED_DEBUG
300-
static int min_sched_granularity_ns = 100000; /* 100 usecs */
301-
static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
302-
static int min_wakeup_granularity_ns; /* 0 usecs */
303-
static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
300+
static int min_sched_granularity_ns __read_only = 100000; /* 100 usecs */
301+
static int max_sched_granularity_ns __read_only = NSEC_PER_SEC; /* 1 second */
302+
static int min_wakeup_granularity_ns __read_only; /* 0 usecs */
303+
static int max_wakeup_granularity_ns __read_only = NSEC_PER_SEC; /* 1 second */
304304
#ifdef CONFIG_SMP
305-
static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
306-
static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
305+
static int min_sched_tunable_scaling __read_only = SCHED_TUNABLESCALING_NONE;
306+
static int max_sched_tunable_scaling __read_only = SCHED_TUNABLESCALING_END-1;
307307
#endif /* CONFIG_SMP */
308308
#endif /* CONFIG_SCHED_DEBUG */
309309

310310
#ifdef CONFIG_COMPACTION
311-
static int min_extfrag_threshold;
312-
static int max_extfrag_threshold = 1000;
311+
static int min_extfrag_threshold __read_only;
312+
static int max_extfrag_threshold __read_only = 1000;
313313
#endif
314314

315315
static struct ctl_table kern_table[] = {

0 commit comments

Comments
 (0)