Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1465583pxk; Thu, 10 Sep 2020 16:34:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYAKuWNN38TKxt44UHBljYN+6WyCRFIQmk+min6FDQwVGDl0XIqhnDmVqs7zW0bf7QG+v5 X-Received: by 2002:a17:906:2b48:: with SMTP id b8mr11992175ejg.125.1599780896053; Thu, 10 Sep 2020 16:34:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599780896; cv=none; d=google.com; s=arc-20160816; b=qz+19SQEeB3ndaCJ+txCVRYCrDGHlv2obRlykieYe9xlV94dcF4FIIvA+TBw3q4uWp EAcwtZgZIgVeKKh6IFduPe3/kkuLMznvIomNjHzgr7+/aJRKNWIFE9MI9//x6VhzRtkD ZIs/2maHPL3jI9sIJr4vRDEcWfpxfhSBX7VhSFWf9Ubo4Vdj0oS3BDQz8IEUboZu1DGC FMdeS4gwbTbHmmO6BsqxDdGOycTcwB5Gg8u5H2IQGED23SgjwC1k0n67LtRrcvjZB4I9 t+V2/3/Ic10zcLT4JA0omgHcVFisdkXZnJDLpMRX0p8HKYu+9Wwe7HgOJd479llP0Cr1 Jfqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=4RBaH+SNtQZyszf95yfys9ev5YuersLuBj4oZ/8U4uI=; b=JJhz+LfDZkHW4tJtJHzmKhL2dOzStmR3l/1eZWFnKrYOAN9XIuK78lFDQzk51Izdvh pMOrBvGBGHlf7rle379wulNDXWg/YWNDcXVyTTx5A65p0dCPW2WWFSRK04lU5TuKbDVw Usskk6G4dlZETbzZfBY1ah+qEsKFP+IveceOEY1KJp9lHhwkxiFZz6rR2zQSKWD9gwa9 EKkViM6wiGYSufWQ0JkGvLf4LcJPr0XIeOoAq1PgYNrngzU9Nj5wtUdru3Gt5L1maRYe 3HEH48mmmPAPiZFHNPCIyM1fBR8stX7iGLS+3NRSqOjp/DBA5tQbP14j80+SWBWesM5R 52AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=N8GTm1Db; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z10si106804ejj.296.2020.09.10.16.34.31; Thu, 10 Sep 2020 16:34:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=N8GTm1Db; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725355AbgIJXdp (ORCPT + 99 others); Thu, 10 Sep 2020 19:33:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725283AbgIJXdl (ORCPT ); Thu, 10 Sep 2020 19:33:41 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEC66C061757 for ; Thu, 10 Sep 2020 16:33:40 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id m5so5203320pgj.9 for ; Thu, 10 Sep 2020 16:33:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=4RBaH+SNtQZyszf95yfys9ev5YuersLuBj4oZ/8U4uI=; b=N8GTm1Dbn84HIt88mWsX44tIFWprbrc8Nc57ldNK0e9KxJ6Y7OPleZjHiHVfU+EuVR Nt6fd0ykv8WwDqUq/5E01PmMJR61Td7yjaCcLKAw3GmXUrIYA18yNyiRiHhfJIls1wi1 iTfm3bQHDHv6CpIyM6R2MGv8nAKpsNuDdrCNg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=4RBaH+SNtQZyszf95yfys9ev5YuersLuBj4oZ/8U4uI=; b=oYpk5ieo7hPVsc8hYG9q1YuHsBkQTJvrUfD6CF7u8KeYBZpadkvief9XC3OM+anTjk 2NqKz9EmNMwWL5oVsKKdolhz0rLgsK2a7a7vGta0d14JAqn/rLgz1NkYcQ85q92JSFU1 gBnQUweEZYRlUIoDt7eVqfUBHNCJ1LLmZFxGJG4rn+xgN0JTIVw9jQhGrW18ui1OhRAR 67IPTl3/vyH9odEMDNDcr3xOP0lmr7ELSxCqp2/uMSpDW3O+CLY4BpnMnZqGXm8d1NfT +lPaGRCGTgx/ZtRw7XFqhCLcPZsKnvmpyX33hNKYyqi/19u4daAz0dWLZbYHUAhqWnvv IkWg== X-Gm-Message-State: AOAM530VEI8Bm0FSHyw1MupzzSy1wY8xPzOO48TKTgs1ElUhISM9p1aL JG2l2KFO5hYk3/qqAzRARdwLVQ== X-Received: by 2002:a17:902:9891:b029:d1:9bd3:6772 with SMTP id s17-20020a1709029891b02900d19bd36772mr985688plp.28.1599780820075; Thu, 10 Sep 2020 16:33:40 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id n7sm172755pfq.114.2020.09.10.16.33.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 16:33:39 -0700 (PDT) Date: Thu, 10 Sep 2020 16:33:38 -0700 From: Kees Cook To: kernel-hardening@lists.openwall.com Cc: John Wood , Matthew Wilcox , Jonathan Corbet , Alexander Viro , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Luis Chamberlain , Iurii Zaikin , James Morris , "Serge E. Hallyn" , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: Re: [RFC PATCH 3/6] security/fbfam: Use the api to manage statistics Message-ID: <202009101625.0E3B6242@keescook> References: <20200910202107.3799376-1-keescook@chromium.org> <20200910202107.3799376-4-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200910202107.3799376-4-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 10, 2020 at 01:21:04PM -0700, Kees Cook wrote: > From: John Wood > > Use the previous defined api to manage statistics calling it accordingly > when a task forks, calls execve or exits. > > Signed-off-by: John Wood > --- > fs/exec.c | 2 ++ > kernel/exit.c | 2 ++ > kernel/fork.c | 4 ++++ > 3 files changed, 8 insertions(+) > > diff --git a/fs/exec.c b/fs/exec.c > index a91003e28eaa..b30118674d32 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -71,6 +71,7 @@ > #include "internal.h" > > #include > +#include > > static int bprm_creds_from_file(struct linux_binprm *bprm); > > @@ -1940,6 +1941,7 @@ static int bprm_execve(struct linux_binprm *bprm, > task_numa_free(current, false); > if (displaced) > put_files_struct(displaced); > + fbfam_execve(); As mentioned in the other emails, I think this could trivially be converted into an LSM: all the hooks are available AFAICT. If you only want to introspect execve _happening_, you can use bprm_creds_for_exec which is called a few lines above. Otherwise, my prior suggestion ("the exec has happened" hook via brpm_cred_committing, etc). > return retval; > > out: > diff --git a/kernel/exit.c b/kernel/exit.c > index 733e80f334e7..39a6139dcf31 100644 > --- a/kernel/exit.c > +++ b/kernel/exit.c > @@ -67,6 +67,7 @@ > #include > #include > #include > +#include > > static void __unhash_process(struct task_struct *p, bool group_dead) > { > @@ -852,6 +853,7 @@ void __noreturn do_exit(long code) > __this_cpu_add(dirty_throttle_leaks, tsk->nr_dirtied); > exit_rcu(); > exit_tasks_rcu_finish(); > + fbfam_exit(); > > lockdep_free_task(tsk); > do_task_dead(); The place for this would be put_task_struct, and the LSM hook is task_free. :) (The only caveat with task_free hook is that it may be called in non-process context due to being freed during RCU, etc. In practice, this is unlikely to cause problems.) > diff --git a/kernel/fork.c b/kernel/fork.c > index 49677d668de4..c933838450a8 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -107,6 +107,8 @@ > #define CREATE_TRACE_POINTS > #include > > +#include > + > /* > * Minimum number of threads to boot the kernel > */ > @@ -941,6 +943,8 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node) > #ifdef CONFIG_MEMCG > tsk->active_memcg = NULL; > #endif > + > + fbfam_fork(tsk); > return tsk; Since you don't need "orig", this is also trivially an LSM hook. dup_task_struct() is called by copy_process(), which will also call the task_alloc LSM hook later on. > > free_stack: > -- > 2.25.1 > -- Kees Cook