Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5832391rdb; Thu, 14 Dec 2023 00:12:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZEIMrL3bf5oLsQhPJBnTukYqWl46bzLx1UlAMD4U6lt+5v1yU63su083CgyY4dqNdIXYA X-Received: by 2002:a17:90a:aa09:b0:28a:f515:f7f7 with SMTP id k9-20020a17090aaa0900b0028af515f7f7mr1855585pjq.3.1702541569459; Thu, 14 Dec 2023 00:12:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702541569; cv=none; d=google.com; s=arc-20160816; b=hst5ly91xC5ML7I1zedsCdF69ER5HtafQiMzDwbRhEp0Lx3xzqj3pYHk+DdR+5VOo3 6+0AODMN4tGybs0cFK8DDrwrQZYxgn4Uvh0P8WQWaAncnAWgzzx5WBh92PQ2Bo/nM57A xp/GOlqN4IsRBelbT374I0PSd2r586umA220S7llpMcGFQqgH15eR3kztMbE/Pt8TRIZ tVM5pLjVLy1n7PHuTQDdELMbb+ukFPPAw+fgVxlTBe46EcRGo963wQ4rAWuPbo4FdWVz LSf1b8g57jik9UIxlnN2YrwRfr8lF3mHLtAoiPTq4loZqi06sNGA5tVaQcGOji7ZF5bf 8Tpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=IDWO5H07PkvnzHoBQ35J//pcV3Lsec9flrFu7/XK3f4=; fh=/4Y1fd/TtJ0SN9Ahj9OSvdxtfUVXtYBhthPT1qVN+jk=; b=xBHlVvkI6ZpCP7WczHwpAf2NZzPPEjIyayspQu4/HEsc2wdfNKzXPzZRe6VcljZDm2 QCaAR9XpM1zH6H0f140/vNh8p+BoAexBtlUpz8vALwduyYUpihLGGIW7noK3hp6ASIoE O/SD4wm9gG7QwgcRPzjgUfD0xlNIp4xvt3mGs37UlvnuXKgXDs2Z8On1ilQpnwqj4um7 +F0fQ7X1EgiN81y7INoNewAn4ToVp+FxdIQRD6HkhTr+J882ptPw3bRRHdLPLe/OIi+d lyGrDK2dW0JewjxH24PR+2gNJLywdknp3KvMNfeYWUMQBslTDha524Qnbi8p+Jn9prsS pJeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EL+Zgvh9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id l10-20020a17090a72ca00b0028b1041dd7esi281040pjk.26.2023.12.14.00.12.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 00:12:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EL+Zgvh9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 018B380DB738; Thu, 14 Dec 2023 00:12:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230064AbjLNIM1 (ORCPT + 99 others); Thu, 14 Dec 2023 03:12:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234342AbjLNILH (ORCPT ); Thu, 14 Dec 2023 03:11:07 -0500 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDFDEB9; Thu, 14 Dec 2023 00:11:13 -0800 (PST) Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-77f320ca2d5so30802085a.1; Thu, 14 Dec 2023 00:11:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702541473; x=1703146273; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IDWO5H07PkvnzHoBQ35J//pcV3Lsec9flrFu7/XK3f4=; b=EL+Zgvh9oRTPlbh0tdgBHcSFh0YbxS17LmE+Eh6fRIFmfpcejw7ln1qZAvBo7iM0XG vi0wyQIWNLrb1cuwrIbGAUaJGDfRpwOJj/MKSj7Q9BESeN3t/jupPYjOoNQhbpv0WNTV +Ij2sx+N0JVXvL9duCv7TazZar61sWaWrmEVFPW3ozWu3ZoKYgZDd6TDiNlJwHesVReR itC5vGAoJeoJhin7Gl+TpTgmEtcUwA63smyW8KCkIl3Ol8ks4GOK1bQFSrNAIpF34yBe mmwKPkqvPFfvn9IE65t62+AeRn2EAz0zylUaCu3ZrUepp5iIuMQ14O/MHxpCS8LW26iQ SQ2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702541473; x=1703146273; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IDWO5H07PkvnzHoBQ35J//pcV3Lsec9flrFu7/XK3f4=; b=itzSbSBMznHRD6ZqPnIr1FbmC2aJ2rOGi226Z9TUo/VTD+ijMz4arLd9QrjlfHcAgu lgNuL6NmjUUGgjxeNZQVsb0EP+betmh/eXukwXHDjsXTtIoDxf2UlvR21kZhxDyqITbp geHII2nQRoYzZT1mRX8WJ+xJy+s1L0zUvVnuCi46gv5jEwHi9wYH8gnRxv15XYB3jraw 3G4L/DlIYlQKdyJvROnF8kCcR8KN0E0MyJkllloKW0iC43HvNIlny8HXNtXnYMKvjZh1 zyPf23oEzRRLO2iB41LQExObCfx2i4GIMKoO3VmRX0nafYM1jZlpLC0Ouvpg1g/YUbp8 p1Qg== X-Gm-Message-State: AOJu0YyPQZpMa+8ekXyjMTLzhKKUuDkzHdL55yMLfxiBItw157huhYJG 4Lqynb31qXesAxo//0v8Y3rkNb+Dy2S+4sT/J3r7kmUKUUA= X-Received: by 2002:a05:620a:430e:b0:77d:5f96:720e with SMTP id u14-20020a05620a430e00b0077d5f96720emr15951323qko.15.1702541472735; Thu, 14 Dec 2023 00:11:12 -0800 (PST) MIME-Version: 1.0 References: <20231214064439.1023011-1-avagin@google.com> In-Reply-To: <20231214064439.1023011-1-avagin@google.com> From: Amir Goldstein Date: Thu, 14 Dec 2023 10:11:01 +0200 Message-ID: Subject: Re: [PATCH 1/2 v2] fs/proc: show correct device and inode numbers in /proc/pid/maps To: Andrei Vagin Cc: Andrew Morton , linux-kernel@vger.kernel.org, Alexander Mikhalitsyn , Christian Brauner , Alexander Viro , linux-fsdevel@vger.kernel.org, overlayfs , Miklos Szeredi Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Thu, 14 Dec 2023 00:12:42 -0800 (PST) On Thu, Dec 14, 2023 at 8:44=E2=80=AFAM Andrei Vagin wr= ote: > > /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. At least i_ino *should* always match st_ino for overlayfs non-dirs. If it doesn't, it is a bug. Reviewed-by: Amir Goldstein Thanks, Amir. > > 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_struc= t *vma) > const char *name =3D NULL; > > if (file) { > - struct inode *inode =3D file_inode(vma->vm_file); > + const struct inode *inode =3D file_user_inode(vma->vm_fil= e); > + > dev =3D inode->i_sb->s_dev; > ino =3D inode->i_ino; > pgoff =3D ((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 underly= ing > - * 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 disp= lay > - * to the user, which is the path of the fd that user has requested to m= ap. > + * 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 th= e fd > + * that user has requested to map and the inode number that would be ret= urned > + * 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 >