dm: passthrough: check romfile path length in command

This patch checks the romfile path length in command line to avoid
possible buffer overflow, maximum path supported is 255 characters.

Tracked-On: #8439
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@linux.intel.com>
Reviewed-by: Jian Jun Chen <jian.jun.chen@intel.com>
This commit is contained in:
Jiaqing Zhao 2023-07-03 06:10:44 +00:00 committed by acrnsi-robot
parent b6cea37b49
commit ce3f31dcb6
1 changed files with 5 additions and 1 deletions

View File

@ -765,7 +765,11 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
} else if (!strncmp(opt, "romfile=", 8)) {
need_rombar = true;
opt += 8;
strcpy(rom_file, opt);
if (strnlen(opt, PATH_MAX) >= sizeof(rom_file)) {
pr_err("romfile path too long, max supported path length is 255");
return -EINVAL;
}
strncpy(rom_file, opt, sizeof(rom_file));
} else
pr_warn("Invalid passthru options:%s", opt);
}