* [PATCH 1/3] fs: ocfs2: Fix possible null-pointer dereferences in ocfs2_xa_prepare_entry()
@ 2019-07-26 3:36 Jia-Ju Bai
2019-07-26 9:37 ` Joseph Qi
0 siblings, 1 reply; 3+ messages in thread
From: Jia-Ju Bai @ 2019-07-26 3:36 UTC (permalink / raw)
To: mark, jlbec, joseph.qi; +Cc: ocfs2-devel, linux-kernel, Jia-Ju Bai
In ocfs2_xa_prepare_entry(), there is an if statement on line 2136 to
check whether loc->xl_entry is NULL:
if (loc->xl_entry)
When loc->xl_entry is NULL, it is used on line 2158:
ocfs2_xa_add_entry(loc, name_hash);
loc->xl_entry->xe_name_hash = cpu_to_le32(name_hash);
loc->xl_entry->xe_name_offset = cpu_to_le16(loc->xl_size);
and line 2164:
ocfs2_xa_add_namevalue(loc, xi);
loc->xl_entry->xe_value_size = cpu_to_le64(xi->xi_value_len);
loc->xl_entry->xe_name_len = xi->xi_name_len;
Thus, possible null-pointer dereferences may occur.
To fix these bugs, if loc-xl_entry is NULL, ocfs2_xa_prepare_entry()
abnormally returns with -EINVAL.
These bugs are found by a static analysis tool STCheck written by us.
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
fs/ocfs2/xattr.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 385f3aaa2448..f690502daf3c 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -2154,8 +2154,10 @@ static int ocfs2_xa_prepare_entry(struct ocfs2_xa_loc *loc,
}
}
ocfs2_xa_wipe_namevalue(loc);
- } else
- ocfs2_xa_add_entry(loc, name_hash);
+ } else {
+ rc = -EINVAL;
+ goto out;
+ }
/*
* If we get here, we have a blank entry. Fill it. We grow our
--
2.17.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/3] fs: ocfs2: Fix possible null-pointer dereferences in ocfs2_xa_prepare_entry()
2019-07-26 3:36 [PATCH 1/3] fs: ocfs2: Fix possible null-pointer dereferences in ocfs2_xa_prepare_entry() Jia-Ju Bai
@ 2019-07-26 9:37 ` Joseph Qi
2019-07-26 9:50 ` Jia-Ju Bai
0 siblings, 1 reply; 3+ messages in thread
From: Joseph Qi @ 2019-07-26 9:37 UTC (permalink / raw)
To: Jia-Ju Bai, mark, jlbec; +Cc: ocfs2-devel, linux-kernel
On 19/7/26 11:36, Jia-Ju Bai wrote:
> In ocfs2_xa_prepare_entry(), there is an if statement on line 2136 to
> check whether loc->xl_entry is NULL:
> if (loc->xl_entry)
>
> When loc->xl_entry is NULL, it is used on line 2158:
> ocfs2_xa_add_entry(loc, name_hash);
> loc->xl_entry->xe_name_hash = cpu_to_le32(name_hash);
> loc->xl_entry->xe_name_offset = cpu_to_le16(loc->xl_size);
> and line 2164:
> ocfs2_xa_add_namevalue(loc, xi);
> loc->xl_entry->xe_value_size = cpu_to_le64(xi->xi_value_len);
> loc->xl_entry->xe_name_len = xi->xi_name_len;
>
> Thus, possible null-pointer dereferences may occur.
>
> To fix these bugs, if loc-xl_entry is NULL, ocfs2_xa_prepare_entry()
> abnormally returns with -EINVAL.
>
> These bugs are found by a static analysis tool STCheck written by us.
>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
> fs/ocfs2/xattr.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
> index 385f3aaa2448..f690502daf3c 100644
> --- a/fs/ocfs2/xattr.c
> +++ b/fs/ocfs2/xattr.c
> @@ -2154,8 +2154,10 @@ static int ocfs2_xa_prepare_entry(struct ocfs2_xa_loc *loc,
> }
> }
> ocfs2_xa_wipe_namevalue(loc);
> - } else
> - ocfs2_xa_add_entry(loc, name_hash);
> + } else {
> + rc = -EINVAL;
> + goto out;
> + }
Since entry not found, so there is nothing to do in
ocfs2_xa_prepare_entry(). We may change it like:
if (!loc->xl_entry) {
rc = -EINVAL;
goto out;
}
if (ocfs2_xa_can_reuse_entry(loc, xi)) {
......
}
.....
Thanks,
Joseph
>
> /*
> * If we get here, we have a blank entry. Fill it. We grow our
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/3] fs: ocfs2: Fix possible null-pointer dereferences in ocfs2_xa_prepare_entry()
2019-07-26 9:37 ` Joseph Qi
@ 2019-07-26 9:50 ` Jia-Ju Bai
0 siblings, 0 replies; 3+ messages in thread
From: Jia-Ju Bai @ 2019-07-26 9:50 UTC (permalink / raw)
To: Joseph Qi, mark, jlbec; +Cc: ocfs2-devel, linux-kernel
On 2019/7/26 17:37, Joseph Qi wrote:
>
> On 19/7/26 11:36, Jia-Ju Bai wrote:
>> In ocfs2_xa_prepare_entry(), there is an if statement on line 2136 to
>> check whether loc->xl_entry is NULL:
>> if (loc->xl_entry)
>>
>> When loc->xl_entry is NULL, it is used on line 2158:
>> ocfs2_xa_add_entry(loc, name_hash);
>> loc->xl_entry->xe_name_hash = cpu_to_le32(name_hash);
>> loc->xl_entry->xe_name_offset = cpu_to_le16(loc->xl_size);
>> and line 2164:
>> ocfs2_xa_add_namevalue(loc, xi);
>> loc->xl_entry->xe_value_size = cpu_to_le64(xi->xi_value_len);
>> loc->xl_entry->xe_name_len = xi->xi_name_len;
>>
>> Thus, possible null-pointer dereferences may occur.
>>
>> To fix these bugs, if loc-xl_entry is NULL, ocfs2_xa_prepare_entry()
>> abnormally returns with -EINVAL.
>>
>> These bugs are found by a static analysis tool STCheck written by us.
>>
>> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
>> ---
>> fs/ocfs2/xattr.c | 6 ++++--
>> 1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
>> index 385f3aaa2448..f690502daf3c 100644
>> --- a/fs/ocfs2/xattr.c
>> +++ b/fs/ocfs2/xattr.c
>> @@ -2154,8 +2154,10 @@ static int ocfs2_xa_prepare_entry(struct ocfs2_xa_loc *loc,
>> }
>> }
>> ocfs2_xa_wipe_namevalue(loc);
>> - } else
>> - ocfs2_xa_add_entry(loc, name_hash);
>> + } else {
>> + rc = -EINVAL;
>> + goto out;
>> + }
> Since entry not found, so there is nothing to do in
> ocfs2_xa_prepare_entry(). We may change it like:
>
> if (!loc->xl_entry) {
> rc = -EINVAL;
> goto out;
> }
>
> if (ocfs2_xa_can_reuse_entry(loc, xi)) {
> ......
> }
> .....
>
Okay, I will send a v2 patch.
Best wishes,
Jia-Ju Bai
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-07-26 9:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-26 3:36 [PATCH 1/3] fs: ocfs2: Fix possible null-pointer dereferences in ocfs2_xa_prepare_entry() Jia-Ju Bai
2019-07-26 9:37 ` Joseph Qi
2019-07-26 9:50 ` Jia-Ju Bai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome