Skip to content

Commit 5a57bca

Browse files
zhangyi089tytso
authored andcommitted
ext4: fix reading leftover inlined symlinks
Since commit 6493792 ("ext4: convert symlink external data block mapping to bdev"), create new symlink with inline_data is not supported, but it missing to handle the leftover inlined symlinks, which could cause below error message and fail to read symlink. ls: cannot read symbolic link 'foo': Structure needs cleaning EXT4-fs error (device sda): ext4_map_blocks:605: inode #12: block 2021161080: comm ls: lblock 0 mapped to illegal pblock 2021161080 (length 1) Fix this regression by adding ext4_read_inline_link(), which read the inline data directly and convert it through a kmalloced buffer. Fixes: 6493792 ("ext4: convert symlink external data block mapping to bdev") Cc: [email protected] Reported-by: Torge Matthies <[email protected]> Signed-off-by: Zhang Yi <[email protected]> Tested-by: Torge Matthies <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 88084a3 commit 5a57bca

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

fs/ext4/ext4.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3583,6 +3583,7 @@ extern struct buffer_head *ext4_get_first_inline_block(struct inode *inode,
35833583
extern int ext4_inline_data_fiemap(struct inode *inode,
35843584
struct fiemap_extent_info *fieinfo,
35853585
int *has_inline, __u64 start, __u64 len);
3586+
extern void *ext4_read_inline_link(struct inode *inode);
35863587

35873588
struct iomap;
35883589
extern int ext4_inline_data_iomap(struct inode *inode, struct iomap *iomap);

fs/ext4/inline.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <linux/iomap.h>
88
#include <linux/fiemap.h>
9+
#include <linux/namei.h>
910
#include <linux/iversion.h>
1011
#include <linux/sched/mm.h>
1112

@@ -1588,6 +1589,35 @@ int ext4_read_inline_dir(struct file *file,
15881589
return ret;
15891590
}
15901591

1592+
void *ext4_read_inline_link(struct inode *inode)
1593+
{
1594+
struct ext4_iloc iloc;
1595+
int ret, inline_size;
1596+
void *link;
1597+
1598+
ret = ext4_get_inode_loc(inode, &iloc);
1599+
if (ret)
1600+
return ERR_PTR(ret);
1601+
1602+
ret = -ENOMEM;
1603+
inline_size = ext4_get_inline_size(inode);
1604+
link = kmalloc(inline_size + 1, GFP_NOFS);
1605+
if (!link)
1606+
goto out;
1607+
1608+
ret = ext4_read_inline_data(inode, link, inline_size, &iloc);
1609+
if (ret < 0) {
1610+
kfree(link);
1611+
goto out;
1612+
}
1613+
nd_terminate_link(link, inode->i_size, ret);
1614+
out:
1615+
if (ret < 0)
1616+
link = ERR_PTR(ret);
1617+
brelse(iloc.bh);
1618+
return link;
1619+
}
1620+
15911621
struct buffer_head *ext4_get_first_inline_block(struct inode *inode,
15921622
struct ext4_dir_entry_2 **parent_de,
15931623
int *retval)

fs/ext4/symlink.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ static const char *ext4_get_link(struct dentry *dentry, struct inode *inode,
7474
struct delayed_call *callback)
7575
{
7676
struct buffer_head *bh;
77+
char *inline_link;
78+
79+
/*
80+
* Create a new inlined symlink is not supported, just provide a
81+
* method to read the leftovers.
82+
*/
83+
if (ext4_has_inline_data(inode)) {
84+
if (!dentry)
85+
return ERR_PTR(-ECHILD);
86+
87+
inline_link = ext4_read_inline_link(inode);
88+
if (!IS_ERR(inline_link))
89+
set_delayed_call(callback, kfree_link, inline_link);
90+
return inline_link;
91+
}
7792

7893
if (!dentry) {
7994
bh = ext4_getblk(NULL, inode, 0, EXT4_GET_BLOCKS_CACHED_NOWAIT);

0 commit comments

Comments
 (0)