From patchwork Wed Mar 29 19:45:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 76809 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp663978vqo; Wed, 29 Mar 2023 13:18:26 -0700 (PDT) X-Google-Smtp-Source: AKy350YGjQlBAmkjKdIhjU4q/KAJFmvoDrKL0nfol7uRBAgqRCvXp+JBgEw6CR0BkGLEIsOLq8aK X-Received: by 2002:a17:906:e918:b0:839:74cf:7c4f with SMTP id ju24-20020a170906e91800b0083974cf7c4fmr16462651ejb.8.1680121106586; Wed, 29 Mar 2023 13:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680121106; cv=none; d=google.com; s=arc-20160816; b=EC94jCr4mnu1PJzifr5ukTwruYfi+K525Rj64FPip80hMut4YEtAIYgWRLCCRe5CGW qb3PDoN4c6Xs0kEkXyU/CLgL6nLSozbMLa6G45sGFPULTXv1mNeyjBt/ZBrk/oZ74BMx aKR0ypBaM+K/XAPdELXPdhsqeMBzAcuI2ZadxAwMYl0VVmw9NWrbEMI0r9a1KdQwNo9u VF9U8howQT/+A57+GzwaPrqeodDTHLqK4+NYBDLCGRy4PgT+TWtgIEsUA8nJW/Z0LR/O sRLdyTCd2Uj7l7+NTA/21F+LpQt6ZTa9/UPo7FiHCFLAN67XhHsUzJThae0h2L+JY9+D lNMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=j2v5Cx1xdvY7OWIuyDgF80JTRA6pWVw+tHpcRQ1qOiw=; b=PerZyXGvhYf/fouDqSfiRHJCB2HvrrBrx/u49mlD++mr5d2Ex19E99nXBamQa2CYV3 4xMpqcieMbu9c4Hkl1C2N7FlhNFYBUaZkPAbZ3qwjk+wJDTvrONr0jLp7dTG+RkzFTli m5ucskzEDPmYw5FZuXlMLiBdoM4gzF9oE4qellap1lO8nLBruwW/zdH12DMuMZ3+5hDo uLyfz8cAf2cz5MA2DPbkHojZ0c+WXW5+SpVAAsTpaWWJagF5hIXNhQTriiiFcOSD6dea BKsmBrsFWqXL0pzwPl7+VS832gbRbVJzUiDwTlkkQp/TTl8hR1W6zyRX1aDQ7L60ORtX kkiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gl7-20020a170906e0c700b0093cda757bd8si16954241ejb.132.2023.03.29.13.18.02; Wed, 29 Mar 2023 13:18:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230463AbjC2Tq1 (ORCPT + 99 others); Wed, 29 Mar 2023 15:46:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbjC2Tpz (ORCPT ); Wed, 29 Mar 2023 15:45:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B72129F for ; Wed, 29 Mar 2023 12:45:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E77F661E29 for ; Wed, 29 Mar 2023 19:45:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3508C433A1; Wed, 29 Mar 2023 19:45:52 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1phbjz-002RlR-2i; Wed, 29 Mar 2023 15:45:51 -0400 Message-ID: <20230329194551.655419033@goodmis.org> User-Agent: quilt/0.66 Date: Wed, 29 Mar 2023 15:45:29 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Mathieu Desnoyers , Beau Belgrave Subject: [for-next][PATCH 13/25] tracing/user_events: Track fork/exec/exit for mm lifetime References: <20230329194516.146147554@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761734669462925492?= X-GMAIL-MSGID: =?utf-8?q?1761734669462925492?= From: Beau Belgrave During tracefs discussions it was decided instead of requiring a mapping within a user-process to track the lifetime of memory descriptors we should hook the appropriate calls. Do this by adding the minimal stubs required for task fork, exec, and exit. Currently this is just a NOP. Future patches will implement these calls fully. Link: https://lkml.kernel.org/r/20230328235219.203-3-beaub@linux.microsoft.com Suggested-by: Mathieu Desnoyers Signed-off-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) --- fs/exec.c | 2 ++ include/linux/sched.h | 5 +++++ include/linux/user_events.h | 18 ++++++++++++++++++ kernel/exit.c | 2 ++ kernel/fork.c | 2 ++ 5 files changed, 29 insertions(+) diff --git a/fs/exec.c b/fs/exec.c index 7c44d0c65b1b..2b0042f8deec 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -65,6 +65,7 @@ #include #include #include +#include #include #include @@ -1859,6 +1860,7 @@ static int bprm_execve(struct linux_binprm *bprm, current->fs->in_exec = 0; current->in_execve = 0; rseq_execve(current); + user_events_execve(current); acct_update_integrals(current); task_numa_free(current, false); return retval; diff --git a/include/linux/sched.h b/include/linux/sched.h index 63d242164b1a..bf37846e90c2 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -69,6 +69,7 @@ struct sighand_struct; struct signal_struct; struct task_delay_info; struct task_group; +struct user_event_mm; /* * Task state bitmask. NOTE! These bits are also @@ -1528,6 +1529,10 @@ struct task_struct { union rv_task_monitor rv[RV_PER_TASK_MONITORS]; #endif +#ifdef CONFIG_USER_EVENTS + struct user_event_mm *user_event_mm; +#endif + /* * New fields for task_struct should be added above here, so that * they are included in the randomized portion of task_struct. diff --git a/include/linux/user_events.h b/include/linux/user_events.h index 13689589d36e..3d747c45d2fa 100644 --- a/include/linux/user_events.h +++ b/include/linux/user_events.h @@ -11,4 +11,22 @@ #include +#ifdef CONFIG_USER_EVENTS +struct user_event_mm { +}; +#endif + +static inline void user_events_fork(struct task_struct *t, + unsigned long clone_flags) +{ +} + +static inline void user_events_execve(struct task_struct *t) +{ +} + +static inline void user_events_exit(struct task_struct *t) +{ +} + #endif /* _LINUX_USER_EVENTS_H */ diff --git a/kernel/exit.c b/kernel/exit.c index f2afdb0add7c..875d6a134df8 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -68,6 +68,7 @@ #include #include #include +#include #include #include @@ -818,6 +819,7 @@ void __noreturn do_exit(long code) coredump_task_exit(tsk); ptrace_event(PTRACE_EVENT_EXIT, code); + user_events_exit(tsk); validate_creds_for_do_exit(tsk); diff --git a/kernel/fork.c b/kernel/fork.c index d8cda4c6de6c..efb1f2257772 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -97,6 +97,7 @@ #include #include #include +#include #include #include @@ -2505,6 +2506,7 @@ static __latent_entropy struct task_struct *copy_process( trace_task_newtask(p, clone_flags); uprobe_copy_process(p, clone_flags); + user_events_fork(p, clone_flags); copy_oom_score_adj(clone_flags, p);