Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5799539rdb; Wed, 13 Dec 2023 22:44:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+hYuH3xoJ4nwh7Q1eJadxQG4U+bnkszz/o2SwaV0RESXmQYttQs4/LJz/pmW+ZCRW+KMA X-Received: by 2002:a05:6358:9497:b0:170:cb4d:7fc0 with SMTP id i23-20020a056358949700b00170cb4d7fc0mr10531355rwb.43.1702536291422; Wed, 13 Dec 2023 22:44:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702536291; cv=none; d=google.com; s=arc-20160816; b=F1JiwVQ4dG21TaafvqqXNHHULHKNgl+vjMJxYwynwPyyJqKWk/XEPfVOgjXDe9h59/ Np2vhM6Ewd09hVIKMsCQDexhsPHBQ0XQUb/5XdrkLJzGqdcEOpBJx4v3hkM1szNEy81s ViLfkjBwzE3SOPEkCee3u8sfoxMOlI5ZHCJTCghQz7BgnCgC2gjO3Dr3q4MDxvAPip2S jUMyKBd+EakmT6xqSfVUigq129daYNVIwHvtx2akrYDV1NzoUw16TiGb8/66PoFqXz8G +J/Hbn9BHqkBRO2TbanfxLzga6Zw11s43E1W2uLimgwTMZsQew9S8EVvnsmQvrZcCvUt 9O3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=Iko8D140eCOFohGA7VQkAes9lkzKAM1WQZ+wO/F/i90=; fh=TSdoqwQqcrmvAEoS85l302O8l0xhikz8mG620Q80Q8A=; b=cPPBw3sDjfJYEABrU34w1jOgxJaFyyqkOU6s39ACph/QZYOuHrA6VI6p36Iqq9IBDA dDsV1KBhal6FYLNMit/T8tFotuyEIw1PfzhmLtTbOGfRMxbW11k6xdexhOxk234/bpgZ 2q5P1d/yKIfYFww05riyRvtme8xhDwOZmAfaGgs4uR0mhhH6Ai89olJsK5XwtZUFYPDy 16T9uxjka+7d4C+0nKlBXf5hlSHfPSYbHnjtZvK4RvyvmHWE0vj/lHgeBfU36S7J1zX4 LGtOQUchVxJhYHT7G7fNnVZc/rG3wJuqJoc7sAlc3DGavIT95bnljmgTSHaKh7Qsft5Z r2jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="onHZnr5/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id mp5-20020a17090b190500b00286922ce5cdsi10849543pjb.108.2023.12.13.22.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 22:44:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="onHZnr5/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 59F188029DD2; Wed, 13 Dec 2023 22:44:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234275AbjLNGol (ORCPT + 99 others); Thu, 14 Dec 2023 01:44:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbjLNGok (ORCPT ); Thu, 14 Dec 2023 01:44:40 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED107B7 for ; Wed, 13 Dec 2023 22:44:45 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dbcb5eb96f7so3344672276.3 for ; Wed, 13 Dec 2023 22:44:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702536285; x=1703141085; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Iko8D140eCOFohGA7VQkAes9lkzKAM1WQZ+wO/F/i90=; b=onHZnr5/C76u4WAUhTwmVougnLzUmAv+9rDMgFylCd+MXirdjLsJk5w4yOzvVXOhvZ /g4AgkKjfdC4HOcRAfYmhcxNmGi3z1q/mYVKugEQoEdI+7cnCh7BmqUhiWcm8wpQTLcF GDT2D35fDRC7k+3WdpAsL9WLmtbgEHqanb6JgPQZ0sZ8+55pWZS6XUdLfH6ROB7cQfyd w0u++OgNvwHPTjjoX1OQjlA4bDe4H0Zmmhzgk29gtNea1O5l1h5dYZ1fvhwCxdBxmqn3 JjXg/r5fGVlmG2oXfsz1jwtMFdIAoJmAPCXVcBS8d18RwzjpOgr8RybW6a+nAXArzaXU kgRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702536285; x=1703141085; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Iko8D140eCOFohGA7VQkAes9lkzKAM1WQZ+wO/F/i90=; b=PSjI3iPWS5HV351SWicok4DB1QxY3wtBPy+w7Xta8y3KQmfOb1LTl0llZPckksSUVM o2IV9b1IPJZ0XcbLbInElH1XQJ44wxMA/8EqEkJB/x/h0V8VIqykTztdBCwz0+kBpj1f 1djSGneQ+2AUz7CptT1wEHBBcFksI+UgKb4y4Hg38kNl0Ds/IAeO0XfuzjnoOQ/pYmns uqbSVwLh8hlSKZy63dMULNJbo3G4Hh4vKa7vCPmZTqF8fNVx4ieBJoOX2JJDJI9ZliUs nJZ+lYc3vnPaB6x96AH3tkfffNVBFcoIOei97TVCtJ485s2lXm5VwC9hDHabNfk1RRER AFNA== X-Gm-Message-State: AOJu0YyUozgcOI2kVYmOT5zNJCz+CU3LRFEbvnI8EyQf2yDguZh3WOSz 1Fr7tN16NWlUGzyD55TdULpzOHkzyhk= X-Received: from avagin.kir.corp.google.com ([2620:0:1008:10:e986:a7c7:2814:c9a8]) (user=avagin job=sendgmr) by 2002:a25:2d2:0:b0:dbc:ca4d:4c1 with SMTP id 201-20020a2502d2000000b00dbcca4d04c1mr32671ybc.11.1702536285111; Wed, 13 Dec 2023 22:44:45 -0800 (PST) Date: Wed, 13 Dec 2023 22:44:38 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231214064439.1023011-1-avagin@google.com> Subject: [PATCH 1/2 v2] fs/proc: show correct device and inode numbers in /proc/pid/maps From: Andrei Vagin To: Andrew Morton , Amir Goldstein Cc: linux-kernel@vger.kernel.org, Alexander Mikhalitsyn , Christian Brauner , Alexander Viro , linux-fsdevel@vger.kernel.org, overlayfs , Miklos Szeredi , Andrei Vagin Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 13 Dec 2023 22:44:50 -0800 (PST) /proc/pid/maps shows device and inode numbers of vma->vm_file-s. Here is an issue. If a mapped file is on a stackable file system (e.g., overlayfs), vma->vm_file is a backing file whose f_inode is on the underlying filesystem. To show correct numbers, we need to get a user file and shows its numbers. The same trick is used to show file paths in /proc/pid/maps. Cc: Alexander Mikhalitsyn Suggested-by: Amir Goldstein Signed-off-by: Andrei Vagin --- v2: Amir explained that vfs_getattr isn't needed, because file_user_inode(vma->vm_file).i_ino always matches an inode number returned by statx. fs/proc/task_mmu.c | 3 ++- include/linux/fs.h | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 435b61054b5b..1801e409a061 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -273,7 +273,8 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma) const char *name = NULL; if (file) { - struct inode *inode = file_inode(vma->vm_file); + const struct inode *inode = file_user_inode(vma->vm_file); + dev = inode->i_sb->s_dev; ino = inode->i_ino; pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT; diff --git a/include/linux/fs.h b/include/linux/fs.h index 98b7a7a8c42e..838ccfc63323 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2523,20 +2523,28 @@ struct file *backing_file_open(const struct path *user_path, int flags, struct path *backing_file_user_path(struct file *f); /* - * file_user_path - get the path to display for memory mapped file - * * When mmapping a file on a stackable filesystem (e.g., overlayfs), the file * stored in ->vm_file is a backing file whose f_inode is on the underlying - * filesystem. When the mapped file path is displayed to user (e.g. via - * /proc//maps), this helper should be used to get the path to display - * to the user, which is the path of the fd that user has requested to map. + * filesystem. When the mapped file path and inode number are displayed to + * user (e.g. via /proc//maps), these helpers should be used to get the + * path and inode number to display to the user, which is the path of the fd + * that user has requested to map and the inode number that would be returned + * by fstat() on that same fd. */ +/* Get the path to display in /proc//maps */ static inline const struct path *file_user_path(struct file *f) { if (unlikely(f->f_mode & FMODE_BACKING)) return backing_file_user_path(f); return &f->f_path; } +/* Get the inode whose inode number to display in /proc//maps */ +static inline const struct inode *file_user_inode(struct file *f) +{ + if (unlikely(f->f_mode & FMODE_BACKING)) + return d_inode(backing_file_user_path(f)->dentry); + return file_inode(f); +} static inline struct file *file_clone_open(struct file *file) { -- 2.43.0.472.g3155946c3a-goog