f2fs crypto: fix corrupted symlink in encrypted case
Subsystems (3)
Jaegeuk Kim
maintainerPATCH 1/8 f2fs crypto: fix corrupted symlink in encrypted case
commit c90e09f7fb498f81cd4e8bb6460d3a26ccebeca3 upstream.
In the encrypted symlink case, we should check its corrupted symname after decrypting it.
Otherwise, we can report -ENOENT incorrectly, if encrypted symname starts with '\0'.
--- fs/f2fs/namei.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
fs/f2fs/namei.c +6 -6
@@ -980,12 +980,6 @@ static const char *f2fs_encrypted_get_link(struct dentry *dentry, }memcpy (cstr.name, sd->encrypted_path, cstr.len); -/* this is broken symlink case */ -if (unlikely (cstr.name[0 ] ==0 )) { - res = -ENOENT ; - goto errout; - } -if ((cstr.len +sizeof (struct f2fs_encrypted_symlink_data ) -1 ) > max_size) {/* Symlink data on the disk is corrupted */
@@ -1002,6 +996,12 @@ static const char *f2fs_encrypted_get_link(struct dentry *dentry,kfree (cstr.name); +/* this is broken symlink case */ +if (unlikely (pstr.name[0 ] ==0 )) { + res = -ENOENT ; + goto errout; + } + paddr = pstr.name;/* Null-terminate the name */
Signature · 1 line
2.6.3
Jaegeuk Kim
maintainerPATCH 3/8 f2fs: cover large section in sanity check of super
commit fd694733d523df1e0a583cf5c4c08e41d7bf9fa3 upstream.
This patch fixes the bug which does not cover a large section case when checking the sanity of superblock.
If f2fs detects misalignment, it will fix the superblock during the mount time, so it doesn't need to trigger fsck.f2fs further.
--- fs/f2fs/super.c | 102 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 37 deletions(-)
fs/f2fs/super.c +65 -37
@@ -926,9 +926,25 @@ static loff_t max_file_blocks(void)return result; } +static int __f2fs_commit_super (struct buffer_head *bh, +struct f2fs_super_block *super) +{ +lock_buffer (bh); +if (super) +memcpy (bh->b_data +F2FS_SUPER_OFFSET , super,sizeof (*super)); +set_buffer_uptodate (bh); +set_buffer_dirty (bh); +unlock_buffer (bh); + +/* it's rare case, we can do fua all the time */ +return __sync_dirty_buffer (bh,WRITE_FLUSH_FUA ); +} +static inline bool sanity_check_area_boundary (struct super_block *sb, -struct f2fs_super_block *raw_super) +struct buffer_head *bh) { +struct f2fs_super_block *raw_super = (struct f2fs_super_block *) + (bh->b_data +F2FS_SUPER_OFFSET );u32 segment0_blkaddr =le32_to_cpu (raw_super->segment0_blkaddr);u32 cp_blkaddr =le32_to_cpu (raw_super->cp_blkaddr);u32 sit_blkaddr =le32_to_cpu (raw_super->sit_blkaddr);
@@ -942,6 +958,10 @@ static inline bool sanity_check_area_boundary(struct super_block *sb,u32 segment_count_main =le32_to_cpu (raw_super->segment_count_main);u32 segment_count =le32_to_cpu (raw_super->segment_count);u32 log_blocks_per_seg =le32_to_cpu (raw_super->log_blocks_per_seg); +u64 main_end_blkaddr = main_blkaddr + + (segment_count_main << log_blocks_per_seg); +u64 seg_end_blkaddr = segment0_blkaddr + + (segment_count << log_blocks_per_seg);if (segment0_blkaddr != cp_blkaddr) { f2fs_msg(sb, KERN_INFO,
@@ -986,22 +1006,45 @@ static inline bool sanity_check_area_boundary(struct super_block *sb,return true; } -if (main_blkaddr + (segment_count_main << log_blocks_per_seg) != - segment0_blkaddr + (segment_count << log_blocks_per_seg)) { +if (main_end_blkaddr > seg_end_blkaddr) {f2fs_msg (sb,KERN_INFO , -"Wrong MAIN_AREA boundary, start(%u) end(%u) blocks(%u)" , +"Wrong MAIN_AREA boundary, start(%u) end(%u) block(%u)" , main_blkaddr, - segment0_blkaddr + (segment_count << log_blocks_per_seg), + segment0_blkaddr + + (segment_count << log_blocks_per_seg), segment_count_main << log_blocks_per_seg);return true; + }else if (main_end_blkaddr < seg_end_blkaddr) { +int err =0 ; +char *res; + +/* fix in-memory information all the time */ + raw_super->segment_count =cpu_to_le32 ((main_end_blkaddr - + segment0_blkaddr) >> log_blocks_per_seg); + +if (f2fs_readonly (sb) ||bdev_read_only (sb->s_bdev)) { + res ="internally" ; + }else { + err =__f2fs_commit_super (bh,NULL ); + res = err ?"failed" :"done" ; + } +f2fs_msg (sb,KERN_INFO , +"Fix alignment : %s, start(%u) end(%u) block(%u)" , + res, main_blkaddr, + segment0_blkaddr + + (segment_count << log_blocks_per_seg), + segment_count_main << log_blocks_per_seg); +if (err) +return true; } -return false; }static int sanity_check_raw_super (struct super_block *sb, -struct f2fs_super_block *raw_super) +struct buffer_head *bh) { +struct f2fs_super_block *raw_super = (struct f2fs_super_block *) + (bh->b_data +F2FS_SUPER_OFFSET );unsigned int blocksize;if (F2FS_SUPER_MAGIC !=le32_to_cpu (raw_super->magic)) {
@@ -1068,7 +1111,7 @@ static int sanity_check_raw_super(struct super_block *sb, }/* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */ -if (sanity_check_area_boundary (sb, raw_super)) +if (sanity_check_area_boundary (sb, bh))return 1 ;return 0 ;
@@ -1144,7 +1187,7 @@ static int read_raw_super_block(struct super_block *sb, {int block;struct buffer_head *bh; -struct f2fs_super_block *super, *buf; +struct f2fs_super_block *super;int err =0 ; super =kzalloc (sizeof (struct f2fs_super_block ),GFP_KERNEL );
@@ -1160,11 +1203,8 @@ static int read_raw_super_block(struct super_block *sb,continue ; } - buf = (struct f2fs_super_block *) - (bh->b_data +F2FS_SUPER_OFFSET ); -/* sanity checking of raw super */ -if (sanity_check_raw_super (sb, buf)) { +if (sanity_check_raw_super (sb, bh)) {f2fs_msg (sb,KERN_ERR ,"Can't find valid F2FS filesystem in %dth superblock" , block +1 );
@@ -1174,7 +1214,8 @@ static int read_raw_super_block(struct super_block *sb, }if (!*raw_super) { -memcpy (super, buf,sizeof (*super)); +memcpy (super, bh->b_data +F2FS_SUPER_OFFSET , +sizeof (*super)); *valid_super_block = block; *raw_super = super; }
@@ -1194,42 +1235,29 @@ static int read_raw_super_block(struct super_block *sb,return err; } -static int __f2fs_commit_super (struct f2fs_sb_info *sbi,int block) +int f2fs_commit_super (struct f2fs_sb_info *sbi,bool recover) { -struct f2fs_super_block *super =F2FS_RAW_SUPER (sbi);struct buffer_head *bh;int err; - bh =sb_getblk (sbi->sb, block); +/* write back-up superblock first */ + bh =sb_getblk (sbi->sb, sbi->valid_super_block ?0 :1 );if (!bh)return -EIO ; - -lock_buffer (bh); -memcpy (bh->b_data +F2FS_SUPER_OFFSET , super,sizeof (*super)); -set_buffer_uptodate (bh); -set_buffer_dirty (bh); -unlock_buffer (bh); - -/* it's rare case, we can do fua all the time */ - err =__sync_dirty_buffer (bh,WRITE_FLUSH_FUA ); + err =__f2fs_commit_super (bh,F2FS_RAW_SUPER (sbi));brelse (bh); -return err; -} - -int f2fs_commit_super (struct f2fs_sb_info *sbi,bool recover) -{ -int err; - -/* write back-up superblock first */ - err =__f2fs_commit_super (sbi, sbi->valid_super_block ?0 :1 ); -/* if we are in recovery path, skip writing valid superblock */ if (recover || err)return err;/* write current valid superblock */ -return __f2fs_commit_super (sbi, sbi->valid_super_block); + bh =sb_getblk (sbi->sb, sbi->valid_super_block); +if (!bh) +return -EIO ; + err =__f2fs_commit_super (bh,F2FS_RAW_SUPER (sbi)); +brelse (bh); +return err; }static int f2fs_fill_super (struct super_block *sb,void *data,int silent)
Signature · 1 line
2.6.3
Jaegeuk Kim
maintainerPATCH 4/8 ext4/fscrypto: avoid RCU lookup in d_revalidate
In reply to Jaegeuk Kimcommit 03a8bb0e53d9562276045bdfcf2b5de2e4cff5a1 upstream.
As Al pointed, d_revalidate should return RCU lookup before using d_inode. This was originally introduced by:
commit 34286d666230 ("fs: rcu-walk aware d_revalidate method").
--- fs/ext4/crypto.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/ext4/crypto.c +4 -0
@@ -34,6 +34,7 @@#include <linux/random.h> #include <linux/scatterlist.h> #include <linux/spinlock_types.h> +#include <linux/namei.h> #include "ext4_extents.h" #include "xattr.h"
@@ -479,6 +480,9 @@ static int ext4_d_revalidate(struct dentry *dentry, unsigned int flags)struct ext4_crypt_info *ci;int dir_has_key, cached_with_key; +if (flags &LOOKUP_RCU ) +return -ECHILD ; + dir =dget_parent (dentry);if (!ext4_encrypted_inode (d_inode (dir))) {dput (dir);
Signature · 1 line
2.6.3