* [PATCH] fs: ntfs3: Fix a possible null-pointer dereference in ni_clear()
@ 2023-01-11 8:59 Jia-Ju Bai
2023-05-08 12:47 ` Konstantin Komarov
0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2023-01-11 8:59 UTC (permalink / raw)
To: almaz.alexandrovich; +Cc: ntfs3, linux-kernel, Jia-Ju Bai
In a previous commit c1006bd13146, ni->mi.mrec in ni_write_inode()
could be NULL, and thus a NULL check is added for this variable.
However, in the same call stack, ni->mi.mrec can be also dereferenced
in ni_clear():
ntfs_evict_inode(inode)
ni_write_inode(inode, ...)
ni = ntfs_i(inode);
is_rec_inuse(ni->mi.mrec) -> Add a NULL check by previous commit
ni_clear(ntfs_i(inode))
is_rec_inuse(ni->mi.mrec) -> No check
Thus, a possible null-pointer dereference may exist in ni_clear().
To fix it, a NULL check is added in this function.
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
---
fs/ntfs3/frecord.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c
index f1df52dfab74..046ec4179d75 100644
--- a/fs/ntfs3/frecord.c
+++ b/fs/ntfs3/frecord.c
@@ -102,7 +102,7 @@ void ni_clear(struct ntfs_inode *ni)
{
struct rb_node *node;
- if (!ni->vfs_inode.i_nlink && is_rec_inuse(ni->mi.mrec))
+ if (!ni->vfs_inode.i_nlink && ni->mi.mrec && is_rec_inuse(ni->mi.mrec))
ni_delete_all(ni);
al_destroy(ni);
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] fs: ntfs3: Fix a possible null-pointer dereference in ni_clear()
2023-01-11 8:59 [PATCH] fs: ntfs3: Fix a possible null-pointer dereference in ni_clear() Jia-Ju Bai
@ 2023-05-08 12:47 ` Konstantin Komarov
0 siblings, 0 replies; 2+ messages in thread
From: Konstantin Komarov @ 2023-05-08 12:47 UTC (permalink / raw)
To: Jia-Ju Bai; +Cc: ntfs3, linux-kernel
In a previous commit c1006bd13146, ni->mi.mrec in ni_write_inode()
> could be NULL, and thus a NULL check is added for this variable.
>
> However, in the same call stack, ni->mi.mrec can be also dereferenced
> in ni_clear():
>
> ntfs_evict_inode(inode)
> ni_write_inode(inode, ...)
> ni = ntfs_i(inode);
> is_rec_inuse(ni->mi.mrec) -> Add a NULL check by previous commit
> ni_clear(ntfs_i(inode))
> is_rec_inuse(ni->mi.mrec) -> No check
>
> Thus, a possible null-pointer dereference may exist in ni_clear().
> To fix it, a NULL check is added in this function.
>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
> ---
> fs/ntfs3/frecord.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c
> index f1df52dfab74..046ec4179d75 100644
> --- a/fs/ntfs3/frecord.c
> +++ b/fs/ntfs3/frecord.c
> @@ -102,7 +102,7 @@ void ni_clear(struct ntfs_inode *ni)
> {
> struct rb_node *node;
>
> - if (!ni->vfs_inode.i_nlink && is_rec_inuse(ni->mi.mrec))
> + if (!ni->vfs_inode.i_nlink && ni->mi.mrec && is_rec_inuse(ni->mi.mrec))
> ni_delete_all(ni);
>
> al_destroy(ni);
I apologize for the delayed response.
Thank you for your work, applied!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-05-08 12:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-11 8:59 [PATCH] fs: ntfs3: Fix a possible null-pointer dereference in ni_clear() Jia-Ju Bai
2023-05-08 12:47 ` Konstantin Komarov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).