All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] ext4: fix reading leftover inlined symlinks
  2022-06-30  9:01 [PATCH] ext4: fix reading leftover inlined symlinks Zhang Yi
@ 2022-06-30  8:51 ` Zhang Yi
  2022-07-03  8:02   ` Torge Matthies
  2022-07-08  3:19 ` Theodore Ts'o
  1 sibling, 1 reply; 4+ messages in thread
From: Zhang Yi @ 2022-06-30  8:51 UTC (permalink / raw)
  To: openglfreak; +Cc: tytso, adilger.kernel, jack, yukuai3, linux-ext4

Hi, Torge.

Please take a look at this patch and check could it solve your problem or not.

Thanks,
Yi.

On 2022/6/30 17:01, Zhang Yi wrote:
> Since commit 6493792d3299 ("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: 6493792d3299 ("ext4: convert symlink external data block mapping to bdev")
> Reported-by: Torge Matthies <openglfreak@googlemail.com>
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
> ---
>  fs/ext4/ext4.h    |  1 +
>  fs/ext4/inline.c  | 30 ++++++++++++++++++++++++++++++
>  fs/ext4/symlink.c | 15 +++++++++++++++
>  3 files changed, 46 insertions(+)
> 
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 75b8d81b2469..adfc30ee4b7b 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -3583,6 +3583,7 @@ extern struct buffer_head *ext4_get_first_inline_block(struct inode *inode,
>  extern int ext4_inline_data_fiemap(struct inode *inode,
>  				   struct fiemap_extent_info *fieinfo,
>  				   int *has_inline, __u64 start, __u64 len);
> +extern void *ext4_read_inline_link(struct inode *inode);
>  
>  struct iomap;
>  extern int ext4_inline_data_iomap(struct inode *inode, struct iomap *iomap);
> diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
> index cff52ff6549d..1fa36cbe09ec 100644
> --- a/fs/ext4/inline.c
> +++ b/fs/ext4/inline.c
> @@ -6,6 +6,7 @@
>  
>  #include <linux/iomap.h>
>  #include <linux/fiemap.h>
> +#include <linux/namei.h>
>  #include <linux/iversion.h>
>  #include <linux/sched/mm.h>
>  
> @@ -1588,6 +1589,35 @@ int ext4_read_inline_dir(struct file *file,
>  	return ret;
>  }
>  
> +void *ext4_read_inline_link(struct inode *inode)
> +{
> +	struct ext4_iloc iloc;
> +	int ret, inline_size;
> +	void *link;
> +
> +	ret = ext4_get_inode_loc(inode, &iloc);
> +	if (ret)
> +		return ERR_PTR(ret);
> +
> +	ret = -ENOMEM;
> +	inline_size = ext4_get_inline_size(inode);
> +	link = kmalloc(inline_size + 1, GFP_NOFS);
> +	if (!link)
> +		goto out;
> +
> +	ret = ext4_read_inline_data(inode, link, inline_size, &iloc);
> +	if (ret < 0) {
> +		kfree(link);
> +		goto out;
> +	}
> +	nd_terminate_link(link, inode->i_size, ret);
> +out:
> +	if (ret < 0)
> +		link = ERR_PTR(ret);
> +	brelse(iloc.bh);
> +	return link;
> +}
> +
>  struct buffer_head *ext4_get_first_inline_block(struct inode *inode,
>  					struct ext4_dir_entry_2 **parent_de,
>  					int *retval)
> diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c
> index d281f5bcc526..3d3ed3c38f56 100644
> --- a/fs/ext4/symlink.c
> +++ b/fs/ext4/symlink.c
> @@ -74,6 +74,21 @@ static const char *ext4_get_link(struct dentry *dentry, struct inode *inode,
>  				 struct delayed_call *callback)
>  {
>  	struct buffer_head *bh;
> +	char *inline_link;
> +
> +	/*
> +	 * Create a new inlined symlink is not supported, just provide a
> +	 * method to read the leftovers.
> +	 */
> +	if (ext4_has_inline_data(inode)) {
> +		if (!dentry)
> +			return ERR_PTR(-ECHILD);
> +
> +		inline_link = ext4_read_inline_link(inode);
> +		if (!IS_ERR(inline_link))
> +			set_delayed_call(callback, kfree_link, inline_link);
> +		return inline_link;
> +	}
>  
>  	if (!dentry) {
>  		bh = ext4_getblk(NULL, inode, 0, EXT4_GET_BLOCKS_CACHED_NOWAIT);
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] ext4: fix reading leftover inlined symlinks
@ 2022-06-30  9:01 Zhang Yi
  2022-06-30  8:51 ` Zhang Yi
  2022-07-08  3:19 ` Theodore Ts'o
  0 siblings, 2 replies; 4+ messages in thread
From: Zhang Yi @ 2022-06-30  9:01 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, adilger.kernel, jack, openglfreak, yi.zhang, yukuai3

Since commit 6493792d3299 ("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: 6493792d3299 ("ext4: convert symlink external data block mapping to bdev")
Reported-by: Torge Matthies <openglfreak@googlemail.com>
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
---
 fs/ext4/ext4.h    |  1 +
 fs/ext4/inline.c  | 30 ++++++++++++++++++++++++++++++
 fs/ext4/symlink.c | 15 +++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 75b8d81b2469..adfc30ee4b7b 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -3583,6 +3583,7 @@ extern struct buffer_head *ext4_get_first_inline_block(struct inode *inode,
 extern int ext4_inline_data_fiemap(struct inode *inode,
 				   struct fiemap_extent_info *fieinfo,
 				   int *has_inline, __u64 start, __u64 len);
+extern void *ext4_read_inline_link(struct inode *inode);
 
 struct iomap;
 extern int ext4_inline_data_iomap(struct inode *inode, struct iomap *iomap);
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index cff52ff6549d..1fa36cbe09ec 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -6,6 +6,7 @@
 
 #include <linux/iomap.h>
 #include <linux/fiemap.h>
+#include <linux/namei.h>
 #include <linux/iversion.h>
 #include <linux/sched/mm.h>
 
@@ -1588,6 +1589,35 @@ int ext4_read_inline_dir(struct file *file,
 	return ret;
 }
 
+void *ext4_read_inline_link(struct inode *inode)
+{
+	struct ext4_iloc iloc;
+	int ret, inline_size;
+	void *link;
+
+	ret = ext4_get_inode_loc(inode, &iloc);
+	if (ret)
+		return ERR_PTR(ret);
+
+	ret = -ENOMEM;
+	inline_size = ext4_get_inline_size(inode);
+	link = kmalloc(inline_size + 1, GFP_NOFS);
+	if (!link)
+		goto out;
+
+	ret = ext4_read_inline_data(inode, link, inline_size, &iloc);
+	if (ret < 0) {
+		kfree(link);
+		goto out;
+	}
+	nd_terminate_link(link, inode->i_size, ret);
+out:
+	if (ret < 0)
+		link = ERR_PTR(ret);
+	brelse(iloc.bh);
+	return link;
+}
+
 struct buffer_head *ext4_get_first_inline_block(struct inode *inode,
 					struct ext4_dir_entry_2 **parent_de,
 					int *retval)
diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c
index d281f5bcc526..3d3ed3c38f56 100644
--- a/fs/ext4/symlink.c
+++ b/fs/ext4/symlink.c
@@ -74,6 +74,21 @@ static const char *ext4_get_link(struct dentry *dentry, struct inode *inode,
 				 struct delayed_call *callback)
 {
 	struct buffer_head *bh;
+	char *inline_link;
+
+	/*
+	 * Create a new inlined symlink is not supported, just provide a
+	 * method to read the leftovers.
+	 */
+	if (ext4_has_inline_data(inode)) {
+		if (!dentry)
+			return ERR_PTR(-ECHILD);
+
+		inline_link = ext4_read_inline_link(inode);
+		if (!IS_ERR(inline_link))
+			set_delayed_call(callback, kfree_link, inline_link);
+		return inline_link;
+	}
 
 	if (!dentry) {
 		bh = ext4_getblk(NULL, inode, 0, EXT4_GET_BLOCKS_CACHED_NOWAIT);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ext4: fix reading leftover inlined symlinks
  2022-06-30  8:51 ` Zhang Yi
@ 2022-07-03  8:02   ` Torge Matthies
  0 siblings, 0 replies; 4+ messages in thread
From: Torge Matthies @ 2022-07-03  8:02 UTC (permalink / raw)
  To: Zhang Yi; +Cc: tytso, adilger.kernel, jack, yukuai3, linux-ext4

On Thu, 30 Jun 2022 at 10:51, Zhang Yi <yi.zhang@huawei.com> wrote:
>
> Hi, Torge.
>
> Please take a look at this patch and check could it solve your problem or not.
>
> Thanks,
> Yi.

Hello Yi,

Thank you for that patch, it does solve the problem on my system, and
has been stable for a few days.
So you can put my tested-by on the patch if you want:

Tested-by: Torge Matthies <openglfreak@googlemail.com>

-Torge

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ext4: fix reading leftover inlined symlinks
  2022-06-30  9:01 [PATCH] ext4: fix reading leftover inlined symlinks Zhang Yi
  2022-06-30  8:51 ` Zhang Yi
@ 2022-07-08  3:19 ` Theodore Ts'o
  1 sibling, 0 replies; 4+ messages in thread
From: Theodore Ts'o @ 2022-07-08  3:19 UTC (permalink / raw)
  To: yi.zhang, linux-ext4
  Cc: Theodore Ts'o, yukuai3, adilger.kernel, openglfreak, jack

On Thu, 30 Jun 2022 17:01:00 +0800, Zhang Yi wrote:
> Since commit 6493792d3299 ("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
> 
> [...]

Applied, thanks!

[1/1] ext4: fix reading leftover inlined symlinks
      commit: f50f5a5eac8092fb9b3365ca4b1d7407cdab8427

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-07-08  3:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30  9:01 [PATCH] ext4: fix reading leftover inlined symlinks Zhang Yi
2022-06-30  8:51 ` Zhang Yi
2022-07-03  8:02   ` Torge Matthies
2022-07-08  3:19 ` Theodore Ts'o

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.