Skip to content

samsung: Fix security vulnerabilities in vs-internal-log - #4016

Open
h1219-kim wants to merge 4 commits into
linux-nvme:masterfrom
h1219-kim:samsung-security-split
Open

samsung: Fix security vulnerabilities in vs-internal-log#4016
h1219-kim wants to merge 4 commits into
linux-nvme:masterfrom
h1219-kim:samsung-security-split

Conversation

@h1219-kim

@h1219-kim h1219-kim commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

shared: add shr_sanitize_name() comes first: shr_valid_name() only validates, and a caller holding a field the device supplies needs to make a usable name rather than turn the device away. It goes next to the validator instead of becoming a third copy of that character set — the micron plugin already carries a local sanitize_serial() that can move over separately.

Then three fixes for nvme samsung vs-internal-log, one issue per commit:

  • The drive-supplied serial number goes into the dump file names unvalidated, so one holding ../ writes the dumps outside the directory -O asked for. The old check refused a ', ran only from compress_dump_files(), and so never ran without -z.
  • tar and rm ran through system(). The single-quoting covers /bin/sh but not the cmd.exe that system() runs on Windows, where ' is not a quoting character and &, |, > and ^ still apply. They now spawn through shr_spawnp() with a fixed argv, as the micron plugin does.
  • The staging directory was created with shr_mkdir_p() and mode 0777, so an existing symlink or somebody else's directory at that predictable name would collect the dumps. It is created with shr_mkdir() and mode 0700 instead, and a path that is already taken fails.

tests/cli/nvme_samsung_test.py grows from 40 to 51 cases, and shared/tests/test-string-util.c covers the new helper.

h1219-kim and others added 4 commits September 11, 2026 04:38
shr_valid_name() answers whether a string may be used as a name, but a
caller holding a field that a device supplies -- a serial number, say --
needs to make one that may, not to turn the device away. Add that next to
the validator so plugins share one definition of the character set rather
than each carrying a copy of it.

The two go through shr_name_char() now, so a sanitized string always
satisfies shr_valid_name(). The micron plugin already carries a local
sanitize_serial() that does the same thing; it can move over separately.

Signed-off-by: Hyuntae Kim <h1219.kim@samsung.com>
vs-internal-log builds every dump file name from the controller serial
number, which the drive supplies and nothing validates. A serial holding
"../" makes make_file_path() return a path outside the directory -O asked
for, and the dumps are opened with O_CREAT | O_TRUNC, so the drive picks
which files get written.

The one check on the serial refuses a "'" and lives in
compress_dump_files(), so it runs only after the dumps are already on
disk, and not at all without -z.

Restrict the serial to the characters a file name may hold as soon as it
is read from Identify Controller, before it reaches any path.

Signed-off-by: Jinmin Hwang <jinmin.hwang@samsung.com>
[h1219: split out of the combined fix, cover the path taken without -z]
Signed-off-by: Hyuntae Kim <h1219.kim@samsung.com>
vs-internal-log built "tar" and "rm" command lines and handed them to
system(). Every interpolated argument was single-quoted and an output
path or serial number holding a "'" was refused, which covers /bin/sh
but not cmd.exe, the shell system() runs on Windows: it does not treat
"'" as a quoting character and keeps honouring &, |, > and ^, so a
drive-supplied serial number could run arbitrary commands there.

Spawn tar and rm through shr_spawnp() with a fixed argv, as the micron
plugin does. No command string is built, so the "'" restriction goes
away along with the shell and an output path may hold one again.

Name the staged files for tar rather than passing ".": a "." operand
also archives the staging directory itself as a "./" member, and
extracting that member applies the staging directory's mode to whatever
directory the archive is unpacked into.

Signed-off-by: Jinmin Hwang <jinmin.hwang@samsung.com>
[h1219: name the staged files for tar rather than ".", report the exit
status instead of an errno, flush stdout before the spawn]
Signed-off-by: Hyuntae Kim <h1219.kim@samsung.com>
vs-internal-log stages the dumps in a temp_samsung_dumps directory before
archiving them. shr_mkdir_p() accepted a path that already existed, so a
symlink, or a directory belonging to somebody else, sitting at that
predictable name would collect the dumps instead; mode 0777 left the
permissions to whatever the umask allowed.

Create it with shr_mkdir() and mode 0700: a path that is already taken
now fails rather than being reused, and the dumps stay unreadable to
others for as long as collecting them takes. This covers the staging
directory alone -- the archive it produces is the deliverable and keeps
the mode tar gives it. The parent is created by the
shr_mkdir_from_fname() that runs first, so dropping the "-p" costs
nothing.

Collecting every dump takes long enough that a run is interrupted now and
then, and the staging directory outlives it, so the failure names the
directory to remove rather than only reporting that the path is taken.

Signed-off-by: Jinmin Hwang <jinmin.hwang@samsung.com>
[h1219: record why shr_mkdir() replaces shr_mkdir_p(), name the directory
to remove, document -z]
Signed-off-by: Hyuntae Kim <h1219.kim@samsung.com>
@h1219-kim
h1219-kim force-pushed the samsung-security-split branch from 99fc64c to 93e5228 Compare September 10, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants