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.133.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 0CD5F182B2 for ; Tue, 27 Aug 2024 10:41:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724755272; cv=none; b=eAS6YriRzi9Q7gTHQkvMnSCUXaNOIsNK2pV5Dlh9f8qZYCS/ON0YqYBcHjLmQQSeRwgMMb2dE0rxyuiJL2JslKtRkjZhoeDzQq3Rj/0TjRpop3kAL8wbeOG97in/c338JxbMZ9FffWYSL7BI1Y0nu5Es336iqJExAGByCEnZOiM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724755272; c=relaxed/simple; bh=Qz1a8CSDv1yDuZmmN9x8YOW7RMcmZ1PT9u2pTyYf5wk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=seGhyQ6AQ9zumuoPi5ZJxtcA74qcDzIM/dCIYTDW5C2VtPyLG/9gmP0ypbs2knOIjx5f70uH+bo0auf1u46euauRCbM53V40/scu6xRE1DyHJ7DDWAIw6LfFuDKe05kCyooLHYgiL20Mv45bz8KLm2MndQoEmiYAtRO7+eRq4mU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=R0JvXc/m; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="R0JvXc/m" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724755270; 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=G+W/iRPFMkEKzQkZrGaweHud29e2ZZ1m/nHKhDZapCE=; b=R0JvXc/mgVmxfTz1UGr0KNeFR2UxofVZATK2rRoUBOnCgeKnEvO/b8v16M9yBAFyK/OfnM N2igkC5yZjahzf0fdnDoM5Ln1w8SLX2vOiHO2fg+KAweKBMpFQVoGYv0RqCMsp9zxJjE+3 VRYbHpF7fCOFBtj6FoVugBset24/6Tg= Received: from mx-prod-mc-02.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-32-7sNbfee2NBmmq7o-qJ9JNQ-1; Tue, 27 Aug 2024 06:41:06 -0400 X-MC-Unique: 7sNbfee2NBmmq7o-qJ9JNQ-1 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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 71A0C1955D53; Tue, 27 Aug 2024 10:41:04 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.12]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 5B7AE1955DC8; Tue, 27 Aug 2024 10:41:00 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 27 Aug 2024 12:40:57 +0200 (CEST) Date: Tue, 27 Aug 2024 12:40:52 +0200 From: Oleg Nesterov To: Jiri Olsa Cc: Tianyi Liu , andrii.nakryiko@gmail.com, mhiramat@kernel.org, ajor@meta.com, albancrequy@linux.microsoft.com, bpf@vger.kernel.org, flaniel@linux.microsoft.com, linux-trace-kernel@vger.kernel.org, linux@jordanrome.com, mathieu.desnoyers@efficios.com Subject: Re: [PATCH v2] tracing/uprobe: Add missing PID filter for uretprobe Message-ID: <20240827104052.GD30765@redhat.com> References: <20240825171417.GB3906@redhat.com> <20240825224018.GD3906@redhat.com> <20240826115752.GA21268@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-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: User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 On 08/27, Jiri Olsa wrote: > > On Mon, Aug 26, 2024 at 01:57:52PM +0200, Oleg Nesterov wrote: > > > > So perhaps we need > > > > - if (link->task && current->mm != link->task->mm) > > + if (link->task && !same_thread_group(current, link->task)) > > > > in uprobe_prog_run() to make "filter by *process*" true, but this won't > > fix the problem with link->task->mm == NULL in uprobe_multi_link_filter(). > > would the same_thread_group(current, link->task) work in such case? > (zombie leader with other alive threads) Why not? task_struct->signal is stable, it can't be changed. But again, uprobe_multi_link_filter() won't work if the leader, uprobe->link->task, exits or it has already exited. Perhaps something like the additional change below... Oleg. --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -3322,13 +3322,28 @@ static int uprobe_prog_run(struct bpf_uprobe *uprobe, return err; } + static bool uprobe_multi_link_filter(struct uprobe_consumer *con, struct mm_struct *mm) { struct bpf_uprobe *uprobe; + struct task_struct *task, *t; + bool ret = false; uprobe = container_of(con, struct bpf_uprobe, consumer); - return uprobe->link->task->mm == mm; + task = uprobe->link->task; + + rcu_read_lock(); + for_each_thread(task, t) { + struct mm_struct *mm = READ_ONCE(t->mm); + if (mm) { + ret = t->mm == mm; + break; + } + } + rcu_read_unlock(); + + return ret; } static int