linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/3] fs: ocfs2: Fix a possible null-pointer dereference in ocfs2_write_end_nolock()
@ 2019-07-26  3:37 Jia-Ju Bai
  2019-07-26  9:38 ` Joseph Qi
  0 siblings, 1 reply; 3+ messages in thread
From: Jia-Ju Bai @ 2019-07-26  3:37 UTC (permalink / raw)
  To: mark, jlbec, joseph.qi; +Cc: ocfs2-devel, linux-kernel, Jia-Ju Bai

In ocfs2_write_end_nolock(), there are an if statement on lines 1976, 
2047 and 2058, to check whether handle is NULL:
    if (handle)

When handle is NULL, it is used on line 2045:
	ocfs2_update_inode_fsync_trans(handle, inode, 1);
        oi->i_sync_tid = handle->h_transaction->t_tid;

Thus, a possible null-pointer dereference may occur.

To fix this bug, handle is checked before calling
ocfs2_update_inode_fsync_trans().

This bug is found by a static analysis tool STCheck written by us.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 fs/ocfs2/aops.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index a4c905d6b575..5473bd99043e 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -2042,7 +2042,8 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
 		inode->i_mtime = inode->i_ctime = current_time(inode);
 		di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec);
 		di->i_mtime_nsec = di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
-		ocfs2_update_inode_fsync_trans(handle, inode, 1);
+		if (handle)
+			ocfs2_update_inode_fsync_trans(handle, inode, 1);
 	}
 	if (handle)
 		ocfs2_journal_dirty(handle, wc->w_di_bh);
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/3] fs: ocfs2: Fix a possible null-pointer dereference in ocfs2_write_end_nolock()
  2019-07-26  3:37 [PATCH 2/3] fs: ocfs2: Fix a possible null-pointer dereference in ocfs2_write_end_nolock() Jia-Ju Bai
@ 2019-07-26  9:38 ` Joseph Qi
  2019-08-05  2:38   ` [Ocfs2-devel] " Changwei Ge
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph Qi @ 2019-07-26  9:38 UTC (permalink / raw)
  To: Jia-Ju Bai, mark, jlbec; +Cc: ocfs2-devel, linux-kernel



On 19/7/26 11:37, Jia-Ju Bai wrote:
> In ocfs2_write_end_nolock(), there are an if statement on lines 1976, 
> 2047 and 2058, to check whether handle is NULL:
>     if (handle)
> 
> When handle is NULL, it is used on line 2045:
> 	ocfs2_update_inode_fsync_trans(handle, inode, 1);
>         oi->i_sync_tid = handle->h_transaction->t_tid;
> 
> Thus, a possible null-pointer dereference may occur.
> 
> To fix this bug, handle is checked before calling
> ocfs2_update_inode_fsync_trans().
> 
> This bug is found by a static analysis tool STCheck written by us.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>

Looks good.
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>

> ---
>  fs/ocfs2/aops.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
> index a4c905d6b575..5473bd99043e 100644
> --- a/fs/ocfs2/aops.c
> +++ b/fs/ocfs2/aops.c
> @@ -2042,7 +2042,8 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
>  		inode->i_mtime = inode->i_ctime = current_time(inode);
>  		di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec);
>  		di->i_mtime_nsec = di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
> -		ocfs2_update_inode_fsync_trans(handle, inode, 1);
> +		if (handle)
> +			ocfs2_update_inode_fsync_trans(handle, inode, 1);
>  	}
>  	if (handle)
>  		ocfs2_journal_dirty(handle, wc->w_di_bh);
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Ocfs2-devel] [PATCH 2/3] fs: ocfs2: Fix a possible null-pointer dereference in ocfs2_write_end_nolock()
  2019-07-26  9:38 ` Joseph Qi
@ 2019-08-05  2:38   ` Changwei Ge
  0 siblings, 0 replies; 3+ messages in thread
From: Changwei Ge @ 2019-08-05  2:38 UTC (permalink / raw)
  To: Joseph Qi, Jia-Ju Bai, mark, jlbec
  Cc: linux-kernel, ocfs2-devel, Andrew Morton

Hi Jia-ju,


Could you please point out how ->w_handle can be NULL if we are changing 
disk inode?

I just checked the ocfs2 code but can't find any clue ...

In my opinion, it's impossible to change disk inode without an existed 
journal transaction. If truly so, it's a another problem.


Thanks,

Changwei


On 2019/7/26 5:38 下午, Joseph Qi wrote:
>
> On 19/7/26 11:37, Jia-Ju Bai wrote:
>> In ocfs2_write_end_nolock(), there are an if statement on lines 1976,
>> 2047 and 2058, to check whether handle is NULL:
>>      if (handle)
>>
>> When handle is NULL, it is used on line 2045:
>> 	ocfs2_update_inode_fsync_trans(handle, inode, 1);
>>          oi->i_sync_tid = handle->h_transaction->t_tid;
>>
>> Thus, a possible null-pointer dereference may occur.
>>
>> To fix this bug, handle is checked before calling
>> ocfs2_update_inode_fsync_trans().
>>
>> This bug is found by a static analysis tool STCheck written by us.
>>
>> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> Looks good.
> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
>
>> ---
>>   fs/ocfs2/aops.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
>> index a4c905d6b575..5473bd99043e 100644
>> --- a/fs/ocfs2/aops.c
>> +++ b/fs/ocfs2/aops.c
>> @@ -2042,7 +2042,8 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
>>   		inode->i_mtime = inode->i_ctime = current_time(inode);
>>   		di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec);
>>   		di->i_mtime_nsec = di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
>> -		ocfs2_update_inode_fsync_trans(handle, inode, 1);
>> +		if (handle)
>> +			ocfs2_update_inode_fsync_trans(handle, inode, 1);
>>   	}
>>   	if (handle)
>>   		ocfs2_journal_dirty(handle, wc->w_di_bh);
>>
> _______________________________________________
> Ocfs2-devel mailing list
> Ocfs2-devel@oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/ocfs2-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-08-05  2:39 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:37 [PATCH 2/3] fs: ocfs2: Fix a possible null-pointer dereference in ocfs2_write_end_nolock() Jia-Ju Bai
2019-07-26  9:38 ` Joseph Qi
2019-08-05  2:38   ` [Ocfs2-devel] " Changwei Ge

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).