Amiga RDB partition support fixes
v7 cover Amiga RDB partition support fixes
(hopefully) final version of the Amiga RDB partition table patch follows.
I've split off the part fixing the incorrect use of signed int for partition start address and size as separate patch. It does fix the bug that Martin Steigerwald reported six years ago for a 2 TB disk. I have tested this patch with the identical RDB partition data that Martin saw the bug with. I have incorporated Andreas' feedback on proper use of casts to avoid integer overflow in this version.
The simple fix still leaves ample room for overflows in calculating start address and size of a RDB partition, though such overflows should only be seen in rather unusual cases. To address these potential overflows, checks are added in the second patch of this series. Comments by Geert have been addressed in full.
Both patches now reviewed by Geert - Reviewed-by tags added.
Cheers,
Michael
PATCH v7 2/2 block: add overflow checks for Amiga partition support
The Amiga partition parser module uses signed int for partition sector address and count, which will overflow for disks larger than 1 TB.
Use u64 as type for sector address and size to allow using disks up to 2 TB without LBD support, and disks larger than 2 TB with LBD. The RBD format allows to specify disk sizes up to 2^128 bytes (though native OS limitations reduce this somewhat, to max 2^68 bytes), so check for u64 overflow carefully to protect against overflowing sector_t.
Bail out if sector addresses overflow 32 bits on kernels without LBD support.
This bug was reported originally in 2012, and the fix was created by the RDB author, Joanne Dow <[email protected]>. A patch had been discussed and reviewed on linux-m68k at that time but never officially submitted (now resubmitted as separate patch).
This patch adds additional error checking and warning messages.
Message-ID: <[email protected]>
---
Changes from RFC:
- use u64 instead of sector_t, since that may be u32 without LBD support
- check multiplication overflows each step - 3 u32 values may exceed u64!
- warn against use on AmigaDOS if partition data overflow u32 sector count.
- warn if partition CylBlocks larger than what's stored in the RDSK header.
- bail out if we were to overflow sector_t (32 or 64 bit).
Changes from v1:
Kars de Jong:
- use defines for magic offsets in DosEnvec struct
Geert Uytterhoeven:
- use u64 cast for multiplications of u32 numbers
- use array3_size for overflow checks
- change pr_err to pr_warn
- discontinue use of pr_cont
- reword log messages
- drop redundant nr_sects overflow test
- warn against 32 bit overflow for each affected partition
- skip partitions that overflow sector_t size instead of aborting scan
Changes from v2:
- further trim 32 bit overflow test
- correct duplicate types.h inclusion introduced in v2
Changes from v3:
- split off sector address type fix for independent review
- change blksize to unsigned
- use check_mul_overflow() instead of array3_size()
- rewrite checks to avoid 64 bit divisions in check_mul_overflow()
Changes from v5:
Geert Uytterhoeven:
- correct ineffective u64 cast to avoid 32 bit mult. overflow
- fix mult. overflow in partition block address calculation
Changes from v6:
Geert Uytterhoeven:
- don't fail hard on partition block address overflow
--- block/partitions/amiga.c | 111 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 89 insertions(+), 22 deletions(-)
block/partitions/amiga.c +89 -22
@@ -11,11 +11,19 @@#define pr_fmt (fmt) fmt#include <linux/types.h> +#include <linux/mm_types.h> +#include <linux/overflow.h> #include <linux/affs_hardblocks.h> #include "check.h" #include "amiga.h" +/* magic offsets in partition DosEnvVec */ +#define NR_HD 3 +#define NR_SECT 5 +#define LO_CYL 9 +#define HI_CYL 10 +static __inline__u32 checksum_block (__be32 *m,int size) {
@@ -32,9 +40,12 @@ int amiga_partition(struct parsed_partitions *state)unsigned char *data;struct RigidDiskBlock *rdb;struct PartitionBlock *pb; -sector_t start_sect, nr_sects; -int blk, part, res =0 ; -int blksize =1 ;/* Multiplier for disk block size */ +u64 start_sect, nr_sects; +sector_t blk, end_sect; +u32 cylblk;/* rdb_CylBlocks = nr_heads*sect_per_track */ +u32 nr_hd, nr_sect, lo_cyl, hi_cyl; +int part, res =0 ; +unsigned int blksize =1 ;/* Multiplier for disk block size */ int slot =1 ;char b[BDEVNAME_SIZE ];
@@ -44,8 +55,8 @@ int amiga_partition(struct parsed_partitions *state) data =read_part_sector (state, blk, §);if (!data) {if (warn_no_part) -pr_err ("Dev %s: unable to read RDB block %d\n" , -bdevname (state->bdev, b), blk); +pr_err ("Dev %s: unable to read RDB block %llu\n" , +bdevname (state->bdev, b), (u64 ) blk); res =-1 ; goto rdb_done; }
@@ -61,13 +72,13 @@ int amiga_partition(struct parsed_partitions *state) *(__be32 *)(data+0xdc ) =0 ;if (checksum_block ((__be32 *)data,be32_to_cpu (rdb->rdb_SummedLongs) &0x7F )==0 ) { -pr_err ("Trashed word at 0xd0 in block %d ignored in checksum calculation\n" , - blk); +pr_err ("Trashed word at 0xd0 in block %llu ignored in checksum calculation\n" , + (u64 ) blk);break ; } -pr_err ("Dev %s: RDB in block %d has bad checksum\n" , -bdevname (state->bdev, b), blk); +pr_err ("Dev %s: RDB in block %llu has bad checksum\n" , +bdevname (state->bdev, b), (u64 ) blk); }/* blksize is blocks per 512 byte standard block */
@@ -83,12 +94,17 @@ int amiga_partition(struct parsed_partitions *state) blk =be32_to_cpu (rdb->rdb_PartitionList);put_dev_sector (sect);for (part =1 ; blk>0 && part<=16 ; part++,put_dev_sector (sect)) { - blk *= blksize;/* Read in terms partition table understands */ +/* Read in terms partition table understands */ +if (check_mul_overflow (blk, (sector_t ) blksize, &blk)) { +pr_err ("Dev %s: overflow calculating partition block %llu! Skipping partitions %u and beyond\n" , +bdevname (state->bdev, b), (u64 ) blk, part); +break ; + } data =read_part_sector (state, blk, §);if (!data) {if (warn_no_part) -pr_err ("Dev %s: unable to read partition block %d\n" , -bdevname (state->bdev, b), blk); +pr_err ("Dev %s: unable to read partition block %llu\n" , +bdevname (state->bdev, b), (u64 ) blk); res =-1 ; goto rdb_done; }
@@ -99,19 +115,70 @@ int amiga_partition(struct parsed_partitions *state)if (checksum_block ((__be32 *)pb,be32_to_cpu (pb->pb_SummedLongs) &0x7F ) !=0 )continue ; -/* Tell Kernel about it */ +/* RDB gives us more than enough rope to hang ourselves with, +* many times over (2^128 bytes if all fields max out). +* Some careful checks are in order, so check for potential +* overflows. +* We are multiplying four 32 bit numbers to one sector_t! +*/ + + nr_hd =be32_to_cpu (pb->pb_Environment[NR_HD ]); + nr_sect =be32_to_cpu (pb->pb_Environment[NR_SECT ]); + +/* CylBlocks is total number of blocks per cylinder */ +if (check_mul_overflow (nr_hd, nr_sect, &cylblk)) { +pr_err ("Dev %s: heads*sects %u overflows u32, skipping partition!\n" , +bdevname (state->bdev, b), cylblk); +continue ; + } + +/* check for consistency with RDB defined CylBlocks */ +if (cylblk >be32_to_cpu (rdb->rdb_CylBlocks)) { +pr_warn ("Dev %s: cylblk %u > rdb_CylBlocks %u!\n" , +bdevname (state->bdev, b), cylblk, +be32_to_cpu (rdb->rdb_CylBlocks)); + } + +/* RDB allows for variable logical block size - +* normalize to 512 byte blocks and check result. +*/ + +if (check_mul_overflow (cylblk, blksize, &cylblk)) { +pr_err ("Dev %s: partition %u bytes per cyl. overflows u32, skipping partition!\n" , +bdevname (state->bdev, b), part); +continue ; + } + +/* Calculate partition start and end. Limit of 32 bit on cylblk +* guarantees no overflow occurs if LBD support is enabled. +*/ + + lo_cyl =be32_to_cpu (pb->pb_Environment[LO_CYL ]); + start_sect = ((u64 ) lo_cyl * cylblk); + + hi_cyl =be32_to_cpu (pb->pb_Environment[HI_CYL ]); + nr_sects = (((u64 ) hi_cyl - lo_cyl +1 ) * cylblk); - nr_sects = ((sector_t )be32_to_cpu (pb->pb_Environment[10 ]) - +1 -be32_to_cpu (pb->pb_Environment[9 ])) * -be32_to_cpu (pb->pb_Environment[3 ]) * -be32_to_cpu (pb->pb_Environment[5 ]) * - blksize;if (!nr_sects)continue ; - start_sect = (sector_t )be32_to_cpu (pb->pb_Environment[9 ]) * -be32_to_cpu (pb->pb_Environment[3 ]) * -be32_to_cpu (pb->pb_Environment[5 ]) * - blksize; + +/* Warn user if partition end overflows u32 (AmigaDOS limit) */ + +if ((start_sect + nr_sects) >UINT_MAX ) { +pr_warn ("Dev %s: partition %u (%llu-%llu) needs 64 bit device support!\n" , +bdevname (state->bdev, b), part, + start_sect, start_sect + nr_sects); + } + +if (check_add_overflow (start_sect, nr_sects, &end_sect)) { +pr_err ("Dev %s: partition %u (%llu-%llu) needs LBD device support, skipping partition!\n" , +bdevname (state->bdev, b), part, + start_sect, (u64 ) end_sect); +continue ; + } + +/* Tell Kernel about it */ +put_partition (state,slot++,start_sect,nr_sects); {/* Be even more informative to aid mounting */
Signature · 1 line
1.9.1
PATCH v7 1/2 block: fix signed int overflow in Amiga partition support
In reply to Michael SchmitzThe Amiga partition parser module uses signed int for partition sector address and count, which will overflow for disks larger than 1 TB.
Use sector_t as type for sector address and size to allow using disks up to 2 TB without LBD support, and disks larger than 2 TB with LBD.
This bug was reported originally in 2012, and the fix was created by the RDB author, Joanne Dow <[email protected]>. A patch had been discussed and reviewed on linux-m68k at that time but never officially submitted. This patch differs from Joanne's patch only in its use of sector_t instead of unsigned int. No checking for overflows is done (see patch 2 of this series for that).
Message-ID: <[email protected]>
---
Changes from v3:
- split off change of sector address type as quick fix.
- cast to sector_t in sector address calculations.
- move overflow checking to separate patch for more thorough review.
Changes from v4:
Andreas Schwab:
- correct cast to sector_t in sector address calculations
--- block/partitions/amiga.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
block/partitions/amiga.c +5 -4
@@ -32,7 +32,8 @@ int amiga_partition(struct parsed_partitions *state)unsigned char *data;struct RigidDiskBlock *rdb;struct PartitionBlock *pb; -int start_sect, nr_sects, blk, part, res =0 ; +sector_t start_sect, nr_sects; +int blk, part, res =0 ;int blksize =1 ;/* Multiplier for disk block size */ int slot =1 ;char b[BDEVNAME_SIZE ];
@@ -100,14 +101,14 @@ int amiga_partition(struct parsed_partitions *state)/* Tell Kernel about it */ - nr_sects = (be32_to_cpu (pb->pb_Environment[10 ]) +1 - -be32_to_cpu (pb->pb_Environment[9 ])) * + nr_sects = ((sector_t )be32_to_cpu (pb->pb_Environment[10 ]) + +1 -be32_to_cpu (pb->pb_Environment[9 ])) *be32_to_cpu (pb->pb_Environment[3 ]) *be32_to_cpu (pb->pb_Environment[5 ]) * blksize;if (!nr_sects)continue ; - start_sect =be32_to_cpu (pb->pb_Environment[9 ]) * + start_sect = (sector_t )be32_to_cpu (pb->pb_Environment[9 ]) *be32_to_cpu (pb->pb_Environment[3 ]) *be32_to_cpu (pb->pb_Environment[5 ]) * blksize;
Signature · 1 line
1.9.1
All,
is there anything further I could do to speed up acceptance of these patches?
Cheers,
Michael
Quoted 21 lines · Michael Schmitz
(hopefully) final version of the Amiga RDB partition table patch follows.
I've split off the part fixing the incorrect use of signed int for partition start address and size as separate patch. It does fix the bug that Martin Steigerwald reported six years ago for a 2 TB disk. I have tested this patch with the identical RDB partition data that Martin saw the bug with. I have incorporated Andreas' feedback on proper use of casts to avoid integer overflow in this version.
The simple fix still leaves ample room for overflows in calculating start address and size of a RDB partition, though such overflows should only be seen in rather unusual cases. To address these potential overflows, checks are added in the second patch of this series. Comments by Geert have been addressed in full.
Both patches now reviewed by Geert - Reviewed-by tags added.
Cheers,
Michael
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
In reply to Michael SchmitzMichael Schmitz - 15.10.18, 04:32:27 CEST:
Quoted 2 lines
The Amiga partition parser module uses signed int for partition sector address and count, which will overflow for disks larger than 1 TB.
Did this go in? I did not find anything in git log. I wonder whether I can close the bug report mentioned below.
Best,
Martin
Quoted 100 lines
Use u64 as type for sector address and size to allow using disks up to 2 TB without LBD support, and disks larger than 2 TB with LBD. The RBD format allows to specify disk sizes up to 2^128 bytes (though native OS limitations reduce this somewhat, to max 2^68 bytes), so check for u64 overflow carefully to protect against overflowing
sector_t.Bail out if sector addresses overflow 32 bits on kernels without LBD support.
This bug was reported originally in 2012, and the fix was created by the RDB author, Joanne Dow <[email protected]>. A patch had been discussed and reviewed on linux-m68k at that time but never officially submitted (now resubmitted as separate patch).
This patch adds additional error checking and warning messages.Reported-by Martin Steigerwald <[email protected]>Message-ID: <[email protected]>
Signed-off-by Michael Schmitz <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>---
Changes from RFC:
- use u64 instead of
sector_t, since that may be u32 without LBD support - check multiplication overflows each step - 3 u32 values may exceed u64! - warn against use on AmigaDOS if partition data overflow u32 sector count. - warn if partition CylBlocks larger than what's stored in the RDSK header. - bail out if we were to overflowsector_t(32 or 64 bit).Changes from v1:
Kars de Jong:
- use defines for magic offsets in DosEnvec structGeert Uytterhoeven:
- use u64 cast for multiplications of u32 numbers
- usearray3_sizefor overflow checks
- changepr_errtopr_warn
- discontinue use ofpr_cont
- reword log messages
- drop redundantnr_sectsoverflow test
- warn against 32 bit overflow for each affected partition
- skip partitions that overflowsector_tsize instead of aborting scanChanges from v2:
- further trim 32 bit overflow test
- correct duplicatetypes.hinclusion introduced in v2Changes from v3:
- split off sector address type fix for independent review
- change blksize to unsigned
- usecheck_mul_overflow()instead ofarray3_size()
- rewrite checks to avoid 64 bit divisions incheck_mul_overflow()Changes from v5:
Geert Uytterhoeven:
- correct ineffective u64 cast to avoid 32 bit mult. overflow
- fix mult. overflow in partition block address calculationChanges from v6:
Geert Uytterhoeven:
- don't fail hard on partition block address overflow--- block/partitions/amiga.c | 111+++++++++++++++++++++++++++++++++++++---------- 1 file changed, 89 insertions(+), 22 deletions(-)
block/partitions/amiga.c +8
-0@@ -11,11 +11,19 @@#define pr_fmt (fmt) fmt#include <linux/types.h> +#include <linux/mm_types.h> +#include <linux/overflow.h> #include <linux/affs_hardblocks.h> #include "check.h" #include "amiga.h" +/* magic offsets in partition DosEnvVec */ +#define NR_HD 3 +#define NR_SECT 5 +#define LO_CYL 9 +#define HI_CYL 10 +static __inline__u32 checksum_block (__be32 *m,int size) {
block/partitions/amiga.c int amiga_partition(struct parsed_partitions · line 45
Quoted 9 lines
block/partitions/amiga.c +3
-3@@ -32,9 +40,12 @@ int amiga_partition(struct parsed_partitions *state) unsigned char *data;struct RigidDiskBlock *rdb;struct PartitionBlock *pb; -sector_t start_sect, nr_sects; -int blk, part, res =0 ; -int blksize =1 ;/* Multiplier for disk block size */ +u64 start_sect, nr_sects; +sector_t blk, end_sect; +u32 cylblk;/* rdb_CylBlocks =
nr_heads*sect_per_track */
block/partitions/amiga.c int amiga_partition(struct parsed_partitions *state) · line 47
Quoted 11 lines
block/partitions/amiga.c +3
-1+u32 nr_hd, nr_sect, lo_cyl, hi_cyl; +int part, res =0 ; +unsigned int blksize =1 ;/* Multiplier for disk block size */ int slot =1 ;char b[BDEVNAME_SIZE ];@@ -44,8 +55,8 @@ int amiga_partition(struct parsed_partitions *state) data =read_part_sector (state, blk, §);if (!data) {if (warn_no_part) - pr_err("Dev %s: unable to read RDB block
%d\n",
block/partitions/amiga.c int amiga_partition(struct parsed_partitions *state) · line 58
Quoted 2 lines
block/partitions/amiga.c +1
-1- bdevname(state->bdev, b), blk); + pr_err("Dev %s: unable to read RDB block
%llu\n",
block/partitions/amiga.c int amiga_partition(struct parsed_partitions *state) · line 59
Quoted 1 line
block/partitions/amiga.c +1
-0+bdevname (state->bdev, b), (u64)
blk);
block/partitions/amiga.c int amiga_partition(struct parsed_partitions · line 74
Quoted 7 lines
block/partitions/amiga.c +0
-0res =-1 ; goto rdb_done; }@@ -61,13 +72,13 @@ int amiga_partition(struct parsed_partitions *state) *(__be32 *)(data+0xdc) = 0; if (checksum_block((__be32 *)data, be32_to_cpu(rdb->rdb_SummedLongs) &
0x7F)==0) {
block/partitions/amiga.c int amiga_partition(struct parsed_partitions · line 64
Quoted 1 line
block/partitions/amiga.c +0
-1- pr_err("Trashed word at 0xd0 in block %d ignored
in checksum
block/partitions/amiga.c int amiga_partition(struct parsed_partitions · line 76
Quoted 2 lines
block/partitions/amiga.c +1
-0calculation\n", - blk); + pr_err("Trashed word at 0xd0 in block %llu ignored
in checksum
Quoted 12 lines
block/partitions/amiga.c +2
-2calculation\n", + (u64) blk); break; } -pr_err ("Dev %s: RDB in block %d has bad checksum\n" , -bdevname (state->bdev, b), blk); +pr_err ("Dev %s: RDB in block %llu has bad checksum\n" , +bdevname (state->bdev, b), (u64 ) blk); }block/partitions/amiga.c +0
-0/* blksize is blocks per 512 byte standard block */
block/partitions/amiga.c int amiga_partition(struct parsed_partitions · line 96
Quoted 3 lines
block/partitions/amiga.c +0
-0@@ -83,12 +94,17 @@ int amiga_partition(struct parsed_partitions *state) blk = be32_to_cpu(rdb->rdb_PartitionList);put_dev_sector (sect);for (part =1 ; blk>0 && part<=16 ; part++,put_dev_sector (sect))
{
block/partitions/amiga.c int amiga_partition(struct parsed_partitions · line 86
Quoted 1 line
block/partitions/amiga.c +0
-1- blk *= blksize;/* Read in terms partition table
understands */
block/partitions/amiga.c int amiga_partition(struct parsed_partitions *state)
Quoted 3 lines
block/partitions/amiga.c +3
-0+/* Read in terms partition table understands */ +if (check_mul_overflow (blk, (sector_t ) blksize, &blk)) { + pr_err("Dev %s: overflow calculating partition
block %llu!
Quoted 1 line
Skipping partitions %u and beyond\n", +
bdevname(state->bdev, b),
block/partitions/amiga.c int amiga_partition(struct parsed_partitions *state)
Quoted 7 lines
(u64) blk, part);
block/partitions/amiga.c +2
-1+break ; + } data =read_part_sector (state, blk, §);if (!data) {if (warn_no_part) - pr_err("Dev %s: unable to read partition
block %d\n",
block/partitions/amiga.c
Quoted 2 lines
block/partitions/amiga.c +1
-1- bdevname(state->bdev, b), blk); + pr_err("Dev %s: unable to read partition
block %llu\n",
block/partitions/amiga.c
Quoted 1 line
block/partitions/amiga.c +1
-0+bdevname (state->bdev, b), (u64)
blk);
block/partitions/amiga.c int amiga_partition(struct parsed_partitions · line 118
Quoted 9 lines
block/partitions/amiga.c +1
-1res =-1 ; goto rdb_done; }@@ -99,19 +115,70 @@ int amiga_partition(struct parsed_partitions *state) if (checksum_block((__be32 *)pb,be32_to_cpu (pb->pb_SummedLongs) &0x7F ) !=0 )continue ; -/* Tell Kernel about it */ +/* RDB gives us more than enough rope to hang ourselves
with,
block/partitions/amiga.c int amiga_partition(struct parsed_partitions · line 120
Quoted 2 lines
block/partitions/amiga.c +2
-0+* many times over (2^128 bytes if all fields max out). +* Some careful checks are in order, so check for
potential
block/partitions/amiga.c int amiga_partition(struct parsed_partitions · line 122
Quoted 2 lines
block/partitions/amiga.c +2
-0+* overflows. +* We are multiplying four 32 bit numbers to one
sector_t!
block/partitions/amiga.c int amiga_partition(struct parsed_partitions *state)
Quoted 8 lines
block/partitions/amiga.c +8
-0+*/ + + nr_hd =be32_to_cpu (pb->pb_Environment[NR_HD ]); + nr_sect =be32_to_cpu (pb->pb_Environment[NR_SECT ]); + +/* CylBlocks is total number of blocks per cylinder */ +if (check_mul_overflow (nr_hd, nr_sect, &cylblk)) { + pr_err("Dev %s: heads*sects %u overflows u32,
skipping
block/partitions/amiga.c int amiga_partition(struct parsed_partitions · line 131
Quoted 1 line
block/partitions/amiga.c +0
-0partition!\n", + bdevname(state->bdev, b),
cylblk);
Quoted 6 lines
block/partitions/amiga.c +6
-0+continue ; + } + +/* check for consistency with RDB defined CylBlocks */ +if (cylblk >be32_to_cpu (rdb->rdb_CylBlocks)) { + pr_warn("Dev %s: cylblk %u > rdb_CylBlocks %u!\n",
block/partitions/amiga.c int amiga_partition(struct parsed_partitions *state)
Quoted 10 lines
block/partitions/amiga.c +10
-0+bdevname (state->bdev, b), cylblk, + be32_to_cpu(rdb->rdb_CylBlocks)); + } + +/* RDB allows for variable logical block size - +* normalize to 512 byte blocks and check result. +*/ + +if (check_mul_overflow (cylblk, blksize, &cylblk)) { + pr_err("Dev %s: partition %u bytes per cyl.
overflows u32,
block/partitions/amiga.c int amiga_partition(struct parsed_partitions · line 148
Quoted 1 line
block/partitions/amiga.c +0
-0skipping partition!\n", + bdevname(state->bdev,
b), part);
block/partitions/amiga.c int amiga_partition(struct parsed_partitions *state)
Quoted 4 lines
block/partitions/amiga.c +4
-0+continue ; + } + +/* Calculate partition start and end. Limit of 32 bit on
cylblk
block/partitions/amiga.c int amiga_partition(struct parsed_partitions · line 153
Quoted 1 line
block/partitions/amiga.c +1
-0+* guarantees no overflow occurs if LBD support is
enabled.
Quoted 18 lines
block/partitions/amiga.c +7
-6+*/ + + lo_cyl =be32_to_cpu (pb->pb_Environment[LO_CYL ]); + start_sect = ((u64 ) lo_cyl * cylblk); + + hi_cyl =be32_to_cpu (pb->pb_Environment[HI_CYL ]); + nr_sects = (((u64 ) hi_cyl - lo_cyl +1 ) * cylblk); - nr_sects = ((sector_t )be32_to_cpu (pb- pb_Environment[10]) - +1 -be32_to_cpu (pb->pb_Environment[9 ])) * -be32_to_cpu (pb->pb_Environment[3 ]) * -be32_to_cpu (pb->pb_Environment[5 ]) * - blksize;if (!nr_sects)continue ; - start_sect = (sector_t) be32_to_cpu(pb-pb_Environment[9]) *
block/partitions/amiga.c int amiga_partition(struct parsed_partitions *state)
Quoted 5 lines
block/partitions/amiga.c +2
-3-be32_to_cpu (pb->pb_Environment[3 ]) * -be32_to_cpu (pb->pb_Environment[5 ]) * - blksize; + +/* Warn user if partition end overflows u32 (AmigaDOS
limit) */
block/partitions/amiga.c int amiga_partition(struct parsed_partitions *state)
Quoted 3 lines
block/partitions/amiga.c +3
-0+ +if ((start_sect + nr_sects) >UINT_MAX ) { + pr_warn("Dev %s: partition %u (%llu-%llu) needs 64
bit device
block/partitions/amiga.c int amiga_partition(struct parsed_partitions *state)
Quoted 6 lines
support!\n", +
bdevname(state->bdev, b), part,block/partitions/amiga.c +5
-0+ start_sect, start_sect + nr_sects); + } + +if (check_add_overflow (start_sect, nr_sects, &end_sect)) { + pr_err("Dev %s: partition %u (%llu-%llu) needs LBD
device support,
Quoted 1 line
skipping partition!\n", + bdevname(state->bdev,
b), part,
Quoted 9 lines
block/partitions/amiga.c +6
-0+ start_sect, (u64) end_sect); +continue ; + } + +/* Tell Kernel about it */ +put_partition (state,slot++,start_sect,nr_sects); {/* Be even more informative to aid mounting */
Signature · 1 line
Martin
Jens Axboe
maintainerRe: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Quoted 6 lines · Martin Steigerwald
Michael Schmitz - 15.10.18, 04:32:27 CEST:
Quoted 2 lines
The Amiga partition parser module uses signed int for partition sector address and count, which will overflow for disks larger than 1 TB.
Did this go in? I did not find anything in git log. I wonder whether I can close the bug report mentioned below.
Looking at the history (2018!), doesn't like they ever got reviewed or went upstream. Looks like they are still needed, however they no longer apply as-is.
Signature · 1 line
Jens Axboe
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Hi Jens,
there's been quite a bit of review on this patch series back in the day (most of that would have been on linux-m68k IIRC; see Geert's Reviewed-By tag), and I addressed the issues raised but as you say, it did never get merged.
I've found a copy of the linux-block repo that has these patches, will see if I can get them updated to apply to current linux-block.
Cheers,
Michael
Quoted 10 lines · Jens Axboe
Quoted 5 lines · Martin Steigerwald
Michael Schmitz - 15.10.18, 04:32:27 CEST:
Quoted 2 lines
The Amiga partition parser module uses signed int for partition sector address and count, which will overflow for disks larger than 1 TB.
Did this go in? I did not find anything in git log. I wonder whether I can close the bug report mentioned below.
Looking at the history (2018!), doesn't like they ever got reviewed or went upstream. Looks like they are still needed, however they no longer apply as-is.
Jens Axboe
maintainerRe: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Quoted 9 lines · Michael Schmitz
Hi Jens,
there's been quite a bit of review on this patch series back in the day (most of that would have been on linux-m68k IIRC; see Geert's Reviewed-By tag), and I addressed the issues raised but as you say, it did never get merged.
I've found a copy of the linux-block repo that has these patches, will see if I can get them updated to apply to current linux-block.
Thanks, please do resend them and we can get them applied.
Signature · 1 line
Jens Axboe
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Hi Jens,
Am 26.07.2022 um 15:40 schrieb Jens Axboe:
Quoted 8 lines · Michael Schmitz
Quoted 7 lines
Hi Jens,
there's been quite a bit of review on this patch series back in the day (most of that would have been on linux-m68k IIRC; see Geert's Reviewed-By tag), and I addressed the issues raised but as you say, it did never get merged.
Quoted 4 lines
Quoted 2 lines
I've found a copy of the linux-block repo that has these patches, will see if I can get them updated to apply to current linux-block.
Thanks, please do resend them and we can get them applied.
Will do - running final compile tests.
Cheers,
Michael
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Michael Schmitz - 26.07.22, 05:58:40 CEST:
Quoted 9 lines
Am 26.07.2022 um 15:40 schrieb Jens Axboe:
Quoted 8 lines · Michael Schmitz
Quoted 7 lines
Hi Jens,
there's been quite a bit of review on this patch series back in the day (most of that would have been on linux-m68k IIRC; see Geert's Reviewed-By tag), and I addressed the issues raised but as you say, it did never get merged.
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
I've found a copy of the linux-block repo that has these patches, will see if I can get them updated to apply to current linux-block.>
Thanks, please do resend them and we can get them applied.
Will do - running final compile tests.
Just reminding. Did this go in meanwhile?
Thanks,
Signature · 1 line
Martin
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Martin,
Am 22.08.2022 um 08:59 schrieb Martin Steigerwald:
Quoted 10 lines
Michael Schmitz - 26.07.22, 05:58:40 CEST:
Quoted 9 lines
Am 26.07.2022 um 15:40 schrieb Jens Axboe:
Quoted 8 lines · Michael Schmitz
Quoted 7 lines
Hi Jens,
there's been quite a bit of review on this patch series back in the day (most of that would have been on linux-m68k IIRC; see Geert's Reviewed-By tag), and I addressed the issues raised but as you say, it did never get merged.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
I've found a copy of the linux-block repo that has these patches, will see if I can get them updated to apply to current linux-block.>
Thanks, please do resend them and we can get them applied.
Will do - running final compile tests.
Just reminding. Did this go in meanwhile?
Not yet, at last count.
Christoph had reviewed v8 and I've addressed his comments in v9. Should have added his Reviewed-by tag for both patches perhaps, not just patch 1.
Shall I resend v9 with that omission rectified, Jens?
Cheers,
Michael
Quoted 3 lines
Thanks,
Jens Axboe
maintainerRe: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Quoted 22 lines · Michael Schmitz
Martin,
Am 22.08.2022 um 08:59 schrieb Martin Steigerwald:
Quoted 10 lines
Michael Schmitz - 26.07.22, 05:58:40 CEST:
Quoted 9 lines
Am 26.07.2022 um 15:40 schrieb Jens Axboe:
Quoted 8 lines · Michael Schmitz
Quoted 7 lines
Hi Jens,
there's been quite a bit of review on this patch series back in the day (most of that would have been on linux-m68k IIRC; see Geert's Reviewed-By tag), and I addressed the issues raised but as you say, it did never get merged.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
I've found a copy of the linux-block repo that has these patches, will see if I can get them updated to apply to current linux-block.>
Thanks, please do resend them and we can get them applied.
Will do - running final compile tests.
Just reminding. Did this go in meanwhile?
Quoted 7 lines
Not yet, at last count.
Christoph had reviewed v8 and I've addressed his comments in v9. Should have added his Reviewed-by tag for both patches perhaps, not just patch 1.
Shall I resend v9 with that omission rectified, Jens?
Yes please, thanks.
Signature · 1 line
Jens Axboe
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Hi Jens,
will do - just waiting to hear back what needs to be done regarding backporting issues raised by Geert.
Cheers,
Michael
Quoted 29 lines · Jens Axboe
Quoted 18 lines · Michael Schmitz
Martin,
Am 22.08.2022 um 08:59 schrieb Martin Steigerwald:
Quoted 15 lines
Michael Schmitz - 26.07.22, 05:58:40 CEST:
Quoted 14 lines
Am 26.07.2022 um 15:40 schrieb Jens Axboe:
Quoted 8 lines · Michael Schmitz
Quoted 7 lines
Hi Jens,
there's been quite a bit of review on this patch series back in the day (most of that would have been on linux-m68k IIRC; see Geert's Reviewed-By tag), and I addressed the issues raised but as you say, it did never get merged.
Quoted 4 lines
Quoted 3 lines
I've found a copy of the linux-block repo that has these patches, will see if I can get them updated to apply to current linux-block.>
Thanks, please do resend them and we can get them applied.
Will do - running final compile tests.
Quoted 8 lines
Quoted 1 line
Just reminding. Did this go in meanwhile?
Not yet, at last count.
Christoph had reviewed v8 and I've addressed his comments in v9. Should have added his Reviewed-by tag for both patches perhaps, not just patch 1.
Shall I resend v9 with that omission rectified, Jens?
Yes please, thanks.
Jens Axboe
maintainerRe: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Quoted 4 lines · Michael Schmitz
Hi Jens,
will do - just waiting to hear back what needs to be done regarding backporting issues raised by Geert.
It needs to go upstream first before it can go to stable. Just mark it with the right Fixes tags and that will happen automatically.
Signature · 1 line
Jens Axboe
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Hi Jens,
thanks - the Fixes tag in my patches refers to Martin's bug report and won't be useful to decide how far back this must be applied.
Now the bug pre-dates git, making the commit to 'fix' 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 ... That one's a bit special, please yell if you want me to lie about this and use a later commit specific to the partition parser code.
Cheers,
Michael
Quoted 8 lines · Jens Axboe
Quoted 4 lines · Michael Schmitz
Hi Jens,
will do - just waiting to hear back what needs to be done regarding backporting issues raised by Geert.
It needs to go upstream first before it can go to stable. Just mark it with the right Fixes tags and that will happen automatically.
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Hi Michael, hi Jens, Hi Geert.
Michael Schmitz - 22.08.22, 22:56:10 CEST:
Quoted 9 lines · Jens Axboe
Quoted 8 lines · Michael Schmitz
Quoted 4 lines
Hi Jens,
will do - just waiting to hear back what needs to be done regarding backporting issues raised by Geert.
It needs to go upstream first before it can go to stable. Just mark it with the right Fixes tags and that will happen automatically.
[…]
Quoted 7 lines
thanks - the Fixes tag in my patches refers to Martin's bug report and won't be useful to decide how far back this must be applied.
Now the bug pre-dates git, making the commit to 'fix'
1da177e4c3f41524e886b7f1b8a0c1fc7321cac2... That one's a bit special, please yell if you want me to lie about this and use a later commit specific to the partition parser code.
After this discussion happened I thought the patch went in. However… as John Paul Adrian asked in "Status of affs support in the kernel and affstools" thread on linux-m68k and debian-68k mailing list, I searched for the patch in git history but did not find it.
So did it go in meanwhile?
Ciao,
Signature · 1 line
Martin
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Hi Martin,
Am 13.06.2023 um 19:25 schrieb Martin Steigerwald:
Quoted 21 lines
Hi Michael, hi Jens, Hi Geert.
Michael Schmitz - 22.08.22, 22:56:10 CEST:
Quoted 9 lines · Jens Axboe
Quoted 8 lines · Michael Schmitz
Quoted 4 lines
Hi Jens,
will do - just waiting to hear back what needs to be done regarding backporting issues raised by Geert.
It needs to go upstream first before it can go to stable. Just mark it with the right Fixes tags and that will happen automatically.
[…]
Quoted 7 lines
thanks - the Fixes tag in my patches refers to Martin's bug report and won't be useful to decide how far back this must be applied.
Now the bug pre-dates git, making the commit to 'fix'
1da177e4c3f41524e886b7f1b8a0c1fc7321cac2... That one's a bit special, please yell if you want me to lie about this and use a later commit specific to the partition parser code.
Quoted 4 lines
After this discussion happened I thought the patch went in. However… as John Paul Adrian asked in "Status of affs support in the kernel and affstools" thread on linux-m68k and debian-68k mailing list, I searched for the patch in git history but did not find it.
I may have messed that one up, as it turns out. Last version was v9 which I had to resend twice, and depending on what Jens uses to keep track of patches, the resends may not have shown up in his tool. I should have bumped the version number instead.
I'll see if my latest version still applies cleanly ...
Cheers,
Michael
Quoted 4 lines
So did it go in meanwhile?
Ciao,
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Michael Schmitz - 13.06.23, 10:18:24 CEST:
Quoted 31 lines
Am 13.06.2023 um 19:25 schrieb Martin Steigerwald:
Quoted 25 lines
Hi Michael, hi Jens, Hi Geert.
Michael Schmitz - 22.08.22, 22:56:10 CEST:
Quoted 11 lines · Jens Axboe
Quoted 10 lines · Michael Schmitz
Quoted 5 lines
Hi Jens,
will do - just waiting to hear back what needs to be done regarding
backporting issues raised by Geert.It needs to go upstream first before it can go to stable. Just mark
it with the right Fixes tags and that will happen automatically.[…]
Quoted 7 lines
thanks - the Fixes tag in my patches refers to Martin's bug report and won't be useful to decide how far back this must be applied.
Now the bug pre-dates git, making the commit to 'fix'
1da177e4c3f41524e886b7f1b8a0c1fc7321cac2... That one's a bit special, please yell if you want me to lie about this and use a later commit specific to the partition parser code.Quoted 4 lines
After this discussion happened I thought the patch went in. However… as John Paul Adrian asked in "Status of affs support in the kernel and affstools" thread on linux-m68k and debian-68k mailing list, I searched for the patch in git history but did not find it.
Quoted 6 lines
I may have messed that one up, as it turns out. Last version was v9 which I had to resend twice, and depending on what Jens uses to keep track of patches, the resends may not have shown up in his tool. I should have bumped the version number instead.
I'll see if my latest version still applies cleanly ...
Many thanks!
Would be nice to see it finally go in.
Best,
Signature · 1 line
Martin
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Hi Martin,
Quoted 33 lines · Martin Steigerwald
Michael Schmitz - 13.06.23, 10:18:24 CEST:
Quoted 32 lines
Am 13.06.2023 um 19:25 schrieb Martin Steigerwald:
Quoted 18 lines
Hi Michael, hi Jens, Hi Geert.
Michael Schmitz - 22.08.22, 22:56:10 CEST:
Quoted 10 lines · Jens Axboe
Quoted 9 lines · Michael Schmitz
Quoted 5 lines
Hi Jens,
will do - just waiting to hear back what needs to be done regarding
backporting issues raised by Geert.It needs to go upstream first before it can go to stable. Just mark
it with the right Fixes tags and that will happen automatically.[…]
Quoted 3 lines
thanks - the Fixes tag in my patches refers to Martin's bug report and won't be useful to decide how far back this must be applied.
Quoted 8 lines
Quoted 4 lines
Now the bug pre-dates git, making the commit to 'fix'
1da177e4c3f41524e886b7f1b8a0c1fc7321cac2... That one's a bit special, please yell if you want me to lie about this and use a later commit specific to the partition parser code.After this discussion happened I thought the patch went in. However… as John Paul Adrian asked in "Status of affs support in the kernel and affstools" thread on linux-m68k and debian-68k mailing list, I searched for the patch in git history but did not find it.
I may have messed that one up, as it turns out. Last version was v9 which I had to resend twice, and depending on what Jens uses to keep track of patches, the resends may not have shown up in his tool. I should have bumped the version number instead.
Quoted 4 lines
Quoted 1 line
I'll see if my latest version still applies cleanly ...
Many thanks!
Would be nice to see it finally go in.
My last version (v9) still applies, but that one still threw a sparse warning for patch 2:
Not sure how to treat that one - rdb_CylBlocks is not declared as big endian so the warning is correct, but as far as I can see, for all practical purposes rdb_CylBlocks would be expected to be in big endian order (partition usually prepared on a big endian system)?
I can drop the be32_to_cpu conversion (and would expect to see a warning printed on little endian systems), or force the cast to __be32. Or rather drop that consistency check outright...
Cheers,
Michael
Quoted 2 lines
Best,
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Quoted 5 lines · Michael Schmitz
My last version (v9) still applies, but that one still threw a sparse warning for patch 2:
Quoted 9 lines
Not sure how to treat that one -
rdb_CylBlocksis not declared as big endian so the warning is correct, but as far as I can see, for all practical purposesrdb_CylBlockswould be expected to be in big endian order (partition usually prepared on a big endian system)?I can drop the
be32_to_cpuconversion (and would expect to see a warning printed on little endian systems), or force the cast to__be32. Or rather drop that consistency check outright...
The new warning comes from this new code:
if (cylblk > be32_to_cpu((__be32)rdb->rdb_CylBlocks)) {
pr_warn("Dev %s: cylblk %u > rdb_CylBlocks %u!\n",
state->disk->disk_name, cylblk,
be32_to_cpu(rdb->rdb_CylBlocks));
}The __be32 cast appears in the first line but not the fourth, which is an inconsistency you might want to tidy up. However, both lines produce the same sparse warning here.
The inconsistent use of big-endian and native-endian members in struct RigidDiskBlock looks like the root cause to me but I know nothing about Amiga partition maps so I'm not going to guess.
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Hi Finn,
Quoted 24 lines · Finn Thain
Quoted 5 lines · Michael Schmitz
My last version (v9) still applies, but that one still threw a sparse warning for patch 2:
Quoted 9 lines
Not sure how to treat that one -
rdb_CylBlocksis not declared as big endian so the warning is correct, but as far as I can see, for all practical purposesrdb_CylBlockswould be expected to be in big endian order (partition usually prepared on a big endian system)?I can drop the
be32_to_cpuconversion (and would expect to see a warning printed on little endian systems), or force the cast to__be32. Or rather drop that consistency check outright...The new warning comes from this new code:
if (cylblk > be32_to_cpu((__be32)rdb->rdb_CylBlocks)) { pr_warn("Dev %s: cylblk %u > rdb_CylBlocks %u!\n", state->disk->disk_name, cylblk, be32_to_cpu(rdb->rdb_CylBlocks)); }
Quoted 3 lines
The
__be32cast appears in the first line but not the fourth, which is an inconsistency you might want to tidy up. However, both lines produce the same sparse warning here.
Thanks for checking that - the cast is redundant as-is (be32_to_cpu() contains the same cast already). Does use of (__force __be32) instead make the warning go away? (I haven't managed to get sparse working for me, so I have no way of checking.)
Quoted 3 lines
The inconsistent use of big-endian and native-endian members in struct RigidDiskBlock looks like the root cause to me but I know nothing about Amiga partition maps so I'm not going to guess.
The check appeared in the first version of the patch, after discussion around the RFC version at length. Going over that thread again, I haven't found why that check was added. It's probably been out of an overabundance of caution (as I know little about RDB, too) and can probably be removed.
Cheers,
Michael
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
In reply to Michael SchmitzHi Michael, hi Joanne.
@Joanne: I am cc'ing you in this patch as I bet you might be able to confirm whether the rdb_CylBlocks value in Amiga RDB is big endian. I hope you do not mind. I would assume that everything in Amiga RDB is big endian, but I bet you know for certain.
Michael Schmitz - 14.06.23, 00:11:45 CEST:
Quoted 50 lines · Martin Steigerwald
Quoted 40 lines
Michael Schmitz - 13.06.23, 10:18:24 CEST:
Quoted 39 lines
Am 13.06.2023 um 19:25 schrieb Martin Steigerwald:
Quoted 26 lines
Hi Michael, hi Jens, Hi Geert.
Michael Schmitz - 22.08.22, 22:56:10 CEST:
Quoted 11 lines · Jens Axboe
Quoted 10 lines · Michael Schmitz
Quoted 5 lines
Hi Jens,
will do - just waiting to hear back what needs to be done regarding
backporting issues raised by Geert.It needs to go upstream first before it can go to stable. Just mark
it with the right Fixes tags and that will happen automatically.[…]
Quoted 8 lines
thanks - the Fixes tag in my patches refers to Martin's bug report
and won't be useful to decide how far back this must be applied.Now the bug pre-dates git, making the commit to 'fix'
1da177e4c3f41524e886b7f1b8a0c1fc7321cac2... That one's a bit special, please yell if you want me to lie about this and use a later commit specific to the partition parser code.Quoted 5 lines
After this discussion happened I thought the patch went in. However…
as John Paul Adrian asked in "Status of affs support in the kernel and affstools" thread on linux-m68k and debian-68k mailing list, I searched for the patch in git history but did not find it.I may have messed that one up, as it turns out. Last version was v9 which I had to resend twice, and depending on what Jens uses to keep
track of patches, the resends may not have shown up in his tool. I should have bumped the version number instead.Quoted 5 lines
Quoted 1 line
I'll see if my latest version still applies cleanly ...
Many thanks!
Would be nice to see it finally go in.
My last version (v9) still applies, but that one still threw a sparse warning for patch 2:
Quoted 6 lines
Not sure how to treat that one -
rdb_CylBlocksis not declared as big endian so the warning is correct, but as far as I can see, for all practical purposesrdb_CylBlockswould be expected to be in big endian order (partition usually prepared on a big endian system)?
While I did not specifically check myself I would be highly surprised in case anything in RDB data structure would be little endian. Amiga is a big endian platform. I'd expect little endian only to be used where there was need to interface with little endian platforms – like in PC emulators.
It may not be easy to find any confirmation in developer documentation, I'd assume that wherever it would not have been stated differently, big endian is assumed for AmigaOS.
Quoted 3 lines
I can drop the
be32_to_cpuconversion (and would expect to see a warning printed on little endian systems), or force the cast to__be32. Or rather drop that consistency check outright...
So "be32_to_cpu" converts big to little endian in case the CPU architecture Linux runs on is little endian?
Well again… I'd say it is safe to assume that anything in Amiga RDB is big endian.
Best,
Signature · 1 line
Martin
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Hi Martin,
Am 14.06.2023 um 19:19 schrieb Martin Steigerwald:
Quoted 65 lines
Hi Michael, hi Joanne.
@Joanne: I am cc'ing you in this patch as I bet you might be able to confirm whether the
rdb_CylBlocksvalue in Amiga RDB is big endian. I hope you do not mind. I would assume that everything in Amiga RDB is big endian, but I bet you know for certain.Michael Schmitz - 14.06.23, 00:11:45 CEST:
Quoted 50 lines · Martin Steigerwald
Quoted 40 lines
Michael Schmitz - 13.06.23, 10:18:24 CEST:
Quoted 39 lines
Am 13.06.2023 um 19:25 schrieb Martin Steigerwald:
Quoted 26 lines
Hi Michael, hi Jens, Hi Geert.
Michael Schmitz - 22.08.22, 22:56:10 CEST:
Quoted 11 lines · Jens Axboe
Quoted 10 lines · Michael Schmitz
Quoted 5 lines
Hi Jens,
will do - just waiting to hear back what needs to be done regarding
backporting issues raised by Geert.It needs to go upstream first before it can go to stable. Just mark
it with the right Fixes tags and that will happen automatically.[…]
Quoted 8 lines
thanks - the Fixes tag in my patches refers to Martin's bug report
and won't be useful to decide how far back this must be applied.Now the bug pre-dates git, making the commit to 'fix'
1da177e4c3f41524e886b7f1b8a0c1fc7321cac2... That one's a bit special, please yell if you want me to lie about this and use a later commit specific to the partition parser code.Quoted 5 lines
After this discussion happened I thought the patch went in. However…
as John Paul Adrian asked in "Status of affs support in the kernel and affstools" thread on linux-m68k and debian-68k mailing list, I searched for the patch in git history but did not find it.I may have messed that one up, as it turns out. Last version was v9 which I had to resend twice, and depending on what Jens uses to keep
track of patches, the resends may not have shown up in his tool. I should have bumped the version number instead.Quoted 5 lines
Quoted 1 line
I'll see if my latest version still applies cleanly ...
Many thanks!
Would be nice to see it finally go in.
My last version (v9) still applies, but that one still threw a sparse warning for patch 2:
Quoted 6 lines
Not sure how to treat that one -
rdb_CylBlocksis not declared as big endian so the warning is correct, but as far as I can see, for all practical purposesrdb_CylBlockswould be expected to be in big endian order (partition usually prepared on a big endian system)?
Quoted 5 lines
While I did not specifically check myself I would be highly surprised in case anything in RDB data structure would be little endian. Amiga is a big endian platform. I'd expect little endian only to be used where there was need to interface with little endian platforms – like in PC emulators.
That's what I thought - mind you, rdb_CylBlocks is not declared little endian, just __u32 which can be either.
The reason why only rdb_SummedLongs, rdb_BlockBytes and rdb_PartitionList are explicitly declared big endian is probably quite simple - nothing else was used by the Linux RDB parser. My patch adds rdb_CylBlocks to that list, so that ought to be changed to big endian, too.
affs_hardblocks.h is a UAPI header - what are the rules and ramifications around changes to those? Might not be worth the hassle in the end.
Quoted 10 lines
It may not be easy to find any confirmation in developer documentation, I'd assume that wherever it would not have been stated differently, big endian is assumed for AmigaOS.
Quoted 3 lines
I can drop the
be32_to_cpuconversion (and would expect to see a warning printed on little endian systems), or force the cast to__be32. Or rather drop that consistency check outright...So "
be32_to_cpu" converts big to little endian in case the CPU architecture Linux runs on is little endian?
Correct - in order to use RDB partitions on little endian systems, all of the data used by the Linux kernel must be converted to host byte order before using them in calculations.
Quoted 3 lines
Well again… I'd say it is safe to assume that anything in Amiga RDB is big endian.
Let's do that then. Unless someone feels strongly otherwise, I'll drop the rdb_CylBlocks check.
Cheers,
Michael
Quoted 3 lines
Best,
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
In reply to a message not in the archiveHi Joanne,
this is about the 2 TB disk issue - 32 bit integer overflow on start_sect and nr_sects. The fix for that never went in.
Thanks for confirming everything in the RDB is meant to be big endian.
Quoted 3 lines · jdow
The patch I did a LONG time ago read the RDBs correctly. I presume it was removed from the kernel build and lost? (I fixed what had been there because it would not mount some of my disks. RDBs permit some very um "unsavory" things such as nested partitions.)
The other 'unsavoury' thing that worries us here is the fact that the number of heads and sectors (per cylinder) is defined in the partition block as well as in the RDB. We use the data from the partition block to calculate start sector and number of sectors for a partition, and my overflow checking path added a test that heads*sectors == rdb_CylBlocks. I wonder how important that test is - do you know of any case where the head and sector numbers in RDB and partition blocks differ?
Thanks again,
Michael
Quoted 109 lines
{^_^}
Quoted 106 lines · Michael Schmitz
Hi Martin,
Am 14.06.2023 um 19:19 schrieb Martin Steigerwald:
Quoted 65 lines
Hi Michael, hi Joanne.
@Joanne: I am cc'ing you in this patch as I bet you might be able to confirm whether the
rdb_CylBlocksvalue in Amiga RDB is big endian. I hope you do not mind. I would assume that everything in Amiga RDB is big endian, but I bet you know for certain.Michael Schmitz - 14.06.23, 00:11:45 CEST:
Quoted 50 lines · Martin Steigerwald
Quoted 40 lines
Michael Schmitz - 13.06.23, 10:18:24 CEST:
Quoted 39 lines
Am 13.06.2023 um 19:25 schrieb Martin Steigerwald:
Quoted 26 lines
Hi Michael, hi Jens, Hi Geert.
Michael Schmitz - 22.08.22, 22:56:10 CEST:
Quoted 11 lines · Jens Axboe
Quoted 10 lines · Michael Schmitz
Quoted 5 lines
Hi Jens,
will do - just waiting to hear back what needs to be done regarding
backporting issues raised by Geert.It needs to go upstream first before it can go to stable. Just mark
it with the right Fixes tags and that will happen automatically.[…]
Quoted 8 lines
thanks - the Fixes tag in my patches refers to Martin's bug report
and won't be useful to decide how far back this must be applied.Now the bug pre-dates git, making the commit to 'fix'
1da177e4c3f41524e886b7f1b8a0c1fc7321cac2... That one's a bit special, please yell if you want me to lie about this and use a later commit specific to the partition parser code.Quoted 5 lines
After this discussion happened I thought the patch went in. However…
as John Paul Adrian asked in "Status of affs support in the kernel and affstools" thread on linux-m68k and debian-68k mailing list, I searched for the patch in git history but did not find it.I may have messed that one up, as it turns out. Last version was v9 which I had to resend twice, and depending on what Jens uses to keep
track of patches, the resends may not have shown up in his tool. I should have bumped the version number instead.Quoted 5 lines
Quoted 1 line
I'll see if my latest version still applies cleanly ...
Many thanks!
Would be nice to see it finally go in.
My last version (v9) still applies, but that one still threw a sparse warning for patch 2:
Quoted 6 lines
Not sure how to treat that one -
rdb_CylBlocksis not declared as big endian so the warning is correct, but as far as I can see, for all practical purposesrdb_CylBlockswould be expected to be in big endian order (partition usually prepared on a big endian system)?Quoted 5 lines
While I did not specifically check myself I would be highly surprised in case anything in RDB data structure would be little endian. Amiga is a big endian platform. I'd expect little endian only to be used where there was need to interface with little endian platforms – like in PC emulators.
That's what I thought - mind you,
rdb_CylBlocksis not declared little endian, just__u32which can be either.The reason why only
rdb_SummedLongs,rdb_BlockBytesandrdb_PartitionListare explicitly declared big endian is probably quite simple - nothing else was used by the Linux RDB parser. My patch addsrdb_CylBlocksto that list, so that ought to be changed to big endian, too.
affs_hardblocks.his a UAPI header - what are the rules and ramifications around changes to those? Might not be worth the hassle in the end.Quoted 10 lines
It may not be easy to find any confirmation in developer documentation, I'd assume that wherever it would not have been stated differently, big endian is assumed for AmigaOS.
Quoted 3 lines
I can drop the
be32_to_cpuconversion (and would expect to see a warning printed on little endian systems), or force the cast to__be32. Or rather drop that consistency check outright...So "
be32_to_cpu" converts big to little endian in case the CPU architecture Linux runs on is little endian?Correct - in order to use RDB partitions on little endian systems, all of the data used by the Linux kernel must be converted to host byte order before using them in calculations.
Quoted 3 lines
Well again… I'd say it is safe to assume that anything in Amiga RDB is big endian.
Let's do that then. Unless someone feels strongly otherwise, I'll drop the
rdb_CylBlockscheck.Cheers,
Michael
Quoted 3 lines
Best,
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
In reply to Michael SchmitzQuoted 11 lines · Michael Schmitz
The reason why only
rdb_SummedLongs,rdb_BlockBytesandrdb_PartitionListare explicitly declared big endian is probably quite simple - nothing else was used by the Linux RDB parser. My patch addsrdb_CylBlocksto that list, so that ought to be changed to big endian, too.
affs_hardblocks.his a UAPI header - what are the rules and ramifications around changes to those? Might not be worth the hassle in the end.
I think it's safe to fix the UAPI header if we are talking about endianness annotations that affect static checking and not code generation. The existing annotations in that struct would appear to support that notion, if indeed they were put there for the benefit of the kernel.
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
Hi Finn,
[resent after it bounced from vger ...]
Quoted 12 lines · Finn Thain
Quoted 10 lines · Michael Schmitz
The reason why only
rdb_SummedLongs,rdb_BlockBytesandrdb_PartitionListare explicitly declared big endian is probably quite simple - nothing else was used by the Linux RDB parser. My patch addsrdb_CylBlocksto that list, so that ought to be changed to big endian, too.
affs_hardblocks.his a UAPI header - what are the rules and ramifications around changes to those? Might not be worth the hassle in the end.
Quoted 5 lines
I think it's safe to fix the UAPI header if we are talking about endianness annotations that affect static checking and not code generation. The existing annotations in that struct would appear to support that notion, if indeed they were put there for the benefit of the kernel.
The annotations pre-date mainstream git history - looking at Thomas Gleixner's full history git (https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/), the annotations were added by Al Viro in 2004 (commit 380768f5a50524ff7eab00d03d82a56cf2fdfe7b <https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/include/linux/affs_hardblocks.h?id=380768f5a50524ff7eab00d03d82a56cf2fdfe7b> there).
Al said at the time that he only annotated only those fields that are used by the kernel, and left everything else alone even though it all ought to be big endian.
Reason enough to now change the rdb_CylBlocks annotation.
Thanks,
Michael
Re: [PATCH v7 2/2] block: add overflow checks for Amiga partition support
In reply to Finn ThainQuoted 10 lines · Finn Thain
Quoted 4 lines
affs_hardblocks.his a UAPI header - what are the rules and ramifications around changes to those? Might not be worth the hassle in the end.I think it's safe to fix the UAPI header if we are talking about endianness annotations that affect static checking and not code generation. The existing annotations in that struct would appear to support that notion, if indeed they were put there for the benefit of the kernel.
More importantly there has never been any API gurantee in the UAPI headers. Compiling user space code absolutely may break due to changes to them (although we avoid that if we can), we just must not change the kernel ABI. But as as said the __be annotations are no-ops for compilers, and do the right thing even in userspace for projects using sparse.