Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp2097995lqe; Tue, 9 Apr 2024 09:25:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWuKtJiE09+gRQZCy3zouMMWBNTbOuuDzs6k8cgHWuvs5Pt2qUmweJPSIKlJFqBgcP0ns5cKAoxeFhnFZFEM3/MOeIeR9coehFBowNVSg== X-Google-Smtp-Source: AGHT+IGkTJDpzYjZLW30ZECpaOyipEK00iTQkHjIWQHtJwhaTneb7+BiXPH6b4wlrfCUPCMsyFqc X-Received: by 2002:a05:6870:5594:b0:22e:d13b:c13d with SMTP id qj20-20020a056870559400b0022ed13bc13dmr72381oac.18.1712679919096; Tue, 09 Apr 2024 09:25:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712679919; cv=pass; d=google.com; s=arc-20160816; b=onR5R7vM19lP9fLnbHBBcmoi0OeQWx1wZCOYGi8WNT5ZqnV0+gIPnFKxREXkz9Y9ib fNR5UN7MYRpK/XVZCtexpLfULlsllVT2ZiMoj/LTPbx8YgwJWNfoKrksSGlen2rMXYo6 lNaJaqGQiS2WI2/H+dQi4FZF/iFs5zVS5p6eFKdaCNnQBSEo+3rmj2bHUvlaC39gheMx obEM5r12w497Lqs2Owz5EpuFO2oWbttqLxB2i1BoIPFVUNVNExhjbxd/WNCXSE+r7D2M JynhgAyDPFsZiGRGQedl80zR9VenJvAQO/k9Tqb5VrT0ZRMaa3Z1yaGrykm6Vf7kzmmV Gz7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=TZb3iRMe5mVHNLzHciI0SO6cgHqSkIE7M20XVfQvi74=; fh=xXqtjQs/5rpkHTzNsCmQUk4n8EbF467btY/G6l8t4zU=; b=VqTxzoN43ka+AbJ+0XgVaGr+AypkVgaI6tWcnoON59D04PjrishQ/JX2CHmJv3MyDi gHxhzAZI+qztoq4ebNWXzyE8Jtlqa1u2i2F4Bs5E3jUfPVXdy+ptbdFQzYJ0jCPXTrtr NjzaEKH2PqJEE/mK7znEL7iUuaD5vcgqzdtT4yLIa/7bnd2sx8w2e0JTIg80zQJBEHWI 8RgK4TvHLY5qmBItcuu1ATcziqe7UPAGEhVzakl/o+fBqH2dNRWgcXOmrAFvLAD5Zljt kK0o9MAB7x/MKoCFmQ2n8ViAFEhr5UNCma9Qnh2akJ/6m0rqBwEF1BTQEtgDP+pF9uOl 39Qw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jSfv7kwU; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-137252-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137252-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d34-20020a631d22000000b005e83f4901a7si8768630pgd.457.2024.04.09.09.25.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 09:25:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137252-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jSfv7kwU; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-137252-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137252-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 882B1B26928 for ; Tue, 9 Apr 2024 15:46:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C3D213848D; Tue, 9 Apr 2024 15:46:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jSfv7kwU" Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 60B8613698F for ; Tue, 9 Apr 2024 15:46:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712677574; cv=none; b=qLXk+b9iHScQoa9QpJsVk2nciRgn1HHmbDa3vJGn0pYBDTA78EhPFE2GOJJBR+vqvy1JTRaAtC1W008j8XpworwXiofJfisNZNdrzlC3azHeASOLlGD/AuBJpqlHEdUcEFKI12HOqvmjHj5lE7BIPN0VwuXhi4Ufmf6Lez3Jbtc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712677574; c=relaxed/simple; bh=4YNynUGh8NwIznE4z7XpT8p/m3+R1fGobPIeDJ73050=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RJCbwJSkUCzgbqOPFMlhS3SEG89824WPtCucxp0qaIFRrSt6T9ndrQho9UYx7yGHk1UwekrvXXnQA2LuzLIzjTfY2mUNgrJcLDPF26hSrx9f13cFbjJIZKzdWJham359ZSVZh+l2eQp3cjKgCGj+G8IkEbDh50aibhDEjMPJivI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=jSfv7kwU; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6ecf1bb7f38so3828219b3a.0 for ; Tue, 09 Apr 2024 08:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1712677572; x=1713282372; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=TZb3iRMe5mVHNLzHciI0SO6cgHqSkIE7M20XVfQvi74=; b=jSfv7kwUb9qEcmOVZWd4NNQ8kkcqpjc5RLqEtWEv9ORulGYOipNAK4T9N6HKEy5lNk pK+tHn0sgT0Cnv2RxvM26AzXwkqoH+YnSi7FnjNNCYo50bzdpV5NJ5N3+T+OUo3PlaGR dSYGvwAio9iV2XG+ndFKn2I1VvnMpgc4AaKvY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712677572; x=1713282372; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TZb3iRMe5mVHNLzHciI0SO6cgHqSkIE7M20XVfQvi74=; b=n1N9LhB89MPJPJNcpkCP+qtAHJixwK8hwhsuyFjWppdKtz9VVksRNGYBpQyWwGSDpt 9XpaER6GrGcbbNgcICOf1LFBHoFVKFFFwiVIapkH6PqfCOD1jSGRCjYPI+e04rgy0CH3 ZFX0Qszi0+3N/ld0FsSKOIcxvr0A2m7CoJXwDO9yfJUh0oMm0Xq7dMmYrduDaaNlwEdK KpFLr5h7dgswe4R4q0SavmhLU+It+BE46jpMSKrbe6ReSFmJVrQW9qi3AEAYuzsgW0xN xFIIYtCdbxg2RU3kowBv2qg1weTXoh0LZqPZd07+1M3jzaW5x+RxIYfWcvaNLwOwsQ5q BJ3g== X-Forwarded-Encrypted: i=1; AJvYcCVWfvTO9nOVKo+JltbbpsOIi5VM8CyOkfGyPviXKrUDEUQMhQxsSMrQXcA3asK5wQ6Zqr+OKRk9a4oxaQa+iW7IbAfEfUqxLuuVhRCS X-Gm-Message-State: AOJu0Yzlj4OZaZsmjU4I0lyoco/qOnOJZMyuOl8UaQA63xirYvw28mr7 wVFCe5iTE8BO9t98He69m7q4W2tZO5lQQmlr0JdUYFDP8u5GVBsVQE8VR6BT7A== X-Received: by 2002:a05:6a00:2355:b0:6ec:da6c:fc2d with SMTP id j21-20020a056a00235500b006ecda6cfc2dmr13723474pfj.23.1712677571643; Tue, 09 Apr 2024 08:46:11 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id 27-20020a630f5b000000b005dc5289c4edsm8296124pgp.64.2024.04.09.08.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 08:46:11 -0700 (PDT) Date: Tue, 9 Apr 2024 08:46:10 -0700 From: Kees Cook To: Marco Elver Cc: Steven Rostedt , Eric Biederman , 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 Subject: Re: [PATCH] tracing: Add new_exec tracepoint Message-ID: <202404090840.E09789B66@keescook> References: <20240408090205.3714934-1-elver@google.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: <20240408090205.3714934-1-elver@google.com> On Mon, Apr 08, 2024 at 11:01:54AM +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"): > > $ cat /sys/kernel/debug/tracing/trace_pipe > <...>-379 [003] ..... 179.626921: new_exec: filename=/usr/bin/sshd pid=379 comm=sshd > <...>-379 [003] ..... 179.629131: sched_process_exec: filename=/usr/bin/sshd pid=379 old_pid=379 > <...>-381 [002] ..... 180.048580: new_exec: filename=/bin/bash pid=381 comm=sshd > <...>-381 [002] ..... 180.053122: sched_process_exec: filename=/bin/bash pid=381 old_pid=381 > <...>-385 [001] ..... 180.068277: new_exec: filename=/usr/bin/tty pid=385 comm=bash > <...>-385 [001] ..... 180.069485: sched_process_exec: filename=/usr/bin/tty pid=385 old_pid=385 > <...>-389 [006] ..... 192.020147: new_exec: filename=/usr/bin/dmesg pid=389 comm=bash > bash-389 [006] ..... 192.021377: sched_process_exec: filename=/usr/bin/dmesg pid=389 old_pid=389 > > Signed-off-by: Marco Elver > --- > fs/exec.c | 2 ++ > include/trace/events/task.h | 30 ++++++++++++++++++++++++++++++ > 2 files changed, 32 insertions(+) > > diff --git a/fs/exec.c b/fs/exec.c > index 38bf71cbdf5e..ab778ae1fc06 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -1268,6 +1268,8 @@ int begin_new_exec(struct linux_binprm * bprm) > if (retval) > return retval; > > + trace_new_exec(current, bprm); > + All other steps in this function have explicit comments about what/why/etc. Please add some kind of comment describing why the tracepoint is where it is, etc. For example, maybe something like: /* * Before any changes to 'current', report that the exec is about to * happen (since we made it to the point of no return). On a successful * exec, the 'sched_process_exec' tracepoint will also fire. On failure, * ... [something else] */ > +TRACE_EVENT(new_exec, > + > + TP_PROTO(struct task_struct *task, struct linux_binprm *bprm), > + > + TP_ARGS(task, bprm), > + > + TP_STRUCT__entry( > + __string( filename, bprm->filename ) > + __field( pid_t, pid ) > + __string( comm, task->comm ) > + ), > + > + TP_fast_assign( > + __assign_str(filename, bprm->filename); What about binfmt_misc, and binfmt_script? You may want bprm->interp too? -Kees > + __entry->pid = task->pid; > + __assign_str(comm, task->comm); > + ), > + > + TP_printk("filename=%s pid=%d comm=%s", > + __get_str(filename), __entry->pid, __get_str(comm)) > +); > + > #endif > > /* This part must be outside protection */ > -- > 2.44.0.478.gd926399ef9-goog > -- Kees Cook