Skip to content

Commit f723edb

Browse files
brauneramir73il
authored andcommitted
ovl: check type and offset of struct vfsmount in ovl_entry
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> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
1 parent 42dd69a commit f723edb

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

fs/overlayfs/ovl_entry.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct ovl_sb {
3232
};
3333

3434
struct ovl_layer {
35+
/* ovl_free_fs() relies on @mnt being the first member! */
3536
struct vfsmount *mnt;
3637
/* Trap in ovl inode cache */
3738
struct inode *trap;
@@ -42,6 +43,14 @@ struct ovl_layer {
4243
int fsid;
4344
};
4445

46+
/*
47+
* ovl_free_fs() relies on @mnt being the first member when unmounting
48+
* the private mounts created for each layer. Let's check both the
49+
* offset and type.
50+
*/
51+
static_assert(offsetof(struct ovl_layer, mnt) == 0);
52+
static_assert(__same_type(typeof_member(struct ovl_layer, mnt), struct vfsmount *));
53+
4554
struct ovl_path {
4655
const struct ovl_layer *layer;
4756
struct dentry *dentry;

0 commit comments

Comments
 (0)