Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp2032987lqe; Tue, 9 Apr 2024 07:49:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVDxGqHExvZQyLgaIywiyzKHHN5tBfNxiHf+tQq9uUpvyohnrUtuIQL00hau2TbsiivaCU1zEpD/057BhHIVK6RyPeZ8q1SAc7cQg2HkQ== X-Google-Smtp-Source: AGHT+IGnsQM7L7kL/LFw4yBnD7tOjp8ud014SQnYfZkOFDuWBqUMeId2G/YhuE1LN6It7oP/LQrL X-Received: by 2002:a17:903:2352:b0:1e4:4740:2114 with SMTP id c18-20020a170903235200b001e447402114mr4588652plh.60.1712674145833; Tue, 09 Apr 2024 07:49:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712674145; cv=pass; d=google.com; s=arc-20160816; b=ElXTRiLCq4ytCcGWIuuBCdjRnXuUZfcjeChFRYBtwSaYlz5PA5azUD328HpUdpUR2k wKpaDsjP6C//ngHy2IOIo3nHT4mIiFS1qPDku3E6xJE/4vQRQufBeLp3h4K+zXobAoUu rGUn5PUXMhG4pmT/QlTzUwz0S9dqyaM/4RzjXk2YWFikUbtcB3TQvu0cWL+ZLyRkE+Ui CGx6lITFvddBXoXSmI0F5Fll2ZtLWSOzD925AlCZrqyFCwwieA/LV0tWoWRHQtGB7f52 SCcwmnQEEsimQP6WWvq/HhLCqKvKs7WNLgwPmb3nCw/LmQVcj0N0Rw+MYQmD2hkqjvyz kAEQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=JGKKqyMnDxDe7Z88TFPiX7ZbsHcnXFBE7VSZEtRsFEI=; fh=kqE5CA3XwGmt1qUivIsmWNQinscHrTzgm7zwVd39bLo=; b=aqcYNJMzYIyyAKgdB4lI7yhz7yqxROfqVmQHE/OjinQlhpRxb341468u3XdZ/l4NPH ZnzPnWGhu9MBvgKZO3S0x1b5V5kR8RCjasNQ9/lrW1N73vozMdjblLV7/gC7pQr4K9Yl tYhBKp5BtWQK46rLAxkoUe+9AYzuMniG5mFoRUqjJZt74gBXkCVoE5ViS1Lhgph2JcRu TkPCdObdeCRxOef9mlNzQ14ZPxyPXbpOTimXleWbnNNwfGjSY62HPJtbqKPR996fQkwp QuxrCJYmn+xOrTieSLe2lvSiZhok/aDZXQXAOvTCndD/DxXNLnWbR5byKYGpm5xfljHJ 9YDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=28vxQEc2; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-137115-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137115-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u6-20020a170902e5c600b001e264881bc3si8858303plf.130.2024.04.09.07.49.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 07:49:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137115-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=28vxQEc2; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-137115-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137115-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 97A4B28B1AA for ; Tue, 9 Apr 2024 14:46:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 54AC683A06; Tue, 9 Apr 2024 14:46:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="28vxQEc2" Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 010EC2C695 for ; Tue, 9 Apr 2024 14:46:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712673989; cv=none; b=KXCAUws5BDaJ9CcC/82hhfKNy0DI8/HslhYBIeXNWizft38o8bt13PKbTd4ayXYsTo6qG3tvyyFU+gnwW2rusWaSPOcAiMDMBd8m247pV2d+MY1OxThdfmrEUgA+Lcbo2mm2fQzTGotAp9zWIJLtJdTg0Uo+FlFrcibngMmRJPc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712673989; c=relaxed/simple; bh=JNYWxfOdBLnkcSOg7S7k0lKm6pw5ifgueS2lI62IYsQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=V13AHHgNjHn1AC+YL0BTz34TrfWFvFfj1I9gpM/7REML2MQqfUOLrvMQyNIkFSufwzgtheQqE+pj+H2lXjqY+hg2TtZxM0uxMgcXt7dck8hk/dK7wCczmvZqdgEIdAEGelK85qiU00T4QJsNb8SqAuyp+0b/s3XXiC1+ZLoyOJA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=28vxQEc2; arc=none smtp.client-ip=209.85.221.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-vk1-f177.google.com with SMTP id 71dfb90a1353d-4daa68eef71so1666490e0c.0 for ; Tue, 09 Apr 2024 07:46:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712673987; x=1713278787; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=JGKKqyMnDxDe7Z88TFPiX7ZbsHcnXFBE7VSZEtRsFEI=; b=28vxQEc2TfpbRqxpk93+D041AjxSexs6rYQNsHGjjZ8SP1AfWYlIvrDbgi+HSQV+NY hE/csZnXhzr0uDz8wJbGZuxVlzPU3tutz+RB6QDriquBTMIkj2eS5AQvPid7Z+GAudkS uUo5KnnmEnv3+VRdF6XIVXQ6mleVvgpSSx9XXITKH7VS40GSIIXRLIczF2XFhkvXOVr3 WclMHKAwcC22dGNNFI4TPb1YDaWKAX40dLh8EXQF7bXTuV5fM10wRgaWo3PGRbMpJeqv OkxRCEEK7iChk5QM4qFrwH/ywqEsaBuDZo4045Y+le2SbaY/fkDoldJctWdf9RzuNwzK /Pag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712673987; x=1713278787; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JGKKqyMnDxDe7Z88TFPiX7ZbsHcnXFBE7VSZEtRsFEI=; b=fRdZFT+ebA/j3Q+3CMfFgH9jhS8yqN0J0/PLAuf2KtHanFlkty+E/PFT54vg6KNbBh XxfkfrZstG+ypoyYa/K3Z9BG/+aF65vZGzRv4NWP4v2kZZ8aSMrYV6ah7Mko3QbgnJzo +BNRh5BIz/YL13LFroZn1qi0NLKjzEVuIxo7C0Tq3nUEjmWB8qsfHmvNNWTGt5qSEhq0 GW/pUHVAc2E6uDt7ptsTuBgaqBK6BPEDMic1rJFoIMNbSvJDDrXqOTbFs46o4g4FDssc 81vBRLWHyoMPgVrnhABz9qDkHcJveo4ery9duOHAuM1fuIyeAnAn6wZgsB9WN66Q1c1u Bypw== X-Forwarded-Encrypted: i=1; AJvYcCXLz8jibYzDp926HtzKcZjdfLs7j6uRVWAxcS1Gnca44SHQKtzCXa1INhnOBAdGQk4sGNJxv8ruwbcRHp83vD+GNrUWAKe8/aVtWo24 X-Gm-Message-State: AOJu0YwqR7R2A0k84WvfZsbpcA4+EpjQdUWf921b4V3C1y1Lh6K84SIs g7nv1okqlUN3szs/8+e6PMUP4BifTOwJbjWDrd7eLNn5SoRhttvkOlDZgLnbYQcBqAckKZCqqpO jSK6Cer5LmiQoVX3AYzmzRDaTLpiluU3o8OGx X-Received: by 2002:a05:6122:48a:b0:4d8:74cb:e3c2 with SMTP id o10-20020a056122048a00b004d874cbe3c2mr33094vkn.9.1712673986727; Tue, 09 Apr 2024 07:46:26 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240408090205.3714934-1-elver@google.com> <20240409103327.7a9012fa@gandalf.local.home> In-Reply-To: <20240409103327.7a9012fa@gandalf.local.home> From: Marco Elver Date: Tue, 9 Apr 2024 16:45:47 +0200 Message-ID: Subject: Re: [PATCH] tracing: Add new_exec tracepoint To: Steven Rostedt Cc: Eric Biederman , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Masami Hiramatsu , Mathieu Desnoyers , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Dmitry Vyukov Content-Type: text/plain; charset="UTF-8" On Tue, 9 Apr 2024 at 16:31, Steven Rostedt wrote: > > On Mon, 8 Apr 2024 11:01:54 +0200 > Marco Elver wrote: > > > Add "new_exec" tracepoint, which is run right after the point of no > > return but before the current task assumes its new exec identity. > > > > Unlike the tracepoint "sched_process_exec", the "new_exec" tracepoint > > runs before flushing the old exec, i.e. while the task still has the > > original state (such as original MM), but when the new exec either > > succeeds or crashes (but never returns to the original exec). > > > > Being able to trace this event can be helpful in a number of use cases: > > > > * allowing tracing eBPF programs access to the original MM on exec, > > before current->mm is replaced; > > * counting exec in the original task (via perf event); > > * profiling flush time ("new_exec" to "sched_process_exec"). > > > > Example of tracing output ("new_exec" and "sched_process_exec"): > > How common is this? And can't you just do the same with adding a kprobe? Our main use case would be to use this in BPF programs to become exec-aware, where using the sched_process_exec hook is too late. This is particularly important where the BPF program must stop inspecting the user space's VM when the task does exec to become a new process. kprobe (or BPF's fentry) is brittle here, because begin_new_exec()'s permission check can still return an error which returns to the original task without crashing. Only at the point of no return are we guaranteed that the exec either succeeds, or the task is terminated on failure. I don't know if "common" is the right question here, because it's a chicken-egg problem: no tracepoint, we give up; we have the tracepoint, it unlocks a range of new use cases (that require robust solution to make BPF programs exec-aware, and a tracepoint is the only option IMHO). Thanks, -- Marco