mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
lkdtm: use kmalloc() instead of __get_free_page
lkdtm_debugfs_entry and direct_entry use __get_free_page to allocate a temporary buffer, perform copy_from_user to get the crashtype name, strim() to strip whitespace and find_crashtype to find the corresponding crashtype that is being requested. The lkdtm_debugfs_read uses __get_free_page to allocate a temporary buffer to store all the available crashtypes, and then copy it to userspace. The buffers that are allocated can be allocated with kmalloc as there is nothing special that requires a struct page, or the page allocator. kmalloc() additionally provides a better API that doesn't require ugly casts which obfuscate the code and kfree does not need to know the size of the freed object. Replace use of __get_free_page() with kmalloc(). Signed-off-by: Mahad Ibrahim <mahad.ibrahim.dev@gmail.com> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Link: https://patch.msgid.link/20260722230246.2869-1-mahad.ibrahim.dev@gmail.com Signed-off-by: Kees Cook <kees@kernel.org>
This commit is contained in:
parent
df2908090c
commit
faebcf725c
|
|
@ -236,11 +236,11 @@ static ssize_t lkdtm_debugfs_entry(struct file *f,
|
|||
if (count >= PAGE_SIZE)
|
||||
return -EINVAL;
|
||||
|
||||
buf = (char *)__get_free_page(GFP_KERNEL);
|
||||
buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
if (copy_from_user(buf, user_buf, count)) {
|
||||
free_page((unsigned long) buf);
|
||||
kfree(buf);
|
||||
return -EFAULT;
|
||||
}
|
||||
/* NULL-terminate and remove enter */
|
||||
|
|
@ -248,7 +248,7 @@ static ssize_t lkdtm_debugfs_entry(struct file *f,
|
|||
strim(buf);
|
||||
|
||||
crashtype = find_crashtype(buf);
|
||||
free_page((unsigned long)buf);
|
||||
kfree(buf);
|
||||
|
||||
if (!crashtype)
|
||||
return -EINVAL;
|
||||
|
|
@ -271,7 +271,7 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
|
|||
ssize_t out;
|
||||
char *buf;
|
||||
|
||||
buf = (char *)__get_free_page(GFP_KERNEL);
|
||||
buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
||||
if (buf == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
@ -290,7 +290,7 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
|
|||
|
||||
out = simple_read_from_buffer(user_buf, count, off,
|
||||
buf, n);
|
||||
free_page((unsigned long) buf);
|
||||
kfree(buf);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
|
@ -313,11 +313,11 @@ static ssize_t direct_entry(struct file *f, const char __user *user_buf,
|
|||
if (count < 1)
|
||||
return -EINVAL;
|
||||
|
||||
buf = (char *)__get_free_page(GFP_KERNEL);
|
||||
buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
if (copy_from_user(buf, user_buf, count)) {
|
||||
free_page((unsigned long) buf);
|
||||
kfree(buf);
|
||||
return -EFAULT;
|
||||
}
|
||||
/* NULL-terminate and remove enter */
|
||||
|
|
@ -325,7 +325,7 @@ static ssize_t direct_entry(struct file *f, const char __user *user_buf,
|
|||
strim(buf);
|
||||
|
||||
crashtype = find_crashtype(buf);
|
||||
free_page((unsigned long) buf);
|
||||
kfree(buf);
|
||||
if (!crashtype)
|
||||
return -EINVAL;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user