From 1a738e00906afde3189e7de01a942b6cc18bc7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Mon, 5 Nov 2018 17:09:18 +0000 Subject: [PATCH 1/6] Save crypttab names before mounting --- src/modules/RootPart.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/modules/RootPart.rb b/src/modules/RootPart.rb index e577d55a..5ffc5317 100644 --- a/src/modules/RootPart.rb +++ b/src/modules/RootPart.rb @@ -1531,9 +1531,23 @@ def MountPartitions(root_device_current) fstab = fstab_ref.value crtab = crtab_ref.value - # Update encryption devices with the names indicated in the crypttab file (bsc#1094963) + # Encryption names indicated in the crypttab file are stored in its correspondig encryption + # device to make possible to find a device by using the name specified in a fstab file, + # (bsc#1094963). + # + # For example, when fstab has: + # + # /dev/disk/by-id/dm-name-cr_home / auto 0 0 + # + # and the fstab device is searched by that name: + # + # devicegraph.find_by_any_name("/dev/disk/by-id/dm-name-cr_home") + # + # The proper encryption device could be found if there is a encrypttion device where + # + # encryption.crypttab_name #=> "cr_home" crypttab_path = File.join(Installation.destdir, "/etc/crypttab") - Y2Storage::Encryption.use_crypttab_names(probed, crypttab_path) + Y2Storage::Encryption.save_crypttab_names(probed, crypttab_path) Update.GetProductName From f3ea1fd54757c7429784a8df49b7998ce349bc0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Mon, 5 Nov 2018 17:09:40 +0000 Subject: [PATCH 2/6] Use safest device name when mounting --- src/modules/RootPart.rb | 46 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/modules/RootPart.rb b/src/modules/RootPart.rb index 5ffc5317..9548cfbd 100644 --- a/src/modules/RootPart.rb +++ b/src/modules/RootPart.rb @@ -1121,7 +1121,18 @@ def MountFSTab(fstab, message) mount_err = "" while mount_err != nil - mount_err = FsckAndMount(fspath, spec, mount_type, mntops) + # An encryption device might be probed with a name that does not match with the name + # indicated in the fstab file. For example, when the fstab entry is: + # + # /dev/mapper/cr_home /home ext4 defaults 0 0 + # + # and that encryption device was probed as /dev/mapper/cr-auto-1. + # + # In that case, to mount /dev/mapper/cr_home would fail because there is not a device + # in the inst-sys with such name. To avoid possible failures when mounting the fstab + # device, the safest device name is used instead, that is, UUID= format or its uuid + # udev name, see {#safest_device_name}. + mount_err = FsckAndMount(fspath, safest_device_name(spec), mount_type, mntops) if mount_err != nil Builtins.y2error( "mounting %1 (type %2) on %3 failed", @@ -2260,6 +2271,39 @@ def fs_by_udev_lookup(devicegraph, name) dev.filesystem end + # Safest device name to perform the mount action + # + # It will be the udev uuid name (e.g., /dev/disk/by-uuid/111-222-333) when the device + # spec has not UUID= format. + # + # @see udev_uuid + # + # @example + # + # safest_device_name("UUID=111-222-333") #=> "UUID=111-222-333" + # safest_device_name("/dev/mapper/cr_home") #=> "/dev/disk/by-uuid/111-222-333" + # + # @param device_spec [String] e.g., "UUID=111-222-333", "/dev/sda2", "/dev/mapper/cr_home" + # @return [String] safest device name, e.g., "/dev/disk/by-uuid/111-222-333" + def safest_device_name(device_spec) + return device_spec if device_spec.start_with?("UUID=") + + udev_uuid(device_spec) || device_spec + end + + # Finds a device and returns its udev uuid name + # + # @param device_spec [String] e.g., "UUID=111-222-333", "/dev/sda2", "/dev/mapper/cr_home" + # @return [String, nil] uuid name (e.g., "/dev/disk/by-uuid/111-222-333") or nil if the + # device is not found. + def udev_uuid(device_spec) + filesystem = fs_by_devicename(probed, device_spec) + return nil if filesystem.nil? + + device = filesystem.blk_devices.first + device.udev_full_uuid + end + # Whether the given fstab spec corresponds to a device mounted by its kernel # device name. # From 79075b22adbf6dc02dd6d367aed58c729a801edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Mon, 5 Nov 2018 17:10:00 +0000 Subject: [PATCH 3/6] Add unit tests --- test/root_part_test.rb | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/test/root_part_test.rb b/test/root_part_test.rb index 652db257..f0095538 100755 --- a/test/root_part_test.rb +++ b/test/root_part_test.rb @@ -236,6 +236,25 @@ end describe "#MountFSTab" do + before do + stub_storage(scenario) + # Mock the system lookup executed as last resort when the devicegraph + # doesn't contain the searched information + allow(Y2Storage::BlkDevice).to receive(:find_by_any_name) + end + + let(:scenario) { "two-disks-two-btrfs.xml" } + + let(:fstab) do + [ + { + "file"=>"/home", "mntops"=>"defaults", "vfstype"=>"ext4", "spec"=> device_spec + } + ] + end + + let(:device_spec) { nil } + it "mounts /dev, /proc and /sys" do allow(subject).to receive(:AddMountedPartition) @@ -247,6 +266,41 @@ fstab = [] subject.MountFSTab(fstab, "") end + + context "when the device spec has UUID= format" do + let(:device_spec) { "UUID=111-222-333" } + + it "tries to mount by using UUID= spec" do + expect(subject).to receive(:FsckAndMount) + .with("/home", "UUID=111-222-333", anything, anything) + + subject.MountFSTab(fstab, "") + end + end + + context "when the device spec does not have UUID= format" do + context "and a device with such spec is not found" do + let(:device_spec) { "/dev/sdc1" } + + it "tries to mount by using the given device spec" do + expect(subject).to receive(:FsckAndMount) + .with("/home", "/dev/sdc1", anything, anything) + + subject.MountFSTab(fstab, "") + end + end + + context "and a device with such spec is found" do + let(:device_spec) { "/dev/sda2" } + + it "tries to mount by using its udev uuid name" do + expect(subject).to receive(:FsckAndMount) + .with("/home", "/dev/disk/by-uuid/d6e5c710-3067-48de-8363-433e54a9d0b5", anything, anything) + + subject.MountFSTab(fstab, "") + end + end + end end describe "#inject_intsys_files" do From 9b056923a9a9f65b59c9ad97f4f78939567835ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Mon, 5 Nov 2018 17:15:23 +0000 Subject: [PATCH 4/6] Update yast2-storage-ng dependency --- package/yast2-update.spec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package/yast2-update.spec b/package/yast2-update.spec index a9abc167..bde9b89e 100644 --- a/package/yast2-update.spec +++ b/package/yast2-update.spec @@ -41,10 +41,10 @@ BuildRequires: yast2-installation-control # Needed for tests BuildRequires: rubygem(rspec) -# Encryption.use_crypttab_names -BuildRequires: yast2-storage-ng >= 4.0.186 -# Encryption.use_crypttab_names -Requires: yast2-storage-ng >= 4.0.186 +# Encryption.save_crypttab_names +BuildRequires: yast2-storage-ng >= 4.1.30 +# Encryption.save_crypttab_names +Requires: yast2-storage-ng >= 4.1.30 # FSSnapshotStore Requires: yast2 >= 3.1.126 Requires: yast2-installation From ebbc31de64fe3e9e7f5c268677d8c4b54c6c720a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Wed, 7 Nov 2018 12:19:31 +0000 Subject: [PATCH 5/6] Update yast2-storage-ng dependency --- package/yast2-update.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/yast2-update.spec b/package/yast2-update.spec index bde9b89e..ff5df712 100644 --- a/package/yast2-update.spec +++ b/package/yast2-update.spec @@ -42,9 +42,9 @@ BuildRequires: yast2-installation-control BuildRequires: rubygem(rspec) # Encryption.save_crypttab_names -BuildRequires: yast2-storage-ng >= 4.1.30 +BuildRequires: yast2-storage-ng >= 4.1.31 # Encryption.save_crypttab_names -Requires: yast2-storage-ng >= 4.1.30 +Requires: yast2-storage-ng >= 4.1.31 # FSSnapshotStore Requires: yast2 >= 3.1.126 Requires: yast2-installation From 445bf0a57eeadb4f2c94aa8a482fe31232103e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Wed, 7 Nov 2018 12:19:51 +0000 Subject: [PATCH 6/6] Update version and changelog --- package/yast2-update.changes | 10 ++++++++++ package/yast2-update.spec | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/package/yast2-update.changes b/package/yast2-update.changes index 4efd2062..252c8fac 100644 --- a/package/yast2-update.changes +++ b/package/yast2-update.changes @@ -1,3 +1,13 @@ +------------------------------------------------------------------- +Mon Nov 5 17:10:54 UTC 2018 - jlopez@suse.com + +- Avoid to crash when crypttab contains entries where the LUKS is + given by UUID= format. +- Avoid to crash when an encryption device is not probed with the + name indicated in a fstab entry. +- Related to bsc#1094963. +- 4.1.5 + ------------------------------------------------------------------- Tue Oct 16 16:37:07 CEST 2018 - schubi@suse.de diff --git a/package/yast2-update.spec b/package/yast2-update.spec index ff5df712..e16fc212 100644 --- a/package/yast2-update.spec +++ b/package/yast2-update.spec @@ -17,7 +17,7 @@ Name: yast2-update -Version: 4.1.4 +Version: 4.1.5 Release: 0 BuildRoot: %{_tmppath}/%{name}-%{version}-build