]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selinux: use k[mz]alloc() to allocate temporary buffers
authorMike Rapoport (Microsoft) <rppt@kernel.org>
Wed, 20 May 2026 08:18:55 +0000 (11:18 +0300)
committerPaul Moore <paul@paul-moore.com>
Wed, 27 May 2026 23:42:39 +0000 (19:42 -0400)
Several functions in selinuxfs.c allocate temporary buffers using
__get_free_page() or get_zeroed_page().

These buffers are used either to store a string generated by snprintf() (in
sel_make_bools()) or to copy data from user (sel_read_avc_hash_stats() and
sel_read_sidtab_hash_stats()).

Such usage does not require struct page access and it is better to allocate
these buffers with kzalloc()/kmalloc() that provide better scalability and
more debugging possibilities.

Replace use of get_zeroed_page() with kzalloc() and usage of
__get_free_page() with kmalloc().

Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/selinuxfs.c

index c4a68d623d40810592c61a2224448b5dbb9744f9..5150361ed1bb08477027874398e0d1d95deef2ff 100644 (file)
@@ -1376,7 +1376,7 @@ static int sel_make_bools(struct selinux_policy *newpolicy, struct dentry *bool_
        char **names, *page;
        u32 i, num;
 
-       page = (char *)get_zeroed_page(GFP_KERNEL);
+       page = kzalloc(PAGE_SIZE, GFP_KERNEL);
        if (!page)
                return -ENOMEM;
 
@@ -1422,7 +1422,7 @@ static int sel_make_bools(struct selinux_policy *newpolicy, struct dentry *bool_
                ret = sel_attach_file(bool_dir, names[i], inode);
        }
 out:
-       free_page((unsigned long)page);
+       kfree(page);
        return ret;
 }
 
@@ -1481,14 +1481,14 @@ static ssize_t sel_read_avc_hash_stats(struct file *filp, char __user *buf,
        char *page;
        ssize_t length;
 
-       page = (char *)__get_free_page(GFP_KERNEL);
+       page = kmalloc(PAGE_SIZE, GFP_KERNEL);
        if (!page)
                return -ENOMEM;
 
        length = avc_get_hash_stats(page);
        if (length >= 0)
                length = simple_read_from_buffer(buf, count, ppos, page, length);
-       free_page((unsigned long)page);
+       kfree(page);
 
        return length;
 }
@@ -1499,7 +1499,7 @@ static ssize_t sel_read_sidtab_hash_stats(struct file *filp, char __user *buf,
        char *page;
        ssize_t length;
 
-       page = (char *)__get_free_page(GFP_KERNEL);
+       page = kmalloc(PAGE_SIZE, GFP_KERNEL);
        if (!page)
                return -ENOMEM;
 
@@ -1507,7 +1507,7 @@ static ssize_t sel_read_sidtab_hash_stats(struct file *filp, char __user *buf,
        if (length >= 0)
                length = simple_read_from_buffer(buf, count, ppos, page,
                                                length);
-       free_page((unsigned long)page);
+       kfree(page);
 
        return length;
 }