Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4864086rdb; Tue, 12 Dec 2023 11:20:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPvLNxBqiR0MQYkTB8HY2E3NOxYGNFTP9unKN0uwam9TKCw3e4XmaDJVgEGfPL/G4QREDU X-Received: by 2002:a05:6e02:1785:b0:35f:6607:28b0 with SMTP id y5-20020a056e02178500b0035f660728b0mr1015501ilu.17.1702408812565; Tue, 12 Dec 2023 11:20:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702408812; cv=none; d=google.com; s=arc-20160816; b=EIlEeM3nhg0YLKJ8xR5KQachnsQoGTUQ29iK+fwcmaA5B/CU68hqQHFcM8MMO2aY3N 2vQKSJEuTeszfjrgf8gRUql4I2gJJjKXGpbOPWOGWDf8ld4VfNbRqVVuWNfk0C/HbABf 0Ii95KIzS73aas8Av4r5XwwIx0LnnMULxrKZs4Yd82pdCG9jFcxF+bN2wftwbbTxEG+V Za8nGEnW3Hl68dGxvzo/eOCVOAlxg+JVuvU3/bCniZbdBWJ1Y854cVF/q7/qksu5ba75 bfZ6aZ0f/F32XTLhvqCMO6llgkGJ8uFT9hPqKl+WhQRQJeTn4x85N4VDxg5hhQVZa1TI So4w== 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=fDZO9rUEaSCIKGPTNLQORxAuPrrJryJu9QjeOQcq1A4=; fh=GRuA9PSYY5K0lohSWB1Hw5uKMDgZUVctws2Hd+/YZDo=; b=fum4vaPpsGsbnDPSRRFheYNCqjTYC4P1rF9ezE59G/vUMWF81eVNAPxQh9x6V2S3L5 pC13tXUyiMThN0X/u0LC6jzRnobcrbQ3G/0Q2l2MuB8qkwj0WfCFVFz08lsn82QNw0Rx gPd/gkddQmumyRsifkZEAXgnnckLOvQJDdTzqrdPEjC8zzYF5/fXkBK5DjmaKYstx+bG ot+b9vV+POMjWNn287h6sGjH2zmosrhwk69mUbu6lSamkhWyJg9Gyv2RVw9MSMEjxMiy IoNGdN0eodbkOUEkQqDZX9M4f/xvUaU2vIYqbWZHMnmVWabtkkM2InPJhxotctEFgi60 ekKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ULRIiX7N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id b2-20020a63eb42000000b005be209ac7fesi8064913pgk.744.2023.12.12.11.20.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 11:20:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ULRIiX7N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 92291806B06B; Tue, 12 Dec 2023 11:20:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376975AbjLLTT4 (ORCPT + 99 others); Tue, 12 Dec 2023 14:19:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377195AbjLLTTz (ORCPT ); Tue, 12 Dec 2023 14:19:55 -0500 Received: from mail-oo1-xc29.google.com (mail-oo1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58E3EF2 for ; Tue, 12 Dec 2023 11:20:00 -0800 (PST) Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-590a2a963baso2391522eaf.2 for ; Tue, 12 Dec 2023 11:20:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702408799; x=1703013599; 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=fDZO9rUEaSCIKGPTNLQORxAuPrrJryJu9QjeOQcq1A4=; b=ULRIiX7NQXM5WPHI3stffAwtHpawpC++J7zI5HHwtWwZGetYluDUHaPZwz0/hg0gn8 2K2MK2IvA+P7jZGRS5uhbJ/tFXLg2Nkw9XOFNmgqIbmJe4CMBBFaowB9AOQ60dFCcB8q +CmEeFEtIcctb8A3ltc+uNotzk5BKlv9l8WACyONkuvQbZRIbfAb3ZZYlHKYXeXeBjZM NN1EtyRt434GQNQtkDlw6wGzVhKd1jjbVuT/Wi8gGWEuAhOVHrEpROmgGt9vDaOpciEL 5ZHMygSMGAE3wGLqNgsIQwT/OeJ7dd8An0XYfRPFTP3WN50b58RVTmWUMbVb6f8a8Cmt bKcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702408799; x=1703013599; 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=fDZO9rUEaSCIKGPTNLQORxAuPrrJryJu9QjeOQcq1A4=; b=boyiBo+jd5dOqL3hwve/xuDIQ1C/kQqhElsHouebBZ67S1K4h/mATxflQRw1mhkPX9 A8OIceMWvd8Ny77amhA3/yzEVc68JSv54Y8oABlZZbEOHLHaKDxB7KEcdxhUkFhB/twB 2HB1+z/BcN9rANDFbs+lOIWF5zmX6Zgaxw9r9RRvN7O27QQiEJdV3mF7flvh2aB1Hg4U +du9Mq62nkh8GnDtXc5QU2z+s4XH+CqZbvCXYBD0V/KWYJ2eDVszK57399F1c0Nwc1bI jBj8mJehFd51BIByEvSaKmUdu4lZpy8witBp5xegR+g+dDHQjVGoKqGjASLuqTVcHypF 87Lg== X-Gm-Message-State: AOJu0YxGOc7+Jsi6eJ9pHozvTZ0RY34fGrCvfKylpQfSxBbMSDqndry7 DFJtGVkOrfpl7pTdMcV706AYvjirwsNfYQJriBMToA== X-Received: by 2002:a4a:1d86:0:b0:58e:1c47:879b with SMTP id 128-20020a4a1d86000000b0058e1c47879bmr4535569oog.16.1702408799400; Tue, 12 Dec 2023 11:19:59 -0800 (PST) MIME-Version: 1.0 References: <20231211193048.580691-1-avagin@google.com> <20231212-brokkoli-trinken-1581d1e99d6a@brauner> In-Reply-To: <20231212-brokkoli-trinken-1581d1e99d6a@brauner> From: Andrei Vagin Date: Tue, 12 Dec 2023 11:19:48 -0800 Message-ID: Subject: Re: [PATCH 1/2] fs/proc: show correct device and inode numbers in /proc/pid/maps To: Christian Brauner Cc: Amir Goldstein , Andrew Morton , linux-kernel@vger.kernel.org, Alexander Mikhalitsyn , linux-fsdevel , Miklos Szeredi , overlayfs Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Tue, 12 Dec 2023 11:20:09 -0800 (PST) On Tue, Dec 12, 2023 at 1:27=E2=80=AFAM Christian Brauner wrote: > > On Tue, Dec 12, 2023 at 07:51:31AM +0200, 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 retu= rned 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. > > > > > > > > /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. > > > > For the *same* trick, see my patch below. > > > > > > > > But it isn't the end of this story. A file system can manipulate inod= e 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 overlayf= s > > traits which are unrelated. > > It is true that a filesystem *can* manipulate st_dev in a way that will= not > > match i_ino and it is true that overlayfs may do that in some non-defau= lt > > configurations (see [1]), but this is not the reason that you are seein= g > > 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. > > > > > > > > Cc: Amir Goldstein > > > Cc: Alexander Mikhalitsyn > > > Signed-off-by: Andrei Vagin > > > --- > > > fs/proc/task_mmu.c | 20 +++++++++++++++++--- > > > 1 file changed, 17 insertions(+), 3 deletions(-) > > > > > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > > > index 435b61054b5b..abbf96c091ad 100644 > > > --- a/fs/proc/task_mmu.c > > > +++ b/fs/proc/task_mmu.c > > > @@ -273,9 +273,23 @@ show_map_vma(struct seq_file *m, struct vm_area_= struct *vma) > > > const char *name =3D NULL; > > > > > > if (file) { > > > - struct inode *inode =3D file_inode(vma->vm_file); > > > - dev =3D inode->i_sb->s_dev; > > > - ino =3D inode->i_ino; > > > + const struct path *path; > > > + struct kstat stat; > > > + > > > + path =3D file_user_path(file); > > > + /* > > > + * A file system can manipulate inode numbers within = the > > > + * getattr callback (e.g. ovl_getattr). > > > + */ > > > + if (!vfs_getattr_nosec(path, &stat, STATX_INO, AT_STA= TX_DONT_SYNC)) { > > > > Should you prefer to keep this solution it should be constrained to > > regular files. > > It's also very dicy calling into the filesystem from procfs. You might > hang the system if you end up talking to a hung NFS server or something. > What locks does show_map_vma() hold? And is it safe to call helpers that > might generate io? I had the same thoughts when I was thinking about whether it is safe to use it here or not. Then I found AT_STATX_DONT_SYNC (don't sync attributes with the server) and decided that it should be safe. Anyway, Amir explains that vfs_getattr_nosec isn't needed for overlay files. Thanks, Andrei