Skip to contentSkip to conversation

autofs: Add BUG_ON(1) for non dir/link inode case

PATCH Superseded Tomohiro Kusumi 3 participants 5 messages Jul 3, 2016 – Jul 4, 2016 Kernel automounter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 autofs: Add BUG_ON(1) for non dir/link inode case

It's invalid if the given mode is neither dir nor link, so don't let it fallthrough on else case.

---
 fs/autofs4/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/autofs4/inode.c +3 -1
index ad0ee93..7f35c82 100644
@@ -305,6 +305,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
 	if (autofs_type_trigger(sbi->type))
 		__managed_dentry_set_managed(root);
 
+	BUG_ON(!root_inode->i_fop || !root_inode->i_op);
 	root_inode->i_fop = &autofs4_root_operations;
 	root_inode->i_op = &autofs4_dir_inode_operations;
 
@@ -368,7 +369,8 @@ struct inode *autofs4_get_inode(struct super_block *sb, umode_t mode)
 		inode->i_fop = &autofs4_dir_operations;
 	} else if (S_ISLNK(mode)) {
 		inode->i_op = &autofs4_symlink_inode_operations;
-	}
+	} else
+		BUG_ON(1);
 
 	return inode;
 }
Signature · 4 lines
2.5.5

--
To unsubscribe from this list: send the line "unsubscribe autofs" in
#1 lore raw
Quoted 2 lines · Tomohiro Kusumi

It's invalid if the given mode is neither dir nor link, so don't let it fallthrough on else case.

Is this case really worth crashing the entire system?

Wouldn't a WARN_ON + return -EINVAL be sufficient? At the very least it means that a developer doesn't need to reboot to reload the module if they hit this.

-Jeff

Quoted 28 lines
---
 fs/autofs4/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/autofs4/inode.c +3 -1
index ad0ee93..7f35c82 100644
@@ -305,6 +305,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
 	if (autofs_type_trigger(sbi->type))
 		__managed_dentry_set_managed(root);
 
+	BUG_ON(!root_inode->i_fop || !root_inode->i_op);
 	root_inode->i_fop = &autofs4_root_operations;
 	root_inode->i_op = &autofs4_dir_inode_operations;
 
@@ -368,7 +369,8 @@ struct inode *autofs4_get_inode(struct super_block *sb, umode_t mode)
 		inode->i_fop = &autofs4_dir_operations;
 	} else if (S_ISLNK(mode)) {
 		inode->i_op = &autofs4_symlink_inode_operations;
-	}
+	} else
+		BUG_ON(1);
 
 	return inode;
 }
Signature · 2 lines
Jeff Mahoney
SUSE Labs
maintainer
#2 lore raw
Quoted 9 lines · Jeff Mahoney
Quoted 2 lines · Tomohiro Kusumi

It's invalid if the given mode is neither dir nor link, so don't let it fallthrough on else case.

Is this case really worth crashing the entire system?

Wouldn't a WARN_ON + return -EINVAL be sufficient? At the very least it means that a developer doesn't need to reboot to reload the module if they hit this.

That error return should be sufficient to cover this case and the WARN_ON() is useful too.

And while there is some justification for the BUG_ON() earlier I also think an E INVAL return would be more sensible there too.

BUG()ing on errors that should be handled is really bad IMHO.

Quoted 30 lines

-Jeff

Quoted 27 lines
---
 fs/autofs4/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/autofs4/inode.c +3 -1
index ad0ee93..7f35c82 100644
@@ -305,6 +305,7 @@ int autofs4_fill_super(struct super_block *s, void
 *data, int silent)
 	if (autofs_type_trigger(sbi->type))
 		__managed_dentry_set_managed(root);
 
+	BUG_ON(!root_inode->i_fop || !root_inode->i_op);
 	root_inode->i_fop = &autofs4_root_operations;
 	root_inode->i_op = &autofs4_dir_inode_operations;
@@ -368,7 +369,8 @@ struct inode *autofs4_get_inode(struct super_block *sb,
 umode_t mode)
 		inode->i_fop = &autofs4_dir_operations;
 	} else if (S_ISLNK(mode)) {
 		inode->i_op = &autofs4_symlink_inode_operations;
-	}
+	} else
+		BUG_ON(1);
 
Quoted 5 lines
Quoted 3 lines
fs/autofs4/inode.c +0 -0
 	return inode;

}

--
To unsubscribe from this list: send the line "unsubscribe autofs" in

#3 lore raw

Thanks for your review.
I've submitted the v2 patch which only changed BUG_ON to WARN_ON.

I didn't use a return value of EINVAL as this function returns a pointer. (and I didn't want to return EINVAL casted to a pointer)

2016-07-04 11:24 GMT+09:00 Ian Kent <[email protected]>:

Quoted 11 lines · Jeff Mahoney
Quoted 9 lines · Tomohiro Kusumi
Quoted 2 lines

It's invalid if the given mode is neither dir nor link, so don't let it fallthrough on else case.

Is this case really worth crashing the entire system?

Wouldn't a WARN_ON + return -EINVAL be sufficient? At the very least it means that a developer doesn't need to reboot to reload the module if they hit this.

Quoted 43 lines

That error return should be sufficient to cover this case and the WARN_ON() is useful too.

And while there is some justification for the BUG_ON() earlier I also think an E INVAL return would be more sensible there too.

BUG()ing on errors that should be handled is really bad IMHO.

Quoted 35 lines

-Jeff

Quoted 30 lines
---
 fs/autofs4/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/autofs4/inode.c +3 -1
index ad0ee93..7f35c82 100644
@@ -305,6 +305,7 @@ int autofs4_fill_super(struct super_block *s, void
 *data, int silent)
    if (autofs_type_trigger(sbi->type))
            __managed_dentry_set_managed(root);
 
+   BUG_ON(!root_inode->i_fop || !root_inode->i_op);
    root_inode->i_fop = &autofs4_root_operations;
    root_inode->i_op = &autofs4_dir_inode_operations;
@@ -368,7 +369,8 @@ struct inode *autofs4_get_inode(struct super_block *sb,
 umode_t mode)
            inode->i_fop = &autofs4_dir_operations;
    } else if (S_ISLNK(mode)) {
            inode->i_op = &autofs4_symlink_inode_operations;
-   }
+   } else
+           BUG_ON(1);
 
    return inode;

}

--
To unsubscribe from this list: send the line "unsubscribe autofs" in

maintainer
#4 lore raw
Quoted 2 lines · Tomohiro Kusumi

Thanks for your review.
I've submitted the v2 patch which only changed BUG_ON to WARN_ON.

Yep, it's always called internally and should return something close to sensible on error.

The case really shouldn't happen so a WARN_ON() is the better way to handle this.

Quoted 62 lines

I didn't use a return value of EINVAL as this function returns a pointer. (and I didn't want to return EINVAL casted to a pointer)

2016-07-04 11:24 GMT+09:00 Ian Kent <[email protected]>:

Quoted 57 lines · Jeff Mahoney
Quoted 9 lines · Tomohiro Kusumi
Quoted 2 lines

It's invalid if the given mode is neither dir nor link, so don't let it fallthrough on else case.

Is this case really worth crashing the entire system?

Wouldn't a WARN_ON + return -EINVAL be sufficient? At the very least it means that a developer doesn't need to reboot to reload the module if they hit this.

That error return should be sufficient to cover this case and the WARN_ON() is
useful too.

And while there is some justification for the BUG_ON() earlier I also think an E
INVAL return would be more sensible there too.

BUG()ing on errors that should be handled is really bad IMHO.

Quoted 36 lines

-Jeff

Quoted 31 lines
---
 fs/autofs4/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/autofs4/inode.c +3 -1
index ad0ee93..7f35c82 100644
@@ -305,6 +305,7 @@ int autofs4_fill_super(struct super_block *s, void
 *data, int silent)
    if (autofs_type_trigger(sbi->type))
            __managed_dentry_set_managed(root);
 
+   BUG_ON(!root_inode->i_fop || !root_inode->i_op);
    root_inode->i_fop = &autofs4_root_operations;
    root_inode->i_op = &autofs4_dir_inode_operations;
@@ -368,7 +369,8 @@ struct inode *autofs4_get_inode(struct super_block
 *sb,
 umode_t mode)
            inode->i_fop = &autofs4_dir_operations;
    } else if (S_ISLNK(mode)) {
            inode->i_op = &autofs4_symlink_inode_operations;
-   }
+   } else
+           BUG_ON(1);
 
    return inode;

}

--
To unsubscribe from this list: send the line "unsubscribe autofs" in