Re: proc race (was: Re: HIGH MEMORY access)

From: Manfred Spraul (manfreds@colorfullife.com)
Date: Thu Apr 13 2000 - 17:39:13 EST


I've attached a patch, but it's ugly: handle_mm_fault() needs a task
structure, so I modify current->mm.

Alan, do you have a better idea?

--
	Manfred

// $Header$ // Kernel Version: // VERSION = 2 // PATCHLEVEL = 3 // SUBLEVEL = 99 // EXTRAVERSION = -pre5 --- 2.3/kernel/fork.c Wed Apr 12 15:00:33 2000 +++ build-2.3/kernel/fork.c Thu Apr 13 23:50:16 2000 @@ -329,6 +329,9 @@ /* * Decrement the use count and release all resources for an mm. + * + * ptrace assumes that this function is only called with the + * kernel lock held. */ void mmput(struct mm_struct *mm) { --- 2.3/kernel/ptrace.c Fri Mar 24 11:10:18 2000 +++ build-2.3/kernel/ptrace.c Fri Apr 14 00:15:10 2000 @@ -14,6 +14,7 @@ #include <asm/pgtable.h> #include <asm/uaccess.h> +#include <asm/mmu_context.h> /* * Access another process' address space, one page at a time. @@ -81,15 +82,25 @@ int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write) { int copied; - struct vm_area_struct * vma; + struct mm_struct *mm, *old_mm, *old_activemm; + struct vm_area_struct *vma; - down(&tsk->mm->mmap_sem); - vma = find_extend_vma(tsk, addr); - if (!vma) { - up(&tsk->mm->mmap_sem); + mm=tsk->mm; + if(!mm) return 0; - } + /* concurrent mmput()'s are prevented by the kernel lock */ + atomic_inc(&mm->mm_users); + old_mm = current->mm; + old_activemm = current->active_mm; + current->mm=current->active_mm=mm; + activate_mm(old_activemm,mm); + down(&mm->mmap_sem); + copied = 0; + vma = find_extend_vma(current, addr); + if (!vma) + goto out; + for (;;) { unsigned long offset = addr & ~PAGE_MASK; int this_len = PAGE_SIZE - offset; @@ -97,7 +108,7 @@ if (this_len > len) this_len = len; - retval = access_one_page(tsk, vma, addr, buf, this_len, write); + retval = access_one_page(current, vma, addr, buf, this_len, write); copied += retval; if (retval != this_len) break; @@ -118,7 +129,12 @@ vma = vma->vm_next; } - up(&tsk->mm->mmap_sem); +out: + up(&mm->mmap_sem); + current->mm = old_mm; + current->active_mm = old_activemm; + activate_mm(mm, old_activemm); + mmput(mm); return copied; }

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Apr 15 2000 - 21:00:23 EST