| From: Jeongjun Park <aha310510@gmail.com> |
| Subject: mm/maps: move kmalloc() call location in do_procmap_query() out of RCU critical section |
| Date: Wed, 2 Jul 2025 22:53:32 +0900 |
| |
| In do_procmap_query(), we are allocating name_buf as much as name_buf_sz |
| with kmalloc(). |
| |
| However, due to the previous commit eff061546ca5 ("mm/maps: execute |
| PROCMAP_QUERY ioctl under per-vma locks"), the location of kmalloc() is |
| located inside the RCU critical section. |
| |
| This causes might_sleep_if() to be called inside the RCU critical section, |
| so we need to move the call location of kmalloc() outside the RCU critical |
| section to prevent this. |
| |
| Link: https://lkml.kernel.org/r/20250702135332.291866-1-aha310510@gmail.com |
| Reported-by: syzbot+6246a83e7bd9f8a3e239@syzkaller.appspotmail.com |
| Closes: https://syzkaller.appspot.com/bug?extid=6246a83e7bd9f8a3e239 |
| Signed-off-by: Jeongjun Park <aha310510@gmail.com> |
| Cc: Alexey Dobriyan <adobriyan@gmail.com> |
| Cc: Andrii Nakryiko <andrii@kernel.org> |
| Cc: Christian Brauner <brauner@kernel.org> |
| Cc: Christophe Leroy <christophe.leroy@csgroup.eu> |
| Cc: David Hildenbrand <david@redhat.com> |
| Cc: Jann Horn <jannh@google.com> |
| Cc: Johannes Weiner <hannes@cmpxchg.org> |
| Cc: Josef Bacik <josef@toxicpanda.com> |
| Cc: Kalesh Singh <kaleshsingh@google.com> |
| Cc: Liam Howlett <liam.howlett@oracle.com> |
| Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> |
| Cc: Matthew Wilcox (Oracle) <willy@infradead.org> |
| Cc: Michal Hocko <mhocko@kernel.org> |
| Cc: Oscar Salvador <osalvador@suse.de> |
| Cc: "Paul E . McKenney" <paulmck@kernel.org> |
| Cc: Peter Xu <peterx@redhat.com> |
| Cc: Ryan Roberts <ryan.roberts@arm.com> |
| Cc: Shuah Khan <shuah@kernel.org> |
| Cc: Suren Baghdasaryan <surenb@google.com> |
| Cc: Thomas Weißschuh <linux@weissschuh.net> |
| Cc: T.J. Mercier <tjmercier@google.com> |
| Cc: Vlastimil Babka <vbabka@suse.cz> |
| Cc: Ye Bin <yebin10@huawei.com> |
| Signed-off-by: Andrew Morton <akpm@linux-foundation.org> |
| --- |
| |
| fs/proc/task_mmu.c | 22 +++++++++++----------- |
| 1 file changed, 11 insertions(+), 11 deletions(-) |
| |
| --- a/fs/proc/task_mmu.c~mm-maps-execute-procmap_query-ioctl-under-per-vma-locks-fix |
| +++ a/fs/proc/task_mmu.c |
| @@ -595,6 +595,7 @@ static int do_procmap_query(struct proc_ |
| char build_id_buf[BUILD_ID_SIZE_MAX], *name_buf = NULL; |
| __u64 usize; |
| int err; |
| + size_t name_buf_sz; |
| |
| if (copy_from_user(&usize, (void __user *)uarg, sizeof(usize))) |
| return -EFAULT; |
| @@ -621,12 +622,18 @@ static int do_procmap_query(struct proc_ |
| if (!mm || !mmget_not_zero(mm)) |
| return -ESRCH; |
| |
| - err = query_vma_setup(priv); |
| - if (err) { |
| + name_buf_sz = min_t(size_t, PATH_MAX, karg.vma_name_size); |
| + |
| + name_buf = kmalloc(name_buf_sz, GFP_KERNEL); |
| + if (!name_buf) { |
| mmput(mm); |
| - return err; |
| + return -ENOMEM; |
| } |
| |
| + err = query_vma_setup(priv); |
| + if (err) |
| + goto fail_vma_setup; |
| + |
| vma = query_matching_vma(priv, karg.query_addr, karg.query_flags); |
| if (IS_ERR(vma)) { |
| err = PTR_ERR(vma); |
| @@ -679,20 +686,12 @@ static int do_procmap_query(struct proc_ |
| } |
| |
| if (karg.vma_name_size) { |
| - size_t name_buf_sz = min_t(size_t, PATH_MAX, karg.vma_name_size); |
| const struct path *path; |
| const char *name_fmt; |
| size_t name_sz = 0; |
| |
| get_vma_name(vma, &path, &name, &name_fmt); |
| |
| - if (path || name_fmt || name) { |
| - name_buf = kmalloc(name_buf_sz, GFP_KERNEL); |
| - if (!name_buf) { |
| - err = -ENOMEM; |
| - goto out; |
| - } |
| - } |
| if (path) { |
| name = d_path(path, name_buf, name_buf_sz); |
| if (IS_ERR(name)) { |
| @@ -733,6 +732,7 @@ static int do_procmap_query(struct proc_ |
| |
| out: |
| query_vma_teardown(priv); |
| +fail_vma_setup: |
| mmput(mm); |
| kfree(name_buf); |
| return err; |
| _ |