Skip to contentSkip to conversation

EVM: fix the evm= __setup handler return value

PATCH In review Randy Dunlap 2 participants 2 messages Feb 22, 2022 – Feb 23, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 EVM: fix the evm= __setup handler return value

__setup() handlers should return 1 if the parameter is handled. Returning 0 causes the entire string to be added to init's environment strings (limited to 32 strings), unnecessarily polluting it.

Using the documented string "evm=fix" causes an Unknown parameter message:
Unknown kernel command line parameters "BOOT_IMAGE=/boot/bzImage-517rc5 evm=fix", will be passed to user space.

and that string is added to init's environment string space:
Run /sbin/init as init process

    with arguments:
     /sbin/init
    with environment:
     HOME=/
     TERM=linux
     BOOT_IMAGE=/boot/bzImage-517rc5
     evm=fix

With this change, using "evm=fix" acts as expected and an invalid option ("evm=evm") causes a warning to be printed:
evm: invalid "evm" mode
but init's environment is not polluted with this string, as expected.

Fixes 7102ebcd65c1 ("evm: permit only valid security.evm xattrs to be updated")
Link lore.kernel.org/r/[email protected]
Cc Mimi Zohar <[email protected]>
Cc James Morris <[email protected]>
Cc "Serge E. Hallyn" <[email protected]>
---
 security/integrity/evm/evm_main.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/integrity/evm/evm_main.c +1 -1
@@ -86,7 +86,7 @@ static int __init evm_set_fixmode(char *
 	else
 		pr_err("invalid \"%s\" mode", str);
 
-	return 0;
+	return 1;
 }
 __setup("evm=", evm_set_fixmode);
 
maintainer
#1 lore raw
Quoted 23 lines · Randy Dunlap

__setup() handlers should return 1 if the parameter is handled. Returning 0 causes the entire string to be added to init's environment strings (limited to 32 strings), unnecessarily polluting it.

Using the documented string "evm=fix" causes an Unknown parameter message:
Unknown kernel command line parameters "BOOT_IMAGE=/boot/bzImage-517rc5 evm=fix", will be passed to user space.

and that string is added to init's environment string space:
Run /sbin/init as init process

    with arguments:
     /sbin/init
    with environment:
     HOME=/
     TERM=linux
     BOOT_IMAGE=/boot/bzImage-517rc5
     evm=fix

With this change, using "evm=fix" acts as expected and an invalid option ("evm=evm") causes a warning to be printed:
evm: invalid "evm" mode
but init's environment is not polluted with this string, as expected.

Quoted 4 lines
Fixes 7102ebcd65c1 ("evm: permit only valid security.evm xattrs to be updated")
Link lore.kernel.org/r/[email protected]

Thanks, Randy, Igor.

The patch is queued in #next-integrity-testing.

Mimi