Skip to contentSkip to conversation

mkfs.f2fs: avoid dumplicate extension

RFC PATCH Superseded Sheng Yong 2 participants 5 messages Nov 27, 2015 – Nov 28, 2015

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Sheng Yong

author
#0 lore raw

RFC PATCH 1/1 mkfs.f2fs: avoid dumplicate extension

Before copying user specified extension to extension_list, check if it is already in the list.

---
 mkfs/f2fs_format.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
mkfs/f2fs_format.c +22 -1
index 176bdea..b7ea19f 100644
@@ -118,6 +118,26 @@ const char *media_ext_lists[] = {
 	NULL
 };
 
+static int extension_exist(const char *name, const int len)
+{
+	const char **extlist = media_ext_lists;
+	int name_len, min_len;
+	int ret;
+
+
+	while (*extlist) {
+		name_len = strlen(*extlist);
+		min_len = name_len < len ? name_len : len;
+		ret = strncmp(*extlist, name, min_len);
+
+		if (ret == 0 && name_len == len)
+			return 1;
+		extlist++;
+	}
+
+	return 0;
+}
+
 static void configure_extension_list(void)
 {
 	const char **extlist = media_ext_lists;
@@ -144,7 +164,8 @@ static void configure_extension_list(void)
 	ue = strtok(ext_str, ",");
 	while (ue != NULL) {
 		name_len = strlen(ue);
-		memcpy(sb.extension_list[i++], ue, name_len);
+		if (!extension_exist(ue, name_len))
+			memcpy(sb.extension_list[i++], ue, name_len);
 		ue = strtok(NULL, ",");
 		if (i >= F2FS_MAX_EXTENSION)
 			break;
Signature · 4 lines
1.9.1


------------------------------------------------------------------------------
#1 lore raw

Hi Sheng Yong,

Quoted 13 lines · Sheng Yong

Before copying user specified extension to extension_list, check if it is already in the list.

---
 mkfs/f2fs_format.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
mkfs/f2fs_format.c +0 -0
index 176bdea..b7ea19f 100644

mkfs/f2fs_format.c const char *media_ext_lists[] = { · line 121

Quoted 4 lines
mkfs/f2fs_format.c +1 -0
@@ -118,6 +118,26 @@ const char *media_ext_lists[] = {
 	NULL
 };
 
+static int extension_exist(const char *name, const int len)

bool is_extension_exist?

mkfs/f2fs_format.c const char *media_ext_lists[] = { · line 131

Quoted 10 lines
mkfs/f2fs_format.c +10 -0
+{
+	const char **extlist = media_ext_lists;
+	int name_len, min_len;
+	int ret;
+
+
+	while (*extlist) {
+		name_len = strlen(*extlist);
+		min_len = name_len < len ? name_len : len;
+		ret = strncmp(*extlist, name, min_len);

How about using strcmp(*extlist, name)? It will return 0 only if the two strings are the same.

Quoted 13 lines
mkfs/f2fs_format.c +9 -0
+
+		if (ret == 0 && name_len == len)
+			return 1;
+		extlist++;
+	}
+
+	return 0;
+}
+
 static void configure_extension_list(void)
 {
 	const char **extlist = media_ext_lists;

mkfs/f2fs_format.c static void configure_extension_list(void) · line 166

Quoted 3 lines
mkfs/f2fs_format.c +0 -0
@@ -144,7 +164,8 @@ static void configure_extension_list(void)
 	ue = strtok(ext_str, ",");
 	while (ue != NULL) {
 		name_len = strlen(ue);

We should verify the length of extension to avoid memcpy overflow. I will send a patch for fixing.

mkfs/f2fs_format.c static void configure_extension_list(void) · line 167

Quoted 2 lines
mkfs/f2fs_format.c +1 -1
-		memcpy(sb.extension_list[i++], ue, name_len);
+		if (!extension_exist(ue, name_len))

How do you think of comparing extension user defined with sb.extension_list? In this way, duplication user defined can be avoided completely.

Thanks,

mkfs/f2fs_format.c static void configure_extension_list(void) · line 171

Quoted 5 lines
mkfs/f2fs_format.c +1 -0
+			memcpy(sb.extension_list[i++], ue, name_len);
 		ue = strtok(NULL, ",");
 		if (i >= F2FS_MAX_EXTENSION)
 			break;

------------------------------------------------------------------------------

author
#2 lore raw
Quoted 23 lines · Chao Yu

Hi Sheng Yong,

Quoted 13 lines · Sheng Yong

Before copying user specified extension to extension_list, check if it is already in the list.

---
 mkfs/f2fs_format.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
mkfs/f2fs_format.c +0 -0
index 176bdea..b7ea19f 100644

mkfs/f2fs_format.c const char *media_ext_lists[] = { · line 121

Quoted 4 lines
mkfs/f2fs_format.c +1 -0
@@ -118,6 +118,26 @@ const char *media_ext_lists[] = {
 	NULL
 };
 
+static int extension_exist(const char *name, const int len)

bool is_extension_exist?

Quoted 14 lines

mkfs/f2fs_format.c const char *media_ext_lists[] = { · line 131

Quoted 10 lines
mkfs/f2fs_format.c +10 -0
+{
+	const char **extlist = media_ext_lists;
+	int name_len, min_len;
+	int ret;
+
+
+	while (*extlist) {
+		name_len = strlen(*extlist);
+		min_len = name_len < len ? name_len : len;
+		ret = strncmp(*extlist, name, min_len);

How about using strcmp(*extlist, name)? It will return 0 only if the two strings are the same.

Hi, Chao Yu

Thanks for your reply. I was considering strcmp may have security issue.

Quoted 11 lines
Quoted 11 lines
mkfs/f2fs_format.c +9 -0
+
+		if (ret == 0 && name_len == len)
+			return 1;
+		extlist++;
+	}
+
+	return 0;
+}
+
 static void configure_extension_list(void)
 {
Quoted 8 lines

mkfs/f2fs_format.c static void configure_extension_list(void) · line 166

Quoted 5 lines
mkfs/f2fs_format.c +0 -0
 	const char **extlist = media_ext_lists;
@@ -144,7 +164,8 @@ static void configure_extension_list(void)
 	ue = strtok(ext_str, ",");
 	while (ue != NULL) {
 		name_len = strlen(ue);

We should verify the length of extension to avoid memcpy overflow. I will send a patch for fixing.

I agree. And I think we should make sure there is a '\0' at the end of each string in extension_list.

Quoted 6 lines

mkfs/f2fs_format.c static void configure_extension_list(void) · line 167

Quoted 3 lines
mkfs/f2fs_format.c +1 -1
-		memcpy(sb.extension_list[i++], ue, name_len);
+		if (!extension_exist(ue, name_len))

How do you think of comparing extension user defined with sb.extension_list? In this way, duplication user defined can be avoided completely.

Right. I'll send a v2 latter.

thanks,
Sheng

Quoted 11 lines

Thanks,

mkfs/f2fs_format.c static void configure_extension_list(void) · line 171

Quoted 5 lines
mkfs/f2fs_format.c +1 -0
+			memcpy(sb.extension_list[i++], ue, name_len);
 		ue = strtok(NULL, ",");
 		if (i >= F2FS_MAX_EXTENSION)
 			break;

.

------------------------------------------------------------------------------

#3 lore raw

Hi Sheng Yong,

Quoted 39 lines · Sheng Yong
Quoted 23 lines · Chao Yu

Hi Sheng Yong,

Quoted 13 lines · Sheng Yong

Before copying user specified extension to extension_list, check if it is already in the list.

---
 mkfs/f2fs_format.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
mkfs/f2fs_format.c +0 -0
index 176bdea..b7ea19f 100644

mkfs/f2fs_format.c const char *media_ext_lists[] = { · line 121

Quoted 4 lines
mkfs/f2fs_format.c +1 -0
@@ -118,6 +118,26 @@ const char *media_ext_lists[] = {
 	NULL
 };
 
+static int extension_exist(const char *name, const int len)

bool is_extension_exist?

Quoted 14 lines

mkfs/f2fs_format.c const char *media_ext_lists[] = { · line 131

Quoted 10 lines
mkfs/f2fs_format.c +10 -0
+{
+	const char **extlist = media_ext_lists;
+	int name_len, min_len;
+	int ret;
+
+
+	while (*extlist) {
+		name_len = strlen(*extlist);
+		min_len = name_len < len ? name_len : len;
+		ret = strncmp(*extlist, name, min_len);

How about using strcmp(*extlist, name)? It will return 0 only if the two strings are the same.

Quoted 3 lines

Hi, Chao Yu

Thanks for your reply. I was considering strcmp may have security issue.

Could you share details about the security issue of using strcmp?

Thanks,

Quoted 27 lines
Quoted 11 lines
Quoted 11 lines
mkfs/f2fs_format.c +9 -0
+
+		if (ret == 0 && name_len == len)
+			return 1;
+		extlist++;
+	}
+
+	return 0;
+}
+
 static void configure_extension_list(void)
 {
Quoted 8 lines

mkfs/f2fs_format.c static void configure_extension_list(void) · line 166

Quoted 5 lines
mkfs/f2fs_format.c +0 -0
 	const char **extlist = media_ext_lists;
@@ -144,7 +164,8 @@ static void configure_extension_list(void)
 	ue = strtok(ext_str, ",");
 	while (ue != NULL) {
 		name_len = strlen(ue);

We should verify the length of extension to avoid memcpy overflow. I will send a patch for fixing.

I agree. And I think we should make sure there is a '\0' at the end of each string in extension_list.

Quoted 6 lines

mkfs/f2fs_format.c static void configure_extension_list(void) · line 167

Quoted 3 lines
mkfs/f2fs_format.c +1 -1
-		memcpy(sb.extension_list[i++], ue, name_len);
+		if (!extension_exist(ue, name_len))

How do you think of comparing extension user defined with sb.extension_list? In this way, duplication user defined can be avoided completely.

Quoted 16 lines

Right. I'll send a v2 latter.

thanks,
Sheng

Quoted 11 lines

Thanks,

mkfs/f2fs_format.c static void configure_extension_list(void) · line 171

Quoted 5 lines
mkfs/f2fs_format.c +1 -0
+			memcpy(sb.extension_list[i++], ue, name_len);
 		ue = strtok(NULL, ",");
 		if (i >= F2FS_MAX_EXTENSION)
 			break;

.

------------------------------------------------------------------------------

author
#4 lore raw
Quoted 42 lines · Chao Yu

Hi Sheng Yong,

Quoted 39 lines · Sheng Yong
Quoted 37 lines · Chao Yu

Hi Sheng Yong,

Quoted 13 lines · Sheng Yong

Before copying user specified extension to extension_list, check if it is already in the list.

---
 mkfs/f2fs_format.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
mkfs/f2fs_format.c +0 -0
index 176bdea..b7ea19f 100644

mkfs/f2fs_format.c const char *media_ext_lists[] = { · line 121

Quoted 4 lines
mkfs/f2fs_format.c +1 -0
@@ -118,6 +118,26 @@ const char *media_ext_lists[] = {
 	NULL
 };
 
+static int extension_exist(const char *name, const int len)

bool is_extension_exist?

mkfs/f2fs_format.c const char *media_ext_lists[] = { · line 131

Quoted 10 lines
mkfs/f2fs_format.c +10 -0
+{
+	const char **extlist = media_ext_lists;
+	int name_len, min_len;
+	int ret;
+
+
+	while (*extlist) {
+		name_len = strlen(*extlist);
+		min_len = name_len < len ? name_len : len;
+		ret = strncmp(*extlist, name, min_len);

How about using strcmp(*extlist, name)? It will return 0 only if the two strings are the same.

Quoted 5 lines
Quoted 3 lines

Hi, Chao Yu

Thanks for your reply. I was considering strcmp may have security issue.

Could you share details about the security issue of using strcmp?

I was wrong, please ignore this :(

thanks,
Sheng

Quoted 47 lines

Thanks,

Quoted 27 lines
Quoted 11 lines
Quoted 11 lines
mkfs/f2fs_format.c +9 -0
+
+		if (ret == 0 && name_len == len)
+			return 1;
+		extlist++;
+	}
+
+	return 0;
+}
+
 static void configure_extension_list(void)
 {
Quoted 8 lines

mkfs/f2fs_format.c static void configure_extension_list(void) · line 166

Quoted 5 lines
mkfs/f2fs_format.c +0 -0
 	const char **extlist = media_ext_lists;
@@ -144,7 +164,8 @@ static void configure_extension_list(void)
 	ue = strtok(ext_str, ",");
 	while (ue != NULL) {
 		name_len = strlen(ue);

We should verify the length of extension to avoid memcpy overflow. I will send a patch for fixing.

I agree. And I think we should make sure there is a '\0' at the end of each string in extension_list.

Quoted 6 lines

mkfs/f2fs_format.c static void configure_extension_list(void) · line 167

Quoted 3 lines
mkfs/f2fs_format.c +1 -1
-		memcpy(sb.extension_list[i++], ue, name_len);
+		if (!extension_exist(ue, name_len))

How do you think of comparing extension user defined with sb.extension_list? In this way, duplication user defined can be avoided completely.

Quoted 16 lines

Right. I'll send a v2 latter.

thanks,
Sheng

Quoted 11 lines

Thanks,

mkfs/f2fs_format.c static void configure_extension_list(void) · line 171

Quoted 5 lines
mkfs/f2fs_format.c +1 -0
+			memcpy(sb.extension_list[i++], ue, name_len);
 		ue = strtok(NULL, ",");
 		if (i >= F2FS_MAX_EXTENSION)
 			break;

.

Quoted 2 lines

.

------------------------------------------------------------------------------