All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] udf: prevent allocation beyond UDF partition
@ 2019-07-28 19:19 Steve Magnani
  2019-07-31  9:59 ` Jan Kara
  0 siblings, 1 reply; 3+ messages in thread
From: Steve Magnani @ 2019-07-28 19:19 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-kernel, linux-fsdevel, Steve Magnani

The UDF bitmap allocation code assumes that a recorded 
Unallocated Space Bitmap is compliant with ECMA-167 4/13,
which requires that pad bytes between the end of the bitmap 
and the end of a logical block are all zero.

When a recorded bitmap does not comply with this requirement,
for example one padded with FF to the block boundary instead
of 00, the allocator may "allocate" blocks that are outside
the UDF partition extent. This can result in UDF volume descriptors
being overwritten by file data or by partition-level descriptors,
and in extreme cases, even in scribbling on a subsequent disk partition.

Add a check that the block selected by the allocator actually
resides within the UDF partition extent.

Signed-off-by: Steven J. Magnani <steve@digidescorp.com>

--- a/fs/udf/balloc.c	2019-07-26 11:35:28.249563705 -0500
+++ b/fs/udf/balloc.c	2019-07-28 13:11:25.061431597 -0500
@@ -325,6 +325,13 @@ got_block:
 	newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) -
 		(sizeof(struct spaceBitmapDesc) << 3);
 
+	if (newblock >= sbi->s_partmaps[partition].s_partition_len) {
+		/* Ran off the end of the bitmap,
+		 * and bits following are non-compliant (not all zero)
+		 */
+		goto error_return;
+	}
+
 	if (!udf_clear_bit(bit, bh->b_data)) {
 		udf_debug("bit already cleared for block %d\n", bit);
 		goto repeat;

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

* Re: [PATCH] udf: prevent allocation beyond UDF partition
  2019-07-28 19:19 [PATCH] udf: prevent allocation beyond UDF partition Steve Magnani
@ 2019-07-31  9:59 ` Jan Kara
  2019-07-31 14:06   ` Steve Magnani
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kara @ 2019-07-31  9:59 UTC (permalink / raw)
  To: Steve Magnani; +Cc: Jan Kara, Steve Magnani, linux-fsdevel, linux-kernel

On Sun 28-07-19 14:19:12, Steve Magnani wrote:
> The UDF bitmap allocation code assumes that a recorded 
> Unallocated Space Bitmap is compliant with ECMA-167 4/13,
> which requires that pad bytes between the end of the bitmap 
> and the end of a logical block are all zero.
> 
> When a recorded bitmap does not comply with this requirement,
> for example one padded with FF to the block boundary instead
> of 00, the allocator may "allocate" blocks that are outside
> the UDF partition extent. This can result in UDF volume descriptors
> being overwritten by file data or by partition-level descriptors,
> and in extreme cases, even in scribbling on a subsequent disk partition.
> 
> Add a check that the block selected by the allocator actually
> resides within the UDF partition extent.
> 
> Signed-off-by: Steven J. Magnani <steve@digidescorp.com>

Thanks for the patch! Added to my tree. I've just slightly modified the
patch to also output error message about filesystem corruption.

								Honza

> 
> --- a/fs/udf/balloc.c	2019-07-26 11:35:28.249563705 -0500
> +++ b/fs/udf/balloc.c	2019-07-28 13:11:25.061431597 -0500
> @@ -325,6 +325,13 @@ got_block:
>  	newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) -
>  		(sizeof(struct spaceBitmapDesc) << 3);
>  
> +	if (newblock >= sbi->s_partmaps[partition].s_partition_len) {
> +		/* Ran off the end of the bitmap,
> +		 * and bits following are non-compliant (not all zero)
> +		 */
> +		goto error_return;
> +	}
> +
>  	if (!udf_clear_bit(bit, bh->b_data)) {
>  		udf_debug("bit already cleared for block %d\n", bit);
>  		goto repeat;
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH] udf: prevent allocation beyond UDF partition
  2019-07-31  9:59 ` Jan Kara
@ 2019-07-31 14:06   ` Steve Magnani
  0 siblings, 0 replies; 3+ messages in thread
From: Steve Magnani @ 2019-07-31 14:06 UTC (permalink / raw)
  To: Jan Kara
  Cc: Jan Kara, Steve Magnani, linux-fsdevel, linux-kernel, Pali Rohár

On 7/31/19 4:59 AM, Jan Kara wrote:
> On Sun 28-07-19 14:19:12, Steve Magnani wrote:
>> The UDF bitmap allocation code assumes that a recorded
>> Unallocated Space Bitmap is compliant with ECMA-167 4/13,
>> which requires that pad bytes between the end of the bitmap
>> and the end of a logical block are all zero.
>>
>> When a recorded bitmap does not comply with this requirement,
>> for example one padded with FF to the block boundary instead
>> of 00, the allocator may "allocate" blocks that are outside
>> the UDF partition extent. This can result in UDF volume descriptors
>> being overwritten by file data or by partition-level descriptors,
>> and in extreme cases, even in scribbling on a subsequent disk partition.
>>
>> Add a check that the block selected by the allocator actually
>> resides within the UDF partition extent.
>>
>> Signed-off-by: Steven J. Magnani <steve@digidescorp.com>
> Thanks for the patch! Added to my tree. I've just slightly modified the
> patch to also output error message about filesystem corruption.
>
> 								Honza


Thanks Jan. Ror the record, it appears that Windows chkdsk has a bug in its
analysis of a space bitmaps. If the last block of a UDF partition falls
in the middle of a bitmap byte, chkdsk reports spurious errors if the bits
in that byte that _don't_ correspond to UDF partition blocks are zero.

To maximize interoperability it would appear that it's best to format such
that UDF partition sizes are always a multiple of 8 blocks.

Note to non-UDF wonks reading this, a UDF partition is a sub-extent of a
disk partition. So achieving the multiple-of-8-blocks involves a change to
mkudffs code.

------------------------------------------------------------------------
  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] 3+ messages in thread

end of thread, other threads:[~2019-07-31 14:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-28 19:19 [PATCH] udf: prevent allocation beyond UDF partition Steve Magnani
2019-07-31  9:59 ` Jan Kara
2019-07-31 14:06   ` Steve Magnani

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.