Skip to content

Commit a73b4bf

Browse files
sgtathamaloktiwa
authored andcommitted
affs: don't write overlarge OFS data block size fields
[ Upstream commit 011ea74 ] If a data sector on an OFS floppy contains a value > 0x1e8 (the largest amount of data that fits in the sector after its header), then an Amiga reading the file can return corrupt data, by taking the overlarge size at its word and reading past the end of the buffer it read the disk sector into! The cause: when affs_write_end_ofs() writes data to an OFS filesystem, the new size field for a data block was computed by adding the amount of data currently being written (into the block) to the existing value of the size field. This is correct if you're extending the file at the end, but if you seek backwards in the file and overwrite _existing_ data, it can lead to the size field being larger than the maximum legal value. This commit changes the calculation so that it sets the size field to the max of its previous size and the position within the block that we just wrote up to. Signed-off-by: Simon Tatham <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 04039a38068a10612a7689aa72c111ff700694c3) Signed-off-by: Alok Tiwari <[email protected]>
1 parent 44d16a1 commit a73b4bf

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/affs/file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,8 @@ static int affs_write_end_ofs(struct file *file, struct address_space *mapping,
724724
tmp = min(bsize - boff, to - from);
725725
BUG_ON(boff + tmp > bsize || tmp > bsize);
726726
memcpy(AFFS_DATA(bh) + boff, data + from, tmp);
727-
be32_add_cpu(&AFFS_DATA_HEAD(bh)->size, tmp);
727+
AFFS_DATA_HEAD(bh)->size = cpu_to_be32(
728+
max(boff + tmp, be32_to_cpu(AFFS_DATA_HEAD(bh)->size)));
728729
affs_fix_checksum(sb, bh);
729730
mark_buffer_dirty_inode(bh, inode);
730731
written += tmp;

0 commit comments

Comments
 (0)