From: Christian Brauner <brauner@kernel.org>
To: Amir Goldstein <amir73il@gmail.com>, Miklos Szeredi <miklos@szeredi.hu>
Cc: linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org,
Christian Brauner <brauner@kernel.org>
Subject: [PATCH v3 1/3] ovl: check type and offset of struct vfsmount in ovl_entry
Date: Tue, 13 Jun 2023 16:49:16 +0200 [thread overview]
Message-ID: <20230605-fs-overlayfs-mount_api-v3-1-730d9646b27d@kernel.org> (raw)
In-Reply-To: <20230605-fs-overlayfs-mount_api-v3-0-730d9646b27d@kernel.org>
Porting overlayfs to the new amount api I started experiencing random
crashes that couldn't be explained easily. So after much debugging and
reasoning it became clear that struct ovl_entry requires the point to
struct vfsmount to be the first member and of type struct vfsmount.
During the port I added a new member at the beginning of struct
ovl_entry which broke all over the place in the form of random crashes
and cache corruptions. While there's a comment in ovl_free_fs() to the
effect of "Hack! Reuse ofs->layers as a vfsmount array before freeing
it" there's no such comment on struct ovl_entry which makes this easy to
trip over.
Add a comment and two static asserts for both the offset and the type of
pointer in struct ovl_entry.
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/overlayfs/ovl_entry.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h
index c6c7d09b494e..e5207c4bf5b8 100644
--- a/fs/overlayfs/ovl_entry.h
+++ b/fs/overlayfs/ovl_entry.h
@@ -32,6 +32,7 @@ struct ovl_sb {
};
struct ovl_layer {
+ /* ovl_free_fs() relies on @mnt being the first member! */
struct vfsmount *mnt;
/* Trap in ovl inode cache */
struct inode *trap;
@@ -42,6 +43,14 @@ struct ovl_layer {
int fsid;
};
+/*
+ * ovl_free_fs() relies on @mnt being the first member when unmounting
+ * the private mounts created for each layer. Let's check both the
+ * offset and type.
+ */
+static_assert(offsetof(struct ovl_layer, mnt) == 0);
+static_assert(__same_type(typeof_member(struct ovl_layer, mnt), struct vfsmount *));
+
struct ovl_path {
const struct ovl_layer *layer;
struct dentry *dentry;
--
2.34.1
next prev parent reply other threads:[~2023-06-13 14:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-13 14:49 [PATCH v3 0/3] ovl: port to new mount api & updated layer parsing Christian Brauner
2023-06-13 14:49 ` Christian Brauner [this message]
2023-06-13 14:49 ` [PATCH v3 2/3] ovl: port to new mount api Christian Brauner
2023-06-16 13:21 ` Amir Goldstein
2023-06-16 13:28 ` Christian Brauner
2023-06-16 13:37 ` Amir Goldstein
2023-06-16 14:03 ` Amir Goldstein
2023-06-13 14:49 ` [PATCH v3 3/3] ovl: change layer mount option handling Christian Brauner
2023-06-17 7:49 ` Amir Goldstein
2023-06-20 11:09 ` Amir Goldstein
2023-06-13 15:02 ` [PATCH v3 0/3] ovl: port to new mount api & updated layer parsing Amir Goldstein
2023-06-16 13:25 ` 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=20230605-fs-overlayfs-mount_api-v3-1-730d9646b27d@kernel.org \
--to=brauner@kernel.org \
--cc=amir73il@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
/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;
as well as URLs for NNTP newsgroup(s).