Skip to content

Commit

Permalink
Merge pull request #546 from yast/security_hardening
Browse files Browse the repository at this point in the history
Security hardening
  • Loading branch information
jreidinger committed Dec 4, 2018
2 parents 1dea8fe + 62ef4ea commit 6351a3d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 25 deletions.
9 changes: 9 additions & 0 deletions package/yast2-bootloader.changes
@@ -1,3 +1,12 @@
-------------------------------------------------------------------
Tue Dec 4 15:14:47 UTC 2018 - jreidinger@suse.com

- always use absolute path to binaries (bsc#1118291)
- escape properly shell arguments (bsc#1118291)
- do not show grub2 password in list of processes when encrypting
(bsc#1118291)
- 4.1.13

-------------------------------------------------------------------
Sat Nov 24 00:39:54 UTC 2018 - Stasiek Michalski <hellcp@mailbox.org>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-bootloader.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-bootloader
Version: 4.1.12
Version: 4.1.13
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
8 changes: 5 additions & 3 deletions src/lib/bootloader/boot_record_backup.rb
@@ -1,5 +1,6 @@
require "yast"
require "date"
require "shellwords"

module Bootloader
# Responsibility of class is to manage backup of MBR, respective PBR of disk,
Expand Down Expand Up @@ -35,7 +36,7 @@ def initialize(device)
# Backup is stored in /var/lib/YaST2/backup_boot_sectors, in logs
# directory and if it is MBR of primary disk, then also in /boot/backup_mbr
def write
Yast::SCR.Execute(BASH_PATH, "mkdir -p #{MAIN_BACKUP_DIR}")
Yast::SCR.Execute(BASH_PATH, "/usr/sbin/mkdir -p #{MAIN_BACKUP_DIR.shellescape}")

if exists?
rotate
Expand Down Expand Up @@ -88,7 +89,8 @@ def formated_file_ctime(filename)
def copy_br(device, target_path, bs: 512)
Yast::SCR.Execute(
BASH_PATH,
"/bin/dd if=#{device} of=#{target_path} bs=#{bs} count=1 2>&1"
"/bin/dd if=#{device.shellescape} of=#{target_path.shellescape} " \
"bs=#{bs.to_s.shellescape} count=1 2>&1"
)
end

Expand All @@ -114,7 +116,7 @@ def rotate
Yast::SCR.Execute(
BASH_PATH,
format("/bin/mv %{path} %{path}-%{date}",
path: device_file_path, date: change_date)
path: device_file_path.shellescape, date: change_date.shellescape)
)
end
end
Expand Down
22 changes: 9 additions & 13 deletions src/lib/bootloader/grub2pwd.rb
@@ -1,4 +1,5 @@
require "yast"
require "shellwords"

Yast.import "Stage"

Expand Down Expand Up @@ -120,28 +121,23 @@ def disable
return unless used_on_target?

# operate on target as we have to remove password during installation from target grub2
Yast::SCR.Execute(Yast::Path.new(".target.bash"), "rm '#{PWD_ENCRYPTION_FILE}'")
Yast::SCR.Execute(Yast::Path.new(".target.bash"), "rm '#{PWD_ENCRYPTION_FILE.shellescape}'")
end

def encrypt(password)
Yast.import "String"
result = Yast::Execute.locally("/usr/bin/grub2-mkpasswd-pbkdf2",
env: { "LANG" => "C" },
stdin: "#{password}\n#{password}\n",
stdout: :capture)

quoted_password = Yast::String.Quote(password)
result = Yast::WFM.Execute(YAST_BASH_PATH,
"echo '#{quoted_password}\n#{quoted_password}\n' | LANG=C grub2-mkpasswd-pbkdf2")

if result["exit"] != 0
raise "Failed to create encrypted password for grub2. Command output: #{result["stderr"]}"
end

pwd_line = result["stdout"].split("\n").grep(/password is/).first
pwd_line = result.split("\n").grep(/password is/).first
if !pwd_line
raise "grub2-mkpasswd output do not contain encrypted password. Output: #{result["stdout"]}"
raise "grub2-mkpasswd output do not contain encrypted password. Output: #{result}"
end

ret = pwd_line[/^.*password is\s*(\S+)/, 1]
if !ret
raise "grub2-mkpasswd output do not contain encrypted password. Output: #{result["stdout"]}"
raise "grub2-mkpasswd output do not contain encrypted password. Output: #{result}"
end

ret
Expand Down
2 changes: 1 addition & 1 deletion src/modules/BootSupportCheck.rb
Expand Up @@ -125,7 +125,7 @@ def check_gpt_reserved_partition

# Check if EFI is needed
def efi?
cmd = "modprobe efivars 2>/dev/null"
cmd = "/usr/sbin/modprobe efivars 2>/dev/null"
SCR.Execute(path(".target.bash_output"), cmd)
FileUtils.Exists("/sys/firmware/efi/systab")
end
Expand Down
10 changes: 3 additions & 7 deletions test/grub2pwd_test.rb
Expand Up @@ -214,13 +214,9 @@ def mock_file_presence(exists)
PBKDF2 hash of your password is #{ENCRYPTED_PASSWORD}
EOF

expect(Yast::WFM).to receive(:Execute)
.with(kind_of(Yast::Path), /grub2-mkpasswd/)
.and_return(
"exit" => 0,
"stderr" => "",
"stdout" => success_stdout
)
expect(Yast::Execute).to receive(:locally)
.with(/grub2-mkpasswd/, anything)
.and_return(success_stdout)
subject.password = "really strong password"

expect(subject.instance_variable_get(:@encrypted_password)).to eq ENCRYPTED_PASSWORD
Expand Down

0 comments on commit 6351a3d

Please sign in to comment.