Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5669164ybp; Tue, 8 Oct 2019 06:38:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUSXb4oj924tQdLGWIF3yLEaKHBR2nPdirTbHJByU0/BPinrgmzoU4Y2bQDcxQHQNCEoVT X-Received: by 2002:a50:cfc7:: with SMTP id i7mr33270135edk.89.1570541895499; Tue, 08 Oct 2019 06:38:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570541895; cv=none; d=google.com; s=arc-20160816; b=xSJAwrgfdDd9oWYfKKWx1YCkjS8cUu1LdYrCwcPcr0OOyCyuAtJin+6j5I3QO2+VMx oQ9J0AwHLhjnM1u3h1fOPX2pzupCs0LKBx1R5YcgLL6FRH+psv2BfxIjttrJ4mf11ROH c4sNL3oQw532gOOyL1IfokBHeYl9LJGTEscrt5Maf2hJP30l4Tya0NVVx+iEXD1p78ow pLM3Z7FXwaK2iFHuF6MxDLM9jkC7uyCKb8qHWv2sX1XyPbfPOvVA1RCn/xm3g+GCaD2c aVm57tg7uw/am63D4sAcN4bG7VjyZwFlGwdQnnzfBtENUJ3z6EeQxoSaeWZoXiyRkCsw 334w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=vTKU4asFHsQZstw1g0KtKeKGEKBYpbJyZV57QnF+Bfw=; b=YCQI94hYJEGdVf17T/4nwV35TJc/1bIksAEz8qrvAAmnVIoGb0YXJuyfXDgRZlgyGo NAEjp+GEWPVjNup5OUd6mkNcRUpeaT16GE3Yunv7182+MQ+/Ketr2Ee42bAyp8RDavVw LV20qXFqlVDy8e+K53zsdsivZlPBbmQQxPRQ8gYAqlYaPxEUCFZGLeoXXEIBCjzyearJ 1GHHQBRsMspsxbhC/DwXcYBp+dniAGXmVhbbEvGrtas7UtFJkCkSB1LPBz528MstOpw1 eUYlGUBNvWKDL2TN33u5WBdM/bRNwCSxGwXq1hI05dkz8PLDSYPs0IV5uqnMfnKJeRf9 Jq3Q== 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 ca9si9885148edb.79.2019.10.08.06.37.51; Tue, 08 Oct 2019 06:38:15 -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 S1725866AbfJHNhK (ORCPT + 99 others); Tue, 8 Oct 2019 09:37:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50352 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbfJHNhK (ORCPT ); Tue, 8 Oct 2019 09:37:10 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CCB13155E0 for ; Tue, 8 Oct 2019 13:37:09 +0000 (UTC) Received: by mail-wr1-f70.google.com with SMTP id w10so9163479wrl.5 for ; Tue, 08 Oct 2019 06:37:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vTKU4asFHsQZstw1g0KtKeKGEKBYpbJyZV57QnF+Bfw=; b=Z58WAsq07N8HSF/zug/LDMaXT6fd5AOd3Q8IzEbeTJawz/T7EdPlCc+gTExMmNESDJ 55+fFKNzFCQXmdG+lXMZNbL4kR+JtvJKKwH6gwk+npe99ngr+/NWdDAlSNVR6CKyLouh +aeMdGkgoTTvPF0B1UtLCA1ZaRR2QtW7gWczSlPlhoCe1+OdmwWVMSOqCx3MqqP9IfpJ pXMKNKlgdN71xxuT+AjiTzvO4P/1Njv13dOAX1txxRx4eO5oOzJxDlP1boB3uCX2UaSG 2PBCgQi6ykzc8iJtfg9ua0yuAUK3JWeFqAJaRiBLBrZkI0u9ZvPtQteprEkn3USo4uMl qzqg== X-Gm-Message-State: APjAAAXPEl4NkOMwLAWjZfdzZoV+m5m9D0xmglxCmxjWlg0OqtHD27On YmtJzcall45SCLYqmtaTunXXj5zYtoizhBWODS24mpr5ja92ABggGO5CRWl1kiVL2SBWfMoZuFi D8c2cGFrFJv4iNm3GAbsAg7/Q X-Received: by 2002:a1c:f01a:: with SMTP id a26mr3795626wmb.84.1570541828210; Tue, 08 Oct 2019 06:37:08 -0700 (PDT) X-Received: by 2002:a1c:f01a:: with SMTP id a26mr3795602wmb.84.1570541827960; Tue, 08 Oct 2019 06:37:07 -0700 (PDT) Received: from localhost ([2a02:2450:102e:d85:877d:43b4:dd8f:144d]) by smtp.gmail.com with ESMTPSA id 36sm24791429wrp.30.2019.10.08.06.37.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 06:37:07 -0700 (PDT) From: Christian Kellner To: linux-kernel@vger.kernel.org Cc: Christian Kellner , Christian Brauner , Andrew Morton , "Peter Zijlstra (Intel)" , Ingo Molnar , Michal Hocko , Elena Reshetova , Thomas Gleixner , Roman Gushchin , Andrea Arcangeli , "Joel Fernandes (Google)" , Al Viro , "Dmitry V. Levin" Subject: [PATCH] pidfd: show pids for nested pid namespaces in fdinfo Date: Tue, 8 Oct 2019 15:36:37 +0200 Message-Id: <20191008133641.23019-1-ckellner@redhat.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christian Kellner The fdinfo file for a process file descriptor already contains the pid of the process in the callers namespaces. Additionally, if pid namespaces are configured, show the process ids of the process in all nested namespaces in the same format as in the procfs status file, i.e. "NSPid:\t%d\%d...". This allows the easy identification of the processes in nested namespaces. Signed-off-by: Christian Kellner --- kernel/fork.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/fork.c b/kernel/fork.c index 5a0fd518e04e..801793789f33 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1685,8 +1685,18 @@ static void pidfd_show_fdinfo(struct seq_file *m, struct file *f) { struct pid_namespace *ns = proc_pid_ns(file_inode(m->file)); struct pid *pid = f->private_data; +#ifdef CONFIG_PID_NS + int i; +#endif seq_put_decimal_ull(m, "Pid:\t", pid_nr_ns(pid, ns)); +#ifdef CONFIG_PID_NS + seq_puts(m, "\nNSpid:"); + for (i = ns->level; i <= pid->level; i++) { + ns = pid_nr_ns(pid, pid->numbers[i].ns); + seq_put_decimal_ull(m, "\t", ns); + } +#endif seq_putc(m, '\n'); } #endif -- 2.21.0