xfs: add bounds checking to xlog_recover_process_ophdr
PATCH 1/1 xfs: add bounds checking to xlog_recover_process_ophdr
Make sure xlog_op_header don't stray beyond valid memory region. Check if there is enough space for the fixed members of each xlog_op_header before visiting.
--- fs/xfs/xfs_log_recover.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/xfs/xfs_log_recover.c +5 -1
@@ -2361,6 +2361,11 @@ xlog_recover_process_ophdr(unsigned int len;int error; +if (dp > end) { +xfs_warn (log->l_mp,"%s: op header overrun" , __func__); +return -EFSCORRUPTED ; + } +/* Do we understand who wrote this op? */ if (ohead->oh_clientid !=XFS_TRANSACTION && ohead->oh_clientid !=XFS_LOG ) {
@@ -2456,7 +2461,6 @@ xlog_recover_process_data( ohead = (struct xlog_op_header *)dp; dp +=sizeof (*ohead); -ASSERT (dp <= end);/* errors will abort recovery */ error = xlog_recover_process_ophdr(log, rhash, rhead, ohead,
Signature · 1 line
2.34.1
Quoted 5 lines · lei lu
Make sure
xlog_op_headerdon't stray beyond valid memory region. Check if there is enough space for the fixed members of eachxlog_op_headerbefore visiting.Signed-off-by lei lu <[email protected]>
Finding a corrupted ophdr chain this deep in recovery implies that there is either a runtime bug when writing out the log buffers during checkpointing or there is memory corruption occurring during log recovery after the log items have been read from the journal and attached to the transaction structure for processing. If that's the case, then addressing the buffer overrun is not fixing the underlying issue that needs to be triaged and fixed.
The only other way I can think of that this might occur is malicious corruption of the journal structures on disk. If that's the case, then you need to state this explicitly so we know that this isn't a potentially critical runtime bug we need to spend time on immediately.
Hence we need to know how you found the issue, what it's symptoms are, how to reproduce the issue, etc. ie. you need to explain where you found a CRC validated journal structure that is internally inconsistent. That's -critical information- that we need to assess the scope of the issue that you have uncovered.
I asked for you to provide this sort of detail to be provided with your last overrun fix - we need to know how such failures come about because they often are just a symptom of some other issue we failed to capture. You might have all the details in your head, but none of us know anything about what you are doing.
Can you describe what tools and processes you are using to find these issues, and please try to include such descriptions in the commit message for future fixes to issues you find?
Quoted 9 lines
--- fs/xfs/xfs_log_recover.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)fs/xfs/xfs_log_recover.c +0
-0
fs/xfs/xfs_log_recover.c xlog_recover_process_ophdr( · line 2367
Quoted 7 lines
fs/xfs/xfs_log_recover.c +4
-0@@ -2361,6 +2361,11 @@ xlog_recover_process_ophdr(unsigned int len;int error; +if (dp > end) { +xfs_warn (log->l_mp,"%s: op header overrun" , __func__); +return -EFSCORRUPTED ; + }
Why did you put the check here, rather than...
fs/xfs/xfs_log_recover.c xlog_recover_process_data( · line 2459
Quoted 9 lines
fs/xfs/xfs_log_recover.c +1
-1+/* Do we understand who wrote this op? */ if (ohead->oh_clientid !=XFS_TRANSACTION && ohead->oh_clientid !=XFS_LOG ) {@@ -2456,7 +2461,6 @@ xlog_recover_process_data( ohead = (struct xlog_op_header *)dp; dp +=sizeof (*ohead); -ASSERT (dp <= end);
.... where the pointer is advanced and the overrun is exposed?
-Dave.
Signature · 2 lines
Dave Chinner [email protected]