Skip to content

Commit 2cfaa84

Browse files
committed
LoadPin: Move pin reporting cleanly out of locking
Refactor the pin reporting to be more cleanly outside the locking. It was already, but moving it around helps clear the path for the root to switch when not enforcing. Cc: Paul Moore <[email protected]> Cc: James Morris <[email protected]> Cc: "Serge E. Hallyn" <[email protected]> Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Serge Hallyn <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 60ba102 commit 2cfaa84

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

security/loadpin/loadpin.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ static int loadpin_check(struct file *file, enum kernel_read_file_id id)
131131
{
132132
struct super_block *load_root;
133133
const char *origin = kernel_read_file_id_str(id);
134+
bool first_root_pin = false;
134135
bool load_root_writable;
135136

136137
/* If the file id is excluded, ignore the pinning. */
@@ -162,18 +163,14 @@ static int loadpin_check(struct file *file, enum kernel_read_file_id id)
162163
*/
163164
if (!pinned_root) {
164165
pinned_root = load_root;
165-
/*
166-
* Unlock now since it's only pinned_root we care about.
167-
* In the worst case, we will (correctly) report pinning
168-
* failures before we have announced that pinning is
169-
* enforcing. This would be purely cosmetic.
170-
*/
171-
spin_unlock(&pinned_root_spinlock);
166+
first_root_pin = true;
167+
}
168+
spin_unlock(&pinned_root_spinlock);
169+
170+
if (first_root_pin) {
172171
report_writable(pinned_root, load_root_writable);
173172
set_sysctl(load_root_writable);
174173
report_load(origin, file, "pinned");
175-
} else {
176-
spin_unlock(&pinned_root_spinlock);
177174
}
178175

179176
if (IS_ERR_OR_NULL(pinned_root) ||

0 commit comments

Comments
 (0)