snapuserd: Address alignment fault on 32-bit systems
When the scratch space is mmap'ed, the metadata buffer will be un-aligned. This may lead to alignment fault on 32-bit systems. Address this by temporarily copying it to buffer. No perf impact as this code path is not in I/O path and the copy is a for the size of metadata buffer which is 8k. Bug: 206426215 Test: Full and Incremental OTA on pixel 1: Compile snapuserd as 32 bit and reproduced the bug on pixel. 2: With fix - OTA applied successfully. 3: Reboot the device when merge was in-flight as the fix is primarily in that path. 4: Verify merge completion and data integrity post merge. Signed-off-by: Akilesh Kailash <akailash@google.com> Change-Id: I63c0d862057ebf138c9d1696a942030e30598739
This commit is contained in:
parent
904cae37ce
commit
14e9504d2e
|
@ -246,9 +246,15 @@ bool ReadAheadThread::ReconstructDataFromCow() {
|
|||
int num_ops = 0;
|
||||
int total_blocks_merged = 0;
|
||||
|
||||
// This memcpy is important as metadata_buffer_ will be an unaligned address and will fault
|
||||
// on 32-bit systems
|
||||
std::unique_ptr<uint8_t[]> metadata_buffer =
|
||||
std::make_unique<uint8_t[]>(snapuserd_->GetBufferMetadataSize());
|
||||
memcpy(metadata_buffer.get(), metadata_buffer_, snapuserd_->GetBufferMetadataSize());
|
||||
|
||||
while (true) {
|
||||
struct ScratchMetadata* bm = reinterpret_cast<struct ScratchMetadata*>(
|
||||
(char*)metadata_buffer_ + metadata_offset);
|
||||
(char*)metadata_buffer.get() + metadata_offset);
|
||||
|
||||
// Done reading metadata
|
||||
if (bm->new_block == 0 && bm->file_offset == 0) {
|
||||
|
|
|
@ -121,9 +121,15 @@ bool ReadAhead::ReconstructDataFromCow() {
|
|||
int num_ops = 0;
|
||||
int total_blocks_merged = 0;
|
||||
|
||||
// This memcpy is important as metadata_buffer_ will be an unaligned address and will fault
|
||||
// on 32-bit systems
|
||||
std::unique_ptr<uint8_t[]> metadata_buffer =
|
||||
std::make_unique<uint8_t[]>(snapuserd_->GetBufferMetadataSize());
|
||||
memcpy(metadata_buffer.get(), metadata_buffer_, snapuserd_->GetBufferMetadataSize());
|
||||
|
||||
while (true) {
|
||||
struct ScratchMetadata* bm = reinterpret_cast<struct ScratchMetadata*>(
|
||||
(char*)metadata_buffer_ + metadata_offset);
|
||||
(char*)metadata_buffer.get() + metadata_offset);
|
||||
|
||||
// Done reading metadata
|
||||
if (bm->new_block == 0 && bm->file_offset == 0) {
|
||||
|
|
Loading…
Reference in New Issue