Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4857729rdb; Tue, 12 Dec 2023 11:09:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQyWogpBDFe2ocFiZZFnBx9x/nbRUdvbkAwBVr5WOLuMEaXWxvm1P60PoLKKqlEnCyNqu9 X-Received: by 2002:a17:902:ee4d:b0:1d0:bb51:d791 with SMTP id 13-20020a170902ee4d00b001d0bb51d791mr6777579plo.62.1702408151624; Tue, 12 Dec 2023 11:09:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702408151; cv=none; d=google.com; s=arc-20160816; b=r+SuTjcB+6YEEbLGWk/E2tjCvJzh5TN2XRlkHNKfYmd8xPg3AvDf4MMqCh2eawh29r qQmUNXxki8pDqh9g/T6+Xha5Iz5lpWijOrG2ZxACG93O0OWn0GILImgf0EMi6CB6ixk4 v4eU2CwpsXBxlvxcrwC4uoLsKPOjNGPFObEe0cKLcobCRql0x7V+GNNW6fe3lRZ0i5B/ rLti4G6jQXcZTBBbKfoSNz49U0zD+/uft/S2OyaT414Dj6e+XrqBuGsCgSp0bxhO35Ud kryHRko5L3w7JdhdxQiWupMWCBAuEzz3mEhSCS6aCTV0aa61ApP9EErv+Yj3PQZW8xU8 4zvQ== 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=7rUE7pKrnOIxQx5S7SZFNs2Wa5Tl3bUr3B6PiXYrTnM=; fh=SQV0VNsFQIOgptEXhLm29UK2ohITKNMfW9inaC2GKzo=; b=YfZgGd9Bbm6Dm8w1Kbto/SoK9MLfNGUsd+GTDZpMjPnBJAbfkPxkPlVMAXYQVSCc+l z1wh5vmkFG/HBwANDvlL4hArdbDGPlvrkc+z8RLJ5drrdHVZbJrkjTgzL9Y0h6wVgd4e azuAvUvt1rO+qsehevRd6MBs12OcKSmSt9HL44w0F2ESgdIpLrllfUylcWqLk+2+tyBd j9YFUDodJiOCWnAJl/qz0Ty7J7zo9+LnMlpFBaID/EInUhLy2H4VBGBKCtFodly1gNv6 gWV0zSXx4zMRw00QHbOmM43H3QKM3qWfGu0j33dqW/eWrz2ojKrg9DVa49Uu6YraAXp8 A9WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=khgiX6Kd; 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 h8-20020a170902704800b001cfa7f91403si8208297plt.183.2023.12.12.11.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 11:09:11 -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=khgiX6Kd; 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 70CBC8047786; Tue, 12 Dec 2023 11:09:10 -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 S1376866AbjLLTI6 (ORCPT + 99 others); Tue, 12 Dec 2023 14:08:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233112AbjLLTIy (ORCPT ); Tue, 12 Dec 2023 14:08:54 -0500 Received: from mail-oo1-xc2e.google.com (mail-oo1-xc2e.google.com [IPv6:2607:f8b0:4864:20::c2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B87AF3 for ; Tue, 12 Dec 2023 11:08:55 -0800 (PST) Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-58ceab7daddso2530330eaf.3 for ; Tue, 12 Dec 2023 11:08:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702408134; x=1703012934; 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=7rUE7pKrnOIxQx5S7SZFNs2Wa5Tl3bUr3B6PiXYrTnM=; b=khgiX6KdaR2dl70A9wTujsTNFxNvd/TtP1my5Gq15PciFa95vPilVAjKLoFotCeLG/ UmEeLqfUFdQz2SDyWiKujiMJAhx2maiGRA90h9JUUAN8hRSX0/1Hezq1I7+HN3fVUWHa dw3bNPPGfWQ/fa6A4jlBPGShZKResuEjIxmT91moxC7+R5H55+yWOfsoaQgJKE1DYJGA Iq69tNULJtuG5sd67BAZ6NpPoBvTPhkfOc3yviUQfaiPCb++ziADU3eRdNnzfAorPTTn VNdc7wuAy555E5YpyJWkbh5r/yunjGm4w3sv2EuwAfjkb3hoD8mI2Zsw6zJuIjxLWQTW u+kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702408134; x=1703012934; 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=7rUE7pKrnOIxQx5S7SZFNs2Wa5Tl3bUr3B6PiXYrTnM=; b=q9CUTigwmFn0NtaT26i50SVgjUkt1yDcV6DhnftyqdQoUdV0zyUD0n8qTyZUsDyzqi Vv4UNtxciJ4uFLxTozxEzhUe84AGFhVt7JgeY2LIM0fNMBZok7+viW6EOaFsvwLTaGxW cNaNHvfZWZKg06uvukZnAFv4l6EgbH8R5KjU3P0WKKTC2Pjjj45D08kT/3UUb+bGxtbf pqGiPQjFgbyRgVQKdEZQcT76AA1CuTruWl4oqtnhtLk95VWjPvOkoj5E5OW3qFI3D7/o NfemGiZT8/csLORnSJ20jXTqxOl6w4USkTtH+vSq77VAg+G/I4RB0JILdYAjt2CJ7SCp 0y8A== X-Gm-Message-State: AOJu0YwjTp5zb9uRXwdK/Siqe6hVbD4tXVu/P2pi/LED04XfB3zZu3h4 1YKcsnXhqGUWInSyy1r56Y3NLKw7WUzfGhxFr30o0DVLN7nzOujgOpdxYw== X-Received: by 2002:a05:6820:47:b0:590:8cbd:5b39 with SMTP id v7-20020a056820004700b005908cbd5b39mr4045345oob.15.1702408134126; Tue, 12 Dec 2023 11:08:54 -0800 (PST) MIME-Version: 1.0 References: <20231211193048.580691-1-avagin@google.com> In-Reply-To: From: Andrei Vagin Date: Tue, 12 Dec 2023 11:08:43 -0800 Message-ID: Subject: Re: [PATCH 1/2] fs/proc: show correct device and inode numbers in /proc/pid/maps To: Amir Goldstein Cc: Andrew Morton , linux-kernel@vger.kernel.org, Alexander Mikhalitsyn , Christian Brauner , linux-fsdevel , Miklos Szeredi , overlayfs Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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]); Tue, 12 Dec 2023 11:09:10 -0800 (PST) Hi Amir, On Mon, Dec 11, 2023 at 9:51=E2=80=AFPM Amir Goldstein = wrote: > > +fsdevel, +overlayfs, +brauner, +miklos > > On Mon, Dec 11, 2023 at 9:30=E2=80=AFPM Andrei Vagin = wrote: > > > > Device and inode numbers in /proc/pid/maps have to match numbers return= ed by > > statx for the same files. > > That statement may be true for regular files. > It is not true for block/char as far as I know. > > I think that your fix will break that by displaying the ino/dev > of the block/char reference inode and not their backing rdev inode. I think it doesn't break anything here. /proc/pid/maps shows dev of a filesystem where the device file resides. 7f336b6c3000-7f336b6c4000 rw-p 00000000 00:05 7 /dev/zero $ stat /dev/zero Device: 0,5 Inode: 7 Links: 1 Device type: 1,5 I checked that it works with and without my patch. It doesn't matter, look = at the following comments. > > > > > /proc/pid/maps shows device and inode numbers of vma->vm_file-s. Here i= s > > 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 i= n > > /proc/pid/maps. > > For the *same* trick, see my patch below. The patch looks good to me. Thanks! Will you send it? > > > > > But it isn't the end of this story. A file system can manipulate inode = numbers > > within the getattr callback (e.g., ovl_getattr), so vfs_getattr must be= used to > > get correct numbers. > > This explanation is inaccurate, because it mixes two different overlayfs > traits which are unrelated. > It is true that a filesystem *can* manipulate st_dev in a way that will n= ot > match i_ino and it is true that overlayfs may do that in some non-default > configurations (see [1]), but this is not the reason that you are seeing > mismatches ino/dev in /proc//maps. > > [1] https://docs.kernel.org/filesystems/overlayfs.html#inode-properties > > The reason is that the vma->vm_file is a special internal backing file > which is not otherwise exposed to userspace. > Please see my suggested fix below. I understand that this is the main root cause of issues that we have seen. But when I was preparing this patch, I found that ovl_getattr manipulates with inode numbers and decided that it can return a different inode number than file_user_inode(vma->vm_file).i_ino. I am glad that I was wrong and we don't need to use vfs_getattr here. > > > > > Cc: Amir Goldstein > > Cc: Alexander Mikhalitsyn > > Signed-off-by: Andrei Vagin > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > index ef2eb12906da..5328266be6b5 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); > + struct inode *inode =3D file_user_inode(vma->vm_file); > + > 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 900d0cd55b50..d78412c6fd47 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -2581,20 +2581,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 helper 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 path *file_user_inode(struct file *f) nit: struct inode * > +{ > + if (unlikely(f->f_mode & FMODE_BACKING)) > + return d_inode(backing_file_user_path(f)->dentry); > + return file_inode(f); > +} Thanks, Andrei