Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp462551ybh; Tue, 10 Mar 2020 02:06:14 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvYiy8blXFaE1cWYL84gXmB/rXLXhsT1Q8/fH7u7NCbwPtEX6D29oudDIv7b4UOYKn+pCEt X-Received: by 2002:a9d:336:: with SMTP id 51mr15995078otv.202.1583831174401; Tue, 10 Mar 2020 02:06:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583831174; cv=none; d=google.com; s=arc-20160816; b=nptrQaB1bberkBspXEwKMdRJAOtrBdMRC890T8WKWswE3I+5WDLjRxq4Se341nNb2+ bb8h7Vae6sBCE4p0ikDuts+W7WIpnDWUy08+3yZITs02PJGyufvZIDBvPw79bAepghOJ 9DF0obVvz4kJ16NpwN4lQodaKG4nlsHwJj4w6utI7XetLoDTK0yUBddaSdC6Khl7lTB1 tyMF7IaCv1lcjQPTCMdj3MoENR4Rr4lxVzvjihCv+7YHOiAwnWriDLjJ7qgbZBEV+7Wh OwR8rxauUju95Gs+wYvHRjpf8xJWDpYSsjAVGPZ2hx1J4Vbn9Rnlc3N+JvUMGZJUeZmc oVqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Xzr8UYzdvftZ6ltdGQbjJdh9bUR9GLrhRRIuy8ArwB4=; b=nJL6fyMWCNqj/6JNjqCTeYwNxBMq6GQvus8ifvPvyW/CfP7uWLUTm7FggirU21C/Wj hBDxSVCPUgAeyONt+9QMsfPRSTqB5S0TR//Wnp+Ig6GxCrDck6w+uGt+wFtXUO4KOgMY FEpLThlzx4VJ9ITbTEuQi7tCdVzjPbYGgAV22e/v2WUzRb4o9F0TsfPil2kGJYRTy3h/ aTXEMsLWzknES+aZJVVR4TEuQus8Zmwsm8zPdZimX4FqXonx9VAJEw1yfVImEzqIamKQ yRy4/MArv4d+4v+Wq9YnR3sOlOV5+S2VwQ0i3GFdMme67P5m32tGXk9ryFE1sYXiOgPn +D4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=RDyHe6m5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q126si5575570oia.8.2020.03.10.02.06.02; Tue, 10 Mar 2020 02:06:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=RDyHe6m5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726546AbgCJJEt (ORCPT + 99 others); Tue, 10 Mar 2020 05:04:49 -0400 Received: from mail-il1-f195.google.com ([209.85.166.195]:40068 "EHLO mail-il1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726463AbgCJJEt (ORCPT ); Tue, 10 Mar 2020 05:04:49 -0400 Received: by mail-il1-f195.google.com with SMTP id g6so11303940ilc.7 for ; Tue, 10 Mar 2020 02:04:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Xzr8UYzdvftZ6ltdGQbjJdh9bUR9GLrhRRIuy8ArwB4=; b=RDyHe6m5+q+Scf2Ni55JlRKzEtOHifAsDgt15eT2pTD2VUKeCE+KYgQtdZAmwFkarQ VKizaqkSXZl/ApSAqJqKTuW8HtJtha4X5WiTaSB8lHdNasnkHa7vIw1Pck0qfsUm0f9K 0TdOkgNWcVzOzIOjdNwjtzWumRcBSZHCrjOJs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Xzr8UYzdvftZ6ltdGQbjJdh9bUR9GLrhRRIuy8ArwB4=; b=Y/NkxFcuLN9rziyBraqIlLXJ0wJFlRZFdwrFKKNVutmt5JqzLpPW8uvcK8VY6MbiZY kEdb9a399jXvRkeEafIagwZl5VeTXXwL/4h+DdfF6O21fyH9mcOuMp4vBvrC58FhVEBZ DLlSLVhLIaUjUfJXfjznG9p7MXUvkt6FCYCnJgdJFpPXN8rYfPs1evJMcydWlpdApOkU IrxB+A4lDwdG5/ysZQMEI+XlAE3EIIVq0s5hjS15Pewj25q1KDtjHPZ8jzku8u4Gl+7M 07DhIgIzVYBICM7ACj1PEhAXAK68jSa5ShgfPyjiJMz2TfEezULuieULEQp+tvE3noDi D/TA== X-Gm-Message-State: ANhLgQ3yhjedTt2y24mqNMSzxji65R9TQV/yHGUkxgnKRXpl5tZLJWQy hfzgyh8VldwxyG3kQJss6zyNdLNVOGJqsSu0vmANkA== X-Received: by 2002:a05:6e02:f43:: with SMTP id y3mr19302685ilj.174.1583831088115; Tue, 10 Mar 2020 02:04:48 -0700 (PDT) MIME-Version: 1.0 References: <158376244589.344135.12925590041630631412.stgit@warthog.procyon.org.uk> <158376251286.344135.12815432977346939752.stgit@warthog.procyon.org.uk> In-Reply-To: <158376251286.344135.12815432977346939752.stgit@warthog.procyon.org.uk> From: Miklos Szeredi Date: Tue, 10 Mar 2020 10:04:36 +0100 Message-ID: Subject: Re: [PATCH 07/14] fsinfo: Allow mount information to be queried [ver #18] To: David Howells Cc: Linus Torvalds , Al Viro , Ian Kent , Miklos Szeredi , Christian Brauner , Jann Horn , "Darrick J. Wong" , Karel Zak , Jeff Layton , Linux API , linux-fsdevel@vger.kernel.org, LSM , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 9, 2020 at 3:02 PM David Howells wrote: > > Allow mount information, including information about the topology tree to > be queried with the fsinfo() system call. Setting AT_FSINFO_QUERY_MOUNT > allows overlapping mounts to be queried by indicating that the syscall > should interpet the pathname as a number indicating the mount ID. > > To this end, a number of fsinfo() attributes are provided: > > (1) FSINFO_ATTR_MOUNT_INFO. > > This is a structure providing information about a mount, including: > > - Mounted superblock ID (mount ID uniquifier). > - Mount ID (can be used with AT_FSINFO_QUERY_MOUNT). > - Parent mount ID. > - Mount attributes (eg. R/O, NOEXEC). > - Mount change/notification counter. > > Note that the parent mount ID is overridden to the ID of the queried > mount if the parent lies outside of the chroot or dfd tree. > > (2) FSINFO_ATTR_MOUNT_PATH. > > This a string providing information about a bind mount relative the > the root that was bound off, though it may get overridden by the > filesystem (NFS unconditionally sets it to "/", for example). > > (3) FSINFO_ATTR_MOUNT_POINT. > > This is a string indicating the name of the mountpoint within the > parent mount, limited to the parent's mounted root and the chroot. > > (4) FSINFO_ATTR_MOUNT_POINT_FULL. > > This is a string indicating the full path of the mountpoint, limited to > the chroot. > > (5) FSINFO_ATTR_MOUNT_CHILDREN. > > This produces an array of structures, one for each child and capped > with one for the argument mount (checked after listing all the > children). Each element contains the mount ID and the change counter > of the respective mount object. > > Signed-off-by: David Howells > --- > > fs/d_path.c | 2 > fs/fsinfo.c | 14 +++ > fs/internal.h | 10 ++ > fs/namespace.c | 177 +++++++++++++++++++++++++++++++++++++++++++ > include/uapi/linux/fsinfo.h | 36 +++++++++ > samples/vfs/test-fsinfo.c | 43 ++++++++++ > 6 files changed, 281 insertions(+), 1 deletion(-) > > diff --git a/fs/d_path.c b/fs/d_path.c > index 0f1fc1743302..4c203f64e45e 100644 > --- a/fs/d_path.c > +++ b/fs/d_path.c > @@ -229,7 +229,7 @@ static int prepend_unreachable(char **buffer, int *buflen) > return prepend(buffer, buflen, "(unreachable)", 13); > } > > -static void get_fs_root_rcu(struct fs_struct *fs, struct path *root) > +void get_fs_root_rcu(struct fs_struct *fs, struct path *root) > { > unsigned seq; > > diff --git a/fs/fsinfo.c b/fs/fsinfo.c > index bafeb73feaf4..6d2bc03998e4 100644 > --- a/fs/fsinfo.c > +++ b/fs/fsinfo.c > @@ -236,6 +236,14 @@ static int fsinfo_generic_seq_read(struct path *path, struct fsinfo_context *ctx > ret = sb->s_op->show_options(&m, path->mnt->mnt_root); > break; > > + case FSINFO_ATTR_MOUNT_PATH: > + if (sb->s_op->show_path) { > + ret = sb->s_op->show_path(&m, path->mnt->mnt_root); > + } else { > + seq_dentry(&m, path->mnt->mnt_root, " \t\n\\"); > + } > + break; > + > case FSINFO_ATTR_FS_STATISTICS: > if (sb->s_op->show_stats) > ret = sb->s_op->show_stats(&m, path->mnt->mnt_root); > @@ -270,6 +278,12 @@ static const struct fsinfo_attribute fsinfo_common_attributes[] = { > > FSINFO_LIST (FSINFO_ATTR_FSINFO_ATTRIBUTES, (void *)123UL), > FSINFO_VSTRUCT_N(FSINFO_ATTR_FSINFO_ATTRIBUTE_INFO, (void *)123UL), > + > + FSINFO_VSTRUCT (FSINFO_ATTR_MOUNT_INFO, fsinfo_generic_mount_info), > + FSINFO_STRING (FSINFO_ATTR_MOUNT_PATH, fsinfo_generic_seq_read), > + FSINFO_STRING (FSINFO_ATTR_MOUNT_POINT, fsinfo_generic_mount_point), > + FSINFO_STRING (FSINFO_ATTR_MOUNT_POINT_FULL, fsinfo_generic_mount_point_full), > + FSINFO_LIST (FSINFO_ATTR_MOUNT_CHILDREN, fsinfo_generic_mount_children), > {} > }; > > diff --git a/fs/internal.h b/fs/internal.h > index abbd5299e7dc..1a318dc85f2f 100644 > --- a/fs/internal.h > +++ b/fs/internal.h > @@ -15,6 +15,7 @@ struct mount; > struct shrink_control; > struct fs_context; > struct user_namespace; > +struct fsinfo_context; > > /* > * block_dev.c > @@ -47,6 +48,11 @@ extern int __block_write_begin_int(struct page *page, loff_t pos, unsigned len, > */ > extern void __init chrdev_init(void); > > +/* > + * d_path.c > + */ > +extern void get_fs_root_rcu(struct fs_struct *fs, struct path *root); > + > /* > * fs_context.c > */ > @@ -93,6 +99,10 @@ extern void __mnt_drop_write_file(struct file *); > extern void dissolve_on_fput(struct vfsmount *); > extern int lookup_mount_object(struct path *, int, struct path *); > extern int fsinfo_generic_mount_source(struct path *, struct fsinfo_context *); > +extern int fsinfo_generic_mount_info(struct path *, struct fsinfo_context *); > +extern int fsinfo_generic_mount_point(struct path *, struct fsinfo_context *); > +extern int fsinfo_generic_mount_point_full(struct path *, struct fsinfo_context *); > +extern int fsinfo_generic_mount_children(struct path *, struct fsinfo_context *); > > /* > * fs_struct.c > diff --git a/fs/namespace.c b/fs/namespace.c > index 54e8eb93fdd6..a6cb8c6b004f 100644 > --- a/fs/namespace.c > +++ b/fs/namespace.c > @@ -4149,4 +4149,181 @@ int lookup_mount_object(struct path *root, int mnt_id, struct path *_mntpt) > goto out_unlock; > } > > +/* > + * Retrieve information about the nominated mount. > + */ > +int fsinfo_generic_mount_info(struct path *path, struct fsinfo_context *ctx) > +{ > + struct fsinfo_mount_info *p = ctx->buffer; > + struct super_block *sb; > + struct mount *m; > + struct path root; > + unsigned int flags; > + > + m = real_mount(path->mnt); > + sb = m->mnt.mnt_sb; > + > + p->sb_unique_id = sb->s_unique_id; > + p->mnt_unique_id = m->mnt_unique_id; > + p->mnt_id = m->mnt_id; > + p->parent_id = m->mnt_parent->mnt_id; > + > + get_fs_root(current->fs, &root); > + if (path->mnt == root.mnt) { > + p->parent_id = p->mnt_id; > + } else { > + rcu_read_lock(); > + if (!are_paths_connected(&root, path)) > + p->parent_id = p->mnt_id; > + rcu_read_unlock(); > + } > + if (IS_MNT_SHARED(m)) > + p->group_id = m->mnt_group_id; > + if (IS_MNT_SLAVE(m)) { > + int master = m->mnt_master->mnt_group_id; > + int dom = get_dominating_id(m, &root); This isn't safe without namespace_sem or mount_lock. Thanks, Miklos