lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1308303665.2355.11.camel@twins>
Date:	Fri, 17 Jun 2011 11:41:05 +0200
From:	Peter Zijlstra <peterz@...radead.org>
To:	Srikar Dronamraju <srikar@...ux.vnet.ibm.com>
Cc:	Ingo Molnar <mingo@...e.hu>, Steven Rostedt <rostedt@...dmis.org>,
	Linux-mm <linux-mm@...ck.org>,
	Arnaldo Carvalho de Melo <acme@...radead.org>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Andi Kleen <andi@...stfloor.org>,
	Hugh Dickins <hughd@...gle.com>,
	Christoph Hellwig <hch@...radead.org>,
	Jonathan Corbet <corbet@....net>,
	Thomas Gleixner <tglx@...utronix.de>,
	Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>,
	Oleg Nesterov <oleg@...hat.com>,
	LKML <linux-kernel@...r.kernel.org>,
	Jim Keniston <jkenisto@...ux.vnet.ibm.com>,
	Roland McGrath <roland@...k.frob.com>,
	Ananth N Mavinakayanahalli <ananth@...ibm.com>,
	Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH v4 3.0-rc2-tip 7/22]  7: uprobes: mmap and fork hooks.

On Fri, 2011-06-17 at 14:35 +0530, Srikar Dronamraju wrote:

> > > > int mmap_uprobe(...)
> > > > {
> > > >   spin_lock(&uprobes_treelock);
> > > >   for_each_probe_in_inode() {
> > > >     // create list;
> 
> Here again if we have multiple mmaps for the same inode occuring on two
> process contexts (I mean two different mm's), we have to manage how we
> add the same uprobe to more than one list. Atleast my current
> uprobe->pending_list wouldnt work.

Sure, wasn't concerned about that particular problem.

> > > >   }
> > > >   spin_unlock(..);
> > > > 
> > > >   list_for_each_entry_safe() {
> > > >     // remove from list
> > > >     ret = install_breakpoint();
> > > >     if (ret)
> > > >       goto fail;
> > > >     if (!uprobe_still_there()) // takes treelock
> > > >       remove_breakpoint();
> > > >   }
> > > > 
> > > >   return 0;
> > > > 
> > > > fail:
> > > >   list_for_each_entry_safe() {
> > > >     // destroy list
> > > >   }
> > > >   return ret;
> > > > }
> > > > 
> > > 
> > > 
> > > register_uprobe will race with mmap_uprobe's first pass.
> > > So we might end up with a vma that doesnot have a breakpoint inserted
> > > but inserted in all other vma that map to the same inode.
> > 
> > I'm not seeing this though, if mmap_uprobe() is before register_uprobe()
> > inserts the probe in the tree, the vma is already in the rmap and
> > register_uprobe() will find it in its vma walk. If its after,
> > mmap_uprobe() will find it and install, if a concurrent
> > register_uprobe()'s vma walk also finds it, it will -EEXISTS and ignore
> > the error.
> > 
> 
> You are right here. 
> 
> What happens if the register_uprobe comes first and walks around the
> vmas, Between mmap comes in does the insertion including the second pass
> and returns.  register_uprobe now finds that it cannot insert breakpoint
> on one of the vmas and hence has to roll-back. The vma on which
> mmap_uprobe inserted will not be in the list of vmas from which we try
> to remove the breakpoint.

Yes it will, remember __register_uprobe() will call
__unregister_uprobe() on fail, which does a new vma-rmap walk which will
then see the newly added mmap.

> How about something like this:

> 	if (!mutex_trylock(uprobes_mutex)) {
> 
> 		/*
> 		 * Unable to get uprobes_mutex; Probably contending with
> 		 * someother thread. Drop mmap_sem; acquire uprobes_mutex
> 		 * and mmap_sem and then verify vma.
> 		 */
> 
> 		up_write(&mm->mmap_sem);
> 		mutex_lock&(uprobes_mutex);
> 		down_write(&mm->mmap_sem);
> 		vma = find_vma(mm, start);
> 		/* Not the same vma */
> 		if (!vma || vma->vm_start != start ||
> 				vma->vm_pgoff != pgoff || !valid_vma(vma) ||
> 				inode->i_mapping != vma->vm_file->f_mapping)
> 			goto mmap_out;
> 	}

Only if we have to, I really don't like dropping mmap_sem in the middle
of mmap. I'm fairly sure we can come up with some ordering scheme that
ought to make mmap_uprobe() work without the uprobes_mutex.

On thing I was thinking of to fix that initial problem of spurious traps
was to leave the uprobe in the tree but skip all probes without
consumers in mmap_uprobe().

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ