Received: by 2002:a19:771d:0:0:0:0:0 with SMTP id s29csp1253125lfc; Wed, 1 Jun 2022 13:09:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyp2BlDrrp1zfuZEucCiFWHc2zxVMJKdA5H86pRUmwGkAeeAohLl5HRO+c6CpWoHCnboOd3 X-Received: by 2002:a17:903:124a:b0:154:c7a4:9375 with SMTP id u10-20020a170903124a00b00154c7a49375mr1160854plh.0.1654114182886; Wed, 01 Jun 2022 13:09:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654114182; cv=none; d=google.com; s=arc-20160816; b=daOBZHBDHqq1NIMJWCwl7V3FQi0Fn4Sc8guPK2Ca/N4CAFIhBwC8wYnzKlUi29Dfj8 7YugIZycQQTjLpYogM8zI64/COBCcRkiaM93UeC4N7lAdb4KvWBaIuanScS4PgjJOgu2 ArziFWpRTTYJ8HS9CmsM8YTaKHechXnreYSyh9lxXR2EsIlVagrlKNElNXUUAbmVArdu s8uh30lm7YAMhaIoXIfg3X/JmJuWGEAebml4TKDARkvGQvKO8x8C78E21P1dPtM9ndai 6hN9AwvAhM0htoemGPvBKziNHixM2COE+WElp23UX/UrWX2rd9W728cocSlBMLE0jvn5 GxNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:cc:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=SHwRUtvrT0NdcbhIAR6+q8dVHlt/noH6zImMf2T6bN4=; b=lSyI3ofvu9+QgKTUT7hwOfbyrOWQ5MgTSmOzAqxv2nDFNaZ+zIegK/oHxue1qWXK2e oXm4eUbutG4jXEV6Hl1JhBq2fWM1lsUUwnnh7v8j3ysF0EkjXBEz1KEvWt6tV1A4IKsO lyiRLpZv+BSrfhrdi3jX/nB05M5V3uke+x0Dnd87XAT3tqtL0hkGmB4dO3umM093CLsz UTD0dXmyMRH/oZ9I/nRJ4XilanVSnuN6SQrneszkbfrFUnSh8avh34cj/wdU2absAOEY jA1UOr1o7lOUSzymvtFHjehoxZ5fTvzhwpcB0yCoJ445rxiwpgPrwjRWDs4jUCR6Lkcv NShg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=T42lyMTL; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q61-20020a17090a1b4300b001d984c76f9asi3326101pjq.127.2022.06.01.13.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 13:09:42 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=T42lyMTL; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 37EF7235241; Wed, 1 Jun 2022 12:25:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348034AbiEaV0C (ORCPT + 99 others); Tue, 31 May 2022 17:26:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348029AbiEaVZ6 (ORCPT ); Tue, 31 May 2022 17:25:58 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 916E99E9DB for ; Tue, 31 May 2022 14:25:48 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-30c2aa26ebfso64700627b3.4 for ; Tue, 31 May 2022 14:25:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:cc; bh=SHwRUtvrT0NdcbhIAR6+q8dVHlt/noH6zImMf2T6bN4=; b=T42lyMTLciKl9Rv8/akmQtqV6uQQ3E9lX3jWMAM9W82MEwX1WhMSTKgLZRje/MNn+N eaMz6KMZQvtrz0QjRD+AfcH6yPO8ZF657CajRVWMHR5EbQcU2E6dqGuctCFu/kMyHUxC vToGcV2W3eMszf/c30QX9yL1UALQwfojoCr5x6IchvuVjlav1j/iJta6sr8IMsKGUQ/k S2lgestauhqAsjGB/Juetw8217qZvtYbVZ17ECFylI8CcKlrM+cJ4qS560kzTM6Q62wT BQSEHpmzBUsOIEvFHF7bCoEe17s+9mMpHlx8aLBwTl+dueknacj39X5zbJHYt5zxLrPZ gabg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:cc; bh=SHwRUtvrT0NdcbhIAR6+q8dVHlt/noH6zImMf2T6bN4=; b=vFtGEvE8gTdGc6MhsMHXeb8UkQoxAb10XeMeEaCOjqszVSanE+lm/Wfw9Om5iZFgb2 s//u+byzOlNKncvnKxQ1IyaBueYBe+mTnBf6BcQuuBQ4eaKh8cNCRiMP8wbBn4n6FbzI euPlg1LN0ouOQevsjrxAt+KbxPJcIK4aJKkJH3AikMk6vTroC4q4a2pkYXrmtAGWvyLa GJzPeociHLuJgCuRP5GRLD8inNwr7tO+fDgz26z+13ke90l8bqDzsoFucg08pxwBur7x t7OSsMwiCWt31iWqDYpqqkHwVAk6/BL/P8KkWM9ckRhM8udhxO6H38UP2dmJPXw7Dkhp jwMw== X-Gm-Message-State: AOAM530EeLIldCai2jdN6xa+YwICPVjpg/3hGFpG3Me5rIykEbNtfYnj mylMj+U6GGDmbdiiRqPXYiztrqsR676P5vl9Tw== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:a3c0:2a66:b25c:16df]) (user=kaleshsingh job=sendgmr) by 2002:a0d:ea44:0:b0:30c:2902:dd96 with SMTP id t65-20020a0dea44000000b0030c2902dd96mr17812893ywe.115.1654032347582; Tue, 31 May 2022 14:25:47 -0700 (PDT) Date: Tue, 31 May 2022 14:25:15 -0700 In-Reply-To: <20220531212521.1231133-1-kaleshsingh@google.com> Message-Id: <20220531212521.1231133-3-kaleshsingh@google.com> Mime-Version: 1.0 References: <20220531212521.1231133-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 2/2] procfs: Add 'path' to /proc//fdinfo/ From: Kalesh Singh Cc: ilkos@google.com, tjmercier@google.com, surenb@google.com, kernel-team@android.com, Kalesh Singh , Jonathan Corbet , Sumit Semwal , "=?UTF-8?q?Christian=20K=C3=B6nig?=" , Andrew Morton , David Hildenbrand , Christoph Anton Mitterer , Johannes Weiner , Colin Cross , Mike Rapoport , Paul Gortmaker , Randy Dunlap , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to identify the type of memory a process has pinned through its open fds, add the file path to fdinfo output. This allows identifying memory types based on common prefixes. e.g. "/memfd...", "/dmabuf...", "/dev/ashmem...". Access to /proc//fdinfo is governed by PTRACE_MODE_READ_FSCREDS the same as /proc//maps which also exposes the file path of mappings; so the security permissions for accessing path is consistent with that of /proc//maps. Signed-off-by: Kalesh Singh --- Changes from rfc: - Split adding 'size' and 'path' into a separate patches, per Christian - Fix indentation (use tabs) in documentaion, per Randy Documentation/filesystems/proc.rst | 14 ++++++++++++-- fs/proc/fd.c | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index 779c05528e87..591f12d30d97 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -1886,14 +1886,16 @@ if precise results are needed. 3.8 /proc//fdinfo/ - Information about opened file --------------------------------------------------------------- This file provides information associated with an opened file. The regular -files have at least five fields -- 'pos', 'flags', 'mnt_id', 'ino', and 'size'. +files have at least six fields -- 'pos', 'flags', 'mnt_id', 'ino', 'size', +and 'path'. The 'pos' represents the current offset of the opened file in decimal form [see lseek(2) for details], 'flags' denotes the octal O_xxx mask the file has been created with [see open(2) for details] and 'mnt_id' represents mount ID of the file system containing the opened file [see 3.5 /proc//mountinfo for details]. 'ino' represents the inode number of -the file, and 'size' represents the size of the file in bytes. +the file, 'size' represents the size of the file in bytes, and 'path' +represents the file path. A typical output is:: @@ -1902,6 +1904,7 @@ A typical output is:: mnt_id: 19 ino: 63107 size: 0 + path: /dev/null All locks associated with a file descriptor are shown in its fdinfo too:: @@ -1920,6 +1923,7 @@ Eventfd files mnt_id: 9 ino: 63107 size: 0 + path: anon_inode:[eventfd] eventfd-count: 5a where 'eventfd-count' is hex value of a counter. @@ -1934,6 +1938,7 @@ Signalfd files mnt_id: 9 ino: 63107 size: 0 + path: anon_inode:[signalfd] sigmask: 0000000000000200 where 'sigmask' is hex value of the signal mask associated @@ -1949,6 +1954,7 @@ Epoll files mnt_id: 9 ino: 63107 size: 0 + path: anon_inode:[eventpoll] tfd: 5 events: 1d data: ffffffffffffffff pos:0 ino:61af sdev:7 where 'tfd' is a target file descriptor number in decimal form, @@ -1968,6 +1974,7 @@ For inotify files the format is the following:: mnt_id: 9 ino: 63107 size: 0 + path: anon_inode:inotify inotify wd:3 ino:9e7e sdev:800013 mask:800afce ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:7e9e0000640d1b6d where 'wd' is a watch descriptor in decimal form, i.e. a target file @@ -1992,6 +1999,7 @@ For fanotify files the format is:: mnt_id: 9 ino: 63107 size: 0 + path: anon_inode:[fanotify] fanotify flags:10 event-flags:0 fanotify mnt_id:12 mflags:40 mask:38 ignored_mask:40000003 fanotify ino:4f969 sdev:800013 mflags:0 mask:3b ignored_mask:40000000 fhandle-bytes:8 fhandle-type:1 f_handle:69f90400c275b5b4 @@ -2018,6 +2026,7 @@ Timerfd files mnt_id: 9 ino: 63107 size: 0 + path: anon_inode:[timerfd] clockid: 0 ticks: 0 settime flags: 01 @@ -2042,6 +2051,7 @@ DMA Buffer files mnt_id: 9 ino: 63107 size: 32768 + path: /dmabuf: count: 2 exp_name: system-heap diff --git a/fs/proc/fd.c b/fs/proc/fd.c index 464bc3f55759..8889a8ba09d4 100644 --- a/fs/proc/fd.c +++ b/fs/proc/fd.c @@ -60,6 +60,10 @@ static int seq_show(struct seq_file *m, void *v) seq_printf(m, "ino:\t%lu\n", file_inode(file)->i_ino); seq_printf(m, "size:\t%lli\n", (long long)file_inode(file)->i_size); + seq_puts(m, "path:\t"); + seq_file_path(m, file, "\n"); + seq_putc(m, '\n'); + /* show_fd_locks() never deferences files so a stale value is safe */ show_fd_locks(m, file, files); if (seq_has_overflowed(m)) -- 2.36.1.255.ge46751e96f-goog