Skip to content

Commit 1a17e5b

Browse files
committed
LoadPin: Ignore the "contents" argument of the LSM hooks
LoadPin only enforces the read-only origin of kernel file reads. Whether or not it was a partial read isn't important. Remove the overly conservative checks so that things like partial firmware reads will succeed (i.e. reading a firmware header). Fixes: 2039bda ("LSM: Add "contents" flag to kernel_read_file hook") 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]> Acked-by: Serge Hallyn <[email protected]> Tested-by: Ping-Ke Shih <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d272e01 commit 1a17e5b

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

security/loadpin/loadpin.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,11 @@ static void loadpin_sb_free_security(struct super_block *mnt_sb)
122122
}
123123
}
124124

125-
static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
126-
bool contents)
125+
static int loadpin_check(struct file *file, enum kernel_read_file_id id)
127126
{
128127
struct super_block *load_root;
129128
const char *origin = kernel_read_file_id_str(id);
130129

131-
/*
132-
* If we will not know that we'll be seeing the full contents
133-
* then we cannot trust a load will be complete and unchanged
134-
* off disk. Treat all contents=false hooks as if there were
135-
* no associated file struct.
136-
*/
137-
if (!contents)
138-
file = NULL;
139-
140130
/* If the file id is excluded, ignore the pinning. */
141131
if ((unsigned int)id < ARRAY_SIZE(ignore_read_file_id) &&
142132
ignore_read_file_id[id]) {
@@ -192,9 +182,25 @@ static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
192182
return 0;
193183
}
194184

185+
static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
186+
bool contents)
187+
{
188+
/*
189+
* LoadPin only cares about the _origin_ of a file, not its
190+
* contents, so we can ignore the "are full contents available"
191+
* argument here.
192+
*/
193+
return loadpin_check(file, id);
194+
}
195+
195196
static int loadpin_load_data(enum kernel_load_data_id id, bool contents)
196197
{
197-
return loadpin_read_file(NULL, (enum kernel_read_file_id) id, contents);
198+
/*
199+
* LoadPin only cares about the _origin_ of a file, not its
200+
* contents, so a NULL file is passed, and we can ignore the
201+
* state of "contents".
202+
*/
203+
return loadpin_check(NULL, (enum kernel_read_file_id) id);
198204
}
199205

200206
static struct security_hook_list loadpin_hooks[] __lsm_ro_after_init = {

0 commit comments

Comments
 (0)