Skip to contentSkip to conversation

ovl: fix error for ovl_fill_super()

PATCH Applied Chengguang Xu 3 participants 3 messages Mar 1, 2021 – Mar 24, 2021 Overlay filesystem

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ovl: fix error for ovl_fill_super()

There are some places should return -EINVAL instead of -ENOMEM in ovl_fill_super(), so just fix it.

---
 fs/overlayfs/super.c | 2 ++
 1 file changed, 2 insertions(+)
fs/overlayfs/super.c +2 -0
index fdd72f1a9c5e..3dda1d530a43 100644
@@ -1984,6 +1984,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
 	if (numlower > OVL_MAX_STACK) {
 		pr_err("too many lower directories, limit is %d\n",
 		       OVL_MAX_STACK);
+		err = -EINVAL;
 		goto out_err;
 	}
 
@@ -2010,6 +2011,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
 	/* alloc/destroy_inode needed for setting up traps in inode cache */
 	sb->s_op = &ovl_super_operations;
 
+	err = -EINVAL;
 	if (ofs->config.upperdir) {
 		struct super_block *upper_sb;
 
Signature · 1 line
2.27.0
maintainer
#1 lore raw
Quoted 22 lines · Chengguang Xu

There are some places should return -EINVAL instead of -ENOMEM in ovl_fill_super(), so just fix it.

---
 fs/overlayfs/super.c | 2 ++
 1 file changed, 2 insertions(+)
fs/overlayfs/super.c +1 -0
index fdd72f1a9c5e..3dda1d530a43 100644
@@ -1984,6 +1984,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
        if (numlower > OVL_MAX_STACK) {
                pr_err("too many lower directories, limit is %d\n",
                       OVL_MAX_STACK);
+               err = -EINVAL;
                goto out_err;
        }
 

fs/overlayfs/super.c static int ovl_fill_super(struct super_block *sb, void *data, int silent) · line 2017

Quoted 7 lines
fs/overlayfs/super.c +1 -0
@@ -2010,6 +2011,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
        /* alloc/destroy_inode needed for setting up traps in inode cache */
        sb->s_op = &ovl_super_operations;
 
+       err = -EINVAL;
        if (ofs->config.upperdir) {
                struct super_block *upper_sb;
 

OK. But we are not really being consistent in the ways we set err in this function, which means we will have more of these bugs in the future (and we have had them in the past as well...)

So either set err = -EINVAL after every pr_err() in this function:
- "missing lowerdir"
- "too many lower dirs"
- "missing workdir"

Or always set err before the tests including err = -ENOMEM before allocating layers.

Mixing seems worse than either choice IMO.

Maybe Miklos has a better idea for tyding this up?

Thanks,
Amir.

maintainer Applied
#2 lore raw
Quoted 41 lines · Amir Goldstein
Quoted 22 lines · Chengguang Xu

There are some places should return -EINVAL instead of -ENOMEM in ovl_fill_super(), so just fix it.

---
 fs/overlayfs/super.c | 2 ++
 1 file changed, 2 insertions(+)
fs/overlayfs/super.c +1 -0
index fdd72f1a9c5e..3dda1d530a43 100644
@@ -1984,6 +1984,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
        if (numlower > OVL_MAX_STACK) {
                pr_err("too many lower directories, limit is %d\n",
                       OVL_MAX_STACK);
+               err = -EINVAL;
                goto out_err;
        }
 

fs/overlayfs/super.c static int ovl_fill_super(struct super_block *sb, void *data, int silent) · line 2017

Quoted 7 lines
fs/overlayfs/super.c +1 -0
@@ -2010,6 +2011,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
        /* alloc/destroy_inode needed for setting up traps in inode cache */
        sb->s_op = &ovl_super_operations;
 
+       err = -EINVAL;
        if (ofs->config.upperdir) {
                struct super_block *upper_sb;
 

OK. But we are not really being consistent in the ways we set err in this function, which means we will have more of these bugs in the future (and we have had them in the past as well...)

So either set err = -EINVAL after every pr_err() in this function:
- "missing lowerdir"
- "too many lower dirs"
- "missing workdir"

Quoted 6 lines

Or always set err before the tests including err = -ENOMEM before allocating layers.

Mixing seems worse than either choice IMO.

Maybe Miklos has a better idea for tyding this up?

Thanks, applied with consistency fixup.

Miklos