Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions mantle/kola/tests/misc/multipath.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ systemd:

[Service]
Type=oneshot
ExecStart=/usr/sbin/mpathconf --enable
ExecStart=/usr/sbin/mpathconf --enable --user_friendly_names n

[Install]
WantedBy=multi-user.target
Expand All @@ -61,8 +61,8 @@ systemd:
[Unit]
Description=Set Up Multipath On /var/lib/containers
ConditionFirstBoot=true
Requires=dev-mapper-mpatha.device
After=dev-mapper-mpatha.device
Requires=dev-disk-by\x2did-dm\x2duuid\x2dmpath\x2d0x0000000000000001.device
After=dev-disk-by\x2did-dm\x2duuid\x2dmpath\x2d0x0000000000000001.device
# See https://github.com/coreos/coreos-assembler/pull/2457
# and https://github.com/openshift/os/issues/743
After=ostree-remount.service
Expand All @@ -71,7 +71,7 @@ systemd:

[Service]
Type=oneshot
ExecStart=/usr/sbin/mkfs.xfs -L containers -m reflink=1 /dev/mapper/mpatha
ExecStart=/usr/sbin/mkfs.xfs -L containers -m reflink=1 /dev/disk/by-id/dm-uuid-mpath-0x0000000000000001
# This is usually created by tmpfiles.d, but we run earlier than that.
ExecStart=/usr/bin/mkdir -p /var/lib/containers

Expand Down Expand Up @@ -119,7 +119,7 @@ func init() {
ClusterSize: 1,
Platforms: []string{"qemu"},
UserData: mpath_on_var_lib_containers,
AdditionalDisks: []string{"1G:mpath"},
AdditionalDisks: []string{"1G:mpath,wwn=1"},
})
}

Expand Down Expand Up @@ -151,7 +151,8 @@ func verifyBootDropins(c cluster.TestCluster, m platform.Machine, checkBootuuid

func verifyMultipath(c cluster.TestCluster, m platform.Machine, path string) {
srcdev := string(c.MustSSHf(m, "findmnt -nvr %s -o SOURCE", path))
if !strings.HasPrefix(srcdev, "/dev/mapper/mpath") {
udevinfo := string(c.MustSSHf(m, "udevadm info %s", srcdev))
Comment on lines 153 to +154
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The output of c.MustSSHf includes the raw standard output of the command, which might include trailing whitespace or newlines. This could cause the subsequent udevadm info command to fail or behave unexpectedly. It's safer to trim the whitespace from the srcdev string before using it in the next command.

Suggested change
srcdev := string(c.MustSSHf(m, "findmnt -nvr %s -o SOURCE", path))
if !strings.HasPrefix(srcdev, "/dev/mapper/mpath") {
udevinfo := string(c.MustSSHf(m, "udevadm info %s", srcdev))
srcdev := strings.TrimSpace(string(c.MustSSHf(m, "findmnt -nvr %s -o SOURCE", path)))
udevinfo := string(c.MustSSHf(m, "udevadm info %s", srcdev))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The srcdev variable is obtained from the output of a command and then used to construct another shell command. This could be a potential command injection vulnerability if srcdev contains shell metacharacters. It's safer to quote it. Using the %q format verb in fmt.Sprintf will properly quote the string, preventing misinterpretation by the shell.

Suggested change
udevinfo := string(c.MustSSHf(m, "udevadm info %s", srcdev))
udevinfo := string(c.MustSSHf(m, "udevadm info %q", srcdev))

if !strings.Contains(udevinfo, "/dev/disk/by-id/dm-uuid-mpath-") && !strings.Contains(udevinfo, "DM_MPATH") {
c.Fatalf("mount %s has non-multipath source %s", path, srcdev)
}
}
Expand Down
Loading