All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] udf: Don't corrupt unalloc spacetable when writing it
@ 2015-07-07 18:06 Steven J. Magnani
  2015-07-09 15:16 ` Jan Kara
  0 siblings, 1 reply; 4+ messages in thread
From: Steven J. Magnani @ 2015-07-07 18:06 UTC (permalink / raw)
  To: jack; +Cc: linux-kernel, Steven J. Magnani

For a UDF filesystem configured with an Unallocated Space Table,
a filesystem operation that triggers an update to the table results
in on-disk corruption that prevents remounting:

  udf_read_tagged: tag version 0x0000 != 0x0002 || 0x0003, block 274

For example:
  1. Create a filesystem
      $ mkudffs --media-type=hd --blocksize=512 --lvid=BUGTEST \
              --vid=BUGTEST --fsid=BUGTEST --space=unalloctable \
              /dev/mmcblk0

  2. Mount it
      # mount /dev/mmcblk0 /mnt

  3. Create a file
      $ echo "No corruption, please" > /mnt/new.file

  4. Umount
      # umount /mnt

  5. Attempt remount
      # mount /dev/mmcblk0 /mnt

This appears to be a longstanding bug caused by zero-initialization of
the Unallocated Space Entry block buffer and only partial repopulation
of required fields before writing to disk. 

Commit 0adfb339fd64 ("udf: Fix unalloc space handling in udf_update_inode")
addressed one such field, but several others are required.

Signed-off-by: Steven J. Magnani <steve@digidescorp.com>
---
diff -uprN a/fs/udf/inode.c b/fs/udf/inode.c
--- a/fs/udf/inode.c	2015-07-06 13:42:08.861499890 -0500
+++ b/fs/udf/inode.c	2015-07-06 13:42:18.153499469 -0500
@@ -1652,17 +1652,9 @@ static int udf_update_inode(struct inode
 		       iinfo->i_ext.i_data, inode->i_sb->s_blocksize -
 					sizeof(struct unallocSpaceEntry));
 		use->descTag.tagIdent = cpu_to_le16(TAG_IDENT_USE);
-		use->descTag.tagLocation =
-				cpu_to_le32(iinfo->i_location.logicalBlockNum);
-		crclen = sizeof(struct unallocSpaceEntry) +
-				iinfo->i_lenAlloc - sizeof(struct tag);
-		use->descTag.descCRCLength = cpu_to_le16(crclen);
-		use->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)use +
-							   sizeof(struct tag),
-							   crclen));
-		use->descTag.tagChecksum = udf_tag_checksum(&use->descTag);
+		crclen = sizeof(struct unallocSpaceEntry);
 
-		goto out;
+		goto finish;
 	}
 
 	if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
@@ -1782,6 +1774,8 @@ static int udf_update_inode(struct inode
 		efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE);
 		crclen = sizeof(struct extendedFileEntry);
 	}
+
+finish:
 	if (iinfo->i_strat4096) {
 		fe->icbTag.strategyType = cpu_to_le16(4096);
 		fe->icbTag.strategyParameter = cpu_to_le16(1);
@@ -1791,7 +1785,9 @@ static int udf_update_inode(struct inode
 		fe->icbTag.numEntries = cpu_to_le16(1);
 	}
 
-	if (S_ISDIR(inode->i_mode))
+	if (iinfo->i_use)
+		fe->icbTag.fileType = ICBTAG_FILE_TYPE_USE;
+	else if (S_ISDIR(inode->i_mode))
 		fe->icbTag.fileType = ICBTAG_FILE_TYPE_DIRECTORY;
 	else if (S_ISREG(inode->i_mode))
 		fe->icbTag.fileType = ICBTAG_FILE_TYPE_REGULAR;
@@ -1828,7 +1824,6 @@ static int udf_update_inode(struct inode
 						  crclen));
 	fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag);
 
-out:
 	set_buffer_uptodate(bh);
 	unlock_buffer(bh);
 

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

* Re: [PATCH] udf: Don't corrupt unalloc spacetable when writing it
  2015-07-07 18:06 [PATCH] udf: Don't corrupt unalloc spacetable when writing it Steven J. Magnani
@ 2015-07-09 15:16 ` Jan Kara
  2015-07-09 18:20   ` Steve Magnani
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Kara @ 2015-07-09 15:16 UTC (permalink / raw)
  To: Steven J. Magnani; +Cc: jack, linux-kernel, Steven J. Magnani

On Tue 07-07-15 13:06:05, Steven J. Magnani wrote:
> For a UDF filesystem configured with an Unallocated Space Table,
> a filesystem operation that triggers an update to the table results
> in on-disk corruption that prevents remounting:
> 
>   udf_read_tagged: tag version 0x0000 != 0x0002 || 0x0003, block 274
> 
> For example:
>   1. Create a filesystem
>       $ mkudffs --media-type=hd --blocksize=512 --lvid=BUGTEST \
>               --vid=BUGTEST --fsid=BUGTEST --space=unalloctable \
>               /dev/mmcblk0
> 
>   2. Mount it
>       # mount /dev/mmcblk0 /mnt
> 
>   3. Create a file
>       $ echo "No corruption, please" > /mnt/new.file
> 
>   4. Umount
>       # umount /mnt
> 
>   5. Attempt remount
>       # mount /dev/mmcblk0 /mnt
> 
> This appears to be a longstanding bug caused by zero-initialization of
> the Unallocated Space Entry block buffer and only partial repopulation
> of required fields before writing to disk. 
> 
> Commit 0adfb339fd64 ("udf: Fix unalloc space handling in udf_update_inode")
> addressed one such field, but several others are required.
> 
> Signed-off-by: Steven J. Magnani <steve@digidescorp.com>

So the patch looks good to me. But what kind of mkudffs are you using?
Because when I use the command you wrote into the changelog, I cannot mount
the filesystem. The kernel complains about:

UDF-fs: error (device ubdb): udf_read_inode: (ino 274) failed ident=256
mount: /dev/ubdb: can't read superblock

Now ident 256 is TAG_IDENT_FSD (file set descriptor). So apparently my
mkudffs doesn't create proper partition table with your parameters...

								Honza

> ---
> diff -uprN a/fs/udf/inode.c b/fs/udf/inode.c
> --- a/fs/udf/inode.c	2015-07-06 13:42:08.861499890 -0500
> +++ b/fs/udf/inode.c	2015-07-06 13:42:18.153499469 -0500
> @@ -1652,17 +1652,9 @@ static int udf_update_inode(struct inode
>  		       iinfo->i_ext.i_data, inode->i_sb->s_blocksize -
>  					sizeof(struct unallocSpaceEntry));
>  		use->descTag.tagIdent = cpu_to_le16(TAG_IDENT_USE);
> -		use->descTag.tagLocation =
> -				cpu_to_le32(iinfo->i_location.logicalBlockNum);
> -		crclen = sizeof(struct unallocSpaceEntry) +
> -				iinfo->i_lenAlloc - sizeof(struct tag);
> -		use->descTag.descCRCLength = cpu_to_le16(crclen);
> -		use->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)use +
> -							   sizeof(struct tag),
> -							   crclen));
> -		use->descTag.tagChecksum = udf_tag_checksum(&use->descTag);
> +		crclen = sizeof(struct unallocSpaceEntry);
>  
> -		goto out;
> +		goto finish;
>  	}
>  
>  	if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
> @@ -1782,6 +1774,8 @@ static int udf_update_inode(struct inode
>  		efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE);
>  		crclen = sizeof(struct extendedFileEntry);
>  	}
> +
> +finish:
>  	if (iinfo->i_strat4096) {
>  		fe->icbTag.strategyType = cpu_to_le16(4096);
>  		fe->icbTag.strategyParameter = cpu_to_le16(1);
> @@ -1791,7 +1785,9 @@ static int udf_update_inode(struct inode
>  		fe->icbTag.numEntries = cpu_to_le16(1);
>  	}
>  
> -	if (S_ISDIR(inode->i_mode))
> +	if (iinfo->i_use)
> +		fe->icbTag.fileType = ICBTAG_FILE_TYPE_USE;
> +	else if (S_ISDIR(inode->i_mode))
>  		fe->icbTag.fileType = ICBTAG_FILE_TYPE_DIRECTORY;
>  	else if (S_ISREG(inode->i_mode))
>  		fe->icbTag.fileType = ICBTAG_FILE_TYPE_REGULAR;
> @@ -1828,7 +1824,6 @@ static int udf_update_inode(struct inode
>  						  crclen));
>  	fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag);
>  
> -out:
>  	set_buffer_uptodate(bh);
>  	unlock_buffer(bh);
>  
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR

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

* Re: [PATCH] udf: Don't corrupt unalloc spacetable when writing it
  2015-07-09 15:16 ` Jan Kara
@ 2015-07-09 18:20   ` Steve Magnani
  2015-07-10 14:01     ` Jan Kara
  0 siblings, 1 reply; 4+ messages in thread
From: Steve Magnani @ 2015-07-09 18:20 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-kernel, Steven J. Magnani



On 07/09/2015 10:16 AM, Jan Kara wrote:
> On Tue 07-07-15 13:06:05, Steven J. Magnani wrote:
>> For a UDF filesystem configured with an Unallocated Space Table,
>> a filesystem operation that triggers an update to the table results
>> in on-disk corruption that prevents remounting:
>>
>>    udf_read_tagged: tag version 0x0000 != 0x0002 || 0x0003, block 274
>>
>> For example:
>>    1. Create a filesystem
>>        $ mkudffs --media-type=hd --blocksize=512 --lvid=BUGTEST \
>>                --vid=BUGTEST --fsid=BUGTEST --space=unalloctable \
>>                /dev/mmcblk0
>>
>>    2. Mount it
>>        # mount /dev/mmcblk0 /mnt
>>
>> ...
> So the patch looks good to me. But what kind of mkudffs are you using?
> Because when I use the command you wrote into the changelog, I cannot mount
> the filesystem. The kernel complains about:
>
> UDF-fs: error (device ubdb): udf_read_inode: (ino 274) failed ident=256
> mount: /dev/ubdb: can't read superblock
>
> Now ident 256 is TAG_IDENT_FSD (file set descriptor). So apparently my
> mkudffs doesn't create proper partition table with your parameters...
>
>
It identifies itself as:
     mkudffs 1.0.0b2 for UDF FS 1.0.0-cvs, 2002/02/09

...from Ubuntu udftools 1.0.0b3-14.2.

------------------------------------------------------------------------
  Steven J. Magnani               "I claim this network for MARS!
  www.digidescorp.com              Earthling, return my space modulator!"

  #include <standard.disclaimer>


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

* Re: [PATCH] udf: Don't corrupt unalloc spacetable when writing it
  2015-07-09 18:20   ` Steve Magnani
@ 2015-07-10 14:01     ` Jan Kara
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2015-07-10 14:01 UTC (permalink / raw)
  To: Steve Magnani; +Cc: Jan Kara, linux-kernel, Steven J. Magnani

On Thu 09-07-15 13:20:27, Steve Magnani wrote:
> 
> 
> On 07/09/2015 10:16 AM, Jan Kara wrote:
> >On Tue 07-07-15 13:06:05, Steven J. Magnani wrote:
> >>For a UDF filesystem configured with an Unallocated Space Table,
> >>a filesystem operation that triggers an update to the table results
> >>in on-disk corruption that prevents remounting:
> >>
> >>   udf_read_tagged: tag version 0x0000 != 0x0002 || 0x0003, block 274
> >>
> >>For example:
> >>   1. Create a filesystem
> >>       $ mkudffs --media-type=hd --blocksize=512 --lvid=BUGTEST \
> >>               --vid=BUGTEST --fsid=BUGTEST --space=unalloctable \
> >>               /dev/mmcblk0
> >>
> >>   2. Mount it
> >>       # mount /dev/mmcblk0 /mnt
> >>
> >>...
> >So the patch looks good to me. But what kind of mkudffs are you using?
> >Because when I use the command you wrote into the changelog, I cannot mount
> >the filesystem. The kernel complains about:
> >
> >UDF-fs: error (device ubdb): udf_read_inode: (ino 274) failed ident=256
> >mount: /dev/ubdb: can't read superblock
> >
> >Now ident 256 is TAG_IDENT_FSD (file set descriptor). So apparently my
> >mkudffs doesn't create proper partition table with your parameters...
> >
> >
> It identifies itself as:
>     mkudffs 1.0.0b2 for UDF FS 1.0.0-cvs, 2002/02/09
> 
> ...from Ubuntu udftools 1.0.0b3-14.2.

OK, I've fixed my mkudffs and verified that your patch indeed fixes the
problem. Thanks. I have merged the patch to my tree and will push it to
Linus.

								Honza
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR

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

end of thread, other threads:[~2015-07-10 14:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-07 18:06 [PATCH] udf: Don't corrupt unalloc spacetable when writing it Steven J. Magnani
2015-07-09 15:16 ` Jan Kara
2015-07-09 18:20   ` Steve Magnani
2015-07-10 14:01     ` Jan Kara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.