Unverified Commit 29f7045c authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!15681 kernel: be more careful about dup_mmap() failures and uprobe registering

parents 7ee7efdc e811c4e3
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <linux/task_work.h>
#include <linux/shmem_fs.h>
#include <linux/khugepaged.h>
#include <linux/oom.h>          /* check_stable_address_space */

#include <linux/uprobes.h>

@@ -1055,6 +1056,9 @@ register_for_each_vma(struct uprobe *uprobe, struct uprobe_consumer *new)
			goto free;

		mmap_write_lock(mm);
		if (check_stable_address_space(mm))
			goto unlock;

		vma = find_vma(mm, info->vaddr);
		if (!vma || !valid_vma(vma, is_register) ||
		    file_inode(vma->vm_file) != uprobe->inode)
+14 −3
Original line number Diff line number Diff line
@@ -794,7 +794,8 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
		mt_set_in_rcu(vmi.mas.tree);
		ksm_fork(mm, oldmm);
		khugepaged_fork(mm, oldmm);
	} else if (mpnt) {
	} else {

		/*
		 * The entire maple tree has already been duplicated. If the
		 * mmap duplication fails, mark the failure point with
@@ -802,8 +803,18 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
		 * stop releasing VMAs that have not been duplicated after this
		 * point.
		 */
		if (mpnt) {
			mas_set_range(&vmi.mas, mpnt->vm_start, mpnt->vm_end - 1);
			mas_store(&vmi.mas, XA_ZERO_ENTRY);
			/* Avoid OOM iterating a broken tree */
			set_bit(MMF_OOM_SKIP, &mm->flags);
		}
		/*
		 * The mm_struct is going to exit, but the locks will be dropped
		 * first.  Set the mm_struct as unstable is advisable as it is
		 * not fully initialised.
		 */
		set_bit(MMF_UNSTABLE, &mm->flags);
	}
out:
	mmap_write_unlock(mm);