From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH v2 4/5] ovl: verify lower root dir by file handle
Date: Thu, 1 Jun 2017 20:01:53 +0300 [thread overview]
Message-ID: <1496336514-11000-5-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1496336514-11000-1-git-send-email-amir73il@gmail.com>
With mount option 'verify_lower', verify that the file handle stored
in upper root dir matches the lower root dir or fail to mount.
If upper root dir has no stored file handle, encode and store the lower
root dir file handle in overlay.origin xattr.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/overlayfs/overlayfs.h | 5 ++++-
fs/overlayfs/super.c | 43 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index e65910ef215b..bf7e1d95e640 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -22,13 +22,16 @@ enum ovl_path_type {
enum ovl_verify_dir {
__OVL_VERIFY_MERGE = (1 << 0),
+ __OVL_VERIFY_ROOT = (1 << 1),
};
/* Verify on lookup of merge dir that lower matches origin fh stored in upper */
#define OVL_VERIFY_MERGE(v) ((v) & __OVL_VERIFY_MERGE)
+/* Verify on mount that lower root matches origin fh stored in upper root */
+#define OVL_VERIFY_ROOT(v) ((v) & __OVL_VERIFY_ROOT)
/* Verify flags for mount options 'verify_lower' */
-#define OVL_VERIFY_LOWER (__OVL_VERIFY_MERGE)
+#define OVL_VERIFY_LOWER (__OVL_VERIFY_MERGE | __OVL_VERIFY_ROOT)
#define OVL_XATTR_PREFIX XATTR_TRUSTED_PREFIX "overlay."
#define OVL_XATTR_OPAQUE OVL_XATTR_PREFIX "opaque"
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index b677d38bca5c..3d7b5c9bc042 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -413,6 +413,41 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config)
return 0;
}
+/*
+ * Verify that stored file handle in dir matches origin.
+ * If dir has no stored file handle, encode and store origin file handle.
+ */
+static int ovl_verify_set_origin(struct dentry *dir, struct vfsmount *mnt,
+ struct dentry *origin, const char *name)
+{
+ const struct ovl_fh *fh = NULL;
+ int err;
+
+ err = ovl_verify_origin(dir, mnt, origin);
+ if (!err)
+ return 0;
+
+ if (err != -ENODATA)
+ goto fail;
+
+ fh = ovl_encode_fh(origin);
+ err = PTR_ERR(fh);
+ if (IS_ERR(fh))
+ goto fail;
+ err = ovl_do_setxattr(dir, OVL_XATTR_ORIGIN, fh, fh->len, 0);
+ if (err)
+ goto fail;
+
+out:
+ kfree(fh);
+ return err;
+
+fail:
+ pr_err("overlayfs: failed to verify %s dir. (err=%i)\n",
+ name, err);
+ goto out;
+}
+
#define OVL_WORKDIR_NAME "work"
static struct dentry *ovl_workdir_create(struct vfsmount *mnt,
@@ -996,6 +1031,14 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
pr_err("overlayfs: option \"verify_lower\" not supported by lower fs.\n");
goto out_put_lower_mnt;
}
+ /* Verify lower root matches origin stored in upper */
+ if (i == 0 && OVL_VERIFY_ROOT(ufs->config.verify_dir)) {
+ err = ovl_verify_set_origin(upperpath.dentry,
+ mnt, mnt->mnt_root,
+ "lower root");
+ if (err)
+ goto out_put_lower_mnt;
+ }
}
}
--
2.7.4
next prev parent reply other threads:[~2017-06-01 17:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-01 17:01 [PATCH v2 0/5] overlayfs upperdir/workdir verifications Amir Goldstein
2017-06-01 17:01 ` [PATCH v2 1/5] vfs: introduce inode 'inuse' lock Amir Goldstein
2017-06-01 17:01 ` [PATCH v2 2/5] ovl: get exclusive ownership on upper/work dirs Amir Goldstein
2017-06-01 17:01 ` [PATCH v2 3/5] ovl: add support for verify_lower mount option Amir Goldstein
2017-06-01 17:01 ` Amir Goldstein [this message]
2017-06-01 17:01 ` [PATCH v2 5/5] ovl: document the 'verify_lower' feature Amir Goldstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1496336514-11000-5-git-send-email-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox