From 2ca0700b450679ccf5855a48b2ffd7fc0a5a76ba Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 19 Jun 2019 19:01:14 -0700 Subject: [PATCH] liblp: Handle invalid alignment offsets correctly. When stacking devices with dm-linear, it is possible to get a -1 alignment offset. In this case we should set alignment_offset to 0 rather than fail later trying to divide -1 by the sector size. Bug: 134536978 Test: manual test Change-Id: I3862fdda69531a3b230b7316707469a49ba871d6 --- fs_mgr/liblp/partition_opener.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs_mgr/liblp/partition_opener.cpp b/fs_mgr/liblp/partition_opener.cpp index 3b12213c3..cc4a8821f 100644 --- a/fs_mgr/liblp/partition_opener.cpp +++ b/fs_mgr/liblp/partition_opener.cpp @@ -64,6 +64,12 @@ bool GetBlockDeviceInfo(const std::string& block_device, BlockDeviceInfo* device PERROR << __PRETTY_FUNCTION__ << "BLKALIGNOFF failed on " << block_device; return false; } + // The kernel can return -1 here when misaligned devices are stacked (i.e. + // device-mapper). + if (alignment_offset == -1) { + alignment_offset = 0; + } + int logical_block_size; if (ioctl(fd, BLKSSZGET, &logical_block_size) < 0) { PERROR << __PRETTY_FUNCTION__ << "BLKSSZGET failed on " << block_device;