@@ -52,7 +52,6 @@ static bool deny_reading_verity_digests;
52
52
#endif
53
53
54
54
#ifdef CONFIG_SYSCTL
55
-
56
55
static struct ctl_path loadpin_sysctl_path [] = {
57
56
{ .procname = "kernel" , },
58
57
{ .procname = "loadpin" , },
@@ -66,18 +65,29 @@ static struct ctl_table loadpin_sysctl_table[] = {
66
65
.maxlen = sizeof (int ),
67
66
.mode = 0644 ,
68
67
.proc_handler = proc_dointvec_minmax ,
69
- .extra1 = SYSCTL_ZERO ,
68
+ .extra1 = SYSCTL_ONE ,
70
69
.extra2 = SYSCTL_ONE ,
71
70
},
72
71
{ }
73
72
};
74
73
75
- static void report_writable ( struct super_block * mnt_sb , bool writable )
74
+ static void set_sysctl ( bool is_writable )
76
75
{
77
76
/*
78
77
* If load pinning is not enforced via a read-only block
79
78
* device, allow sysctl to change modes for testing.
80
79
*/
80
+ if (is_writable )
81
+ loadpin_sysctl_table [0 ].extra1 = SYSCTL_ZERO ;
82
+ else
83
+ loadpin_sysctl_table [0 ].extra1 = SYSCTL_ONE ;
84
+ }
85
+ #else
86
+ static inline void set_sysctl (bool is_writable ) { }
87
+ #endif
88
+
89
+ static void report_writable (struct super_block * mnt_sb , bool writable )
90
+ {
81
91
if (mnt_sb -> s_bdev ) {
82
92
pr_info ("%pg (%u:%u): %s\n" , mnt_sb -> s_bdev ,
83
93
MAJOR (mnt_sb -> s_bdev -> bd_dev ),
@@ -86,21 +96,9 @@ static void report_writable(struct super_block *mnt_sb, bool writable)
86
96
} else
87
97
pr_info ("mnt_sb lacks block device, treating as: writable\n" );
88
98
89
- if (writable ) {
90
- if (!register_sysctl_paths (loadpin_sysctl_path ,
91
- loadpin_sysctl_table ))
92
- pr_notice ("sysctl registration failed!\n" );
93
- else
94
- pr_info ("enforcement can be disabled.\n" );
95
- } else
99
+ if (!writable )
96
100
pr_info ("load pinning engaged.\n" );
97
101
}
98
- #else
99
- static void report_writable (struct super_block * mnt_sb , bool writable )
100
- {
101
- pr_info ("load pinning engaged.\n" );
102
- }
103
- #endif
104
102
105
103
/*
106
104
* This must be called after early kernel init, since then the rootdev
@@ -172,6 +170,7 @@ static int loadpin_check(struct file *file, enum kernel_read_file_id id)
172
170
*/
173
171
spin_unlock (& pinned_root_spinlock );
174
172
report_writable (pinned_root , load_root_writable );
173
+ set_sysctl (load_root_writable );
175
174
report_load (origin , file , "pinned" );
176
175
} else {
177
176
spin_unlock (& pinned_root_spinlock );
@@ -259,6 +258,10 @@ static int __init loadpin_init(void)
259
258
pr_info ("ready to pin (currently %senforcing)\n" ,
260
259
enforce ? "" : "not " );
261
260
parse_exclude ();
261
+ #ifdef CONFIG_SYSCTL
262
+ if (!register_sysctl_paths (loadpin_sysctl_path , loadpin_sysctl_table ))
263
+ pr_notice ("sysctl registration failed!\n" );
264
+ #endif
262
265
security_add_hooks (loadpin_hooks , ARRAY_SIZE (loadpin_hooks ), "loadpin" );
263
266
264
267
return 0 ;
0 commit comments