Skip to content

Commit ff3aea0

Browse files
Dave JohnsonLinus Torvalds
authored andcommitted
[PATCH] cramfs mounts provide corrupted content since 2.6.15
Fix handling of cramfs images created by util-linux containing empty regular files. Images created by cramfstools 1.x were ok. Fill out inode contents in cramfs_iget5_set() instead of get_cramfs_inode() to prevent issues if cramfs_iget5_test() is called with I_LOCK|I_NEW still set. Signed-off-by: Dave Johnson <djohnson+linux-kernel@sw.starentnetworks.com> Cc: Olaf Hering <olh@suse.de> Cc: Chris Mason <mason@suse.com> Cc: Andreas Gruenbacher <agruen@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 9888e6f commit ff3aea0

1 file changed

Lines changed: 29 additions & 31 deletions

File tree

‎fs/cramfs/inode.c‎

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static DECLARE_MUTEX(read_mutex);
3636

3737
/* These two macros may change in future, to provide better st_ino
3838
semantics. */
39-
#define CRAMINO(x) ((x)->offset?(x)->offset<<2:1)
39+
#define CRAMINO(x) (((x)->offset && (x)->size)?(x)->offset<<2:1)
4040
#define OFFSET(x) ((x)->i_ino)
4141

4242

@@ -66,8 +66,36 @@ static int cramfs_iget5_test(struct inode *inode, void *opaque)
6666

6767
static int cramfs_iget5_set(struct inode *inode, void *opaque)
6868
{
69+
static struct timespec zerotime;
6970
struct cramfs_inode *cramfs_inode = opaque;
71+
inode->i_mode = cramfs_inode->mode;
72+
inode->i_uid = cramfs_inode->uid;
73+
inode->i_size = cramfs_inode->size;
74+
inode->i_blocks = (cramfs_inode->size - 1) / 512 + 1;
75+
inode->i_blksize = PAGE_CACHE_SIZE;
76+
inode->i_gid = cramfs_inode->gid;
77+
/* Struct copy intentional */
78+
inode->i_mtime = inode->i_atime = inode->i_ctime = zerotime;
7079
inode->i_ino = CRAMINO(cramfs_inode);
80+
/* inode->i_nlink is left 1 - arguably wrong for directories,
81+
but it's the best we can do without reading the directory
82+
contents. 1 yields the right result in GNU find, even
83+
without -noleaf option. */
84+
if (S_ISREG(inode->i_mode)) {
85+
inode->i_fop = &generic_ro_fops;
86+
inode->i_data.a_ops = &cramfs_aops;
87+
} else if (S_ISDIR(inode->i_mode)) {
88+
inode->i_op = &cramfs_dir_inode_operations;
89+
inode->i_fop = &cramfs_directory_operations;
90+
} else if (S_ISLNK(inode->i_mode)) {
91+
inode->i_op = &page_symlink_inode_operations;
92+
inode->i_data.a_ops = &cramfs_aops;
93+
} else {
94+
inode->i_size = 0;
95+
inode->i_blocks = 0;
96+
init_special_inode(inode, inode->i_mode,
97+
old_decode_dev(cramfs_inode->size));
98+
}
7199
return 0;
72100
}
73101

@@ -77,37 +105,7 @@ static struct inode *get_cramfs_inode(struct super_block *sb,
77105
struct inode *inode = iget5_locked(sb, CRAMINO(cramfs_inode),
78106
cramfs_iget5_test, cramfs_iget5_set,
79107
cramfs_inode);
80-
static struct timespec zerotime;
81-
82108
if (inode && (inode->i_state & I_NEW)) {
83-
inode->i_mode = cramfs_inode->mode;
84-
inode->i_uid = cramfs_inode->uid;
85-
inode->i_size = cramfs_inode->size;
86-
inode->i_blocks = (cramfs_inode->size - 1) / 512 + 1;
87-
inode->i_blksize = PAGE_CACHE_SIZE;
88-
inode->i_gid = cramfs_inode->gid;
89-
/* Struct copy intentional */
90-
inode->i_mtime = inode->i_atime = inode->i_ctime = zerotime;
91-
inode->i_ino = CRAMINO(cramfs_inode);
92-
/* inode->i_nlink is left 1 - arguably wrong for directories,
93-
but it's the best we can do without reading the directory
94-
contents. 1 yields the right result in GNU find, even
95-
without -noleaf option. */
96-
if (S_ISREG(inode->i_mode)) {
97-
inode->i_fop = &generic_ro_fops;
98-
inode->i_data.a_ops = &cramfs_aops;
99-
} else if (S_ISDIR(inode->i_mode)) {
100-
inode->i_op = &cramfs_dir_inode_operations;
101-
inode->i_fop = &cramfs_directory_operations;
102-
} else if (S_ISLNK(inode->i_mode)) {
103-
inode->i_op = &page_symlink_inode_operations;
104-
inode->i_data.a_ops = &cramfs_aops;
105-
} else {
106-
inode->i_size = 0;
107-
inode->i_blocks = 0;
108-
init_special_inode(inode, inode->i_mode,
109-
old_decode_dev(cramfs_inode->size));
110-
}
111109
unlock_new_inode(inode);
112110
}
113111
return inode;

0 commit comments

Comments
 (0)