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  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 26 Oct 2020 22:43:17 +0800
From:   xiakaixu1987@...il.com
To:     linux-ext4@...r.kernel.org
Cc:     tytso@....edu, adilger.kernel@...ger.ca,
        Kaixu Xia <kaixuxia@...cent.com>
Subject: [PATCH] ext4: do the quotafile name safe check before allocating new string

From: Kaixu Xia <kaixuxia@...cent.com>

Now we do the quotafile name safe check after allocating the new string
by using kmalloc(), and have to release the string with kfree() if check
fails. Maybe we can check them before allocating memory and directly
return error if check fails to avoid the unnecessary kmalloc()/kfree()
operations.

Signed-off-by: Kaixu Xia <kaixuxia@...cent.com>
---
 fs/ext4/super.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 5308f0d5fb5a..83fdde498414 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1861,7 +1861,6 @@ static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
 {
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
 	char *qname, *old_qname = get_qf_name(sb, sbi, qtype);
-	int ret = -1;
 
 	if (sb_any_quota_loaded(sb) && !old_qname) {
 		ext4_msg(sb, KERN_ERR,
@@ -1874,32 +1873,30 @@ static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
 			 "ignored when QUOTA feature is enabled");
 		return 1;
 	}
-	qname = match_strdup(args);
-	if (!qname) {
-		ext4_msg(sb, KERN_ERR,
-			"Not enough memory for storing quotafile name");
-		return -1;
-	}
 	if (old_qname) {
-		if (strcmp(old_qname, qname) == 0)
-			ret = 1;
-		else
+		if (strlen(old_qname) != args->to - args->from ||
+		    strncmp(old_qname, args->from, args->to - args->from)) {
 			ext4_msg(sb, KERN_ERR,
 				 "%s quota file already specified",
 				 QTYPE2NAME(qtype));
-		goto errout;
+			return -1;
+		}
+		return 1;
 	}
-	if (strchr(qname, '/')) {
+	if (strnchr(args->from, args->to - args->from, '/')) {
 		ext4_msg(sb, KERN_ERR,
 			"quotafile must be on filesystem root");
-		goto errout;
+		return -1;
+	}
+	qname = match_strdup(args);
+	if (!qname) {
+		ext4_msg(sb, KERN_ERR,
+			"Not enough memory for storing quotafile name");
+		return -1;
 	}
 	rcu_assign_pointer(sbi->s_qf_names[qtype], qname);
 	set_opt(sb, QUOTA);
 	return 1;
-errout:
-	kfree(qname);
-	return ret;
 }
 
 static int clear_qf_name(struct super_block *sb, int qtype)
-- 
2.20.0

Powered by blists - more mailing lists