Skip to contentSkip to conversation

nvme-pci: return error when parsing a quirk string fails

PATCH In review Guixin Liu 3 participants 3 messages Jul 29 NVMe

lore
Share & tools
lore

Guixin Liu

author
#0 lore raw

PATCH 3/4 nvme-pci: return error when parsing a quirk string fails

quirks_param_set() reuses 'err', which param_set_copystring() left as 0, as the return value of the whole function. When nvme_parse_quirk_entry() fails to parse a field, the code jumps to out_free_qlist and returns that stale 0, so a malformed quirks= parameter is silently accepted as valid.

Set err to -EINVAL before jumping out on a parse failure.

Fixes 7bb8c40f5ad8 ("nvme: add support for dynamic quirk configuration via module parameter")
---
 drivers/nvme/host/pci.c | 1 +
 1 file changed, 1 insertion(+)
drivers/nvme/host/pci.c +1 -0
index 69932d640b53..560560268c05 100644
@@ -213,6 +213,7 @@ static int quirks_param_set(const char *value, const struct kernel_param *kp)
 		if (nvme_parse_quirk_entry(field, &qlist[i])) {
 			pr_err("nvme: failed to parse quirk string %s\n",
 				value);
+			err = -EINVAL;
 			goto out_free_qlist;
 		}
 
Signature · 1 line
2.43.7
maintainer Reviewed-by on v1 3/4
#1 lore raw
Quoted 6 lines · Guixin Liu

quirks_param_set() reuses 'err', which param_set_copystring() left as 0, as the return value of the whole function. When nvme_parse_quirk_entry() fails to parse a field, the code jumps to out_free_qlist and returns that stale 0, so a malformed quirks= parameter is silently accepted as valid.

Set err to -EINVAL before jumping out on a parse failure.

Looks good:

Reviewed-by on v1 3/4
#2 lore raw
In reply to Guixin Liu
Quoted 9 lines · Guixin Liu

quirks_param_set() reuses 'err', which param_set_copystring() left as 0, as the return value of the whole function. When nvme_parse_quirk_entry() fails to parse a field, the code jumps to out_free_qlist and returns that stale 0, so a malformed quirks= parameter is silently accepted as valid.

Set err to -EINVAL before jumping out on a parse failure.

Fixes 7bb8c40f5ad8 ("nvme: add support for dynamic quirk configuration via module parameter")

Looks good.