@@ -72,28 +72,21 @@ static struct ctl_table loadpin_sysctl_table[] = {
72
72
{ }
73
73
};
74
74
75
- /*
76
- * This must be called after early kernel init, since then the rootdev
77
- * is available.
78
- */
79
- static void check_pinning_enforcement (struct super_block * mnt_sb )
75
+ static void report_writable (struct super_block * mnt_sb , bool writable )
80
76
{
81
- bool ro = false;
82
-
83
77
/*
84
78
* If load pinning is not enforced via a read-only block
85
79
* device, allow sysctl to change modes for testing.
86
80
*/
87
81
if (mnt_sb -> s_bdev ) {
88
- ro = bdev_read_only (mnt_sb -> s_bdev );
89
82
pr_info ("%pg (%u:%u): %s\n" , mnt_sb -> s_bdev ,
90
83
MAJOR (mnt_sb -> s_bdev -> bd_dev ),
91
84
MINOR (mnt_sb -> s_bdev -> bd_dev ),
92
- ro ? "read-only " : "writable " );
85
+ writable ? "writable " : "read-only " );
93
86
} else
94
87
pr_info ("mnt_sb lacks block device, treating as: writable\n" );
95
88
96
- if (! ro ) {
89
+ if (writable ) {
97
90
if (!register_sysctl_paths (loadpin_sysctl_path ,
98
91
loadpin_sysctl_table ))
99
92
pr_notice ("sysctl registration failed!\n" );
@@ -103,12 +96,26 @@ static void check_pinning_enforcement(struct super_block *mnt_sb)
103
96
pr_info ("load pinning engaged.\n" );
104
97
}
105
98
#else
106
- static void check_pinning_enforcement (struct super_block * mnt_sb )
99
+ static void report_writable (struct super_block * mnt_sb , bool writable )
107
100
{
108
101
pr_info ("load pinning engaged.\n" );
109
102
}
110
103
#endif
111
104
105
+ /*
106
+ * This must be called after early kernel init, since then the rootdev
107
+ * is available.
108
+ */
109
+ static bool sb_is_writable (struct super_block * mnt_sb )
110
+ {
111
+ bool writable = true;
112
+
113
+ if (mnt_sb -> s_bdev )
114
+ writable = !bdev_read_only (mnt_sb -> s_bdev );
115
+
116
+ return writable ;
117
+ }
118
+
112
119
static void loadpin_sb_free_security (struct super_block * mnt_sb )
113
120
{
114
121
/*
@@ -126,6 +133,7 @@ static int loadpin_check(struct file *file, enum kernel_read_file_id id)
126
133
{
127
134
struct super_block * load_root ;
128
135
const char * origin = kernel_read_file_id_str (id );
136
+ bool load_root_writable ;
129
137
130
138
/* If the file id is excluded, ignore the pinning. */
131
139
if ((unsigned int )id < ARRAY_SIZE (ignore_read_file_id ) &&
@@ -146,6 +154,7 @@ static int loadpin_check(struct file *file, enum kernel_read_file_id id)
146
154
}
147
155
148
156
load_root = file -> f_path .mnt -> mnt_sb ;
157
+ load_root_writable = sb_is_writable (load_root );
149
158
150
159
/* First loaded module/firmware defines the root for all others. */
151
160
spin_lock (& pinned_root_spinlock );
@@ -162,7 +171,7 @@ static int loadpin_check(struct file *file, enum kernel_read_file_id id)
162
171
* enforcing. This would be purely cosmetic.
163
172
*/
164
173
spin_unlock (& pinned_root_spinlock );
165
- check_pinning_enforcement (pinned_root );
174
+ report_writable (pinned_root , load_root_writable );
166
175
report_load (origin , file , "pinned" );
167
176
} else {
168
177
spin_unlock (& pinned_root_spinlock );
0 commit comments