Skip to contentSkip to conversation

env: mmc: Correct partition comparison in mmc_offset_try_partition

PATCH New Hoyeonjiki Kim 4 participants 8 messages Nov 10, 2020 – Nov 16, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 env: mmc: Correct partition comparison in mmc_offset_try_partition

The function mmc_offset_try_partition searches MMC partition to save the environment data by name. However, it only compares the first word-size bytes (size of 'const char *'), which may make the function to find unintended partition.

Correct the function not to partially compare the partition name with config "u-boot,,mmc-env-partition".

---
 env/mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
env/mmc.c +1 -1
index 4e67180b23..505f7aa2b8 100644
@@ -42,7 +42,7 @@ static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
 		if (ret < 0)
 			return ret;
 
-		if (!strncmp((const char *)info.name, str, sizeof(str)))
+		if (!strcmp((const char *)info.name, str))
 			break;
 	}
 
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 env: mmc: Correct partition comparison in mmc_offset_try_partition

Quoted 18 lines · Hoyeonjiki Kim

The function mmc_offset_try_partition searches MMC partition to save the environment data by name. However, it only compares the first word-size bytes (size of 'const char *'), which may make the function to find unintended partition.

Correct the function not to partially compare the partition name with config "u-boot,,mmc-env-partition".

---
 env/mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
env/mmc.c +0 -0
index 4e67180b23..505f7aa2b8 100644

env/mmc.c static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val) · line 45

Quoted 5 lines
env/mmc.c +1 -1
@@ -42,7 +42,7 @@ static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
 		if (ret < 0)
 			return ret;
 
-		if (!strncmp((const char *)info.name, str, sizeof(str)))
+		if (!strcmp((const char *)info.name, str))

Using "strlen(str)" is better than changing to strcmp.

strncmp(..., ..., strlen(str))

Best Regards,
Jaehoon Chung

Quoted 4 lines
env/mmc.c +0 -0
 			break;
 	}
 
#2 lore raw

PATCH 1/1 env: mmc: Correct partition comparison in mmc_offset_try_partition

Quoted 22 lines · Jaehoon Chung
Quoted 21 lines · Hoyeonjiki Kim

The function mmc_offset_try_partition searches MMC partition to save the environment data by name. However, it only compares the first word-size bytes (size of 'const char *'), which may make the function to find unintended partition.

Correct the function not to partially compare the partition name with config "u-boot,,mmc-env-partition".

---
 env/mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
env/mmc.c +0 -0
index 4e67180b23..505f7aa2b8 100644
@@ -42,7 +42,7 @@ static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
 		if (ret < 0)
 			return ret;
 
Quoted 6 lines

env/mmc.c static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val) · line 45

Quoted 2 lines
env/mmc.c +1 -1
-		if (!strncmp((const char *)info.name, str, sizeof(str)))
+		if (!strcmp((const char *)info.name, str))

Using "strlen(str)" is better than changing to strcmp.

strncmp(..., ..., strlen(str))

absolutely.
maybe also modify the commit like to indicate a fix to the current bug?

Quoted 10 lines

Best Regards,
Jaehoon Chung

Quoted 4 lines
env/mmc.c +0 -0
 			break;
 	}
 
#3 lore raw

PATCH 1/1 env: mmc: Correct partition comparison in mmc_offset_try_partition

Quoted 29 lines · Gmail
Quoted 27 lines · Jaehoon Chung
Quoted 18 lines · Hoyeonjiki Kim

The function mmc_offset_try_partition searches MMC partition to save the environment data by name. However, it only compares the first word-size bytes (size of 'const char *'), which may make the function to find unintended partition.

Correct the function not to partially compare the partition name with config "u-boot,,mmc-env-partition".

---
 env/mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
env/mmc.c +0 -0
index 4e67180b23..505f7aa2b8 100644

env/mmc.c static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val) · line 45

Quoted 5 lines
env/mmc.c +1 -1
@@ -42,7 +42,7 @@ static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
            if (ret < 0)
                    return ret;
 
-           if (!strncmp((const char *)info.name, str, sizeof(str)))
+           if (!strcmp((const char *)info.name, str))

Using "strlen(str)" is better than changing to strcmp.

Quoted 4 lines
Quoted 1 line

strncmp(..., ..., strlen(str))

absolutely.
maybe also modify the commit like to indicate a fix to the current bug?

Thanks for the feedback for both.

However, when we do so, isn't there still the possibility for the function searching incorrect partition if,
1) "str" is shorter than "info.name", and
2) the first "strlen(str)" letters of "info.name" is same with those of "str"?

This commit is for fixing the current bug, but also I wanna make sure that partition name matches fully.

Let me know your opinion.

Best Regards,
Hoeyonjiki Kim

Quoted 11 lines
Quoted 11 lines

Best Regards,
Jaehoon Chung

Quoted 4 lines
env/mmc.c +0 -0
                    break;
    }
 
#4 lore raw

PATCH 1/1 env: mmc: Correct partition comparison in mmc_offset_try_partition

Hi,

Quoted 36 lines · ?????
Quoted 29 lines · Gmail
Quoted 27 lines · Jaehoon Chung
Quoted 18 lines · Hoyeonjiki Kim

The function mmc_offset_try_partition searches MMC partition to save the environment data by name. However, it only compares the first word-size bytes (size of 'const char *'), which may make the function to find unintended partition.

Correct the function not to partially compare the partition name with config "u-boot,,mmc-env-partition".

---
 env/mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
env/mmc.c +0 -0
index 4e67180b23..505f7aa2b8 100644

env/mmc.c static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val) · line 45

Quoted 5 lines
env/mmc.c +1 -1
@@ -42,7 +42,7 @@ static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
            if (ret < 0)
                    return ret;
 
-           if (!strncmp((const char *)info.name, str, sizeof(str)))
+           if (!strcmp((const char *)info.name, str))

Using "strlen(str)" is better than changing to strcmp.

Quoted 4 lines
Quoted 1 line

strncmp(..., ..., strlen(str))

absolutely.
maybe also modify the commit like to indicate a fix to the current bug?

Quoted 6 lines

Thanks for the feedback for both.

However, when we do so, isn't there still the possibility for the function searching incorrect partition if,
1) "str" is shorter than "info.name", and
2) the first "strlen(str)" letters of "info.name" is same with those of "str"?

Make sense. You're right. :)

There are two approach. One is that choose one of those length what is longer. Other is your approach. I don't have any objection to fix whatever.

Just resend your patch with Jorge's comment, plz.

Best Regards,
Jaehoon Chung

Quoted 21 lines

This commit is for fixing the current bug, but also I wanna make sure that partition name matches fully.

Let me know your opinion.

Best Regards,
Hoeyonjiki Kim

Quoted 11 lines
Quoted 11 lines

Best Regards,
Jaehoon Chung

Quoted 4 lines
env/mmc.c +0 -0
                    break;
    }
 
#5 lore raw

PATCH 1/1 env: mmc: Correct partition comparison in mmc_offset_try_partition

Quoted 49 lines · Jaehoon Chung

Hi,

Quoted 36 lines · ?????
Quoted 29 lines · Gmail
Quoted 27 lines · Jaehoon Chung
Quoted 18 lines · Hoyeonjiki Kim

The function mmc_offset_try_partition searches MMC partition to save the environment data by name. However, it only compares the first word-size bytes (size of 'const char *'), which may make the function to find unintended partition.

Correct the function not to partially compare the partition name with config "u-boot,,mmc-env-partition".

---
 env/mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
env/mmc.c +0 -0
index 4e67180b23..505f7aa2b8 100644

env/mmc.c static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val) · line 45

Quoted 5 lines
env/mmc.c +1 -1
@@ -42,7 +42,7 @@ static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
            if (ret < 0)
                    return ret;
 
-           if (!strncmp((const char *)info.name, str, sizeof(str)))
+           if (!strcmp((const char *)info.name, str))

Using "strlen(str)" is better than changing to strcmp.

Quoted 4 lines
Quoted 1 line

strncmp(..., ..., strlen(str))

absolutely.
maybe also modify the commit like to indicate a fix to the current bug?

Quoted 6 lines

Thanks for the feedback for both.

However, when we do so, isn't there still the possibility for the function searching incorrect partition if,
1) "str" is shorter than "info.name", and
2) the first "strlen(str)" letters of "info.name" is same with those of "str"?

Make sense. You're right. :)

Quoted 8 lines

There are two approach. One is that choose one of those length what is longer. Other is your approach. I don't have any objection to fix whatever.

Just resend your patch with Jorge's comment, plz.

Best Regards,
Jaehoon Chung

Sure, thanks for your opinion.
Will be back with v2.

Best Regards,
Hoyeonjiki Kim

Quoted 23 lines
Quoted 22 lines

This commit is for fixing the current bug, but also I wanna make sure that partition name matches fully.

Let me know your opinion.

Best Regards,
Hoeyonjiki Kim

Quoted 11 lines
Quoted 11 lines

Best Regards,
Jaehoon Chung

Quoted 4 lines
env/mmc.c +0 -0
                    break;
    }
 
#6 lore raw

PATCH 1/1 env: mmc: Correct partition comparison in mmc_offset_try_partition

In reply to Jaehoon Chung

Dear Jaehoon Chung,

Quoted 22 lines · In message <[email protected]> you wrote:
Quoted 21 lines · Hoyeonjiki Kim

The function mmc_offset_try_partition searches MMC partition to save the environment data by name. However, it only compares the first word-size bytes (size of 'const char *'), which may make the function to find unintended partition.

Correct the function not to partially compare the partition name with config "u-boot,,mmc-env-partition".

---
 env/mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
env/mmc.c +0 -0
index 4e67180b23..505f7aa2b8 100644
@@ -42,7 +42,7 @@ static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
 		if (ret < 0)
 			return ret;
 
Quoted 6 lines

env/mmc.c static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val) · line 45

Quoted 2 lines
env/mmc.c +1 -1
-		if (!strncmp((const char *)info.name, str, sizeof(str)))
+		if (!strcmp((const char *)info.name, str))

Using "strlen(str)" is better than changing to strcmp.

strncmp(..., ..., strlen(str))

Is either of this a good idea? I mean, if you pass in random data, this will run forever and eventually create undefined behaviour. We know the maximum size, so why not limit it to that, as strncmp() did?

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"To IBM, 'open' means there is a modicum  of  interoperability  among
some of their equipment."                            - Harv Masterson
#7 lore raw

PATCH 1/1 env: mmc: Correct partition comparison in mmc_offset_try_partition

Dear Wolfgang,

Quoted 30 lines · Wolfgang Denk

Dear Jaehoon Chung,

Quoted 27 lines · In message <[email protected]> you wrote:
Quoted 18 lines · Hoyeonjiki Kim

The function mmc_offset_try_partition searches MMC partition to save the environment data by name. However, it only compares the first word-size bytes (size of 'const char *'), which may make the function to find unintended partition.

Correct the function not to partially compare the partition name with config "u-boot,,mmc-env-partition".

---
 env/mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
env/mmc.c +0 -0
index 4e67180b23..505f7aa2b8 100644

env/mmc.c static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val) · line 45

Quoted 5 lines
env/mmc.c +1 -1
@@ -42,7 +42,7 @@ static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
 		if (ret < 0)
 			return ret;
 
-		if (!strncmp((const char *)info.name, str, sizeof(str)))
+		if (!strcmp((const char *)info.name, str))

Using "strlen(str)" is better than changing to strcmp.

Quoted 5 lines
Quoted 1 line

strncmp(..., ..., strlen(str))

Is either of this a good idea? I mean, if you pass in random data, this will run forever and eventually create undefined behaviour. We know the maximum size, so why not limit it to that, as strncmp() did?

Actually, i don' want to use strcmp.
If my remember is correct, strcmp is already reported about having security hole. I had commented one example for using to check length.
But i agreed it's not good idea. Thanks for pointing out!

Best Regards,
Jaehoon Chung

Quoted 5 lines

Best regards,

Wolfgang Denk