lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211217063224.3474-3-mikoxyzzz@gmail.com>
Date:   Fri, 17 Dec 2021 07:32:24 +0100
From:   Miko Larsson <mikoxyzzz@...il.com>
To:     minchan@...nel.org, ngupta@...are.org, senozhatsky@...omium.org,
        axboe@...nel.dk, linux-kernel@...r.kernel.org,
        linux-block@...r.kernel.org
Cc:     Miko Larsson <mikoxyzzz@...il.com>, hch@...radead.org
Subject: [PATCH v2 2/2] zram: zram_drv: replace 'strlcpy()'

'strlcpy()' shouldn't be used, and should be replaced with safer
alternatives. Cristoph Hellwig suggested [1] that 'kmemdup_nul()' should
be used in two cases instead of 'strscpy()', and that a regular
'strcpy()' should be used in the third case. [2][3]

[1] https://lore.kernel.org/all/YbsRlDYT2BfgrXRX@infradead.org/
[2] https://lore.kernel.org/all/Ybt8wY3U2ETjQijH@infradead.org/
[3] https://lore.kernel.org/all/Ybt8554NZpscKx2K@infradead.org/

Signed-off-by: Miko Larsson <mikoxyzzz@...il.com>
---
 drivers/block/zram/zram_drv.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 4de6fe13edaf..c7c751e6ca2e 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -482,7 +482,7 @@ static ssize_t backing_dev_store(struct device *dev,
 	int err;
 	struct zram *zram = dev_to_zram(dev);
 
-	file_name = kmalloc(PATH_MAX, GFP_KERNEL);
+	file_name = kmemdup_nul(buf, PATH_MAX, GFP_KERNEL);
 	if (!file_name)
 		return -ENOMEM;
 
@@ -493,7 +493,6 @@ static ssize_t backing_dev_store(struct device *dev,
 		goto out;
 	}
 
-	strlcpy(file_name, buf, PATH_MAX);
 	/* ignore trailing newline */
 	sz = strlen(file_name);
 	if (sz > 0 && file_name[sz - 1] == '\n')
@@ -1024,10 +1023,10 @@ static ssize_t comp_algorithm_store(struct device *dev,
 		struct device_attribute *attr, const char *buf, size_t len)
 {
 	struct zram *zram = dev_to_zram(dev);
-	char compressor[ARRAY_SIZE(zram->compressor)];
+	char *compressor;
 	size_t sz;
 
-	strlcpy(compressor, buf, sizeof(compressor));
+	compressor = kmemdup_nul(buf, sizeof(zram->compressor), GFP_KERNEL);
 	/* ignore trailing newline */
 	sz = strlen(compressor);
 	if (sz > 0 && compressor[sz - 1] == '\n')
@@ -1981,7 +1980,7 @@ static int zram_add(void)
 	if (ret)
 		goto out_cleanup_disk;
 
-	strlcpy(zram->compressor, default_compressor, sizeof(zram->compressor));
+	strcpy(zram->compressor, default_compressor);
 
 	zram_debugfs_register(zram);
 	pr_info("Added device: %s\n", zram->disk->disk_name);
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ