* [PATCH v2] ext4: fix error pointer dereference
@ 2020-04-23 7:46 Jeffle Xu
2020-04-23 8:42 ` Ritesh Harjani
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jeffle Xu @ 2020-04-23 7:46 UTC (permalink / raw)
To: tytso, jack; +Cc: linux-ext4, joseph.qi
Don't pass error pointers to brelse().
commit 7159a986b420 ("ext4: fix some error pointer dereferences") has fixed
some cases, fix the remaining one case.
Once ext4_xattr_block_find()->ext4_sb_bread() failed, error pointer is
stored in @bs->bh, which will be passed to brelse() in the cleanup
routine of ext4_xattr_set_handle(). This will then cause a NULL panic
crash in __brelse().
BUG: unable to handle kernel NULL pointer dereference at 000000000000005b
RIP: 0010:__brelse+0x1b/0x50
Call Trace:
ext4_xattr_set_handle+0x163/0x5d0
ext4_xattr_set+0x95/0x110
__vfs_setxattr+0x6b/0x80
__vfs_setxattr_noperm+0x68/0x1b0
vfs_setxattr+0xa0/0xb0
setxattr+0x12c/0x1a0
path_setxattr+0x8d/0xc0
__x64_sys_setxattr+0x27/0x30
do_syscall_64+0x60/0x250
entry_SYSCALL_64_after_hwframe+0x49/0xbe
In this case, @bs->bh stores '-EIO' actually.
Fixes: fb265c9cb49e ("ext4: add ext4_sb_bread() to disambiguate ENOMEM cases")
Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: stable@kernel.org # 2.6.19
---
fs/ext4/xattr.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 21df43a..01ba663 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -1800,8 +1800,11 @@ struct ext4_xattr_block_find {
if (EXT4_I(inode)->i_file_acl) {
/* The inode already has an extended attribute block. */
bs->bh = ext4_sb_bread(sb, EXT4_I(inode)->i_file_acl, REQ_PRIO);
- if (IS_ERR(bs->bh))
- return PTR_ERR(bs->bh);
+ if (IS_ERR(bs->bh)) {
+ error = PTR_ERR(bs->bh);
+ bs->bh = NULL;
+ return error;
+ }
ea_bdebug(bs->bh, "b_count=%d, refcount=%d",
atomic_read(&(bs->bh->b_count)),
le32_to_cpu(BHDR(bs->bh)->h_refcount));
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ext4: fix error pointer dereference
2020-04-23 7:46 [PATCH v2] ext4: fix error pointer dereference Jeffle Xu
@ 2020-04-23 8:42 ` Ritesh Harjani
2020-04-23 11:07 ` Jan Kara
2020-05-14 14:59 ` Theodore Y. Ts'o
2 siblings, 0 replies; 4+ messages in thread
From: Ritesh Harjani @ 2020-04-23 8:42 UTC (permalink / raw)
To: Jeffle Xu, tytso, jack; +Cc: linux-ext4, joseph.qi
On 4/23/20 1:16 PM, Jeffle Xu wrote:
> Don't pass error pointers to brelse().
>
> commit 7159a986b420 ("ext4: fix some error pointer dereferences") has fixed
> some cases, fix the remaining one case.
>
> Once ext4_xattr_block_find()->ext4_sb_bread() failed, error pointer is
> stored in @bs->bh, which will be passed to brelse() in the cleanup
> routine of ext4_xattr_set_handle(). This will then cause a NULL panic
> crash in __brelse().
>
> BUG: unable to handle kernel NULL pointer dereference at 000000000000005b
> RIP: 0010:__brelse+0x1b/0x50
> Call Trace:
> ext4_xattr_set_handle+0x163/0x5d0
> ext4_xattr_set+0x95/0x110
> __vfs_setxattr+0x6b/0x80
> __vfs_setxattr_noperm+0x68/0x1b0
> vfs_setxattr+0xa0/0xb0
> setxattr+0x12c/0x1a0
> path_setxattr+0x8d/0xc0
> __x64_sys_setxattr+0x27/0x30
> do_syscall_64+0x60/0x250
> entry_SYSCALL_64_after_hwframe+0x49/0xbe
>
> In this case, @bs->bh stores '-EIO' actually.
>
> Fixes: fb265c9cb49e ("ext4: add ext4_sb_bread() to disambiguate ENOMEM cases")
> Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> Cc: stable@kernel.org # 2.6.19
Thanks for your patch. Looks good to me.
Feel free to add:
Reviewed-by: Ritesh Harjani <riteshh@linux.ibm.com>
> ---
> fs/ext4/xattr.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
> index 21df43a..01ba663 100644
> --- a/fs/ext4/xattr.c
> +++ b/fs/ext4/xattr.c
> @@ -1800,8 +1800,11 @@ struct ext4_xattr_block_find {
> if (EXT4_I(inode)->i_file_acl) {
> /* The inode already has an extended attribute block. */
> bs->bh = ext4_sb_bread(sb, EXT4_I(inode)->i_file_acl, REQ_PRIO);
> - if (IS_ERR(bs->bh))
> - return PTR_ERR(bs->bh);
> + if (IS_ERR(bs->bh)) {
> + error = PTR_ERR(bs->bh);
> + bs->bh = NULL;
> + return error;
> + }
> ea_bdebug(bs->bh, "b_count=%d, refcount=%d",
> atomic_read(&(bs->bh->b_count)),
> le32_to_cpu(BHDR(bs->bh)->h_refcount));
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ext4: fix error pointer dereference
2020-04-23 7:46 [PATCH v2] ext4: fix error pointer dereference Jeffle Xu
2020-04-23 8:42 ` Ritesh Harjani
@ 2020-04-23 11:07 ` Jan Kara
2020-05-14 14:59 ` Theodore Y. Ts'o
2 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2020-04-23 11:07 UTC (permalink / raw)
To: Jeffle Xu; +Cc: tytso, jack, linux-ext4, joseph.qi
On Thu 23-04-20 15:46:44, Jeffle Xu wrote:
> Don't pass error pointers to brelse().
>
> commit 7159a986b420 ("ext4: fix some error pointer dereferences") has fixed
> some cases, fix the remaining one case.
>
> Once ext4_xattr_block_find()->ext4_sb_bread() failed, error pointer is
> stored in @bs->bh, which will be passed to brelse() in the cleanup
> routine of ext4_xattr_set_handle(). This will then cause a NULL panic
> crash in __brelse().
>
> BUG: unable to handle kernel NULL pointer dereference at 000000000000005b
> RIP: 0010:__brelse+0x1b/0x50
> Call Trace:
> ext4_xattr_set_handle+0x163/0x5d0
> ext4_xattr_set+0x95/0x110
> __vfs_setxattr+0x6b/0x80
> __vfs_setxattr_noperm+0x68/0x1b0
> vfs_setxattr+0xa0/0xb0
> setxattr+0x12c/0x1a0
> path_setxattr+0x8d/0xc0
> __x64_sys_setxattr+0x27/0x30
> do_syscall_64+0x60/0x250
> entry_SYSCALL_64_after_hwframe+0x49/0xbe
>
> In this case, @bs->bh stores '-EIO' actually.
>
> Fixes: fb265c9cb49e ("ext4: add ext4_sb_bread() to disambiguate ENOMEM cases")
> Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> Cc: stable@kernel.org # 2.6.19
Thanks for the patch! It looks good to me. You can add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/ext4/xattr.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
> index 21df43a..01ba663 100644
> --- a/fs/ext4/xattr.c
> +++ b/fs/ext4/xattr.c
> @@ -1800,8 +1800,11 @@ struct ext4_xattr_block_find {
> if (EXT4_I(inode)->i_file_acl) {
> /* The inode already has an extended attribute block. */
> bs->bh = ext4_sb_bread(sb, EXT4_I(inode)->i_file_acl, REQ_PRIO);
> - if (IS_ERR(bs->bh))
> - return PTR_ERR(bs->bh);
> + if (IS_ERR(bs->bh)) {
> + error = PTR_ERR(bs->bh);
> + bs->bh = NULL;
> + return error;
> + }
> ea_bdebug(bs->bh, "b_count=%d, refcount=%d",
> atomic_read(&(bs->bh->b_count)),
> le32_to_cpu(BHDR(bs->bh)->h_refcount));
> --
> 1.8.3.1
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ext4: fix error pointer dereference
2020-04-23 7:46 [PATCH v2] ext4: fix error pointer dereference Jeffle Xu
2020-04-23 8:42 ` Ritesh Harjani
2020-04-23 11:07 ` Jan Kara
@ 2020-05-14 14:59 ` Theodore Y. Ts'o
2 siblings, 0 replies; 4+ messages in thread
From: Theodore Y. Ts'o @ 2020-05-14 14:59 UTC (permalink / raw)
To: Jeffle Xu; +Cc: jack, linux-ext4, joseph.qi
On Thu, Apr 23, 2020 at 03:46:44PM +0800, Jeffle Xu wrote:
> Don't pass error pointers to brelse().
>
> commit 7159a986b420 ("ext4: fix some error pointer dereferences") has fixed
> some cases, fix the remaining one case.
>
> Once ext4_xattr_block_find()->ext4_sb_bread() failed, error pointer is
> stored in @bs->bh, which will be passed to brelse() in the cleanup
> routine of ext4_xattr_set_handle(). This will then cause a NULL panic
> crash in __brelse().
>
> BUG: unable to handle kernel NULL pointer dereference at 000000000000005b
> RIP: 0010:__brelse+0x1b/0x50
> Call Trace:
> ext4_xattr_set_handle+0x163/0x5d0
> ext4_xattr_set+0x95/0x110
> __vfs_setxattr+0x6b/0x80
> __vfs_setxattr_noperm+0x68/0x1b0
> vfs_setxattr+0xa0/0xb0
> setxattr+0x12c/0x1a0
> path_setxattr+0x8d/0xc0
> __x64_sys_setxattr+0x27/0x30
> do_syscall_64+0x60/0x250
> entry_SYSCALL_64_after_hwframe+0x49/0xbe
>
> In this case, @bs->bh stores '-EIO' actually.
>
> Fixes: fb265c9cb49e ("ext4: add ext4_sb_bread() to disambiguate ENOMEM cases")
> Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> Cc: stable@kernel.org # 2.6.19
> Reviewed-by: Ritesh Harjani <riteshh@linux.ibm.com>
> Reviewed-by: Jan Kara <jack@suse.cz>
Applied, thanks.
- Ted
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-05-14 14:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-23 7:46 [PATCH v2] ext4: fix error pointer dereference Jeffle Xu
2020-04-23 8:42 ` Ritesh Harjani
2020-04-23 11:07 ` Jan Kara
2020-05-14 14:59 ` Theodore Y. 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.