Merge lp://staging/~jderose/ecryptfs/fix-1597154 into lp://staging/ecryptfs
Status: | Merged |
---|---|
Merged at revision: | 882 |
Proposed branch: | lp://staging/~jderose/ecryptfs/fix-1597154 |
Merge into: | lp://staging/ecryptfs |
Diff against target: |
20 lines (+8/-2) 1 file modified
src/utils/ecryptfs-setup-swap (+8/-2) |
To merge this branch: | bzr merge lp://staging/~jderose/ecryptfs/fix-1597154 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tyler Hicks | Approve | ||
Jason Gerard DeRose (community) | Needs Resubmitting | ||
Review via email: mp+298591@code.staging.launchpad.net |
Description of the change
In ecryptfs-setup-swap on line 169, the $drive and $partno are currently built from $swap like this:
drive="
partno=
But this is incorrect for /dev/nvme* and /dev/mmcblk* drives.
For example, when $swap is "/dev/nvme0n1p3", you get a correct $partno of "3", but an incorrect $drive of "/dev/nvme0n1p" (it should be "/dev/nvme0n1", with no "p" at the end).
To fix this I added a conditional to build $drive differently when $swap matches "^/dev/
To verify the logic I wrote a little (out-of-band) test script:
"""
#!/bin/sh -e
test_fix() {
swap=$1
drive=
partno=
if echo $swap | grep -qE "^/dev/
fi
echo "$swap\
}
test_fix /dev/sda3
test_fix /dev/vda3
test_fix /dev/nvme0n1p3
test_fix /dev/mmcblk0p3
"""
Which correctly outputs:
/dev/sda3 /dev/sda 3
/dev/vda3 /dev/vda 3
/dev/nvme0n1p3 /dev/nvme0n1 3
/dev/mmcblk0p3 /dev/mmcblk0 3
I also tested this by running ecryptfs-setup-swap (from the source tree) on a system with an NVMe drive that previously hadn't had encrypted swap or encrypted home directory setup. With my change, ecryptfs-setup-swap now correctly marks the GPT swap partition as non-auto-mounting.
Hi Jason - Thank you for the merge proposal! I see two issues that I think should be addressed:
1) This change is brittle in that if another drive type comes along that has the foo0p0 format, this same bug will be reintroduced. Can you come up with a way to manipulate the drive path so that it handles the situation in a generic way without the need for the `echo $swap | grep -qE "^/dev/ nvme*|^ /dev/mmcblk* "` conditional?
2) The (existing) logic doesn't handle partition numbers with multiple digits. This can be seen by adding "test_fix /dev/mmcblk0p13" to your test script.
Thanks again!