]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
acpi: nfit: fix narrowing conversion in acpi_nfit_ctl
authorMurad Masimov <m.masimov@mt-integration.ru>
Thu, 23 Jan 2025 16:39:45 +0000 (19:39 +0300)
committerIra Weiny <ira.weiny@intel.com>
Mon, 3 Mar 2025 14:03:43 +0000 (08:03 -0600)
Syzkaller has reported a warning in to_nfit_bus_uuid(): "only secondary
bus families can be translated". This warning is emited if the argument
is equal to NVDIMM_BUS_FAMILY_NFIT == 0. Function acpi_nfit_ctl() first
verifies that a user-provided value call_pkg->nd_family of type u64 is
not equal to 0. Then the value is converted to int, and only after that
is compared to NVDIMM_BUS_FAMILY_MAX. This can lead to passing an invalid
argument to acpi_nfit_ctl(), if call_pkg->nd_family is non-zero, while
the lower 32 bits are zero.

Furthermore, it is best to return EINVAL immediately upon seeing the
invalid user input.  The WARNING is insufficient to prevent further
undefined behavior based on other invalid user input.

All checks of the input value should be applied to the original variable
call_pkg->nd_family.

[iweiny: update commit message]

Fixes: 6450ddbd5d8e ("ACPI: NFIT: Define runtime firmware activation commands")
Cc: stable@vger.kernel.org
Reported-by: syzbot+c80d8dc0d9fa81a3cd8c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c80d8dc0d9fa81a3cd8c
Signed-off-by: Murad Masimov <m.masimov@mt-integration.ru>
Link: https://patch.msgid.link/20250123163945.251-1-m.masimov@mt-integration.ru
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
drivers/acpi/nfit/core.c

index a5d47819b3a4e295f7fe16e7f465c6d3c5fa792d..ae035b93da087812dee6ec47d9ef4aa97dc8e7bc 100644 (file)
@@ -485,7 +485,7 @@ int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
                cmd_mask = nd_desc->cmd_mask;
                if (cmd == ND_CMD_CALL && call_pkg->nd_family) {
                        family = call_pkg->nd_family;
-                       if (family > NVDIMM_BUS_FAMILY_MAX ||
+                       if (call_pkg->nd_family > NVDIMM_BUS_FAMILY_MAX ||
                            !test_bit(family, &nd_desc->bus_family_mask))
                                return -EINVAL;
                        family = array_index_nospec(family,