diff --git a/patches.suse/RDMA-rtrs-clt-Check-strnlen-return-len-in-sysfs-mpat.patch b/patches.suse/RDMA-rtrs-clt-Check-strnlen-return-len-in-sysfs-mpat.patch new file mode 100644 index 0000000..771d977 --- /dev/null +++ b/patches.suse/RDMA-rtrs-clt-Check-strnlen-return-len-in-sysfs-mpat.patch @@ -0,0 +1,41 @@ +From 7a7b7f575a25aa68ee934ee8107294487efcb3fe Mon Sep 17 00:00:00 2001 +From: Alexey Kodanev +Date: Wed, 21 Feb 2024 11:32:04 +0000 +Subject: [PATCH 1/1] RDMA/rtrs-clt: Check strnlen return len in sysfs + mpath_policy_store() +Git-commit: 7a7b7f575a25aa68ee934ee8107294487efcb3fe +Patch-mainline: v6.9-rc1 +References: git-fixes + +strnlen() may return 0 (e.g. for "\0\n" string), it's better to +check the result of strnlen() before using 'len - 1' expression +for the 'buf' array index. + +Detected using the static analysis tool - Svace. + +Fixes: dc3b66a0ce70 ("RDMA/rtrs-clt: Add a minimum latency multipath policy") +Signed-off-by: Alexey Kodanev +Link: https://lore.kernel.org/r/20240221113204.147478-1-aleksei.kodanev@bell-sw.com +Acked-by: Jack Wang +Signed-off-by: Leon Romanovsky +Acked-by: Nicolas Morey +--- + drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c b/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c +index d3c436ead694..4aa80c9388f0 100644 +--- a/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c ++++ b/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c +@@ -133,7 +133,7 @@ static ssize_t mpath_policy_store(struct device *dev, + + /* distinguish "mi" and "min-latency" with length */ + len = strnlen(buf, NAME_MAX); +- if (buf[len - 1] == '\n') ++ if (len && buf[len - 1] == '\n') + len--; + + if (!strncasecmp(buf, "round-robin", 11) || +-- +2.39.1.1.gbe015eda0162 + diff --git a/series.conf b/series.conf index 32fe4a8..3062200 100644 --- a/series.conf +++ b/series.conf @@ -45684,6 +45684,7 @@ patches.suse/RDMA-srpt-Do-not-register-event-handler-until-srpt-d.patch patches.suse/RDMA-hns-Fix-mis-modifying-default-congestion-contro.patch patches.suse/RDMA-device-Fix-a-race-between-mad_client-and-cm_cli.patch + patches.suse/RDMA-rtrs-clt-Check-strnlen-return-len-in-sysfs-mpat.patch # jejb/scsi for-next patches.suse/scsi-lpfc-Initialize-status-local-variable-in-lpfc_s.patch