mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
LSM: Introduce kernel_post_load_data() hook
There are a few places in the kernel where LSMs would like to have visibility into the contents of a kernel buffer that has been loaded or read. While security_kernel_post_read_file() (which includes the buffer) exists as a pairing for security_kernel_read_file(), no such hook exists to pair with security_kernel_load_data(). Earlier proposals for just using security_kernel_post_read_file() with a NULL file argument were rejected (i.e. "file" should always be valid for the security_..._file hooks, but it appears at least one case was left in the kernel during earlier refactoring. (This will be fixed in a subsequent patch.) Since not all cases of security_kernel_load_data() can have a single contiguous buffer made available to the LSM hook (e.g. kexec image segments are separately loaded), there needs to be a way for the LSM to reason about its expectations of the hook coverage. In order to handle this, add a "contents" argument to the "kernel_load_data" hook that indicates if the newly added "kernel_post_load_data" hook will be called with the full contents once loaded. That way, LSMs requiring full contents can choose to unilaterally reject "kernel_load_data" with contents=false (which is effectively the existing hook coverage), but when contents=true they can allow it and later evaluate the "kernel_post_load_data" hook once the buffer is loaded. With this change, LSMs can gain coverage over non-file-backed data loads (e.g. init_module(2) and firmware userspace helper), which will happen in subsequent patches. Additionally prepare IMA to start processing these cases. Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: KP Singh <kpsingh@google.com> Link: https://lore.kernel.org/r/20201002173828.2099543-9-keescook@chromium.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
885352881f
commit
b64fcae74b
@@ -1695,17 +1695,31 @@ int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(security_kernel_post_read_file);
|
||||
|
||||
int security_kernel_load_data(enum kernel_load_data_id id)
|
||||
int security_kernel_load_data(enum kernel_load_data_id id, bool contents)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = call_int_hook(kernel_load_data, 0, id);
|
||||
ret = call_int_hook(kernel_load_data, 0, id, contents);
|
||||
if (ret)
|
||||
return ret;
|
||||
return ima_load_data(id);
|
||||
return ima_load_data(id, contents);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(security_kernel_load_data);
|
||||
|
||||
int security_kernel_post_load_data(char *buf, loff_t size,
|
||||
enum kernel_load_data_id id,
|
||||
char *description)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = call_int_hook(kernel_post_load_data, 0, buf, size, id,
|
||||
description);
|
||||
if (ret)
|
||||
return ret;
|
||||
return ima_post_load_data(buf, size, id, description);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(security_kernel_post_load_data);
|
||||
|
||||
int security_task_fix_setuid(struct cred *new, const struct cred *old,
|
||||
int flags)
|
||||
{
|
||||
|
Reference in New Issue
Block a user