module: avoid *goto*s in module_sig_check()
authorSergey Shtylyov <s.shtylyov@omprussia.ru>
Sat, 31 Oct 2020 20:09:31 +0000 (23:09 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 7 Apr 2021 12:47:38 +0000 (14:47 +0200)
[ Upstream commit 10ccd1abb808599a6dc7c9389560016ea3568085 ]

Let's move the common handling of the non-fatal errors after the *switch*
statement -- this avoids *goto*s inside that *switch*...

Suggested-by: Joe Perches <joe@perches.com>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Sergey Shtylyov <s.shtylyov@omprussia.ru>
Signed-off-by: Jessica Yu <jeyu@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/module.c

index 9fe3e9b85348f0f42b9286f64dba3a85ed4c9321..8d1def62a415cd0bbc97e64bd2a408c5efb136fd 100644 (file)
@@ -2909,20 +2909,13 @@ static int module_sig_check(struct load_info *info, int flags)
                 */
        case -ENODATA:
                reason = "unsigned module";
-               goto decide;
+               break;
        case -ENOPKG:
                reason = "module with unsupported crypto";
-               goto decide;
+               break;
        case -ENOKEY:
                reason = "module with unavailable key";
-       decide:
-               if (is_module_sig_enforced()) {
-                       pr_notice("%s: loading of %s is rejected\n",
-                                 info->name, reason);
-                       return -EKEYREJECTED;
-               }
-
-               return security_locked_down(LOCKDOWN_MODULE_SIGNATURE);
+               break;
 
                /* All other errors are fatal, including nomem, unparseable
                 * signatures and signature check failures - even if signatures
@@ -2931,6 +2924,13 @@ static int module_sig_check(struct load_info *info, int flags)
        default:
                return err;
        }
+
+       if (is_module_sig_enforced()) {
+               pr_notice("%s: loading of %s is rejected\n", info->name, reason);
+               return -EKEYREJECTED;
+       }
+
+       return security_locked_down(LOCKDOWN_MODULE_SIGNATURE);
 }
 #else /* !CONFIG_MODULE_SIG */
 static int module_sig_check(struct load_info *info, int flags)