Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp261784ybp; Thu, 10 Oct 2019 17:43:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkhmPY7MqE0MXymaRUc8LOK9+cnUUGwE2t1qPYloXWjqPJtWGTMkn4jpirydNxxuVX/MTL X-Received: by 2002:aa7:d304:: with SMTP id p4mr10963930edq.224.1570754619530; Thu, 10 Oct 2019 17:43:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570754619; cv=none; d=google.com; s=arc-20160816; b=kztLxhKjrOrWkQtkMYplE6woTmLpB/IDJsrSTxaGVzlW3RdLP6ASQb0CakrFS04DXr 3dA9ciz+WakpYHCm2b1XlD7LMmdfZAUU31SPGJSs2bo1jnKiJURum9Bg6z6QsfNCVlX0 tgfFde8phMIEXyADrtuGx79TksNCEijFw739bXHX0ygjehmLtoNgnS13IeVnhyFhzsgl v4+0BpWKpVJlMDjxbHwajZxfFlCnIJMTZYy9S2J2IDenqD3ImX87HOmf++KS9mXybKu/ ie1uGY/uuYnVByCl/95aPfP70D0J6FE8UtSlrZ4BBAO9z9fSdK6o00ErEeOoLRx3LQtk rkeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=LCEP7qB3GzqBwKUjXrPpebibZKO1XQqLNLbhlrB2o3E=; b=pivYgAgR/Dyi/mWLIKCKNttrRWRvHyv+CdHbVUGZIy+k6gOhuv8KCAka4egVqwsA1a CURMWKwoZgYm+Ci0AqJ07+rkCK/uuk5fJLzj7HvxMVt+vasmUdYvY74BEjqVK3O2v2sr REwbZKXkwcfUME1NA9exclZZ/acnAq0d5Qql/EPj9p4HMlKnXw72RcCDyEuvfn4sQnoV DHKGOe2fXTF5L+Fq3VeIGu8g8aNb3KhaSE11rcpRWF3sNuDY7Mk6BRqKZuOZDbsm6q32 oHAOhuHndoga60Wx3W2Px9T1iv1Yy/bi0vYU/h96H9ZjldTwk1MEL/J5lLILqYNk5/Ga to4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=Ode2StGq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z15si4897002edd.431.2019.10.10.17.43.16; Thu, 10 Oct 2019 17:43:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=Ode2StGq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728042AbfJKAkb (ORCPT + 99 others); Thu, 10 Oct 2019 20:40:31 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:42041 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727640AbfJKAka (ORCPT ); Thu, 10 Oct 2019 20:40:30 -0400 Received: by mail-lf1-f67.google.com with SMTP id c195so5723932lfg.9 for ; Thu, 10 Oct 2019 17:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LCEP7qB3GzqBwKUjXrPpebibZKO1XQqLNLbhlrB2o3E=; b=Ode2StGqxHsnxHEGGTE3HLNMobXIF5IZ/OqxGpl8IF35NIz+jdNAY4QmhCTeZt7bzf RIouuQ5ZFY9iPPPH6W+K/p/hXGh4cgkT0H7toCQy7pVdb68g3Z4YUM9zznH9VgEl21VC XzFbi3oO9JsfFbBfkQV5GyaSud7A0V8C75pIKhGNO43vlfbqDiWVkDN78XfMVcsJxpkT uWX+QkjYEo6I8kcxtCgFJfmzpIeQoHkwHpG2iQnCFeHE6uu2dpDnWEIYBfJubRp3kgZ4 MDFwyruRud7cN3h62qeSkmLZgf58oqDvxgGRlvkFbA3m2Wge2p8u4totjJ9iUBQVeSwQ iH0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LCEP7qB3GzqBwKUjXrPpebibZKO1XQqLNLbhlrB2o3E=; b=aQpUXGPuDE56E6BVj2lp86at9U3kQf2rVGAR8xbFvynWZSC8w3hpJo2TaMRGFTQk2p l2l0BJ3szVGU+iXPq3fP479fHOOthHQW4QYCZN+YREVW+L48Vjn1K+DFoUbo6F1Ag/AV tlD4aN+naUmCAmASlaRQanrF7pJzdu6CQcTaKxWxEQVLm1DCqDk57HXW8q2N553mz/yt QDQ/feSMl3mEx2CKZbosXfyaB+Ou63EwLnYRkV8ICr2BxH9MF/QA6IvHeWXWy4Yk0qHk HYqPNpkSC+45WZhLYBgB17M3bZfPnnsO4AWoUIj37j/AR6gBmH6E/7aKHrh3dg6e5uo6 kaRA== X-Gm-Message-State: APjAAAUSoULVeCI/Qaftp5Zpn7Em7PqF1j8vp12av6thY4JNonJhZLPs +9hEdabOCZrvAiP9l1mm7ikkyK3+m0ygc8jnh9oY X-Received: by 2002:ac2:428b:: with SMTP id m11mr7385787lfh.64.1570754428347; Thu, 10 Oct 2019 17:40:28 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Paul Moore Date: Thu, 10 Oct 2019 20:40:17 -0400 Message-ID: Subject: Re: [PATCH ghak90 V7 15/21] sched: pull task_is_descendant into kernel/sched/core.c To: Richard Guy Briggs Cc: containers@lists.linux-foundation.org, linux-api@vger.kernel.org, Linux-Audit Mailing List , linux-fsdevel@vger.kernel.org, LKML , netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, sgrubb@redhat.com, omosnace@redhat.com, dhowells@redhat.com, simo@redhat.com, Eric Paris , Serge Hallyn , ebiederm@xmission.com, nhorman@tuxdriver.com, Dan Walsh , mpatel@redhat.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 18, 2019 at 9:26 PM Richard Guy Briggs wrote: > Since the task_is_descendant() function is used in YAMA and in audit, > pull the function into kernel/core/sched.c > > Signed-off-by: Richard Guy Briggs > --- > include/linux/sched.h | 3 +++ > kernel/audit.c | 33 --------------------------------- > kernel/sched/core.c | 33 +++++++++++++++++++++++++++++++++ > security/yama/yama_lsm.c | 33 --------------------------------- > 4 files changed, 36 insertions(+), 66 deletions(-) I'm not really reviewing this as I'm still a little confused from patch 14/21, but if 14/21 works out as correct this patch should be squashed into that one. > diff --git a/include/linux/sched.h b/include/linux/sched.h > index a936d162513a..b251f018f4db 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -1988,4 +1988,7 @@ static inline void rseq_syscall(struct pt_regs *regs) > > const struct cpumask *sched_trace_rd_span(struct root_domain *rd); > > +extern int task_is_descendant(struct task_struct *parent, > + struct task_struct *child); > + > #endif > diff --git a/kernel/audit.c b/kernel/audit.c > index 69fe1e9af7cb..4fe7678304dd 100644 > --- a/kernel/audit.c > +++ b/kernel/audit.c > @@ -2560,39 +2560,6 @@ static struct task_struct *audit_cont_owner(struct task_struct *tsk) > } > > /* > - * task_is_descendant - walk up a process family tree looking for a match > - * @parent: the process to compare against while walking up from child > - * @child: the process to start from while looking upwards for parent > - * > - * Returns 1 if child is a descendant of parent, 0 if not. > - */ > -static int task_is_descendant(struct task_struct *parent, > - struct task_struct *child) > -{ > - int rc = 0; > - struct task_struct *walker = child; > - > - if (!parent || !child) > - return 0; > - > - rcu_read_lock(); > - if (!thread_group_leader(parent)) > - parent = rcu_dereference(parent->group_leader); > - while (walker->pid > 0) { > - if (!thread_group_leader(walker)) > - walker = rcu_dereference(walker->group_leader); > - if (walker == parent) { > - rc = 1; > - break; > - } > - walker = rcu_dereference(walker->real_parent); > - } > - rcu_read_unlock(); > - > - return rc; > -} > - > -/* > * audit_set_contid - set current task's audit contid > * @task: target task > * @contid: contid value > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 2b037f195473..7ba9e07381fa 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -7509,6 +7509,39 @@ void dump_cpu_task(int cpu) > } > > /* > + * task_is_descendant - walk up a process family tree looking for a match > + * @parent: the process to compare against while walking up from child > + * @child: the process to start from while looking upwards for parent > + * > + * Returns 1 if child is a descendant of parent, 0 if not. > + */ > +int task_is_descendant(struct task_struct *parent, > + struct task_struct *child) > +{ > + int rc = 0; > + struct task_struct *walker = child; > + > + if (!parent || !child) > + return 0; > + > + rcu_read_lock(); > + if (!thread_group_leader(parent)) > + parent = rcu_dereference(parent->group_leader); > + while (walker->pid > 0) { > + if (!thread_group_leader(walker)) > + walker = rcu_dereference(walker->group_leader); > + if (walker == parent) { > + rc = 1; > + break; > + } > + walker = rcu_dereference(walker->real_parent); > + } > + rcu_read_unlock(); > + > + return rc; > +} > + > +/* > * Nice levels are multiplicative, with a gentle 10% change for every > * nice level changed. I.e. when a CPU-bound task goes from nice 0 to > * nice 1, it will get ~10% less CPU time than another CPU-bound task > diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c > index 94dc346370b1..25eae205eae8 100644 > --- a/security/yama/yama_lsm.c > +++ b/security/yama/yama_lsm.c > @@ -263,39 +263,6 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3, > } > > /** > - * task_is_descendant - walk up a process family tree looking for a match > - * @parent: the process to compare against while walking up from child > - * @child: the process to start from while looking upwards for parent > - * > - * Returns 1 if child is a descendant of parent, 0 if not. > - */ > -static int task_is_descendant(struct task_struct *parent, > - struct task_struct *child) > -{ > - int rc = 0; > - struct task_struct *walker = child; > - > - if (!parent || !child) > - return 0; > - > - rcu_read_lock(); > - if (!thread_group_leader(parent)) > - parent = rcu_dereference(parent->group_leader); > - while (walker->pid > 0) { > - if (!thread_group_leader(walker)) > - walker = rcu_dereference(walker->group_leader); > - if (walker == parent) { > - rc = 1; > - break; > - } > - walker = rcu_dereference(walker->real_parent); > - } > - rcu_read_unlock(); > - > - return rc; > -} > - > -/** > * ptracer_exception_found - tracer registered as exception for this tracee > * @tracer: the task_struct of the process attempting ptrace > * @tracee: the task_struct of the process to be ptraced -- paul moore www.paul-moore.com