All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] module: fix signature check failures when using in-kernel decompression
@ 2022-01-14  0:51 Dmitry Torokhov
  2022-01-14 16:12 ` Doug Anderson
  2022-01-14 17:43 ` Luis Chamberlain
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2022-01-14  0:51 UTC (permalink / raw)
  To: Luis Chamberlain; +Cc: Jessica Yu, linux-kernel

The new flag MODULE_INIT_COMPRESSED_FILE unintentionally trips check in
module_sig_check(). The check was supposed to catch case when version
info or magic was removed from a signed module, making signature
invalid, but it was coded too broadly and was catching this new flag as
well.

Change the check to only test the 2 particular flags affecting signature
validity.

Fixes: b1ae6dc41eaa ("module: add in-kernel support for decompressing")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 kernel/module.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 201398d58079..24dab046e16c 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2883,12 +2883,13 @@ static int module_sig_check(struct load_info *info, int flags)
 	const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
 	const char *reason;
 	const void *mod = info->hdr;
-
+	bool mangled_module = flags & (MODULE_INIT_IGNORE_MODVERSIONS |
+				       MODULE_INIT_IGNORE_VERMAGIC);
 	/*
-	 * Require flags == 0, as a module with version information
-	 * removed is no longer the module that was signed
+	 * Do not allow mangled modules as a module with version information
+	 * removed is no longer the module that was signed.
 	 */
-	if (flags == 0 &&
+	if (!mangled_module &&
 	    info->len > markerlen &&
 	    memcmp(mod + info->len - markerlen, MODULE_SIG_STRING, markerlen) == 0) {
 		/* We truncate the module to discard the signature */
-- 
2.34.1.703.g22d0c6ccf7-goog


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] module: fix signature check failures when using in-kernel decompression
  2022-01-14  0:51 [PATCH] module: fix signature check failures when using in-kernel decompression Dmitry Torokhov
@ 2022-01-14 16:12 ` Doug Anderson
  2022-01-14 17:43 ` Luis Chamberlain
  1 sibling, 0 replies; 3+ messages in thread
From: Doug Anderson @ 2022-01-14 16:12 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Luis Chamberlain, Jessica Yu, LKML

Hi,

On Thu, Jan 13, 2022 at 4:52 PM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
> The new flag MODULE_INIT_COMPRESSED_FILE unintentionally trips check in
> module_sig_check(). The check was supposed to catch case when version
> info or magic was removed from a signed module, making signature
> invalid, but it was coded too broadly and was catching this new flag as
> well.
>
> Change the check to only test the 2 particular flags affecting signature
> validity.
>
> Fixes: b1ae6dc41eaa ("module: add in-kernel support for decompressing")
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  kernel/module.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/module.c b/kernel/module.c
> index 201398d58079..24dab046e16c 100644
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -2883,12 +2883,13 @@ static int module_sig_check(struct load_info *info, int flags)
>         const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
>         const char *reason;
>         const void *mod = info->hdr;
> -
> +       bool mangled_module = flags & (MODULE_INIT_IGNORE_MODVERSIONS |
> +                                      MODULE_INIT_IGNORE_VERMAGIC);
>         /*
> -        * Require flags == 0, as a module with version information
> -        * removed is no longer the module that was signed
> +        * Do not allow mangled modules as a module with version information
> +        * removed is no longer the module that was signed.
>          */
> -       if (flags == 0 &&
> +       if (!mangled_module &&

Seems reasonable to me. I guess the only question in my mind is
whether this is the best way to handle "unknown" new flags. If someone
introduces a new flag to "uapi/linux/module.h" should we consider it
as "mangled" or not? Given that I can't predict the future and the
comments seem to indicate that we're only trying to detect
version-related issues, your choice seems OK to me.

Reviewed-by: Douglas Anderson <dianders@chromium.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] module: fix signature check failures when using in-kernel decompression
  2022-01-14  0:51 [PATCH] module: fix signature check failures when using in-kernel decompression Dmitry Torokhov
  2022-01-14 16:12 ` Doug Anderson
@ 2022-01-14 17:43 ` Luis Chamberlain
  1 sibling, 0 replies; 3+ messages in thread
From: Luis Chamberlain @ 2022-01-14 17:43 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Jessica Yu, linux-kernel

On Thu, Jan 13, 2022 at 04:51:52PM -0800, Dmitry Torokhov wrote:
> The new flag MODULE_INIT_COMPRESSED_FILE unintentionally trips check in
> module_sig_check(). The check was supposed to catch case when version
> info or magic was removed from a signed module, making signature
> invalid, but it was coded too broadly and was catching this new flag as
> well.
> 
> Change the check to only test the 2 particular flags affecting signature
> validity.
> 
> Fixes: b1ae6dc41eaa ("module: add in-kernel support for decompressing")
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Queued on to modules-next.

  Luis

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-14 17:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-14  0:51 [PATCH] module: fix signature check failures when using in-kernel decompression Dmitry Torokhov
2022-01-14 16:12 ` Doug Anderson
2022-01-14 17:43 ` Luis Chamberlain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.