All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lucas De Marchi <lucas.demarchi@intel.com>
To: <emil.l.velikov@gmail.com>
Cc: <linux-modules@vger.kernel.org>
Subject: Re: [PATCH kmod 06/13] libkmod: propagate {zstd,xz,zlib}_load errors
Date: Mon, 29 Apr 2024 18:14:39 -0500	[thread overview]
Message-ID: <qhghzwotzcjmzlxfgbpyfgq7tk2mw3bfe3bzgfauk4n4gjyyg5@3s5oiwhcqym5> (raw)
In-Reply-To: <20240212-decompression-fixes-v1-6-06f92ad07985@gmail.com>

On Mon, Feb 12, 2024 at 05:23:07PM GMT, Emil Velikov via B4 Relay wrote:
>From: Emil Velikov <emil.l.velikov@gmail.com>
>
>Propagate any errors during decompression further up the call stack.
>Without this we could easily pass NULL as mem to init_module(2).
>
>Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>


Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>

thanks
Lucas De Marchi

>---
> libkmod/libkmod-file.c     | 15 +++++++++++----
> libkmod/libkmod-internal.h |  2 +-
> libkmod/libkmod-module.c   |  4 +++-
> 3 files changed, 15 insertions(+), 6 deletions(-)
>
>diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c
>index 8a0336f..3a79464 100644
>--- a/libkmod/libkmod-file.c
>+++ b/libkmod/libkmod-file.c
>@@ -381,10 +381,17 @@ static int load_reg(struct kmod_file *file)
>
> struct kmod_elf *kmod_file_get_elf(struct kmod_file *file)
> {
>+	int err;
>+
> 	if (file->elf)
> 		return file->elf;
>
>-	kmod_file_load_contents(file);
>+	err = kmod_file_load_contents(file);
>+	if (err) {
>+		errno = err;
>+		return NULL;
>+	}
>+
> 	file->elf = kmod_elf_new(file->memory, file->size);
> 	return file->elf;
> }
>@@ -460,13 +467,13 @@ error:
> /*
>  *  Callers should just check file->memory got updated
>  */
>-void kmod_file_load_contents(struct kmod_file *file)
>+int kmod_file_load_contents(struct kmod_file *file)
> {
> 	if (file->memory)
>-		return;
>+		return 0;
>
> 	/*  The load functions already log possible errors. */
>-	file->load(file);
>+	return file->load(file);
> }
>
> void *kmod_file_get_contents(const struct kmod_file *file)
>diff --git a/libkmod/libkmod-internal.h b/libkmod/libkmod-internal.h
>index 26a7e28..3bc6e11 100644
>--- a/libkmod/libkmod-internal.h
>+++ b/libkmod/libkmod-internal.h
>@@ -160,7 +160,7 @@ bool kmod_module_is_builtin(struct kmod_module *mod) __attribute__((nonnull(1)))
> /* libkmod-file.c */
> struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename) _must_check_ __attribute__((nonnull(1,2)));
> struct kmod_elf *kmod_file_get_elf(struct kmod_file *file) __attribute__((nonnull(1)));
>-void kmod_file_load_contents(struct kmod_file *file) __attribute__((nonnull(1)));
>+int kmod_file_load_contents(struct kmod_file *file) __attribute__((nonnull(1)));
> void *kmod_file_get_contents(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1)));
> off_t kmod_file_get_size(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1)));
> enum kmod_file_compression_type kmod_file_get_compression(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1)));
>diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
>index 585da41..1e43482 100644
>--- a/libkmod/libkmod-module.c
>+++ b/libkmod/libkmod-module.c
>@@ -903,7 +903,9 @@ static int do_init_module(struct kmod_module *mod, unsigned int flags,
> 	off_t size;
> 	int err;
>
>-	kmod_file_load_contents(mod->file);
>+	err = kmod_file_load_contents(mod->file);
>+	if (err)
>+		return err;
>
> 	if (flags & (KMOD_INSERT_FORCE_VERMAGIC | KMOD_INSERT_FORCE_MODVERSION)) {
> 		elf = kmod_file_get_elf(mod->file);
>
>-- 
>2.43.0
>

  reply	other threads:[~2024-04-29 23:14 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-12 17:23 [PATCH kmod 00/13] Load compressed modules with compression-less kmod Emil Velikov via B4 Relay
2024-02-12 17:23 ` Emil Velikov
2024-02-12 17:23 ` [PATCH kmod 01/13] libkmod: use a dup()'d fd for zlib Emil Velikov via B4 Relay
2024-02-12 17:23   ` Emil Velikov
2024-04-29 23:13   ` Lucas De Marchi
2024-02-12 17:23 ` [PATCH kmod 02/13] libkmod: keep gzFile gzf local to load_zlib() Emil Velikov via B4 Relay
2024-02-12 17:23   ` Emil Velikov
2024-04-29 21:52   ` Lucas De Marchi
2024-02-12 17:23 ` [PATCH kmod 03/13] libkmod: remove kmod_file::{zstd,xz}_used flags Emil Velikov via B4 Relay
2024-02-12 17:23   ` Emil Velikov
2024-04-29 21:54   ` Lucas De Marchi
2024-02-12 17:23 ` [PATCH kmod 04/13] libkmod: clear file->memory if map fails Emil Velikov via B4 Relay
2024-02-12 17:23   ` Emil Velikov
2024-04-29 23:13   ` Lucas De Marchi
2024-02-12 17:23 ` [PATCH kmod 05/13] libkmod: nuke struct file_ops Emil Velikov via B4 Relay
2024-02-12 17:23   ` Emil Velikov
2024-04-29 23:13   ` Lucas De Marchi
2024-02-12 17:23 ` [PATCH kmod 06/13] libkmod: propagate {zstd,xz,zlib}_load errors Emil Velikov via B4 Relay
2024-02-12 17:23   ` Emil Velikov
2024-04-29 23:14   ` Lucas De Marchi [this message]
2024-02-12 17:23 ` [PATCH kmod 07/13] libkmod: move kmod_file_load_contents as applicable Emil Velikov via B4 Relay
2024-02-12 17:23   ` Emil Velikov
2024-04-29 23:14   ` Lucas De Marchi
2024-02-12 17:23 ` [PATCH kmod 08/13] libkmod: always detect the module compression Emil Velikov via B4 Relay
2024-02-12 17:23   ` Emil Velikov
2024-02-13 16:33   ` Emil Velikov
2024-04-29 23:13   ` Lucas De Marchi
2024-02-12 17:23 ` [PATCH kmod 09/13] libkmod: swap alloca usage for a few assert_cc Emil Velikov via B4 Relay
2024-02-12 17:23   ` Emil Velikov
2024-04-29 23:19   ` Lucas De Marchi
2024-04-30 17:39   ` Lucas De Marchi
2024-04-30 17:54     ` Emil Velikov
2024-04-30 18:17       ` Lucas De Marchi
2024-04-30 18:27         ` Emil Velikov
2024-04-30 18:43           ` Lucas De Marchi
2024-04-30 18:47             ` Emil Velikov
2024-04-30 20:36               ` Lucas De Marchi
2024-02-12 17:23 ` [PATCH kmod 10/13] libkmod: tidy-up kmod_file_open() Emil Velikov via B4 Relay
2024-02-12 17:23   ` Emil Velikov
2024-04-29 23:25   ` Lucas De Marchi
2024-02-12 17:23 ` [PATCH kmod 11/13] libkmod: move load_reg() further up Emil Velikov via B4 Relay
2024-02-12 17:23   ` Emil Velikov
2024-04-29 23:30   ` Lucas De Marchi
2024-02-12 17:23 ` [PATCH kmod 12/13] libkmod: keep KMOD_FILE_COMPRESSION_NONE/load_reg in comp_types Emil Velikov via B4 Relay
2024-02-12 17:23   ` Emil Velikov
2024-04-29 23:32   ` Lucas De Marchi
2024-02-12 17:23 ` [PATCH kmod 13/13] libkmod: always fallback to do_init_module() Emil Velikov via B4 Relay
2024-02-12 17:23   ` Emil Velikov
2024-04-29 23:39   ` Lucas De Marchi
2024-04-30 17:48     ` Emil Velikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=qhghzwotzcjmzlxfgbpyfgq7tk2mw3bfe3bzgfauk4n4gjyyg5@3s5oiwhcqym5 \
    --to=lucas.demarchi@intel.com \
    --cc=emil.l.velikov@gmail.com \
    --cc=linux-modules@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.