udf: Inline format expansion fixes
Subsystems (3)
Jan Kara
reviewercover udf: Inline format expansion fixes
Hello,
these two patches fix problems identified by a syzkaller in expansion of inodes with inline data. I plan to queue them in my tree.
Honza
Jan Kara
reviewerPATCH 1/2 udf: Fix NULL ptr deref when converting from inline format
udf_expand_file_adinicb() calls directly ->writepage to write data expanded into a page. This however misses to setup inode for writeback properly and so we can crash on inode->i_wb dereference when submitting page for IO like:
BUG: kernel NULL pointer dereference, address: 0000000000000158 #PF: supervisor read access in kernel mode ... <TASK> __folio_start_writeback+0x2ac/0x350 __block_write_full_page+0x37d/0x490 udf_expand_file_adinicb+0x255/0x400 [udf] udf_file_write_iter+0xbe/0x1b0 [udf] new_sync_write+0x125/0x1c0 vfs_write+0x28e/0x400
Fix the problem by marking the page dirty and going through the standard writeback path to write the page. Strictly speaking we would not even have to write the page but we want to catch e.g. ENOSPC errors early.
--- fs/udf/inode.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
fs/udf/inode.c +3 -5
@@ -258,10 +258,6 @@ int udf_expand_file_adinicb(struct inode *inode)char *kaddr;struct udf_inode_info *iinfo =UDF_I (inode);int err; -struct writeback_control udf_wbc = { - .sync_mode =WB_SYNC_NONE , - .nr_to_write =1 , - };WARN_ON_ONCE (!inode_is_locked (inode));if (!iinfo->i_lenAlloc) {
@@ -305,8 +301,10 @@ int udf_expand_file_adinicb(struct inode *inode) iinfo->i_alloc_type =ICBTAG_FLAG_AD_LONG ;/* from now on we have normal address_space methods */ inode->i_data.a_ops = &udf_aops; +set_page_dirty (page); +unlock_page (page);up_write (&iinfo->i_data_sem); - err = inode->i_data.a_ops->writepage (page, &udf_wbc); + err =filemap_fdatawrite (inode->i_mapping);if (err) {/* Restore everything back so that we don't lose data... */ lock_page (page);
Signature · 1 line
2.31.1
Jan Kara
reviewerPATCH 2/2 udf: Restore i_lenAlloc when inode expansion fails
In reply to Jan KaraWhen we fail to expand inode from inline format to a normal format, we restore inode to contain the original inline formatting but we forgot to set i_lenAlloc back. The mismatch between i_lenAlloc and i_size was then causing further problems such as warnings and lost data down the line.
--- fs/udf/inode.c | 1 + 1 file changed, 1 insertion(+)
fs/udf/inode.c +1 -0
@@ -315,6 +315,7 @@ int udf_expand_file_adinicb(struct inode *inode)unlock_page (page); iinfo->i_alloc_type =ICBTAG_FLAG_AD_IN_ICB ; inode->i_data.a_ops = &udf_adinicb_aops; + iinfo->i_lenAlloc = inode->i_size;up_write (&iinfo->i_data_sem); }put_page (page);
Signature · 1 line
2.31.1
Thanks for the update.
Regards,
butt3rflyh4ck.
Quoted 7 lines · Jan Kara
Hello,
these two patches fix problems identified by a syzkaller in expansion of inodes with inline data. I plan to queue them in my tree.
Honza
Signature · 1 line
Active Defense Lab of Venustech
Re: [PATCH 1/2] udf: Fix NULL ptr deref when converting from inline format
In reply to Jan KaraLooks good,
Re: [PATCH 2/2] udf: Restore i_lenAlloc when inode expansion fails
In reply to Jan KaraQuoted 4 lines · Jan Kara
When we fail to expand inode from inline format to a normal format, we restore inode to contain the original inline formatting but we forgot to set
i_lenAllocback. The mismatch betweeni_lenAllocandi_sizewas then causing further problems such as warnings and lost data down the line.
Looks good,
Btw, how did the reported even hit that failure in a way where the file system continues working? If we fail to write back data we'd probably better stop modifying anything and bail out..
Jan Kara
reviewerRe: [PATCH 2/2] udf: Restore i_lenAlloc when inode expansion fails
Quoted 6 lines · Christoph Hellwig
Quoted 4 lines · Jan Kara
When we fail to expand inode from inline format to a normal format, we restore inode to contain the original inline formatting but we forgot to set
i_lenAllocback. The mismatch betweeni_lenAllocandi_sizewas then causing further problems such as warnings and lost data down the line.
Quoted 7 lines
Looks good,
Reviewed-by Christoph Hellwig <[email protected]>Btw, how did the reported even hit that failure in a way where the file system continues working? If we fail to write back data we'd probably better stop modifying anything and bail out..
We can fail the expansion from inline to out-of-line format e.g. when the filesystem is full (ENOSPC). So we have to handle that case gracefully and the filesystem should be fully operational after this.
Thanks for review!
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR