Skip to contentSkip to conversation

dosfstools: fix out of bound writes

PATCH In review [email protected] 3 participants 3 messages Nov 11, 2019 – Jan 18, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 dosfstools: fix out of bound writes

From: AJ Bagwell <[email protected]>

Fix write issues where sprintf writes across both name and ext fields and drops the final null ternimator outside the struct

---
 .../fixing-out-of-bound-writes.patch          | 54 +++++++++++++++++++
 .../dosfstools/dosfstools_2.11.bb             |  1 +
 2 files changed, 55 insertions(+)
 create mode 100644 recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound-writes.patch
recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound-writes.patch new file +54 -0
new file mode 100644
index 0000000..f80f5ab
@@ -0,0 +1,54 @@
+Fix out of bound write issues where sprintf writes across both
+name and ext fields and drops the final null ternimator outside the struct
+
+Upstream-Status: Inappropriate [licensing]
+We're tracking an old release of dosfstools due to licensing issues.
+
+diff --git a/dosfsck/check.c b/dosfsck/check.c
+index e8c13bb..91177d3 100644
+--- a/dosfsck/check.c
++++ b/dosfsck/check.c
+@@ -58,6 +58,13 @@ static DOS_FILE *root;
+     }									\
+   } while(0)
+ 
++static void de_printf(DIR_ENT *de, const char *pattern, int curr_num)
++{
++    char buffer[12];
++    sprintf(buffer, pattern, curr_num);
++    memcpy(de->name, buffer, 8);
++    memcpy(de->ext, buffer + 8, 3);
++}
+ 
+ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern)
+ {
+@@ -110,7 +117,8 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern)
+ 	}
+ 	memset(de,0,sizeof(DIR_ENT));
+ 	while (1) {
+-	    sprintf(de->name,pattern,curr_num);
++	    de_printf(de, pattern, curr_num);
++
+ 	    clu_num = fs->root_cluster;
+ 	    i = 0;
+ 	    offset2 = cluster_start(fs,clu_num);
+@@ -150,7 +158,7 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern)
+ 	offset = fs->root_start+next_free*sizeof(DIR_ENT);
+ 	memset(de,0,sizeof(DIR_ENT));
+ 	while (1) {
+-	    sprintf(de->name,pattern,curr_num);
++	    de_printf(de, pattern, curr_num);
+ 	    for (scan = 0; scan < fs->root_entries; scan++)
+ 		if (scan != next_free &&
+ 		    !strncmp(root[scan].name,de->name,MSDOS_NAME))
+@@ -311,8 +319,8 @@ static void auto_rename(DOS_FILE *file)
+     first = file->parent ? file->parent->first : root;
+     number = 0;
+     while (1) {
+-	sprintf(file->dir_ent.name,"FSCK%04d",number);
+-	strncpy(file->dir_ent.ext,"REN",3);
++	de_printf(&file->dir_ent, "FSCK%04dREN", number);
++
+ 	for (walk = first; walk; walk = walk->next)
+ 	    if (walk != file && !strncmp(walk->dir_ent.name,file->dir_ent.
+ 	      name,MSDOS_NAME)) break;
recipes-devtools/dosfstools/dosfstools_2.11.bb +1 -0
index dd543b1..37c2181 100644
@@ -19,6 +19,7 @@ SRC_URI = "http://pkgs.fedoraproject.org/repo/pkgs/${BPN}/${BP}.src.tar.gz/407d4
            file://nofat32_autoselect.patch \
            file://fix_populated_dosfs_creation.patch \
            file://0001-Include-fcntl.h-for-getting-loff_t-definition.patch \
+	   file://fixing-out-of-bound-writes.patch \
 "
 
 SRC_URI[md5sum] = "407d405ade410f7597d364ab5dc8c9f6"
Signature · 1 line
2.17.1
#1 lore raw
Quoted 26 lines · On Mon, 2019-11-11 at 10:32 +0000, [email protected] wrote:

From: AJ Bagwell <[email protected]>

Fix write issues where sprintf writes across both name and ext fields and drops the final null ternimator outside the struct

---
 .../fixing-out-of-bound-writes.patch          | 54
+++++++++++++++++++
 .../dosfstools/dosfstools_2.11.bb             |  1 +
 2 files changed, 55 insertions(+)
 create mode 100644 recipes-devtools/dosfstools/dosfstools/fixing-

out-of-bound-writes.patch

(quoted diff) +0 -0

bound-writes.patch b/recipes-devtools/dosfstools/dosfstools/fixing- out-of-bound-writes.patch
new file mode 100644
index 0000000..f80f5ab

recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound- new file +0 -0

writes.patch

recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound- new file +2 -0
@@ -0,0 +1,54 @@
+Fix out of bound write issues where sprintf writes across both
+name and ext fields and drops the final null ternimator outside the

struct

recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound-

Quoted 4 lines
recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound- new file +4 -0
+
+Upstream-Status: Inappropriate [licensing]
+We're tracking an old release of dosfstools due to licensing issues.
+

patch is fine, I wonder if the latest version in OE-Core is also affected by this issue ?

Quoted 72 lines
recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound- new file +6 -0
+diff --git a/dosfsck/check.c b/dosfsck/check.c
+index e8c13bb..91177d3 100644
+--- a/dosfsck/check.c
++++ b/dosfsck/check.c
+@@ -58,6 +58,13 @@ static DOS_FILE *root;
+     }								
	\

+ } while(0)
+
++static void de_printf(DIR_ENT *de, const char *pattern, int curr_num)
++{

++    char buffer[12];
++    sprintf(buffer, pattern, curr_num);
++    memcpy(de->name, buffer, 8);
++    memcpy(de->ext, buffer + 8, 3);

++}
+
+ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern)
+ {
+@@ -110,7 +117,8 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern)

recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound- new file +10 -0
+ 	}
+ 	memset(de,0,sizeof(DIR_ENT));
+ 	while (1) {
+-	    sprintf(de->name,pattern,curr_num);
++	    de_printf(de, pattern, curr_num);
++
+ 	    clu_num = fs->root_cluster;
+ 	    i = 0;
+ 	    offset2 = cluster_start(fs,clu_num);
+@@ -150,7 +158,7 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT

*de, const char *pattern)

recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound- new file +18 -0
+ 	offset = fs->root_start+next_free*sizeof(DIR_ENT);
+ 	memset(de,0,sizeof(DIR_ENT));
+ 	while (1) {
+-	    sprintf(de->name,pattern,curr_num);
++	    de_printf(de, pattern, curr_num);
+ 	    for (scan = 0; scan < fs->root_entries; scan++)
+ 		if (scan != next_free &&
+ 		    !strncmp(root[scan].name,de->name,MSDOS_NAME))
+@@ -311,8 +319,8 @@ static void auto_rename(DOS_FILE *file)
+     first = file->parent ? file->parent->first : root;
+     number = 0;
+     while (1) {
+-	sprintf(file->dir_ent.name,"FSCK%04d",number);
+-	strncpy(file->dir_ent.ext,"REN",3);
++	de_printf(&file->dir_ent, "FSCK%04dREN", number);
++
+ 	for (walk = first; walk; walk = walk->next)
+ 	    if (walk != file && !strncmp(walk->dir_ent.name,file-
Quoted 1 line

dir_ent.

recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound- new file +1 -0
+ 	      name,MSDOS_NAME)) break;
recipes-devtools/dosfstools/dosfstools_2.11.bb +0 -0
index dd543b1..37c2181 100644
@@ -19,6 +19,7 @@ SRC_URI = "

http://pkgs.fedoraproject.org/repo/pkgs/${BPN}/${BP}.src.tar.gz/407d4

            file://nofat32_autoselect.patch \
            file://fix_populated_dosfs_creation.patch \
            file://0001-Include-fcntl.h-for-getting-loff_t-

definition.patch \

recipes-devtools/dosfstools/dosfstools_2.11.bb +1 -0
+	   file://fixing-out-of-bound-writes.patch \
 "
 
 SRC_URI[md5sum] = "407d405ade410f7597d364ab5dc8c9f6"
Signature · 1 line
2.17.1
#2 lore raw
Quoted 27 lines · Khem Raj
Quoted 25 lines · On Mon, 2019-11-11 at 10:32 +0000, [email protected] wrote:

From: AJ Bagwell <[email protected]>

Fix write issues where sprintf writes across both name and ext fields and drops the final null ternimator outside the struct

---
 .../fixing-out-of-bound-writes.patch          | 54
+++++++++++++++++++
 .../dosfstools/dosfstools_2.11.bb             |  1 +
 2 files changed, 55 insertions(+)
 create mode 100644 recipes-devtools/dosfstools/dosfstools/fixing-

out-of-bound-writes.patch

(quoted diff) +0 -0

bound-writes.patch b/recipes-devtools/dosfstools/dosfstools/fixing- out-of-bound-writes.patch
new file mode 100644
index 0000000..f80f5ab

recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound- new file +0 -0

writes.patch

recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound- new file +2 -0
@@ -0,0 +1,54 @@
+Fix out of bound write issues where sprintf writes across both
+name and ext fields and drops the final null ternimator outside the
Quoted 9 lines

recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound-

Quoted 5 lines

struct

recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound- new file +4 -0
+
+Upstream-Status: Inappropriate [licensing]
+We're tracking an old release of dosfstools due to licensing issues.
+

patch is fine, I wonder if the latest version in OE-Core is also affected by this issue ?

It's not - upstream has an equivalent fix.

Quoted 79 lines
Quoted 65 lines
recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound- new file +9 -0
+diff --git a/dosfsck/check.c b/dosfsck/check.c
+index e8c13bb..91177d3 100644
+--- a/dosfsck/check.c
++++ b/dosfsck/check.c
+@@ -58,6 +58,13 @@ static DOS_FILE *root;
+     }
      \
+   } while(0)
+
++static void de_printf(DIR_ENT *de, const char *pattern, int

curr_num)
++{

++    char buffer[12];
++    sprintf(buffer, pattern, curr_num);
++    memcpy(de->name, buffer, 8);
++    memcpy(de->ext, buffer + 8, 3);

++}
+
+ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern)
+ {
+@@ -110,7 +117,8 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT *de, const char *pattern)

recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound- new file +10 -0
+     }
+     memset(de,0,sizeof(DIR_ENT));
+     while (1) {
+-        sprintf(de->name,pattern,curr_num);
++        de_printf(de, pattern, curr_num);
++
+         clu_num = fs->root_cluster;
+         i = 0;
+         offset2 = cluster_start(fs,clu_num);
+@@ -150,7 +158,7 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, DIR_ENT

*de, const char *pattern)

recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound- new file +18 -0
+     offset = fs->root_start+next_free*sizeof(DIR_ENT);
+     memset(de,0,sizeof(DIR_ENT));
+     while (1) {
+-        sprintf(de->name,pattern,curr_num);
++        de_printf(de, pattern, curr_num);
+         for (scan = 0; scan < fs->root_entries; scan++)
+             if (scan != next_free &&
+                 !strncmp(root[scan].name,de->name,MSDOS_NAME))
+@@ -311,8 +319,8 @@ static void auto_rename(DOS_FILE *file)
+     first = file->parent ? file->parent->first : root;
+     number = 0;
+     while (1) {
+-    sprintf(file->dir_ent.name,"FSCK%04d",number);
+-    strncpy(file->dir_ent.ext,"REN",3);
++    de_printf(&file->dir_ent, "FSCK%04dREN", number);
++
+     for (walk = first; walk; walk = walk->next)
+         if (walk != file && !strncmp(walk->dir_ent.name,file-
Quoted 1 line

dir_ent.

recipes-devtools/dosfstools/dosfstools/fixing-out-of-bound- new file +1 -0
+           name,MSDOS_NAME)) break;
recipes-devtools/dosfstools/dosfstools_2.11.bb +0 -0
index dd543b1..37c2181 100644
@@ -19,6 +19,7 @@ SRC_URI = "

http://pkgs.fedoraproject.org/repo/pkgs/${BPN}/${BP}.src.tar.gz/407d4

            file://nofat32_autoselect.patch \
            file://fix_populated_dosfs_creation.patch \
            file://0001-Include-fcntl.h-for-getting-loff_t-
Quoted 8 lines

definition.patch \
+ file://fixing-out-of-bound-writes.patch \
"

SRC_URI[md5sum] = "407d405ade410f7597d364ab5dc8c9f6"
--
2.17.1

--
_______________________________________________
yocto mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/yocto

Signature · 1 line
Alex Kiernan