From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 171453B6C15 for ; Wed, 5 Aug 2026 15:14:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785942868; cv=none; b=tZhdhgFygeArO2I/SyeYo+nVocXnmnL4Pk/xzM/K7tI+BucVarZkHZLqi+oisfeZu6XYHj80lh+dtfgAbqD01HSAJocwZXbpO5dq7GPvdFfRkC19IMLz381hpa9e3HGCPL2CLIC1qhACAzxVYap/OECyV5IMqQWG0QUqT3Guiqw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785942868; c=relaxed/simple; bh=Hs5V3juOMVZH5ra/jogh0AuQcuuOORr/9WsnqQU1PDw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PlEvwZmHX5W5b7h1oD2xfD5mXwwNheestg0W7ITLXOQ21mA8oBDZX7GggZJj7o5CeYTPdNNYIM7GGVmLROY8seNbMxumPgBXMc9b1movNnXELR7683CbJerL02bJHDrR9eC79svD93PiKO1l1lmTbzEOh0dENZHVM4KgnN/4BfU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZMJnccff; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZMJnccff" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785942863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3rCq9tsK99vV/IKDIQH4AsvKIO8wZbuF/vm3wB8OIMI=; b=ZMJnccffDC5CJC/WPMEPPzNfRn19t9klQdMFDbfWkYx28GkPb8Thkdsb2JdEkLe4a3IMA9 sqs6cpUW3Msla1Fqh6ZkyHfsGUoZiyCcLO1ZuxicAcrwXgdKwMfj0MfL+qbw4jvpJT9Z2B TS8fmxrDod3jccGKs/dE13okPJAflO4= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-679-EbKoPf_FPNCZjbBdEtddHg-1; Wed, 05 Aug 2026 11:14:20 -0400 X-MC-Unique: EbKoPf_FPNCZjbBdEtddHg-1 X-Mimecast-MFC-AGG-ID: EbKoPf_FPNCZjbBdEtddHg_1785942858 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A62A119560B5; Wed, 5 Aug 2026 15:14:18 +0000 (UTC) Received: from fedora (unknown [10.44.32.54]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 2B303195DF93; Wed, 5 Aug 2026 15:14:14 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 5 Aug 2026 17:14:18 +0200 (CEST) Date: Wed, 5 Aug 2026 17:14:13 +0200 From: Oleg Nesterov To: Sumanth Korikkar , Jiri Olsa , Andrii Nakryiko Cc: Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Ilya Leoshkevich , Heiko Carstens , Vasily Gorbik , Alexander Gordeev Subject: Re: [PATCH] uprobes: Skip breakpoint installation on non executable vmas Message-ID: References: <20260805131904.1127416-1-sumanthk@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260805131904.1127416-1-sumanthk@linux.ibm.com> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 On 08/05, Sumanth Korikkar wrote: > > bpftrace -e 'usdt:./testprogs/usdt_semaphore_test:tracetest:testprobe { > printf("%s\n", str(arg1) ); exit(); }' I am hoping that Andrii and Jiri (cc'ed) can take a look, I know nothing about usdt... And TBH, I don't even know what RELRO is ;) Let me ask a couple of questions for now. > expects a semaphore increment of 1, but semaphore gets double incremented > > Test program: > https://github.com/bpftrace/bpftrace/blob/master/tests/testprogs/usdt_semaphore_test.c Perhaps you can provide the test-case which I could compile on my machine without libbpf-usdt/usdt.h? And can you explain what the bpftrace cmd above actually does? I mean, where does it put the uprobe? I guess the ref_ctr_offset argument of uprobe_register() refers to USDT_DEFINE_SEMA() in that test-case... > Reason: .text mapping and RELRO mapping resolve to the same page aligned > file offset 0 > 01000000-01001000 r-xp 00000000 5e:01 usdt_semaphore_test (.text) > 01001000-01002000 r--p 00000000 5e:01 usdt_semaphore_test (RELRO) > 01002000-01003000 rw-p 00001000 5e:01 usdt_semaphore_test (semaphore) > > valid_vma() currently accepts both mappings (which contains executable > text and RELRO mapping) during uprobe registration, since both have > VM_MAYEXEC set. This causes register_for_each_vma() to call > install_breakpoint() twice for the same underlying uprobe offset in the > process. This means, update_ref_ctr() is called twice for the same > process, so a usdt semaphore is incremented from 0 to 2. So, 2 vmas map the same binary, install_breakpoint() is called twice. But, the 2nd install_breakpoint() -> ... -> uprobe_write() should see that the original insn was already replaced by int3, in this case verify_opcode() returns 0 and uprobe_write() should do nothing. And, if this uprobe was optimized before the 2nd install_breakpoint(), uprobe_write() won't be called. Hmm. > Installing a breakpoint for mapping without VM_EXEC and > updating usdt reference counter in that case is not useful. > > Skip non VM_EXEC mappings in install_breakpoint(). This fixes semaphore > double increment as shown in the above usecase. > > Signed-off-by: Sumanth Korikkar > --- > kernel/events/uprobes.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c > index 6300b216012c..9e0bbc3cf401 100644 > --- a/kernel/events/uprobes.c > +++ b/kernel/events/uprobes.c > @@ -1155,6 +1155,9 @@ static int install_breakpoint(struct uprobe *uprobe, struct vm_area_struct *vma, > bool first_uprobe; > int ret; > > + if (!(vma->vm_flags & VM_EXEC)) > + return 0; > + Well, but then it makes more sense to change valid_vma() to nack the non VM_EXEC mappings ? Oleg.