Skip to contentSkip to conversation

env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

PATCH New Martin Fuzzey 5 participants 15 messages Jan 11, 2021 – Apr 18, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

Since commit 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set") a warning message is displayed when setenv -f is used WITHOUT CONFIG_ENV_ACCESS_IGNORE_FORCE, but the variable is set anyway, resulting in lots of log pollution.

env_flags_validate() returns 0 if the access is accepted, or non zero if it is refused.

So the original code

	#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
		if (flag & H_FORCE)
			return 0;
	#endif

was correct, it returns 0 (accepts the modification) if forced UNLESS IGNORE_FORCE is set (in which case access checks in the following code are applied). The broken patch just added a printf to the force accepted case.

To obtain the intent of the patch we need this:

	if (flag & H_FORCE) {
	#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
		printf("## Error: Can't force access to \"%s\"\n", name);
	#else
		return 0;
	#endif
	}
Fixes 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set")
---
 env/flags.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
env/flags.c +3 -2
index df4aed2..e3e833c 100644
@@ -563,12 +563,13 @@ int env_flags_validate(const struct env_entry *item, const char *newval,
 		return 1;
 #endif
 
-#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
 	if (flag & H_FORCE) {
+#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
 		printf("## Error: Can't force access to \"%s\"\n", name);
+#else
 		return 0;
-	}
 #endif
+	}
 	switch (op) {
 	case env_op_delete:
 		if (item->flags & ENV_FLAGS_VARACCESS_PREVENT_DELETE) {
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

Quoted 45 lines · Martin Fuzzey

Since commit 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set") a warning message is displayed when setenv -f is used WITHOUT CONFIG_ENV_ACCESS_IGNORE_FORCE, but the variable is set anyway, resulting in lots of log pollution.

env_flags_validate() returns 0 if the access is accepted, or non zero if it is refused.

So the original code

	#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
		if (flag & H_FORCE)
			return 0;
	#endif

was correct, it returns 0 (accepts the modification) if forced UNLESS IGNORE_FORCE is set (in which case access checks in the following code are applied). The broken patch just added a printf to the force accepted case.

To obtain the intent of the patch we need this:

	if (flag & H_FORCE) {
	#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
		printf("## Error: Can't force access to \"%s\"\n", name);
	#else
		return 0;
	#endif
	}
Fixes 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set")
---
 env/flags.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
env/flags.c +0 -1
index df4aed2..e3e833c 100644
@@ -563,12 +563,13 @@ int env_flags_validate(const struct env_entry *item, const char *newval,
 		return 1;
 #endif
 
-#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
 	if (flag & H_FORCE) {

env/flags.c int env_flags_validate(const struct env_entry *item, const char *newval, · line 575

Quoted 10 lines
env/flags.c +3 -1
+#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
 		printf("## Error: Can't force access to \"%s\"\n", name);
+#else
 		return 0;
-	}
 #endif
+	}
 	switch (op) {
 	case env_op_delete:
 		if (item->flags & ENV_FLAGS_VARACCESS_PREVENT_DELETE) {

Marek, does this look right to you? Heinrich, I think this means there''s a follow-up commit that I made to one of the tests that can probably be reverted as well? Thanks for digging in to this Martin!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210115/15268e04/attachment.sig>
#2 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

Quoted 45 lines · Tom Rini
Quoted 43 lines · Martin Fuzzey

Since commit 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set") a warning message is displayed when setenv -f is used WITHOUT CONFIG_ENV_ACCESS_IGNORE_FORCE, but the variable is set anyway, resulting in lots of log pollution.

env_flags_validate() returns 0 if the access is accepted, or non zero if it is refused.

So the original code

	#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
		if (flag & H_FORCE)
			return 0;
	#endif

was correct, it returns 0 (accepts the modification) if forced UNLESS IGNORE_FORCE is set (in which case access checks in the following code are applied). The broken patch just added a printf to the force accepted case.

To obtain the intent of the patch we need this:

	if (flag & H_FORCE) {
	#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
		printf("## Error: Can't force access to \"%s\"\n", name);
	#else
		return 0;
	#endif
	}
Fixes 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set")
---
 env/flags.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
env/flags.c +0 -0
index df4aed2..e3e833c 100644
@@ -563,12 +563,13 @@ int env_flags_validate(const struct env_entry *item, const char *newval,
 		return 1;
 #endif
 
Quoted 16 lines

env/flags.c int env_flags_validate(const struct env_entry *item, const char *newval, · line 575

Quoted 12 lines
env/flags.c +3 -2
-#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
 	if (flag & H_FORCE) {
+#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
 		printf("## Error: Can't force access to \"%s\"\n", name);
+#else
 		return 0;
-	}
 #endif
+	}
 	switch (op) {
 	case env_op_delete:
 		if (item->flags & ENV_FLAGS_VARACCESS_PREVENT_DELETE) {

Marek, does this look right to you? Heinrich, I think this means there''s a follow-up commit that I made to one of the tests that can probably be reverted as well? Thanks for digging in to this Martin!

Marek? Heinrich? I really want a little feedback on this patch since I think it addresses a tricky problem. Thanks.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210128/947c0eef/attachment.sig>
#3 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

In reply to Martin Fuzzey

env/flags.c int env_flags_validate(const struct env_entry *item, const char *newval,

Quoted 40 lines · Martin Fuzzey

Since commit 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set") a warning message is displayed when setenv -f is used WITHOUT CONFIG_ENV_ACCESS_IGNORE_FORCE, but the variable is set anyway, resulting in lots of log pollution.

env_flags_validate() returns 0 if the access is accepted, or non zero if it is refused.

So the original code

	#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
		if (flag & H_FORCE)
			return 0;
	#endif

was correct, it returns 0 (accepts the modification) if forced UNLESS IGNORE_FORCE is set (in which case access checks in the following code are applied). The broken patch just added a printf to the force accepted case.

To obtain the intent of the patch we need this:

	if (flag & H_FORCE) {
	#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
		printf("## Error: Can't force access to \"%s\"\n", name);
	#else
		return 0;
	#endif
	}
Fixes 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set")
---
 env/flags.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
env/flags.c +0 -0
index df4aed2..e3e833c 100644
@@ -563,12 +563,13 @@ int env_flags_validate(const struct env_entry *item, const char *newval,

Please, add a Sphinx style function description in include/env_flags.h explaining exactly what this function is meant to do.

Cf.
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation

env/flags.c int env_flags_validate(const struct env_entry *item, const char *newval, · line 568

Quoted 7 lines
env/flags.c +1 -1
 		return 1;
 #endif
 
-#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
 	if (flag & H_FORCE) {
+#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
 		printf("## Error: Can't force access to \"%s\"\n", name);

If this is an error, why don't you return 1 (failure)? Please, use log_err() for error messages.

env/flags.c int env_flags_validate(const struct env_entry *item, const char *newval, · line 570

Quoted 2 lines
env/flags.c +1 -0
+#else
 		return 0;

Why shouldn't the other tests be executed?

Best regards

Heinrich

Quoted 7 lines
env/flags.c +1 -1
-	}
 #endif
+	}
 	switch (op) {
 	case env_op_delete:
 		if (item->flags & ENV_FLAGS_VARACCESS_PREVENT_DELETE) {
#4 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

On 1/28/21 10:11 AM, Heinrich Schuchardt wrote:
[...]

Quoted 11 lines

env/flags.c int env_flags_validate(const struct env_entry *item, const char *newval,

Quoted 5 lines
env/flags.c +0 -0
index df4aed2..e3e833c 100644
@@ -563,12 +563,13 @@ int env_flags_validate(const struct env_entry *item, const char *newval,

Please, add a Sphinx style function description in include/env_flags.h explaining exactly what this function is meant to do.

Cf.
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation

This is irrelevant, it's a bugfix so docs/improvements are a separate patch.

Quoted 11 lines

env/flags.c int env_flags_validate(const struct env_entry *item, const char *newval, · line 568

Quoted 7 lines
env/flags.c +1 -1
  		return 1;
  #endif
 
-#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
  	if (flag & H_FORCE) {
+#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
  		printf("## Error: Can't force access to \"%s\"\n", name);

If this is an error, why don't you return 1 (failure)? Please, use log_err() for error messages.

Quoted 4 lines

env/flags.c int env_flags_validate(const struct env_entry *item, const char *newval, · line 570

Quoted 2 lines
env/flags.c +1 -0
+#else
  		return 0;

Why shouldn't the other tests be executed?

Because the code is a total mess and thus error prone.

#5 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

In reply to Martin Fuzzey
Quoted 41 lines · Martin Fuzzey

Since commit 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set") a warning message is displayed when setenv -f is used WITHOUT CONFIG_ENV_ACCESS_IGNORE_FORCE, but the variable is set anyway, resulting in lots of log pollution.

env_flags_validate() returns 0 if the access is accepted, or non zero if it is refused.

So the original code

	#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
		if (flag & H_FORCE)
			return 0;
	#endif

was correct, it returns 0 (accepts the modification) if forced UNLESS IGNORE_FORCE is set (in which case access checks in the following code are applied). The broken patch just added a printf to the force accepted case.

To obtain the intent of the patch we need this:

	if (flag & H_FORCE) {
	#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
		printf("## Error: Can't force access to \"%s\"\n", name);
	#else
		return 0;
	#endif
	}
Fixes 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set")
---
  env/flags.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
env/flags.c +0 -0
index df4aed2..e3e833c 100644
@@ -563,12 +563,13 @@ int env_flags_validate(const struct env_entry *item, const char *newval,
  		return 1;

env/flags.c int env_flags_validate(const struct env_entry *item, const char *newval, · line 571

Quoted 10 lines
env/flags.c +2 -2
  #endif
 
-#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
  	if (flag & H_FORCE) {
+#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
  		printf("## Error: Can't force access to \"%s\"\n", name);
+#else
  		return 0;
-	}
  #endif

Based on env/Kconfig description of this option:

config ENV_ACCESS_IGNORE_FORCE
bool "Block forced environment operations" default n
help
If defined, don't allow the -f switch to env set override
variable
access flags.

I would think the code should look like this:

#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
         if (flag & H_FORCE) {
                 printf("## Error: Can't force access to \"%s\"\n", name);
                 return 1;
         }

#else
if (flag & H_FORCE)
return 0;
#endif

#6 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

Quoted 68 lines · Marek Vasut
Quoted 40 lines · Martin Fuzzey

Since commit 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set") a warning message is displayed when setenv -f is used WITHOUT CONFIG_ENV_ACCESS_IGNORE_FORCE, but the variable is set anyway, resulting in lots of log pollution.

env_flags_validate() returns 0 if the access is accepted, or non zero if it is refused.

So the original code

	#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
		if (flag & H_FORCE)
			return 0;
	#endif

was correct, it returns 0 (accepts the modification) if forced UNLESS IGNORE_FORCE is set (in which case access checks in the following code are applied). The broken patch just added a printf to the force accepted case.

To obtain the intent of the patch we need this:

	if (flag & H_FORCE) {
	#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
		printf("## Error: Can't force access to \"%s\"\n", name);
	#else
		return 0;
	#endif
	}
Fixes 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set")
---
  env/flags.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
env/flags.c +0 -0
index df4aed2..e3e833c 100644

env/flags.c int env_flags_validate(const struct env_entry *item, const char *newval, · line 570

Quoted 10 lines
env/flags.c +2 -2
@@ -563,12 +563,13 @@ int env_flags_validate(const struct env_entry *item, const char *newval,
  		return 1;
  #endif
-#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
  	if (flag & H_FORCE) {
+#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
  		printf("## Error: Can't force access to \"%s\"\n", name);
+#else
  		return 0;
-	}
  #endif

Based on env/Kconfig description of this option:

config ENV_ACCESS_IGNORE_FORCE
bool "Block forced environment operations"
default n
help
If defined, don't allow the -f switch to env set override variable access flags.

I would think the code should look like this:

#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
        if (flag & H_FORCE) {
                printf("## Error: Can't force access to \"%s\"\n", name);
                return 1;
        }
Quoted 4 lines

#else
if (flag & H_FORCE)
return 0;
#endif

So, prior to 0f036bf4b87e we had what you're suggesting, and that lead to 8a5cdf601f8d (which is the commit I was trying to think of) which Heinrich did not like, but was what was needed to get things to function again. Wouldn't what you're proposing break the use case you had in the first place?

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210128/3575122d/attachment.sig>
#7 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

Quoted 74 lines · Tom Rini
Quoted 68 lines · Marek Vasut
Quoted 40 lines · Martin Fuzzey

Since commit 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set") a warning message is displayed when setenv -f is used WITHOUT CONFIG_ENV_ACCESS_IGNORE_FORCE, but the variable is set anyway, resulting in lots of log pollution.

env_flags_validate() returns 0 if the access is accepted, or non zero if it is refused.

So the original code

	#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
		if (flag & H_FORCE)
			return 0;
	#endif

was correct, it returns 0 (accepts the modification) if forced UNLESS IGNORE_FORCE is set (in which case access checks in the following code are applied). The broken patch just added a printf to the force accepted case.

To obtain the intent of the patch we need this:

	if (flag & H_FORCE) {
	#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
		printf("## Error: Can't force access to \"%s\"\n", name);
	#else
		return 0;
	#endif
	}
Fixes 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set")
---
   env/flags.c | 5 +++--
   1 file changed, 3 insertions(+), 2 deletions(-)
env/flags.c +0 -0
index df4aed2..e3e833c 100644

env/flags.c int env_flags_validate(const struct env_entry *item, const char *newval, · line 570

Quoted 10 lines
env/flags.c +2 -2
@@ -563,12 +563,13 @@ int env_flags_validate(const struct env_entry *item, const char *newval,
   		return 1;
   #endif
-#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
   	if (flag & H_FORCE) {
+#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
   		printf("## Error: Can't force access to \"%s\"\n", name);
+#else
   		return 0;
-	}
   #endif

Based on env/Kconfig description of this option:

config ENV_ACCESS_IGNORE_FORCE
bool "Block forced environment operations"
default n
help
If defined, don't allow the -f switch to env set override variable access flags.

I would think the code should look like this:

#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
         if (flag & H_FORCE) {
                 printf("## Error: Can't force access to \"%s\"\n", name);
                 return 1;
         }
Quoted 4 lines

#else
if (flag & H_FORCE)
return 0;
#endif

Quoted 5 lines

So, prior to 0f036bf4b87e we had what you're suggesting, and that lead to 8a5cdf601f8d (which is the commit I was trying to think of) which Heinrich did not like, but was what was needed to get things to function again. Wouldn't what you're proposing break the use case you had in the first place?

No, the idea is to completely block the -f flag if CONFIG_ENV_ACCESS_IGNORE_FORCE is set from setting anything in the environment. That's how I understand the Kconfig entry help text.

#8 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

Quoted 81 lines · Marek Vasut
Quoted 74 lines · Tom Rini
Quoted 68 lines · Marek Vasut
Quoted 40 lines · Martin Fuzzey

Since commit 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set") a warning message is displayed when setenv -f is used WITHOUT CONFIG_ENV_ACCESS_IGNORE_FORCE, but the variable is set anyway, resulting in lots of log pollution.

env_flags_validate() returns 0 if the access is accepted, or non zero if it is refused.

So the original code

	#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
		if (flag & H_FORCE)
			return 0;
	#endif

was correct, it returns 0 (accepts the modification) if forced UNLESS IGNORE_FORCE is set (in which case access checks in the following code are applied). The broken patch just added a printf to the force accepted case.

To obtain the intent of the patch we need this:

	if (flag & H_FORCE) {
	#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
		printf("## Error: Can't force access to \"%s\"\n", name);
	#else
		return 0;
	#endif
	}
Fixes 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set")
---
   env/flags.c | 5 +++--
   1 file changed, 3 insertions(+), 2 deletions(-)
env/flags.c +0 -0
index df4aed2..e3e833c 100644

env/flags.c int env_flags_validate(const struct env_entry *item, const char *newval, · line 570

Quoted 10 lines
env/flags.c +2 -2
@@ -563,12 +563,13 @@ int env_flags_validate(const struct env_entry *item, const char *newval,
   		return 1;
   #endif
-#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
   	if (flag & H_FORCE) {
+#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
   		printf("## Error: Can't force access to \"%s\"\n", name);
+#else
   		return 0;
-	}
   #endif

Based on env/Kconfig description of this option:

config ENV_ACCESS_IGNORE_FORCE
bool "Block forced environment operations"
default n
help
If defined, don't allow the -f switch to env set override variable access flags.

I would think the code should look like this:

#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
         if (flag & H_FORCE) {
                 printf("## Error: Can't force access to \"%s\"\n", name);
                 return 1;
         }
Quoted 4 lines

#else
if (flag & H_FORCE)
return 0;
#endif

Quoted 5 lines

So, prior to 0f036bf4b87e we had what you're suggesting, and that lead to 8a5cdf601f8d (which is the commit I was trying to think of) which Heinrich did not like, but was what was needed to get things to function again. Wouldn't what you're proposing break the use case you had in the first place?

Quoted 3 lines

No, the idea is to completely block the -f flag if CONFIG_ENV_ACCESS_IGNORE_FORCE is set from setting anything in the environment. That's how I understand the Kconfig entry help text.

So was this all a "by inspection" bug then and not something you ran in to in use? I'm a bit worried that "how it's implemented" is relied upon more than "how it's documented in the help", esp since the former is probably older than the latter.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210201/a4b49527/attachment.sig>
#9 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

Quoted 82 lines · Tom Rini
Quoted 81 lines · Marek Vasut
Quoted 79 lines · Tom Rini
Quoted 68 lines · Marek Vasut
Quoted 40 lines · Martin Fuzzey

Since commit 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set") a warning message is displayed when setenv -f is used WITHOUT CONFIG_ENV_ACCESS_IGNORE_FORCE, but the variable is set anyway, resulting in lots of log pollution.

env_flags_validate() returns 0 if the access is accepted, or non zero if it is refused.

So the original code

	#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
		if (flag & H_FORCE)
			return 0;
	#endif

was correct, it returns 0 (accepts the modification) if forced UNLESS IGNORE_FORCE is set (in which case access checks in the following code are applied). The broken patch just added a printf to the force accepted case.

To obtain the intent of the patch we need this:

	if (flag & H_FORCE) {
	#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
		printf("## Error: Can't force access to \"%s\"\n", name);
	#else
		return 0;
	#endif
	}
Fixes 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set")
---
    env/flags.c | 5 +++--
    1 file changed, 3 insertions(+), 2 deletions(-)
env/flags.c +0 -0
index df4aed2..e3e833c 100644

env/flags.c int env_flags_validate(const struct env_entry *item, const char *newval, · line 570

Quoted 10 lines
env/flags.c +2 -2
@@ -563,12 +563,13 @@ int env_flags_validate(const struct env_entry *item, const char *newval,
    		return 1;
    #endif
-#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
    	if (flag & H_FORCE) {
+#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
    		printf("## Error: Can't force access to \"%s\"\n", name);
+#else
    		return 0;
-	}
    #endif

Based on env/Kconfig description of this option:

config ENV_ACCESS_IGNORE_FORCE
bool "Block forced environment operations"
default n
help
If defined, don't allow the -f switch to env set override variable access flags.

I would think the code should look like this:

#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
          if (flag & H_FORCE) {
                  printf("## Error: Can't force access to \"%s\"\n", name);
                  return 1;
          }
Quoted 4 lines

#else
if (flag & H_FORCE)
return 0;
#endif

So, prior to 0f036bf4b87e we had what you're suggesting, and that lead to 8a5cdf601f8d (which is the commit I was trying to think of) which Heinrich did not like, but was what was needed to get things to function again. Wouldn't what you're proposing break the use case you had in the first place?

Quoted 8 lines
Quoted 3 lines

No, the idea is to completely block the -f flag if CONFIG_ENV_ACCESS_IGNORE_FORCE is set from setting anything in the environment. That's how I understand the Kconfig entry help text.

So was this all a "by inspection" bug then and not something you ran in to in use? I'm a bit worried that "how it's implemented" is relied upon more than "how it's documented in the help", esp since the former is probably older than the latter.

The usecase of the writeable list is to completely block the -f flag. Maybe some further cleanup of the env config options is required, because it is poorly documented it seems.

#10 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

In reply to Marek Vasut

Hi Marek,

Quoted 18 lines · Marek Vasut

Based on env/Kconfig description of this option:

config ENV_ACCESS_IGNORE_FORCE
bool "Block forced environment operations" default n
help
If defined, don't allow the -f switch to env set override
variable
access flags.

I would think the code should look like this:

#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
         if (flag & H_FORCE) {
                 printf("## Error: Can't force access to \"%s\"\n", name);
                 return 1;
         }
Quoted 4 lines

#else
if (flag & H_FORCE)
return 0;
#endif

I don't think that is right.

If you do that force update will be refused when CONFIG_ENV_ACCESS_IGNORE_FORCE, regardless if the access would be valid without the force

The kconfig options says don't allow the -f switch to OVERRIDE variable access flags, not "don't allow the -f switch to be used"

I think we want this truth table

-f used ENV_ACCESS_IGNORE _FORCE Access valid ====> result
N X
N refused
N X
Y accepted
Y N
Y accepted
Y N
N accepted (forced)
Y Y
Y accepted
Y Y
N refused with warning

Regards,

Martin

Signature · 5 lines
Martin Fuzzey | Software Architect
Transport Intelligence Division
Parc La Fayette - 6 rue Isaac Newton | Besan?on | 25075 | FR
Office: +33381546880 Mobile: +33677158582
martin.fuzzey at flowbird.group | www.flowbird.group/transport
#11 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

Quoted 1 line · Martin

Hi Marek,

Hi,

Quoted 24 lines · Marek Vasut
Quoted 18 lines

Based on env/Kconfig description of this option:

config ENV_ACCESS_IGNORE_FORCE
bool "Block forced environment operations" default n
help
If defined, don't allow the -f switch to env set override
variable
access flags.

I would think the code should look like this:

#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
          if (flag & H_FORCE) {
                  printf("## Error: Can't force access to \"%s\"\n", name);
                  return 1;
          }
Quoted 4 lines

#else
if (flag & H_FORCE)
return 0;
#endif

Quoted 5 lines

I don't think that is right.

If you do that force update will be refused when CONFIG_ENV_ACCESS_IGNORE_FORCE, regardless if the access would be valid without the force

That's how I understand the option was intended to work, based on the Kconfig help text.

Quoted 2 lines

The kconfig options says don't allow the -f switch to OVERRIDE variable access flags, not "don't allow the -f switch to be used"

I suspect the help text needs clarification then.

#12 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

Quoted 30 lines · Marek Vasut
Quoted 1 line · Martin

Hi Marek,

Hi,

Quoted 24 lines · Marek Vasut
Quoted 22 lines

Based on env/Kconfig description of this option:

config ENV_ACCESS_IGNORE_FORCE
bool "Block forced environment operations" default n
help
If defined, don't allow the -f switch to env set override
variable
access flags.

I would think the code should look like this:

#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
          if (flag & H_FORCE) {
                  printf("## Error: Can't force access to \"%s\"\n", name);
                  return 1;
          }

#else
if (flag & H_FORCE)
return 0;
#endif

Quoted 9 lines
Quoted 5 lines

I don't think that is right.

If you do that force update will be refused when CONFIG_ENV_ACCESS_IGNORE_FORCE, regardless if the access would be valid without the force

That's how I understand the option was intended to work, based on the Kconfig help text.

Ok we are understanding different things about what it's supposed to do then.

But if everyone agrees that the option should completely disable -f then I'm fine with that, in which case the version of the patch you propose is good (and easier to understand).

The problem I have is with the current 0f036bf4b87e which leads to log spam on boards that *don't* have CONFIG_ENV_ACCESS_IGNORE_FORCE set and do use -f.

Quoted 4 lines
Quoted 2 lines

The kconfig options says don't allow the -f switch to OVERRIDE variable access flags, not "don't allow the -f switch to be used"

I suspect the help text needs clarification then.

Agreed

Martin

#13 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

Quoted 43 lines · Martin
Quoted 30 lines · Marek Vasut
Quoted 1 line · Martin

Hi Marek,

Hi,

Quoted 24 lines · Marek Vasut
Quoted 22 lines

Based on env/Kconfig description of this option:

config ENV_ACCESS_IGNORE_FORCE
bool "Block forced environment operations" default n
help
If defined, don't allow the -f switch to env set override
variable
access flags.

I would think the code should look like this:

#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
           if (flag & H_FORCE) {
                   printf("## Error: Can't force access to \"%s\"\n", name);
                   return 1;
           }

#else
if (flag & H_FORCE)
return 0;
#endif

Quoted 9 lines
Quoted 5 lines

I don't think that is right.

If you do that force update will be refused when CONFIG_ENV_ACCESS_IGNORE_FORCE, regardless if the access would be valid without the force

That's how I understand the option was intended to work, based on the Kconfig help text.

Ok we are understanding different things about what it's supposed to do then.

Quoted 7 lines

But if everyone agrees that the option should completely disable -f then I'm fine with that, in which case the version of the patch you propose is good (and easier to understand).

The problem I have is with the current 0f036bf4b87e which leads to log spam on boards that *don't* have CONFIG_ENV_ACCESS_IGNORE_FORCE set and do use -f.

Yes, that should be fixed, one way or the other. (in fact, can you also write a test for this case ?)

#14 lore raw

PATCH 1/1 env: Fix warning when forcing environment without ENV_ACCESS_IGNORE_FORCE

In reply to Martin Fuzzey
Quoted 28 lines · Martin Fuzzey

Since commit 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set") a warning message is displayed when setenv -f is used WITHOUT CONFIG_ENV_ACCESS_IGNORE_FORCE, but the variable is set anyway, resulting in lots of log pollution.

env_flags_validate() returns 0 if the access is accepted, or non zero if it is refused.

So the original code

	#ifndef CONFIG_ENV_ACCESS_IGNORE_FORCE
		if (flag & H_FORCE)
			return 0;
	#endif

was correct, it returns 0 (accepts the modification) if forced UNLESS IGNORE_FORCE is set (in which case access checks in the following code are applied). The broken patch just added a printf to the force accepted case.

To obtain the intent of the patch we need this:

	if (flag & H_FORCE) {
	#ifdef CONFIG_ENV_ACCESS_IGNORE_FORCE
		printf("## Error: Can't force access to \"%s\"\n", name);
	#else
		return 0;
	#endif
	}
Quoted 3 lines
Fixes 0f036bf4b87e ("env: Warn on force access if ENV_ACCESS_IGNORE_FORCE set")

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210418/9f8bc0d5/attachment.sig>