Thread (30 messages) 30 messages, 4 authors, 2021-03-16
STALE1938d

[PATCH 10/10] fabrics: fix invalid memory access in discover_from_conf_file()

From: <hidden>
Date: 2021-03-06 00:38:52
Subsystem: the rest · Maintainer: Linus Torvalds

From: Martin Wilck <redacted>

argconfig_parse() assigns pointers in cfg to point to memory allocated
in all_args. If this memory is freed, these pointers become dangling.
This is particularly dangerous if discovery.conf contains empty lines,
comment lines, or invalid lines.

Fix it by setting all transport parameter to NULL after processing each
line, and not proceeding if the basic parameters aren't set.

Signed-off-by: Martin Wilck <redacted>
---
 fabrics.c | 5 +++++
 1 file changed, 5 insertions(+)
diff --git a/fabrics.c b/fabrics.c
index f2ff511..1fcc6cf 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -1508,6 +1508,9 @@ static int discover_from_conf_file(const char *desc, char *argstr,
 		if (err)
 			goto free_and_continue;
 
+		if (!cfg.transport || !cfg.traddr)
+			goto free_and_continue;
+
 		err = flags = validate_output_format(cfg.output_format);
 		if (err < 0)
 			goto free_and_continue;
@@ -1535,6 +1538,8 @@ static int discover_from_conf_file(const char *desc, char *argstr,
 free_and_continue:
 		free(all_args);
 		free(argv);
+		cfg.transport = cfg.traddr = cfg.trsvcid =
+			cfg.host_traddr = NULL;
 	}
 
 out:
-- 
2.29.2


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help