Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp344379ybe; Wed, 18 Sep 2019 18:33:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxA5YOWJadmrrvumOBEUNSD527mpTYrKiDTWPYKkDbAlPvqsqtGX2mqoHpoi6uinfwp0hBr X-Received: by 2002:a50:b6c8:: with SMTP id f8mr13644556ede.33.1568856824757; Wed, 18 Sep 2019 18:33:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568856824; cv=none; d=google.com; s=arc-20160816; b=ei9j1+t0fX9TCBSiXTdm2sZcr4ieF7BkQ9uHWXJTmpja4PlvVeVy2EpSkXRhyEndMQ MXRp4NBYaE3CQSGAiAuiggBVnYwNH1Jtjnj8/IFQw5sY+i6UhaUX9tQ/io97oB1cqZ3m dBoDCOw13TJmcpltw9SPKH0x3fQebnxbvqoXTAy1gY6IUEUITTvMQR3e0EBzJA/cqnVb 4nhPBH8mqmmnVAixF6T6OAQ5ZNgsHkN5RumKxhVApsU5FQYunz+bw4M1FWof5lp1hzB9 XAwHlqeh5qG3Kq9HbnXmQyF3UW2T1Z248hKmStqvAApFjAuWGrPvqApQowgVHVzDJmZB WAUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from; bh=/UOrl2QswtWVSKhQARPPl2m30dqPtm3IYz0zdZioMyI=; b=LY/SbAle6CzyLTA0ymVxDO7zmXTNnExNKAvRgSc4M2bplHK6ENWrFCwbDiFzFq8enj jOJZx9fNeeyzbZcRasreZEDkPKYYPJqWrqkeCUPzCdRoX8HjmFa4ZP5fLIquzeKtl0rj gA3QUyTZp4XAa6QhFyKYEoXlk00xKm7CUrSv1VUPmbQBUy3ZwpSXpgJDXi6wPRSYWWil SQbe70hGXbAT8lmnrlbhWZV/Vg39TB5rc/h2jORzKuWl0Vo7B7rHIWoP+wgHsOVq0cOC qW+wNxBY0YFhQyQox07jwYDsgRu5dYqao/uwzy7fg7a2iA+ybviPnl64OI9OVVnWgY2m CU9Q== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3si3747842ejd.71.2019.09.18.18.33.21; Wed, 18 Sep 2019 18:33:44 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387911AbfISB0s (ORCPT + 99 others); Wed, 18 Sep 2019 21:26:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49254 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387882AbfISB0q (ORCPT ); Wed, 18 Sep 2019 21:26:46 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3CBEA302C080; Thu, 19 Sep 2019 01:26:42 +0000 (UTC) Received: from madcap2.tricolour.ca (ovpn-112-19.phx2.redhat.com [10.3.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6F5760C18; Thu, 19 Sep 2019 01:26:36 +0000 (UTC) From: Richard Guy Briggs To: 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 Cc: Paul Moore , sgrubb@redhat.com, omosnace@redhat.com, dhowells@redhat.com, simo@redhat.com, eparis@parisplace.org, serge@hallyn.com, ebiederm@xmission.com, nhorman@tuxdriver.com, dwalsh@redhat.com, mpatel@redhat.com, Richard Guy Briggs Subject: [PATCH ghak90 V7 15/21] sched: pull task_is_descendant into kernel/sched/core.c Date: Wed, 18 Sep 2019 21:22:32 -0400 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 19 Sep 2019 01:26:46 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) 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 -- 1.8.3.1