Skip to content

Fix memory corruptions in SD#616

Merged
arogge merged 2 commits intobareos:masterfrom
arogge:dev/arogge/master/TT4200696
Oct 1, 2020
Merged

Fix memory corruptions in SD#616
arogge merged 2 commits intobareos:masterfrom
arogge:dev/arogge/master/TT4200696

Conversation

@arogge
Copy link
Member

@arogge arogge commented Sep 30, 2020

When a device in the SD is configured with custom Maximum Block Size, autolabeling may cause a memory corruption. When writing to a volume with a larger blocksize than the label blocksize and then autolabels a new volume, WriteNewVolumeLabel() would call EmptyBlock() with an invalid pointer leading to heap corruption.
While pinpointing this problem, valgrind also flagged the use of uninitialized struct mtop in generic_tape_device. While this was probably not a real issue, the struct mtop is now always initialized, so valgrind does not complain anymore.

pointer lifetime in WriteNewVolumeLabelToDev()
Previously, in WriteNewVolumeLabelToDev() a copy of the pointer
dcr->block was saved and then used as a parameter to EmptyBlock(). This
pointer's lifetime ends in dev->SetLabelBlockSize() when the previously
written device's block size was larger than the label block size.
This patch removes the copy and uses dcr->block directly, so the updated
pointer is used.
When running in valgrind the ioctl() call that consumes struct mtop is
flagged as accessing uninitialized memory. This patch initializes every
struct mtop.
@arogge arogge requested a review from franku September 30, 2020 14:32
Copy link
Contributor

@franku franku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good you found that!

@arogge arogge merged commit 15397ad into bareos:master Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants