chreipl passes additional boot parameters via the firmware scp_data
sysfs attribute. This mechanism is shared by multiple re-IPL types (FCP,
NVMe, and ECKD) and they all have the same scp_data size limit. The
BOOTPARMS_FCP_MAX name is therefore misleading.
Rename BOOTPARMS_FCP_MAX to BOOTPARMS_SCPDATA_MAX and update all callers
to make the intent clear and avoid implying this limit is FCP-only.
Reviewed-by: Jan Polensky <japo@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
chreipl accepts --bootparms for list-directed IPL, but for ECKD re-IPL the
value was never committed to sysfs, so the requested boot parameters did
not take effect.
Write the boot parameters to the firmware scp_data attribute when
configuring an ECKD re-IPL target. Also validate that the ECKD re-IPL
sysfs interface exists and enforce the maximum supported boot parameter
length up front.
Fixes: 7c24855ba1 ("ipl_tools: add support for list-directed IPL from ECKD DASD")
Reviewed-by: Jan Polensky <japo@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Some environments do not expose the /sys/firmware/reipl/*/clear attribute
(e.g. z/VM guests without "Load Normal" support). lsreipl currently tries to
read the attribute unconditionally for ECKD re-IPL and emits a confusing
"Could not read file .../clear" error when it is missing.
Re-IPL type: eckd
Device: 0.0.6d74
bootprog: 0
br_chr: auto
Bootparm: ""
Loadparm: ""
Could not read file /sys/firmware/reipl/eckd/clear: No such file or directory
clear: (null)
Secure boot: 0
Only print the "clear" field when the corresponding sysfs attribute is
present, avoiding the spurious error output.
Fixes: 7c24855ba1 ("ipl_tools: add support for list-directed IPL from ECKD DASD")
Reviewed-by: Jan Polensky <japo@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Eliminated redundant code to improve clarity and maintainability.
Replaced with existing utility functions from the library.
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Function declarations in header files are implicitly extern, making
the explicit use of extern unnecessary. Removing it simplifies the
code without changing semantics and behavior.
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Replace read_str() helper in ipl_tools/system.c with
util_file_read_text_file() to enhance maintainability and reduce
code duplication.
Additionally, allocate the buffer dynamically instead of using
fixed-size buffer to prevent potential overflows and data loss.
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Optimize dependency management by reducing header inclusions. This
reduces hidden dependencies, improves modularity, and enhances
compilation performance.
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Optimize dependency management by limiting header inclusions to
implementation files where possible. This reduces hidden dependencies,
improves modularity, and enhances compilation performance.
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
The actual secure boot state ensures that a Linux instance has loaded
only trusted, signed software. During boot component signatures are
verified. If secure boot is enabled, unsigned or unverifiable components
prevent booting. Since Secure Boot on IBM Z is always triggered by the
hypervisor, its state is merely observable by the active system.
Secure boot: 1 - Linux booted secure (only trusted sources)
Secure boot: 0 - Booted from any source without verification
$ dmesg -t | grep Secure-IPL
setup: Linux is running with Secure-IPL enabled
$ cat /sys/kernel/security/lockdown
none [integrity] confidentiality
$ lsreipl
Re-IPL type: fcp
WWPN: 0x500507630710572c
LUN: 0x4022409600000000
Device: 0.0.1908
bootprog: 0
br_lba: 0
Loadparm: ""
Bootparms: ""
Secure boot: 1
References:
* https://www.ibm.com/docs/en/linux-on-systems?topic=using-verifying-secure-boot
* https://www.ibm.com/docs/en/linux-on-systems?topic=introduction-requirements
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
The default sysfs path is always set to '/sys' unless the SYSFS_ROOT
environment variable is defined.
To address security concerns, secure_getenv() is used within
util_path_sysfs() to protect against malicious values in SYSFS_ROOT.
Additionally, constructing the sysfs path dynamically in an allocated
buffer, rather than using a fixed-size buffer, helps prevent potential
buffer overflows.
These modifications also significantly improve testability by allowing
sysfs read and write operations to be redirected to an alternative file
path, which enables testing without affecting the active system state.
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
The function is no longer required since the removal of the PHYSDEVPATH
entry in /sys/block/%s/uevent with commit 39aba963d937 ("driver core:
remove CONFIG_SYSFS_DEPRECATED_V2 but keep it for block devices") in
2010.
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
The default sysfs path is always set to '/sys' unless the SYSFS_ROOT
environment variable is defined.
To address security concerns, secure_getenv() is used within
util_path_sysfs() to protect against malicious values in SYSFS_ROOT.
Additionally, constructing the sysfs path dynamically in an allocated
buffer, rather than using a fixed-size buffer, helps prevent potential
buffer overflows.
These modifications also significantly improve testability by allowing
sysfs read operations to be redirected to an alternative file path,
which enables testing without affecting the active system state.
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
The default sysfs path is always set to '/sys' unless the SYSFS_ROOT
environment variable is defined.
To address security concerns, secure_getenv() is used within
util_path_sysfs() to protect against malicious values in SYSFS_ROOT.
Additionally, constructing the sysfs path dynamically in an allocated
buffer, rather than using a fixed-size buffer, helps prevent potential
buffer overflows.
These modifications also significantly improve testability by allowing
sysfs read operations to be redirected to an alternative file path,
which enables testing without affecting the active system state.
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Fix typo in comment also helps to prevent pre-commit hook issues, w/o
functional changes or changes in behavior.
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Remove unnecessary empty lines to prevent pre-commit hook issues, w/o
functional changes or changes in behavior.
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Under QEMU user can attach disk with smth like:
```
-device virtio-scsi-ccw,... -device scsi-hd,...
```
So virtio block device appears as '/dev/sda' instead of '/dev/vda'.
chreipl assumes all '/dev/sd*' disks as FCP disks, which is not a
case in such setup.
Closes: https://github.com/ibm-s390-linux/s390-tools/pull/154
Signed-off-by: Nikita Dubrovskii <nikita@linux.ibm.com>
Acked-by: Marc Hartmayer mhartmay@linux.ibm.com
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Add helper function to get device's real path under SYSFS_ROOT devices
hierarchy.
Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/154
Signed-off-by: Nikita Dubrovskii <nikita@linux.ibm.com>
[hoeppner@linux.ibm.com: Adapt commit message]
Acked-by: Marc Hartmayer mhartmay@linux.ibm.com
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Add support to chreipl/lsreipl to show and reconfigure ipl parameters
for list-directed IPL from ECKD DASD.
Parameters accepted:
device - ccw device id
bootprog - Boot Prog Selector
loadparm - Load parameters
brchr - location of bootrecord in cylinder/head/record format.
clear - clear memory before loading
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
When the kernel is build with CONFIG_NVME_MULTIPATH enabled and an NVMe
where the driver exposes its controller separately is used, chreipl node
on a mount point of the NVMe fails. The failure occurs because chreipl
tries to get the function_id from the NVMe's nvmeXnY block device via
the path '/sys/block/nvmeXnY/device/device/function_id' which does not
exist.
The underlying problem is that with NVMe multipath support the PCI
function is not associated directly with a particular NVMe namespace but
instead with the entire NVMe device which may host multiple NVMe
namespaces. The correct way to get from the block device to the
underlying PCI device and its function ID is then to extract the device
name i.e. the 'nvmeX' part from 'nvmeXnY' and use that to get the
function ID via '/sys/class/nvme/nvme<X>/device/function_id'.
Fixes: 0472b5ea5c ("ipl-tools: Add nvme device support to lsreipl/chreipl")
Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This patch adds support for the "clear" sysfs attribute for nvme re-IPL,
if available. This attribute allows to control whether the memory should
be cleared on re-IPL.
Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Support is added to lsreipl to detect the nvme reipl type and list the
appropriate parameters.
Support is added to chreipl to specify and populate sysfs reipl entries
with nvme device targets.
Signed-off-by: Jason J. Herne <jjherne@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Change the buffer size to what we actually need and use util_strlcpy()
to correctly copy strings.
This gets rid of the following GCC8 compile warnings:
fcp.c: In function ‘fcp_wwpn_get’:
fcp.c:44:2: warning: ‘strncpy’ output may be truncated copying 20 bytes
from a string of length 4095 [-Wstringop-truncation]
strncpy(wwpn, buf, 20);
^~~~~~~~~~~~~~~~~~~~~~
fcp.c: In function ‘fcp_lun_get’:
fcp.c:65:2: warning: ‘strncpy’ output may be truncated copying 20 bytes
from a string of length 4095 [-Wstringop-truncation]
strncpy(lun, buf, 20);
^~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Use util_asprintf() to allocate memory for the string buffers
dynamically and get rid of the following GCC8 compile warnings:
system.c: In function ‘print_fw_str’:
system.c:86:46: warning: ‘%s’ directive output may be truncated writing
up to 4095 bytes into a region of size 4082 [-Wformat-truncation=]
snprintf(path, sizeof(path), "/sys/firmware/%s", file);
^~
system.c:98:19:
read_fw_str(str, path, sizeof(str));
~~~~
system.c:86:2: note: ‘snprintf’ output between 15 and 4110 bytes into a
destination of size 4096
snprintf(path, sizeof(path), "/sys/firmware/%s", file);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cmd_chreipl.c: In function ‘set_reipl_type_helper’:
cmd_chreipl.c:316:19: warning: ‘%d’ directive writing between 1 and 11
bytes into a region of size between 0 and 4095 [-Wformat-overflow=]
sprintf(cmd, "%s %d:%d", chreipl_helper, major(dev), minor(dev));
^~
cmd_chreipl.c:316:15: note: using the range [-2147483648, 2147483647]
for directive argument
sprintf(cmd, "%s %d:%d", chreipl_helper, major(dev), minor(dev));
^~~~~~~~~~
cmd_chreipl.c:316:15: note: using the range [-2147483648, 2147483647]
for directive argument
cmd_chreipl.c:316:2: note: ‘sprintf’ output between 5 and 4120 bytes
into a destination of size 4096
sprintf(cmd, "%s %d:%d", chreipl_helper, major(dev), minor(dev));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Use util_strlcpy() to copy strings correctly and get rid of the
following GCC8 compile warnings:
main.c: In function ‘main’:
main.c:34:2: warning: ‘strncpy’ specified bound 256 equals destination
size [-Wstringop-truncation]
strncpy(g.prog_name, argv[0], sizeof(g.prog_name));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘set_bootprog’,
inlined from ‘parse_chreipl_options’ at cmd_chreipl.c:510:4:
cmd_chreipl.c:185:2: warning: ‘strncpy’ specified bound 11 equals
destination size [-Wstringop-truncation]
strncpy(l.bootprog, bootprog, sizeof(l.bootprog));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cmd_chreipl.c: In function ‘set_reipl_type’:
cmd_chreipl.c:297:2: warning: ‘strncpy’ specified bound 15 equals
destination size [-Wstringop-tr uncation]
strncpy(l.dev, dev_name, sizeof(l.dev));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
chreipl could only be used as root (effective userid 0), which is
explicitly checked upon invocation.
"access" call is a wrong method to check super user read/write access
for sysfs files, because it is simply always returns 0 (success), despite
actual sysfs file permissions or underlying sysfs file callbacks setup.
The only guaranteed way of checking sysfs file super user access is an
actual open call with the corresponding access mode.
The problem is that chreipl always tries to update some sysfs attributes
even through they are not specified as command line arguments. Together
with a broken sysfs file access checks this leads to inability to use
the tool, when some sysfs attributes are read-only (which is the case
on older systems where diag308 set does not work).
$ chreipl ccw -d 0.0.ec5a
chreipl: Could not open "reipl/ccw/parm" (Permission denied)
The change fixes access checks, which are in place to handle "diag308
set does not work" case (presence of read-only sysfs attributes).
Also replaces R_OK with F_OK in "set_target_type_auto" to underline that
only file presence is checked, not an actual read access.
Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
Make write_str_errno return errno in all error cases, so that it would
be usable in scenarious where open call could fail and we just want to
get an errno, not to exit.
This function is currently only used by chshut in a context where
such a change wouldn't hurt debug ability.
159 if (write_str_errno(argv[2], path))
160 ERR_EXIT_ERRNO("Could not set \"%s\"", path);
Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
kdump reipl implementation relies on os_info kernel structure
residing in old memory being dumped. os_info contains reipl block, which
is used (if valid) by the kdump kernel for reipl parameters.
The problem is that the reipl block and its checksum inside
os_info is updated only when /sys/firmware/reipl/reipl_type is
written. This sets an offset of a reipl block for "reipl_type" and
re-calculates reipl block checksum. Any further alteration of values
under /sys/firmware/reipl/{reipl_type}/ without subsequent write to
/sys/firmware/reipl/reipl_type lead to incorrect os_info reipl block
checksum. In such a case kdump kernel ignores it and reboots using
default logic.
This change makes sure that all fcp values are written before
reipl_type, to avoid potential problem with incorrect checksum.
Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
With gcc 7 we get warnings like the following:
fdasd.c: In function 'main':
fdasd.c:3055:4: warning: this statement may fall through
[-Wimplicit-fallthrough=]
fdasd_exit(&anchor, 0);
^~~~~~~~~~~~~~~~~~~~~~
fdasd.c:3056:3: note: here
default:
^~~~~~~
Fix this by marking functions with "__noreturn" to help gcc.
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
This commit is based on the s390-tools-1.39.0 version.
Changes on top of s390-tools-1.39.0:
- Add MIT license to all source files
- Add LICENSE file
- Transform REAMDE to README.md (markdown)
- Add AUTHORS.md file
- Add CONTRIBUTING.md file
- Move changelog from README to CHANGELOG.md file
Reviewed-by: Stefan Haberland <sth@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>