From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BE3D1C433F5 for ; Mon, 6 Dec 2021 00:24:35 +0000 (UTC) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-582-Dbk3Vu9rOneJJjUYIK4RBw-1; Sun, 05 Dec 2021 19:24:31 -0500 X-MC-Unique: Dbk3Vu9rOneJJjUYIK4RBw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7F7EC835B4F; Mon, 6 Dec 2021 00:24:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5E50610016F4; Mon, 6 Dec 2021 00:24:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 044A91809CB8; Mon, 6 Dec 2021 00:24:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B5EpMWO001460 for ; Sun, 5 Dec 2021 09:51:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id 16F91492C3B; Sun, 5 Dec 2021 14:51:22 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 127AC492C38 for ; Sun, 5 Dec 2021 14:51:22 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EC356811E76 for ; Sun, 5 Dec 2021 14:51:21 +0000 (UTC) Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-483-wGICBGryPp2ThtxHdx76Jw-1; Sun, 05 Dec 2021 09:51:20 -0500 X-MC-Unique: wGICBGryPp2ThtxHdx76Jw-1 Received: by mail-pl1-f175.google.com with SMTP id u17so5395544plg.9 for ; Sun, 05 Dec 2021 06:51:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YNiShhLycQhgX5gYnC4y4VBBuFZNS7ZHSY9AFesdrV8=; b=dCl9bnphppgGmQPMo1gvZ2cI9r2I5j4XIisiFR2JmTFzkIzJcyxK1Ut9J80vdP6TP7 3jeH1MpSCR1HmnWXcrBWr7NADunUgZCMyo4DHtaYVELP35ImYcbo0gOv9s+HfQkLY4lz yqJGr639NoaHjJkwih93Tl7ml3326s7Q/ljyKmycT6ZlDrRLZlHIpRz9wGfHwZfdbyI9 J87fQf1R9I4tG1ez8FMr6uKton4lRKouA1jb9N29Y1WR4DMlZEUAub12gQeFNuVSl+fE 4SXPs0dn7Pc+4Wv+cStBHK6nv3WGMOcy4AHhBpxtsZ1N2Q92828837jXlpGicIwsCpg5 a+PA== X-Gm-Message-State: AOAM5329l/FqLFTPaCgxvMdU7LdeLqBxurTauWr0/ht2nMyCe/+LyQju PVvcZGc7VD6YAul/35ERxSOOTFhVOntAdqcnAmQ= X-Google-Smtp-Source: ABdhPJzc9deUn8Xmj0L2AU7C6UVvRT82dukgejEcgPuHYSOcdCGBPFUz1V0TrkJ2f6OtnuKQPz44Jw== X-Received: by 2002:a17:90a:fe0b:: with SMTP id ck11mr29446156pjb.15.1638715878962; Sun, 05 Dec 2021 06:51:18 -0800 (PST) Received: from localhost ([2602:feda:dd1:19c7:f5dc:98c2:a1a4:6c61]) by smtp.gmail.com with ESMTPSA id o2sm9507666pfu.206.2021.12.05.06.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 06:51:18 -0800 (PST) From: Leo Yan To: "David S. Miller" , Jakub Kicinski , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , Jan Harkes , coda@cs.cmu.edu, Paul Moore , Eric Paris , Balbir Singh , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, codalist@telemann.coda.cs.cmu.edu, linux-audit@redhat.com Subject: [PATCH v1 1/7] pid: Introduce helper task_is_in_root_ns() Date: Sun, 5 Dec 2021 22:50:59 +0800 Message-Id: <20211205145105.57824-2-leo.yan@linaro.org> In-Reply-To: <20211205145105.57824-1-leo.yan@linaro.org> References: <20211205145105.57824-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-loop: linux-audit@redhat.com X-Mailman-Approved-At: Sun, 05 Dec 2021 19:21:46 -0500 Cc: Leo Yan X-BeenThere: linux-audit@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Linux Audit Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=linux-audit-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Currently the kernel uses open code in multiple places to check if a task is in the root PID namespace with the kind of format: if (task_active_pid_ns(current) == &init_pid_ns) do_something(); This patch creates a new helper function, task_is_in_root_ns(), it returns true if a passed task is in the root PID namespace, otherwise returns false. So it will be used to replace open codes. Suggested-by: Suzuki K Poulose Signed-off-by: Leo Yan --- include/linux/pid_namespace.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h index 7c7e627503d2..bf82b373f022 100644 --- a/include/linux/pid_namespace.h +++ b/include/linux/pid_namespace.h @@ -86,4 +86,9 @@ extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk); void pidhash_init(void); void pid_idr_init(void); +static inline bool task_is_in_root_ns(struct task_struct *tsk) +{ + return task_active_pid_ns(tsk) == &init_pid_ns; +} + #endif /* _LINUX_PID_NS_H */ -- 2.25.1 -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit