From patchwork Mon Feb 12 17:23:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13553772 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 063693EA83 for ; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; cv=none; b=URD4G09FDrYmZ1qE5JVvVl2E/pw8VwqhQ8vs2wmugsbAc0IH0InsJR+DmgVwfWKA1tb93V+GQjo9TjnX0M5okTlYfe1jixY0WEfVSfoQfaALkArN/pyPNyBHZDd7DoenbYjqIiDg+jFoeWwAn9IcaiWenq03oV0eEmeG3uqBXR0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; c=relaxed/simple; bh=Y4L/om0NPArWtsOGcRdMiUyMpIqcXqeEZjnUGy6q+70=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tcTCGE4Pd+TpPEcaBCZVK8geK1I7QpgdGdtcY7MuDxu8Vylwv5rsx70x5DBeU2/I8ZRMvq055LizkUa1H3fU47Uido7UrtEF4ncXd2ZvT7OKfPsmwwZqf+kPjhL26amidyE+WAWFg9ll9F+LbFGNL0EdtPXn+0fp4JP3htfaATU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rvfsOAFj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rvfsOAFj" Received: by smtp.kernel.org (Postfix) with ESMTPS id 9E3A1C43399; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707758585; bh=Y4L/om0NPArWtsOGcRdMiUyMpIqcXqeEZjnUGy6q+70=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rvfsOAFj8Y8cccWw5Z6ndXyci1JrBln6Idd5RWCVvc+TRQLmqlrEia0h07CjCQPK0 4LmPsfVukYuKfBz5SHdlNZfYdEfYfoABPblLNTV6+gxNGjWnQQc/l0tm8cq2ngHwBH VL0tcVMY9fuCPd5OZjBFryFOe65xOsAkSsQBulrUs/NDrxKSaUWINBdB9K1C11Iijl fAHEykBvLRTpH+p2Qil7NyUpp2i94B2dh+C0anahyCKEqSvlH4jV5poLaXjEZUGtoD UfzdDmxr1ssW5UYjIxl1AM9eS5cGwUY3p/fMeoDdePGkLkkG7d4CeZiwwefGp3kzWw iIVv69RefUrKA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84F90C48BC0; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 12 Feb 2024 17:23:02 +0000 Subject: [PATCH kmod 01/13] libkmod: use a dup()'d fd for zlib Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-decompression-fixes-v1-1-06f92ad07985@gmail.com> References: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> In-Reply-To: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> To: linux-modules@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707758583; l=1845; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=snuU8CYNYYFir4PHCqEikR5PrKmafS0jh0cCrGpEUuM=; b=A/1wI8pVP1bQlACvosmS2wNa1xBBVLNlKwBUCiOpgOtLSjrsJz8Nr6LUXy8LzXPKGfyCybfd1 8iki4PVtcToDyhlELSQlynjr6lOEQoDlR47N2zPai316QqMjLV25iXJ X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov The gzdopen() API used, takes ownership of the fd. To make that more explicit we clear it (-1) as applicable. Yet again, kmod has explicit API to return the fd to the user - which currently is used solely when uncompressed, so we're safe. Regardless - simply duplicate the fd locally and use that with zlib. Signed-off-by: Emil Velikov Reviewed-by: Lucas De Marchi --- libkmod/libkmod-file.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index b138e7e..b97062b 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -317,12 +317,18 @@ static int load_zlib(struct kmod_file *file) int err = 0; off_t did = 0, total = 0; _cleanup_free_ unsigned char *p = NULL; + int gzfd; errno = 0; - file->gzf = gzdopen(file->fd, "rb"); - if (file->gzf == NULL) + gzfd = fcntl(file->fd, F_DUPFD_CLOEXEC, 3); + if (gzfd < 0) + return -errno; + + file->gzf = gzdopen(gzfd, "rb"); /* takes ownership of the fd */ + if (file->gzf == NULL) { + close(gzfd); return -errno; - file->fd = -1; /* now owned by gzf due gzdopen() */ + } for (;;) { int r; @@ -359,7 +365,7 @@ static int load_zlib(struct kmod_file *file) return 0; error: - gzclose(file->gzf); + gzclose(file->gzf); /* closes the gzfd */ return err; } @@ -368,7 +374,7 @@ static void unload_zlib(struct kmod_file *file) if (file->gzf == NULL) return; free(file->memory); - gzclose(file->gzf); /* closes file->fd */ + gzclose(file->gzf); } static const char magic_zlib[] = {0x1f, 0x8b}; @@ -535,7 +541,6 @@ void kmod_file_unref(struct kmod_file *file) if (file->memory) file->ops->unload(file); - if (file->fd >= 0) - close(file->fd); + close(file->fd); free(file); } From patchwork Mon Feb 12 17:23:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13553773 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C5633D978 for ; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; cv=none; b=Ry4c07Cq6U9Sun2unKBV1sjZY/KPIiHHld159n6sUUnTmyW1G/0sOmn3CHUOVz/rZsNsnE9fo/p/tJL70Y8NixbiZ3jnuaGOVncoSCawYhRC+aW02xp4+/AJxGAB6Gj9Irq2+fSap7C0BFhX+5hA/wVSgcjTpqQRDALfwH4+OGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; c=relaxed/simple; bh=OSn12E7RuIDFHVDzki3PcAWWT9S6I3+PV7ShqzZOkAE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nSydjBb6DGp2TSxlJva46TqlqSmxxbMy3RyV3XOgk9cHTrTyJv7oEbFevQK+coRlEMwKqhht8o8fqML6fwmUe477h9oFABlE08YRJ/ALdINZSKskQlJAZXJAQHqU0ddUcX/3fNnYsHPWnXCa3Pt17r7lrW5T8b/WkMU1mQYz1lw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H0ndWNwy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H0ndWNwy" Received: by smtp.kernel.org (Postfix) with ESMTPS id AE2EFC433F1; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707758585; bh=OSn12E7RuIDFHVDzki3PcAWWT9S6I3+PV7ShqzZOkAE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=H0ndWNwyLscroLZSwCJnwV6QWWBHS5kp3AMzzZMG9e4ypPfSQARnME6yVNaj2Tu21 4rxoL1XUZTKPs0SmNLt+VgOOw7ZA/J/scDklCpcI6+8BwVRy5h7UbR/QzfekZGn8uj qSQF0RQM2Ncp0xLYPDLw91JWSETq4BERtvR+izqVAJqWednP/4+9rtRiYGxxWkV5Z0 /4QlPUIhmsvCO8XC/qAJpw3pdK/Ige4n0NQV7X+H2GPGywkj68MK5kLUkwN8UTd6Qe qlO775nODKXFTCH5M5A9VB2u5fDw0kr+ExjaF7cZbcdpCcrBq0/uyNJQybrFE7fjLA 4JBESs0vOw2EA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94E4AC48297; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 12 Feb 2024 17:23:03 +0000 Subject: [PATCH kmod 02/13] libkmod: keep gzFile gzf local to load_zlib() Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-decompression-fixes-v1-2-06f92ad07985@gmail.com> References: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> In-Reply-To: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> To: linux-modules@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707758583; l=2092; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=dynpgl/ahQS0pC4J5FA730cbtaNUmwCDCWyHTxZtfko=; b=OnaUsbxYZ1j1uQmSCFipwGIFtNN8dmD0R7GfYhZHCJ6r1O5/r7Ky9N25ElRq+TF9mpNveY4dr yjzTTMwWFB4CPJeIKLtf5C+Kac7WAC5GaD+20bc0kU5EXgOGd02rQ9q X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov There is no need to keep the root gzFile context open for the whole duration. Once we've copied the decompressed module to file->memory we can close the handle. Signed-off-by: Emil Velikov Reviewed-by: Lucas De Marchi --- libkmod/libkmod-file.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index b97062b..9a014ea 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -53,9 +53,6 @@ struct kmod_file { #endif #ifdef ENABLE_XZ bool xz_used; -#endif -#ifdef ENABLE_ZLIB - gzFile gzf; #endif int fd; enum kmod_file_compression_type compression; @@ -317,6 +314,7 @@ static int load_zlib(struct kmod_file *file) int err = 0; off_t did = 0, total = 0; _cleanup_free_ unsigned char *p = NULL; + gzFile gzf; int gzfd; errno = 0; @@ -324,8 +322,8 @@ static int load_zlib(struct kmod_file *file) if (gzfd < 0) return -errno; - file->gzf = gzdopen(gzfd, "rb"); /* takes ownership of the fd */ - if (file->gzf == NULL) { + gzf = gzdopen(gzfd, "rb"); /* takes ownership of the fd */ + if (gzf == NULL) { close(gzfd); return -errno; } @@ -343,12 +341,12 @@ static int load_zlib(struct kmod_file *file) p = tmp; } - r = gzread(file->gzf, p + did, total - did); + r = gzread(gzf, p + did, total - did); if (r == 0) break; else if (r < 0) { int gzerr; - const char *gz_errmsg = gzerror(file->gzf, &gzerr); + const char *gz_errmsg = gzerror(gzf, &gzerr); ERR(file->ctx, "gzip: %s\n", gz_errmsg); @@ -362,19 +360,17 @@ static int load_zlib(struct kmod_file *file) file->memory = p; file->size = did; p = NULL; + gzclose(gzf); return 0; error: - gzclose(file->gzf); /* closes the gzfd */ + gzclose(gzf); /* closes the gzfd */ return err; } static void unload_zlib(struct kmod_file *file) { - if (file->gzf == NULL) - return; free(file->memory); - gzclose(file->gzf); } static const char magic_zlib[] = {0x1f, 0x8b}; From patchwork Mon Feb 12 17:23:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13553774 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 331543D984 for ; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; cv=none; b=Uvyma6ju3D2ZEGQbnOElNtJKVaMPFohM6OAYMIwQa6gfXBnAdE3jCeP1PCcSzZkKCBYYHnWdFzARDmtE0mywd0PId1jdb9rDelTnaXqOIlNoj/PLzIZF8Xxn5Jt//GIqJzPGXWMEhHi8mBAlbwZmLvC9xb65Ooip8scDdsGJQqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; c=relaxed/simple; bh=8/AVQ5SXvVfJfMOebZlieCFe0Uwf9pKNuUce6KoTrHI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JtJAdM1H2z3sUm95fLmJrrK1SBawJhk1cUCbwasMYWFfxVDzkzlI+r7aQemXfyAEXle1pKnVMJR7b7TMJ2W6zsfnJ/kNgvZxwMznBR5jGnaCC/YSPpPVpOSMXDjDI34emqelnauLyA9tp8b8KGciQaSqUqrHg0bsxRZccHVhn+Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IYNY1ILl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IYNY1ILl" Received: by smtp.kernel.org (Postfix) with ESMTPS id B6607C433A6; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707758585; bh=8/AVQ5SXvVfJfMOebZlieCFe0Uwf9pKNuUce6KoTrHI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=IYNY1ILljQlBaNKMCxW7q8fpPH/2t28T6tD0TNMPprwePcRGcqTC9KR4ezQHWpkZE OQPSZ2+paA8HkGBehZ3n8ZarlFh2w+kraTAvYESLD8NmMAhOOAslLvxH3oerCE4u/l 0+lEqOzCvIY2JD33I3HVKNGTkx5NqDlk6bXP+AFEQqcOEIBWGrgM43YHgRs70NukB/ B1R6zrACe3hYAs58BnCTlWAVUKQkWt7VeIRoblnsHFH5n4P93WEcB90qXo90yUw8XB YaA/fQGekVD3wMc4A9Vzs6o7No3jB1M7lRvNjxWhpYrXMTe6PbiyqfzK8FdmBYH8ye JFJ1jVN4zwyvA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A52A0C4829E; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 12 Feb 2024 17:23:04 +0000 Subject: [PATCH kmod 03/13] libkmod: remove kmod_file::{zstd,xz}_used flags Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-decompression-fixes-v1-3-06f92ad07985@gmail.com> References: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> In-Reply-To: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> To: linux-modules@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707758583; l=1540; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=Og0Ag/13F9A4cnAYBK+i+58A4Qix9B4oLZpytfwcabE=; b=aqf5N4FQGPUJAkW7v1M065AjQGCZxzI5UInNS0o3k8GazeKKfCR1OKQNJtmvKH6MCNDNBKR6K obDFm5x/S3+CxA9y7o9AY+DIA7ZDyuuIVZ9t12G1IGf5Ist8bvXzdWi X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov These are used to protect a free(file->memory), within their respective unload functions. Where the sole caller of the unload function already does a NULL check prior. Even so, free(NULL) is guaranteed to be safe by the standard. Signed-off-by: Emil Velikov Reviewed-by: Lucas De Marchi --- libkmod/libkmod-file.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index 9a014ea..abd4723 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -48,12 +48,6 @@ struct file_ops { }; struct kmod_file { -#ifdef ENABLE_ZSTD - bool zstd_used; -#endif -#ifdef ENABLE_XZ - bool xz_used; -#endif int fd; enum kmod_file_compression_type compression; off_t size; @@ -176,7 +170,6 @@ static int load_zstd(struct kmod_file *file) ZSTD_freeDStream(dstr); free((void *)zst_inb.src); - file->zstd_used = true; file->memory = zst_outb.dst; file->size = zst_outb.pos; return 0; @@ -190,8 +183,6 @@ out: static void unload_zstd(struct kmod_file *file) { - if (!file->zstd_used) - return; free(file->memory); } @@ -269,7 +260,6 @@ static int xz_uncompress(lzma_stream *strm, struct kmod_file *file) goto out; } } - file->xz_used = true; file->memory = p; file->size = total; return 0; @@ -299,8 +289,6 @@ static int load_xz(struct kmod_file *file) static void unload_xz(struct kmod_file *file) { - if (!file->xz_used) - return; free(file->memory); } From patchwork Mon Feb 12 17:23:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13553776 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B1903DB81 for ; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; cv=none; b=lQWUtN9j6hJxqSctlqq3Yrn6GW6qlDKpO3g6UvT0BdwQxMWjOL7P1Pt7uD7vPDVQ2M2N648XjmAqjahb6gYNPO1s8VTCQVr3aXU84uc9VJcyeDT3e912chg88rK2vKdqc9NyiyXrkEy2Qcn6TukjPxAHbzNk7xHUR6AypNZq4ds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; c=relaxed/simple; bh=asgG9/cLMuHUP3quTuOb+BojWCY1bbHQeraYWuEvABA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Eih7hOg88ClBqmFdi1VT3NkfgZRBs7ZLcm+txIxHuOQ+T2w050wul6qY/E6Qx+SOaNdjwMv6lguFCPJM2Ooechn9NDjUmWSEGNUZ+/UUh4h//FWsH/Wny5soSIf3cw8dFGr4TEuXI9I9Kkn5e8MBa3kbFxbUCOLt8CkiBz1XDBQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qnsmPjyJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qnsmPjyJ" Received: by smtp.kernel.org (Postfix) with ESMTPS id C3DB4C43330; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707758585; bh=asgG9/cLMuHUP3quTuOb+BojWCY1bbHQeraYWuEvABA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=qnsmPjyJ6aGXY4u6pC5MLqFzQ54RhcUFI7E/l8nzXMHbPtQubCruwqXyGsZSEdMup JVqO8mLKPbJKNGvEl8b7ElYo72FopGlaNYE8wLnKcMl9epbNzbeebWSaTD0hQcgWAe bqzhPqWHWXMyAz8vRIn5mWB5hk9ugTzujIG8F6ueN/s+lEotZisaCoeRWUlrAmZ1VL tBPqCkznUTFguqXEcdbdfFAOTpZ2rFOqj5+3F2zTU2cNx1+qdD80eAh4jVRKfP52/z oaQELd1nIGaz1S9yYOxggvJuhZTGcvJaQ1GrjTcWW1Pcy8WdquGuHJP5xKKjv1vmp/ WgbmdAyWCEVyA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B69C9C48BC1; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 12 Feb 2024 17:23:05 +0000 Subject: [PATCH kmod 04/13] libkmod: clear file->memory if map fails Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-decompression-fixes-v1-4-06f92ad07985@gmail.com> References: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> In-Reply-To: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> To: linux-modules@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707758583; l=1017; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=al1dK4HvZ5PCQ4yUkG1+INHPpcQTPWCE4hwkvTyh6Uo=; b=udM3cpyiH3c1vGygmQo+2yfr1L4mDfY1Mk21tp8R9fjbY+vbbiIiyIEcm4a9Qyb1F1arhZeVJ iJyCq1c1NUWDn02kEphWkyNyJMaR8ADvcEs+5rDieWgJtc6GnVrAwrZ X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov On mmap failure file->memory is set to -1, which we'll happily pass down to munmap later on. More importantly, since we do a NULL check in kmod_file_load_contents() we will exit the function without (re)attempting the load again. Since we ignore the return code for the load function(s), one can end up calling kmod_elf_get_memory() and feed that -1 into init_module. Signed-off-by: Emil Velikov Reviewed-by: Lucas De Marchi --- libkmod/libkmod-file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index abd4723..b408aed 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -392,8 +392,10 @@ static int load_reg(struct kmod_file *file) file->size = st.st_size; file->memory = mmap(NULL, file->size, PROT_READ, MAP_PRIVATE, file->fd, 0); - if (file->memory == MAP_FAILED) + if (file->memory == MAP_FAILED) { + file->memory = NULL; return -errno; + } return 0; } From patchwork Mon Feb 12 17:23:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13553775 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AF3D3D994 for ; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; cv=none; b=ctSMbVK1DgYqMz9SW88QxucjOEvOMtrtQiTPDaB1d8bNh9bA2VZS2w/4Q/ESL2agIAQLLNCiJZIoIiS+uQ9Xva+4SltENGzmW5t13PcBjY8wPNPtDVW5jct1XjxMgj5H3jDsJdhBdeaKloIFdKg9ZfMR5iRjIPkm1vvaWaA7ZuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; c=relaxed/simple; bh=S8TZlFFuXRRD+9NbDnfE7pcVtD937tHarEs60R5Gt4Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lt/B1Qx5AgN9TPAuzmoOcHbHqSYRkbN+YVu85BYyKjqgFsKkDCYU9GxajyaBLwT3C7N/7MY8BH9for0z/lSjz+w0dGgu2oAgaB/jw9AL5bDtvnmhSczK4Te2j1SmGruExC6cln+eHz8+rJ76sdxfiBDn8gZyZnnXlsLJaqkc1fU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ci0XB/QT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ci0XB/QT" Received: by smtp.kernel.org (Postfix) with ESMTPS id D4863C433B1; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707758585; bh=S8TZlFFuXRRD+9NbDnfE7pcVtD937tHarEs60R5Gt4Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Ci0XB/QTos3J2g9p/86dbt+nLEk7+eH3UGI43991QU9N4L57BExWGth+O/Lvwm8Or qylempit7MdxYYP0nmaoR3HrU8y0ozRVJVV62P2OuU31lmG/hmbRJptWFeEdT5oB43 yja7wZe10x7IuyBmSixWv1cqWFCWZ1HQaFyPLNL9e0QcIwr7Xyra7bI0zkWj+hG01R EFnnA3xnnOdDqUmyEco5wZS7VHdvB3GJf7Xd33bAvSNOCVnFBppt0M6aHvda+l3Psu RAPs9jLlq/0M2GPKZKcTURqhwqaMNOiludjEfu6MjwbWhEJLrJvkvawrdGsM8sGej7 HeM9eUuHM9pOw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2F27C48BC3; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 12 Feb 2024 17:23:06 +0000 Subject: [PATCH kmod 05/13] libkmod: nuke struct file_ops Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-decompression-fixes-v1-5-06f92ad07985@gmail.com> References: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> In-Reply-To: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> To: linux-modules@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707758583; l=4466; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=0Vi3uPtKabgYtJwqqoOuNWe6m7WAwfuOOzVybC1+mxc=; b=6nMv7lsUTpUGAdN8xblVMwtjE4FhsCIXCc3bSCk7IXVXeBgnmw8kGK0mzTtvFFby+LhcH1FP/ /XI9gFgfvArB87PrD/49nT++9/dzxR4+SKyeYDrul8SacWMru2Oj9c2 X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov With the previous commits, we removed the need for a distinct unload callback. So nuke the struct all together and only use/keep the load one around. Signed-off-by: Emil Velikov Reviewed-by: Lucas De Marchi --- libkmod/libkmod-file.c | 62 +++++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 44 deletions(-) diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index b408aed..8a0336f 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -41,18 +41,12 @@ #include "libkmod.h" #include "libkmod-internal.h" -struct kmod_file; -struct file_ops { - int (*load)(struct kmod_file *file); - void (*unload)(struct kmod_file *file); -}; - struct kmod_file { int fd; enum kmod_file_compression_type compression; off_t size; void *memory; - const struct file_ops *ops; + int (*load)(struct kmod_file *file); const struct kmod_ctx *ctx; struct kmod_elf *elf; }; @@ -181,11 +175,6 @@ out: return ret; } -static void unload_zstd(struct kmod_file *file) -{ - free(file->memory); -} - static const char magic_zstd[] = {0x28, 0xB5, 0x2F, 0xFD}; #endif @@ -287,11 +276,6 @@ static int load_xz(struct kmod_file *file) return ret; } -static void unload_xz(struct kmod_file *file) -{ - free(file->memory); -} - static const char magic_xz[] = {0xfd, '7', 'z', 'X', 'Z', 0}; #endif @@ -356,11 +340,6 @@ error: return err; } -static void unload_zlib(struct kmod_file *file) -{ - free(file->memory); -} - static const char magic_zlib[] = {0x1f, 0x8b}; #endif @@ -368,18 +347,18 @@ static const struct comp_type { size_t magic_size; enum kmod_file_compression_type compression; const char *magic_bytes; - const struct file_ops ops; + int (*load)(struct kmod_file *file); } comp_types[] = { #ifdef ENABLE_ZSTD - {sizeof(magic_zstd), KMOD_FILE_COMPRESSION_ZSTD, magic_zstd, {load_zstd, unload_zstd}}, + {sizeof(magic_zstd), KMOD_FILE_COMPRESSION_ZSTD, magic_zstd, load_zstd}, #endif #ifdef ENABLE_XZ - {sizeof(magic_xz), KMOD_FILE_COMPRESSION_XZ, magic_xz, {load_xz, unload_xz}}, + {sizeof(magic_xz), KMOD_FILE_COMPRESSION_XZ, magic_xz, load_xz}, #endif #ifdef ENABLE_ZLIB - {sizeof(magic_zlib), KMOD_FILE_COMPRESSION_ZLIB, magic_zlib, {load_zlib, unload_zlib}}, + {sizeof(magic_zlib), KMOD_FILE_COMPRESSION_ZLIB, magic_zlib, load_zlib}, #endif - {0, KMOD_FILE_COMPRESSION_NONE, NULL, {NULL, NULL}} + {0, KMOD_FILE_COMPRESSION_NONE, NULL, NULL} }; static int load_reg(struct kmod_file *file) @@ -400,15 +379,6 @@ static int load_reg(struct kmod_file *file) return 0; } -static void unload_reg(struct kmod_file *file) -{ - munmap(file->memory, file->size); -} - -static const struct file_ops reg_ops = { - load_reg, unload_reg -}; - struct kmod_elf *kmod_file_get_elf(struct kmod_file *file) { if (file->elf) @@ -436,7 +406,7 @@ struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, goto error; } - for (itr = comp_types; itr->ops.load != NULL; itr++) { + for (itr = comp_types; itr->load != NULL; itr++) { if (magic_size_max < itr->magic_size) magic_size_max = itr->magic_size; } @@ -459,17 +429,17 @@ struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, goto error; } - for (itr = comp_types; itr->ops.load != NULL; itr++) { + for (itr = comp_types; itr->load != NULL; itr++) { if (memcmp(buf, itr->magic_bytes, itr->magic_size) == 0) { - file->ops = &itr->ops; + file->load = itr->load; file->compression = itr->compression; break; } } } - if (file->ops == NULL) { - file->ops = ®_ops; + if (file->load == NULL) { + file->load = load_reg; file->compression = KMOD_FILE_COMPRESSION_NONE; } @@ -496,7 +466,7 @@ void kmod_file_load_contents(struct kmod_file *file) return; /* The load functions already log possible errors. */ - file->ops->load(file); + file->load(file); } void *kmod_file_get_contents(const struct kmod_file *file) @@ -524,8 +494,12 @@ void kmod_file_unref(struct kmod_file *file) if (file->elf) kmod_elf_unref(file->elf); - if (file->memory) - file->ops->unload(file); + if (file->compression == KMOD_FILE_COMPRESSION_NONE) { + if (file->memory) + munmap(file->memory, file->size); + } else { + free(file->memory); + } close(file->fd); free(file); From patchwork Mon Feb 12 17:23:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13553778 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59CFE3E468 for ; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; cv=none; b=CKzuXkFEJ5Ahg+tstHPT6uYRehLJ8gR7XdGV+B6oonElda+lTdqts/aU1zkuSSQkbENWGdQcXt72ma9/3qPLYGq8O3yGTE19G/HbqLNSHvbyEqe3CNv5o2ZovZWI0BFNyQF4I5j3DPReau3OcDYzGKGTM8j6Nrdmhwd1PvvaluY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; c=relaxed/simple; bh=FIw+zvOJlEF+AaA78DfgEGnylDyg5quXI4v7xQ4SsDQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eH/Ehc3gUl0rdK+J85H++0PdRBrcjdZnQR6diQx1IqVptw4QX7NLiNPt88gClv9L+2UtFOtR/krYEnuEPh/jeiumHrWqVf5xd/1KxrYvhrX2TqxWNJX5Z60wlnvuWnFlNOrahRYKE5TRDay9R7ipzIwUAeW8SWnJ7Q1nasn5xgI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gPf2skuC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gPf2skuC" Received: by smtp.kernel.org (Postfix) with ESMTPS id E3372C43141; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707758585; bh=FIw+zvOJlEF+AaA78DfgEGnylDyg5quXI4v7xQ4SsDQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=gPf2skuCAoLgIkeQYoIyJnprTv6UO2d3nc4miRx4fsiY1rt5dUW4aLiODKzQyoek3 Bw7F3Tn2sX93R2+bHkaI2SESTy19jLNKL5b/3/MbKvDKlDSlc4M2XhrGBWzOhfvmjX fT9/S65yvkemrF/vUkykaPxZXwALNxaYjgXr0ieaHYd3+EzVuk/KbllCm7/qXPE0QK l9pLFzpQyp5+NZ4yoIKBK0IW5jt1C5/oudObfG6FHZxaqQHUf/qvM+XanwfD0hlwUB oitsdczwrxc4gy0Bg8wkiZhItjH8a5TXBtttLQ0hm4cPVBIVPuyWDNuAPGkfMZvJmU TgsDTsrsu+Iog== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFD6FC4829E; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 12 Feb 2024 17:23:07 +0000 Subject: [PATCH kmod 06/13] libkmod: propagate {zstd,xz,zlib}_load errors Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-decompression-fixes-v1-6-06f92ad07985@gmail.com> References: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> In-Reply-To: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> To: linux-modules@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707758583; l=2916; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=1wTsCflduLgjBjz0zHH+IVD4+idKLEWwqQ0UYa76W0U=; b=cnsIcWPK/UmkEpJ9lOwKD/Mksdbx2R0i5LjTEnrqQCYbLm+4LI6DHbRs1PYBCLJ6hOXc3uXxl LAxWc/sUpawDHEX1Nkab15N4PqMW0OHelpJt1w8VxDbuDXbv0DX8fxg X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov 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 Reviewed-by: 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); From patchwork Mon Feb 12 17:23:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13553777 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58AE73E464 for ; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; cv=none; b=FvXonnS8JGcOrZe+XGGW85ZSANRZiVKNUgo/6STAvqz1uqBqHAit0/3UuCOx95z2QnqQUx3VsiejQXNDfkzSRa5mffhdm9TOekIV3IjGxk3S3oSkvzn0akhgsJ3ZmeKRaOZFV6Z3ZJD3Ao/bT/4bcti16i7AI6vMPtXTRTgVDA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; c=relaxed/simple; bh=i0w/N1kme4K9ELI3ZZ4I7KCak551RKEE1CoF9dzzTt8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YZYfhIRmGrLZZ3P7PuCcRPYCesS++OCRC4UhkRy0EcXaT5p1VnFqg6AghKiOhnbQHNNOECYbPOkKb+3sIBXd/yTdKeyuAKNTS3rXdP59oyWKLIbn9bfdTxMS6X6A1gdNqjDzTa2vXlyXVd1xnbgQSqFW35PhLRvstAQh4uhLePk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g1aiJ519; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="g1aiJ519" Received: by smtp.kernel.org (Postfix) with ESMTPS id 01F45C43142; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707758586; bh=i0w/N1kme4K9ELI3ZZ4I7KCak551RKEE1CoF9dzzTt8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=g1aiJ519NoF/mmoVzXYN9jmb27OcbMuMxznmPZtax0pHbyUlKZzX1FJ4SXqNATlJT CY8qSonxFCBboxsVBHSSR+GsilMJOu1WnhJNlvBhksDHGHzS3MsAmg5EJ0ZS0TxTkw CbGhQ3NBvLxTfMi34TzewcVQg4l6tlr5hrMDyaktW6dcC5mrUXcQx/CorkxBFsoYIZ 5DDAl5mZh0khuFn7H4+DdhxKtQO4vvOaPpEdmjSV+c5d+/5jicNQWhLS+lb74R9uCr egUSZC3+ZYw1ea2Gn8mo1RiYm7Ec0fFRe64UAOP+0LBvbcSpuqD5Z5SQcvm7X9r0cb FCGluY4Dc1jYA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0676C48297; Mon, 12 Feb 2024 17:23:05 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 12 Feb 2024 17:23:08 +0000 Subject: [PATCH kmod 07/13] libkmod: move kmod_file_load_contents as applicable Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-decompression-fixes-v1-7-06f92ad07985@gmail.com> References: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> In-Reply-To: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> To: linux-modules@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707758583; l=1207; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=P4udCeYuUMpIW9quBl7lfm1aEgAkNyDIYoV/mJWVVoQ=; b=XUvBbmBX6Y/ENcaTa6JI/AV0aVBXrs82P2iIirqcUF16Q16DVaep0Re0Pim1fUzwgHxOfQ13h dAf8Fk4IExsD8UDr6zHqJeZkOx4q5GMWc92FaveloIW6hZwzv6pKROH X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov When dealing with an elf, we don't know or care about loading the file. The kmod_elf subsystem/API will deal with the required parts itself. Which in this case, already calls kmod_file_load_contents() as applicable. Signed-off-by: Emil Velikov Reviewed-by: Lucas De Marchi --- libkmod/libkmod-module.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 1e43482..d309948 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -903,10 +903,6 @@ static int do_init_module(struct kmod_module *mod, unsigned int flags, off_t size; int err; - 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); if (elf == NULL) { @@ -928,6 +924,10 @@ static int do_init_module(struct kmod_module *mod, unsigned int flags, mem = kmod_elf_get_memory(elf); } else { + err = kmod_file_load_contents(mod->file); + if (err) + return err; + mem = kmod_file_get_contents(mod->file); } size = kmod_file_get_size(mod->file); From patchwork Mon Feb 12 17:23:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13553781 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D83C3E499 for ; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; cv=none; b=dvZI/cD9dxgZSWTOEAhOWaINNXPiT3EghcOZrSdpS2QezvKyCVekHo1QvRq2Ibom/339re8qsPIGNR5DmqQ79GJnWxeSNXObv0/MFsC1tlqatxid+CGRomWRjJabpLQkLVugyeQgBakOBk2tt9PM5bGSYUj6slb08OC42yty/zs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; c=relaxed/simple; bh=ldEDUCkPI5C/bJm7mVquDR47uX8LHbZYUjpQ8z+9/jo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BioKR73YloIRjXmQEUfaUEz5HcZ5MsM4kRX01rHRj+aLYmE9cUAbbS13IAlZKMS7GDPDC1rz21rIkRNjMyD/b+B2q7Sd+1pwGBpdf3HVcaEjblswFcyK2fTeWFtaN7zcByhJ1uayW12JQSJrbdR4jeLLzJ0m1KMLHIfkr48pyoA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ir6JuLn9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ir6JuLn9" Received: by smtp.kernel.org (Postfix) with ESMTPS id 14C25C43143; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707758586; bh=ldEDUCkPI5C/bJm7mVquDR47uX8LHbZYUjpQ8z+9/jo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Ir6JuLn9aBDAZ981Y4c6ZSacTI4hc84UCU2fTdvR7+i1maM3zGMQ8OX3nL4b3lNIC Pg4XQJaFFWO3s0Kr4LFTQaSf4qZowQuua84RVjtNbemsmZquxMuilNWepJqabRwt5P 9va+x+PJlTnydJl2yfHGHI6/ZQzYaGxwAkVzRPiMS7w9GXFZ1Pk5jWuqT3D8t6NoZE E7NnMYN/uj2PykL63xOH0xXLC42W3QlsyzMxxfdltMrsD928XxFH8Zpw8svvMQYNrI lXRSKCAkhcA7PGE0XStBUyAbm1KzePgqOTxjH+QKjGUMQRxmnVVSnhnroX2TETmBPI z0ToCpMKIix6A== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 048CEC48BC3; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 12 Feb 2024 17:23:09 +0000 Subject: [PATCH kmod 08/13] libkmod: always detect the module compression Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-decompression-fixes-v1-8-06f92ad07985@gmail.com> References: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> In-Reply-To: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> To: linux-modules@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707758583; l=2385; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=vnwce2nmhp+gEWObCw0gKQhrZ2WjtAclB1+9aE/85S8=; b=N2d9JcCxy/n8uPTm3GLc3XE68bos/hi+cNfNg3vQfzE38+bxAugKCSQKaJI5QyXq15WsecDsU +uv2gnZoD+ED061sNEYeRuEr2BJRmPdokQvyo8WMkv37KdX0KHC+e2N X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov Currently, when built w/o given compression we'll incorrectly report a "compression_none". As we reach do_finit_module(), we'll naively assume that the kernel can handle the compressed module, yet omit the MODULE_INIT_COMPRESSED_FILE flag. As result the kernel will barf at us, do_finit_module will fail with non -ENOSYS and we won't end in the do_init_module codepath (which will also fail). In other words: with this change, you can build kmod without zstd, xz and zlib support and the kernel will load the modules, assuming it supports the format \o/ Signed-off-by: Emil Velikov Reviewed-by: Lucas De Marchi --- libkmod/libkmod-file.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index 3a79464..b69f1ef 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -174,9 +174,14 @@ out: free((void *)zst_outb.dst); return ret; } +#else +static int load_zstd(struct kmod_file *file) +{ + return -ENOSYS; +} +#endif static const char magic_zstd[] = {0x28, 0xB5, 0x2F, 0xFD}; -#endif #ifdef ENABLE_XZ static void xz_uncompress_belch(struct kmod_file *file, lzma_ret ret) @@ -275,9 +280,14 @@ static int load_xz(struct kmod_file *file) lzma_end(&strm); return ret; } +#else +static int load_xz(struct kmod_file *file) +{ + return -ENOSYS; +} +#endif static const char magic_xz[] = {0xfd, '7', 'z', 'X', 'Z', 0}; -#endif #ifdef ENABLE_ZLIB #define READ_STEP (4 * 1024 * 1024) @@ -339,9 +349,14 @@ error: gzclose(gzf); /* closes the gzfd */ return err; } +#else +static int load_zlib(struct kmod_file *file) +{ + return -ENOSYS; +} +#endif static const char magic_zlib[] = {0x1f, 0x8b}; -#endif static const struct comp_type { size_t magic_size; @@ -349,15 +364,9 @@ static const struct comp_type { const char *magic_bytes; int (*load)(struct kmod_file *file); } comp_types[] = { -#ifdef ENABLE_ZSTD {sizeof(magic_zstd), KMOD_FILE_COMPRESSION_ZSTD, magic_zstd, load_zstd}, -#endif -#ifdef ENABLE_XZ {sizeof(magic_xz), KMOD_FILE_COMPRESSION_XZ, magic_xz, load_xz}, -#endif -#ifdef ENABLE_ZLIB {sizeof(magic_zlib), KMOD_FILE_COMPRESSION_ZLIB, magic_zlib, load_zlib}, -#endif {0, KMOD_FILE_COMPRESSION_NONE, NULL, NULL} }; From patchwork Mon Feb 12 17:23:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13553779 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60A6F3E476 for ; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; cv=none; b=fwyLgVVwJkMVLTkQ7yFbf25E8dmx6PuIm+Nifbjdt609DVRWh3l3FH1Z6tRClO9ck0qTBABbB2+Wi0wre0WyXqR4YMmbPkHqHy0gZ8bTQWGNSrmq9MBwP1sdZWjfs1UvLPPw8L4xlvuqsNeUs1RZaCO5rNJKs2lxSFAAFLLPNY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; c=relaxed/simple; bh=722WuASjlqY/S4jd8A11LRaTnRtRjDFwZUt9oHhXLdg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cYDE/0llvgNwNq6mT6exxUCRWnAx5HbCE4AX06xOvQTJJUAuFUMvbgAVt3FBmaFCc9X0NEIsyHssILbqzw6YsYRVcg/7rWzCKTO95XpapsZU/Rbdh/gIggKa+KEjn7XleJdWTxHPAiWy9mx8VmX6nUKqZKh14NtYs6SxJP1vYQU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LEH0KQ7S; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LEH0KQ7S" Received: by smtp.kernel.org (Postfix) with ESMTPS id 262A0C43609; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707758586; bh=722WuASjlqY/S4jd8A11LRaTnRtRjDFwZUt9oHhXLdg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=LEH0KQ7SV6lSDxAROav5XYdlhnlJfw1+EQpBPmlwkCQ5jRnRTDavvVC2CZAhU5VPL VTw0g9lHU1AWXHdknSuBHTG/OOVWnTcIzmwZ53cB2RRqf9rR5mOes/Jh1LpzB1PajP Yq4IF/qlhZgmvmbBfkhDc0SPKhnQwhnFl2GlaooZRBoESc+1R509xfMWsRviRPdSvI fEXdvPSDhUjuJntXTy+ErRFA6Gk0UEIRS7XGlOPgrZRAo9b58YgpIfamsLXnHwREOL hV8vLK+INvgXQ/jpM5fRQ0PYgYLXljFsMrMHz42wfWL/odgDGcHx3PjSS2fZ+w6mS7 sUeIGnqkFnE3A== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 158CBC48BC1; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 12 Feb 2024 17:23:10 +0000 Subject: [PATCH kmod 09/13] libkmod: swap alloca usage for a few assert_cc Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-decompression-fixes-v1-9-06f92ad07985@gmail.com> References: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> In-Reply-To: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> To: linux-modules@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707758583; l=1663; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=XPT/ZixMYN/E3QF0xKFi5IKVYm1O2Fs0Z8DdyQGwNPg=; b=jsdW4IsoknHmKJGjSqwIeZ974sfzKlQNxyU7QbZXEyfleS0NmbphAOBRNIdyI3Ei+fDPUlAqC 5aq88pNxiVgBZdSpX/5gupR9OzyIV2Y3Bv5ZvegpecqO7ZKMR8UPC4g X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov Since all the compression magic is always available now, we don't need to loop at runtime nor use alloca - latter of which comes with a handful of caveats. Simply throw in a few assert_cc(), which will trigger at build-time. Signed-off-by: Emil Velikov Reviewed-by: Lucas De Marchi --- libkmod/libkmod-file.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index b69f1ef..5b88d6c 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -410,7 +410,6 @@ struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, { struct kmod_file *file = calloc(1, sizeof(struct kmod_file)); const struct comp_type *itr; - size_t magic_size_max = 0; int err = 0; if (file == NULL) @@ -422,22 +421,17 @@ struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, goto error; } - for (itr = comp_types; itr->load != NULL; itr++) { - if (magic_size_max < itr->magic_size) - magic_size_max = itr->magic_size; - } - - if (magic_size_max > 0) { - char *buf = alloca(magic_size_max + 1); + { + char buf[7]; ssize_t sz; - if (buf == NULL) { - err = -errno; - goto error; - } - sz = read_str_safe(file->fd, buf, magic_size_max + 1); + assert_cc(sizeof(magic_zstd) < sizeof(buf)); + assert_cc(sizeof(magic_xz) < sizeof(buf)); + assert_cc(sizeof(magic_zlib) < sizeof(buf)); + + sz = read_str_safe(file->fd, buf, sizeof(buf)); lseek(file->fd, 0, SEEK_SET); - if (sz != (ssize_t)magic_size_max) { + if (sz != (sizeof(buf) - 1)) { if (sz < 0) err = sz; else From patchwork Mon Feb 12 17:23:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13553780 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 663773E477 for ; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; cv=none; b=dM0XkG6Tc1rx4GtGXnAfA8hrgLPXTe0Wh5MZShfx2KuR4PeTQRgqBTCraUS3uVwwQOBAZupuzco0ATIqCfj4UFE+VZhjvbjinbGZm0qoIFvVHZ/RyRXtlRwrZZMWeeFMAhNCov0HVCwBGiUPhcR65z1BQxq0lFzntpT8dUmtDnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; c=relaxed/simple; bh=TZBNiHOLDF13i5bmBVUDnvfTXoZyU6dW90MffHP8vIA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dsDhVd4zKfO5DJ7jm4OFkWE3aG3Z/c+Fr+L4WJZuds+9Q2zADYtboPx/o6HDdCg95TU25TdirRhnqn8dU5PUTwwC7namkODgxjyoYJ5Q3kRLvc/MA8fruTohDGbe60E+cttKrzU3mZqgJ51P8o+WC2Jl+gqmi5KqUML1+0vqwNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DI27nuEj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DI27nuEj" Received: by smtp.kernel.org (Postfix) with ESMTPS id 45DF1C4166B; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707758586; bh=TZBNiHOLDF13i5bmBVUDnvfTXoZyU6dW90MffHP8vIA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=DI27nuEjZNCMGuPKduVxzt+WVt87sziLUT3rGMx40mFiNYtaZZuBQouBcED2w5hcY uI11Di1xmV6O0d4jWlmVjlguzRMlgsmGgYoxeT/9jHZLTbJp5p9wgq9Y1iWIuAqSJb ZJbXd3wsC+bQV5OCo4F2LjdMS+tZ9//ugQa5KoN6D6waW2IrZwjmM/F/SKv9iBtC5m 3ND9zFdgY5+b6Cb76w8AQiRBG8QqJ7vavuRBQBEj1Nap5VT5yCbVnzn9JN+gm5z5CA eqzXHez8Jy89/aEkiJH1UNhVQDrHJaF4r7zT/kL3Jsmk1mZ5NKJvvkLzrtQ4AdsSij ACs6wFvtJvSSw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33BB9C4829E; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 12 Feb 2024 17:23:11 +0000 Subject: [PATCH kmod 10/13] libkmod: tidy-up kmod_file_open() Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-decompression-fixes-v1-10-06f92ad07985@gmail.com> References: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> In-Reply-To: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> To: linux-modules@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707758583; l=2378; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=UfzSecSP8vIYsHmd21SFJIic/SxgSObW4SMoY5ZZ5mI=; b=Gh/abScOoWeSs/fl6sH1LlQ+em0F5Pa5ZcmJMSceZ/nUmxJtEHe2B0HizqB1/Uh2wukLUt2Lh x7AwKrpVhUKBFQ/7P/bBNO25hPnZDM58kXESBA3oGaNMEHo3UCyWLkq X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov This commit cleans up the indentation and the error path of the function. It bears no functional changes. Signed-off-by: Emil Velikov Reviewed-by: Lucas De Marchi --- libkmod/libkmod-file.c | 60 +++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index 5b88d6c..c4893fd 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -410,41 +410,40 @@ struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, { struct kmod_file *file = calloc(1, sizeof(struct kmod_file)); const struct comp_type *itr; - int err = 0; + char buf[7]; + ssize_t sz; if (file == NULL) return NULL; file->fd = open(filename, O_RDONLY|O_CLOEXEC); if (file->fd < 0) { - err = -errno; - goto error; + free(file); + return NULL; } - { - char buf[7]; - ssize_t sz; - - assert_cc(sizeof(magic_zstd) < sizeof(buf)); - assert_cc(sizeof(magic_xz) < sizeof(buf)); - assert_cc(sizeof(magic_zlib) < sizeof(buf)); - - sz = read_str_safe(file->fd, buf, sizeof(buf)); - lseek(file->fd, 0, SEEK_SET); - if (sz != (sizeof(buf) - 1)) { - if (sz < 0) - err = sz; - else - err = -EINVAL; - goto error; - } + assert_cc(sizeof(magic_zstd) < sizeof(buf)); + assert_cc(sizeof(magic_xz) < sizeof(buf)); + assert_cc(sizeof(magic_zlib) < sizeof(buf)); - for (itr = comp_types; itr->load != NULL; itr++) { - if (memcmp(buf, itr->magic_bytes, itr->magic_size) == 0) { - file->load = itr->load; - file->compression = itr->compression; - break; - } + sz = read_str_safe(file->fd, buf, sizeof(buf)); + lseek(file->fd, 0, SEEK_SET); + if (sz != (sizeof(buf) - 1)) { + if (sz < 0) + errno = -sz; + else + errno = EINVAL; + + close(file->fd); + free(file); + return NULL; + } + + for (itr = comp_types; itr->load != NULL; itr++) { + if (memcmp(buf, itr->magic_bytes, itr->magic_size) == 0) { + file->load = itr->load; + file->compression = itr->compression; + break; } } @@ -455,15 +454,6 @@ struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, file->ctx = ctx; -error: - if (err < 0) { - if (file->fd >= 0) - close(file->fd); - free(file); - errno = -err; - return NULL; - } - return file; } From patchwork Mon Feb 12 17:23:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13553782 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 820793E49C for ; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; cv=none; b=Eoon+Le+Z0V4y6YILI8t5YQbphEoccc7hGfNRzRNXeumsJtbmCa4g/6caAbiv7dTNK7iGCKLdphtRd8PW0VuQpTCD5AalxDqqEaUPgA9sp617vfEsjKF13u+tDhvkDOolZsLalUp2GwsZqjaiNZwaAqEJC+cE7ISY+EQO156mUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; c=relaxed/simple; bh=3BGP/vZWVd6Fz4QD1oM4T5+MZqwiZCwqPX677URBqrs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o7GNq9rwqnibo67Y64F5rOXUvRvJo8d8izW/PrxPjwaxzvE3EJ1FtznQz2OmaUn0FszlktAk6nUCUbBHBj0HvmVC6PZaFQH14Rf/gV0rIACmRiu4h76PK2N8CnPl7Alp0Y3/uEuaPPDaQlDjuKOBae2+hU2ALWXeEyjDOmtQHG8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bv2B8aJ7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bv2B8aJ7" Received: by smtp.kernel.org (Postfix) with ESMTPS id 63C85C41674; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707758586; bh=3BGP/vZWVd6Fz4QD1oM4T5+MZqwiZCwqPX677URBqrs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=bv2B8aJ7sBqvjCCuZ5QTeaVTn5xNOILPMh0Cl65GtclYSynZ5nyUsZLDMFRB3NFif lzUJfBb5AbKrWLuSuBq5DQ2qg+uUTi0Rr/V5Fq+71qnGXJDdhL8ubgZGL1jghKEbJt psbEzCDMcaTCJGwossDiCqbaFeq5C3CeDxRLh7327B8n3Ju1AejiLzaYXFDQ7brSxi 0xsVksoFAPBM7EvBSDOYK5+eOErhKPtcmh9qsfTTUQSts9k3zhNmCuKlZwZ9mB7jAs W+/YvvK2k2AxXxsYFA31JPSvDR//feOsio60MSRiCMpU+LBZN/8PObAOe5kSqG08wh xe1SQ7rMBMTjA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D502C48BC1; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 12 Feb 2024 17:23:12 +0000 Subject: [PATCH kmod 11/13] libkmod: move load_reg() further up Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-decompression-fixes-v1-11-06f92ad07985@gmail.com> References: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> In-Reply-To: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> To: linux-modules@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707758583; l=1695; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=s7DGIk3v5vJZUPUJq4qUIG5k2dwH6qeNbl7Ccp04tdM=; b=r+xUgnwpNFv2pLM9zfu/g+v/Ncb451QKQmLwLfooiRmjkaiKwgrO8YpIpoo1nNwAZGpC8KHlN 3Ax90X3qGebDHBMoyGar0BjA3ntxKXFtVlwhzoSzZWsQQJKuY4R32ze X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov We're about to reference it in comp_types with next commit. Signed-off-by: Emil Velikov Reviewed-by: Lucas De Marchi --- libkmod/libkmod-file.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index c4893fd..db775a6 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -358,18 +358,6 @@ static int load_zlib(struct kmod_file *file) static const char magic_zlib[] = {0x1f, 0x8b}; -static const struct comp_type { - size_t magic_size; - enum kmod_file_compression_type compression; - const char *magic_bytes; - int (*load)(struct kmod_file *file); -} comp_types[] = { - {sizeof(magic_zstd), KMOD_FILE_COMPRESSION_ZSTD, magic_zstd, load_zstd}, - {sizeof(magic_xz), KMOD_FILE_COMPRESSION_XZ, magic_xz, load_xz}, - {sizeof(magic_zlib), KMOD_FILE_COMPRESSION_ZLIB, magic_zlib, load_zlib}, - {0, KMOD_FILE_COMPRESSION_NONE, NULL, NULL} -}; - static int load_reg(struct kmod_file *file) { struct stat st; @@ -388,6 +376,18 @@ static int load_reg(struct kmod_file *file) return 0; } +static const struct comp_type { + size_t magic_size; + enum kmod_file_compression_type compression; + const char *magic_bytes; + int (*load)(struct kmod_file *file); +} comp_types[] = { + {sizeof(magic_zstd), KMOD_FILE_COMPRESSION_ZSTD, magic_zstd, load_zstd}, + {sizeof(magic_xz), KMOD_FILE_COMPRESSION_XZ, magic_xz, load_xz}, + {sizeof(magic_zlib), KMOD_FILE_COMPRESSION_ZLIB, magic_zlib, load_zlib}, + {0, KMOD_FILE_COMPRESSION_NONE, NULL, NULL} +}; + struct kmod_elf *kmod_file_get_elf(struct kmod_file *file) { int err; From patchwork Mon Feb 12 17:23:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13553783 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B2013EA87 for ; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; cv=none; b=mX/E2+Hjrh+gmDh12uiTKVuC/6vW34ufEmNmSRJRawwaHIhKJswy72rB6wXwE5LCPMtr4Xj3zScHtdNQlpqbejRCxNegJ7o5WWJKv402WrGDBC+XyrpDJY/kXtV2lVXiez9q/0TQUNsGUv4OeMM3wy/3xtBcC35DGUDd1gLpzIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; c=relaxed/simple; bh=7PvciUt4dOCJSgji0+k94M2TQWxFMf+kFJtQXAVtMG0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t5Qw13UqAXzdtAmZI4S1v7fYhnOEfQU/GiMQohyb01KC7sXr6C4VX/sYi8CaWzFHjE5tL0tK2C60cX5bcF8nAUWBgU+juAYEXPzaxPKsZTu8pc/wDgel3vZsLcdKBw9jqMEDHkHVUfSYUPqVm0uKFXDicK2E8xU4kHl3SdciA9E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rB06tPLA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rB06tPLA" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7D96FC4167D; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707758586; bh=7PvciUt4dOCJSgji0+k94M2TQWxFMf+kFJtQXAVtMG0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rB06tPLA6iurb7fFhgC41ItDGqc9bgOaOGCTuTo5IYNsEHBGfX3svjLUyA+JNmlo3 fmU6cW9M000PXW+S0cMGUnWgID5DSDXtMxxXr6Hb9dfgw0r9SKIoho6Ky2LZruaFG7 YvSn6O2pxOX+fHJN1x/hSJlibItmhKvky8R/Vc4e37g65F24iwEZmjm230Y+y/gbom zORFNKJCLsKcRmgid40JS/kt5XF9+NzB5x3ci/sJRzAvOr9D1YKMdJ2DQ8SoZItSs3 B1/M2Ly9LdWus2p8oPZzZ9/SW0CKaaVsSgQ34rmqqqFgtMuX0xizko5r+NW5hDWfcn 6hW77QrUTEDxA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CF5FC48297; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 12 Feb 2024 17:23:13 +0000 Subject: [PATCH kmod 12/13] libkmod: keep KMOD_FILE_COMPRESSION_NONE/load_reg in comp_types Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-decompression-fixes-v1-12-06f92ad07985@gmail.com> References: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> In-Reply-To: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> To: linux-modules@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707758583; l=1865; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=eg4QwfmoJWQ60x2hJ543Y3vC1Tb/8riHCGxkXzk+eG8=; b=uzOuE6T9A8QFRCFEYa+9kvPc9yobUxetur2RoHCrRNC8K9OaeJaju0woiZkOM7hW5w8BUg4kd 1IHLkUj3hvGC81pZAKt20+9VMguL3Whp4D1NhFRbuOdi8XGxbVTVz7S X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov It's cleaner to handle all compression types and load functions in the same style. Signed-off-by: Emil Velikov Reviewed-by: Lucas De Marchi --- libkmod/libkmod-file.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index db775a6..f162a10 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -385,7 +385,7 @@ static const struct comp_type { {sizeof(magic_zstd), KMOD_FILE_COMPRESSION_ZSTD, magic_zstd, load_zstd}, {sizeof(magic_xz), KMOD_FILE_COMPRESSION_XZ, magic_xz, load_xz}, {sizeof(magic_zlib), KMOD_FILE_COMPRESSION_ZLIB, magic_zlib, load_zlib}, - {0, KMOD_FILE_COMPRESSION_NONE, NULL, NULL} + {0, KMOD_FILE_COMPRESSION_NONE, NULL, load_reg} }; struct kmod_elf *kmod_file_get_elf(struct kmod_file *file) @@ -409,7 +409,6 @@ struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename) { struct kmod_file *file = calloc(1, sizeof(struct kmod_file)); - const struct comp_type *itr; char buf[7]; ssize_t sz; @@ -439,19 +438,17 @@ struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, return NULL; } - for (itr = comp_types; itr->load != NULL; itr++) { - if (memcmp(buf, itr->magic_bytes, itr->magic_size) == 0) { - file->load = itr->load; - file->compression = itr->compression; + for (unsigned int i = 0; i < ARRAY_SIZE(comp_types); i++) { + const struct comp_type *itr = &comp_types[i]; + + file->load = itr->load; + file->compression = itr->compression; + if (itr->magic_size && + memcmp(buf, itr->magic_bytes, itr->magic_size) == 0) { break; } } - if (file->load == NULL) { - file->load = load_reg; - file->compression = KMOD_FILE_COMPRESSION_NONE; - } - file->ctx = ctx; return file; From patchwork Mon Feb 12 17:23:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 13553784 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4DBA3E464 for ; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; cv=none; b=Alv9EuhvE7yebCxk48NiHGrCe75592EHi3G6zCyDT+l0e1IG0qXTV6y73pgvi68iJKLNt0bIDnzp4vQ7ErbEQMI4ptXZm4bxdD/6in99OHyUejqvbKtYk9D4eofL56QZGzVXTtX1HYqC9vUWeemyP/HReJ7Op/sgMyYJetYqA4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707758586; c=relaxed/simple; bh=F6UiGTpuA/8JbAelVRgUhY745RWrx19JN3E3FsJtnyw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=keDlz8NOtnonBSi/h8eOufODyRPk5a7hldMzmH32zmDz1meXNY2muapfwPIUMW/kJczJqAZzTeLUzlc4a12Gt9i7lFJSsXbfpc2Lto7QE7tXtadiiodWNfad9KfmwrqPdLuzS5LpakGifLNFomt0kWCpKbdbI2s1Cej+E3aFK2M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=K+zOFpPW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="K+zOFpPW" Received: by smtp.kernel.org (Postfix) with ESMTPS id 94E6FC3277F; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707758586; bh=F6UiGTpuA/8JbAelVRgUhY745RWrx19JN3E3FsJtnyw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=K+zOFpPWrkIYfxvRhxpk0NIXVgaS1oJCCqUsxsm5fRGUueAKH1XaEHsaV3wcWlPCB yeOf0EkFjEpKo+EXGtgjB7og2R5QAKbH+SW2l3AyPKNUQkOB3IrBUUIk6S4ym9tOOV 2y5bVC+Uv+cFSU4iydHxUPWsweY55rgx+QOjEwNM/uOWG4Ltjh5kGjlrlqdPMdVcjw cL4l+rEpi0bE4VPyns33XcEIwgki9JJNCoDQAhInrvDWzcseaoXiOIAX2WIrmoTIMf X+kNrh8VBrhlb8f5iVF5H78F8xh48RN5rvrcgRqJXzQXx/WF81XNLuEB4o7Z2vxJ2Q lRIwri/e2TKmg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84BE7C48BC1; Mon, 12 Feb 2024 17:23:06 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 12 Feb 2024 17:23:14 +0000 Subject: [PATCH kmod 13/13] libkmod: always fallback to do_init_module() Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-decompression-fixes-v1-13-06f92ad07985@gmail.com> References: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> In-Reply-To: <20240212-decompression-fixes-v1-0-06f92ad07985@gmail.com> To: linux-modules@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707758583; l=1269; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=YLQVRnZVvgDMYMKMKqUNfuI2u4VvagtQrxxbP0HW96w=; b=dH9WZxNZmaYSoFEZa/rC5AiBsh5aZi9t5itP654DCBcT+JFdIyGDIzRU6uyQQXm70fARrWTdP TWZDCB/oeUFBmTOmWcqP6UJ66tRJgDEAhcXhLZ+SNtKM1HwYwcUfWkM X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov Since the direct loading was introduced a few bugs became obvious that the compression args used were off - both in-kernel and dkms. While both of those are fixed already, not all of those have reached all users. For example: for dkms I'm aiming to do a release just as kmod has theirs (to align /lib/modules <> /usr/lib/modules support). Although I am wondering if we can indiscriminatingly callback to the old do_init_module() in all the cases. This means that we'll catch any in-kernel decompression issues - invalid args, ENOMEM, other.... Although for others (wrong magic, perm, etc) we will end up doing the exact kernel work twice. Overall the trade-off seems worth it, so flip this. Signed-off-by: Emil Velikov --- libkmod/libkmod-module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index d309948..2c0d46d 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -980,7 +980,7 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, } err = do_finit_module(mod, flags, args); - if (err == -ENOSYS) + if (err) err = do_init_module(mod, flags, args); if (err < 0)