From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936085AbdIYQQW (ORCPT ); Mon, 25 Sep 2017 12:16:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49870 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933946AbdIYQQV (ORCPT ); Mon, 25 Sep 2017 12:16:21 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7D5B82027C Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=oleg@redhat.com Date: Mon, 25 Sep 2017 18:16:19 +0200 From: Oleg Nesterov To: "Naveen N. Rao" Cc: Ingo Molnar , Srikar Dronamraju , Ananth N Mavinakayanahalli , Anton Blanchard , Michael Ellerman , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 3/3] kernel/uprobes: Fix check for active uprobe Message-ID: <20170925161619.GA15325@redhat.com> References: <6718c4ebec1d71524bb81c907180bad90fc8d3c3.1506061547.git.naveen.n.rao@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6718c4ebec1d71524bb81c907180bad90fc8d3c3.1506061547.git.naveen.n.rao@linux.vnet.ibm.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 25 Sep 2017 16:16:21 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/22, Naveen N. Rao wrote: > > --- a/kernel/events/uprobes.c > +++ b/kernel/events/uprobes.c > @@ -1751,6 +1751,19 @@ static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp) > uprobe = find_uprobe(inode, offset); > } > > + /* Ensure that the breakpoint was actually installed */ > + if (uprobe) { > + /* > + * TODO: move copy_insn/etc into _register and remove > + * this hack. After we hit the bp, _unregister + > + * _register can install the new and not-yet-analyzed > + * uprobe at the same address, restart. > + */ > + smp_rmb(); /* pairs with wmb() in prepare_uprobe() */ > + if (unlikely(!test_bit(UPROBE_COPY_INSN, &uprobe->flags))) > + uprobe = NULL; > + } ACK ... but the comment is no longer valid, it only mentions the race unregister + register. And note that "restart" is not true in that we are not going to simply restart, we will check is_trap_at_addr() and then either send SIGTRAP or restart. This is correct because we do this check under mmap_sem so we can't race with install_breakpoint(), so is_trap_at_addr() == T can't be falsely true if UPROBE_COPY_INSN is not set. And btw, perhaps you should do this check right after find_uprobe() in the if (valid_vma) block. Oleg.