mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] btrfs: harden parsing of compress mount option
@ 2025-04-23  7:33 Daniel Vacek
  2025-04-23 10:24 ` David Sterba
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Daniel Vacek @ 2025-04-23  7:33 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba, Nick Terrell
  Cc: Daniel Vacek, linux-btrfs, linux-kernel

Btrfs happily but incorrectly accepts the `-o compress=zlib+foo` and similar
options with any random suffix. Let's handle that correctly.

Signed-off-by: Daniel Vacek <neelx@suse.com>
---
 fs/btrfs/super.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 40709e2a44fce..f7e064b8c6d88 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -354,7 +354,10 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
 			btrfs_set_opt(ctx->mount_opt, COMPRESS);
 			btrfs_clear_opt(ctx->mount_opt, NODATACOW);
 			btrfs_clear_opt(ctx->mount_opt, NODATASUM);
-		} else if (strncmp(param->string, "zlib", 4) == 0) {
+		} else if (strncmp(param->string, "zlib", 4) == 0 &&
+				(param->string[4] == ':' ||
+				 param->string[4] == ',' ||
+				 param->string[4] == '\0')) {
 			ctx->compress_type = BTRFS_COMPRESS_ZLIB;
 			ctx->compress_level =
 				btrfs_compress_str2level(BTRFS_COMPRESS_ZLIB,
@@ -362,13 +365,18 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
 			btrfs_set_opt(ctx->mount_opt, COMPRESS);
 			btrfs_clear_opt(ctx->mount_opt, NODATACOW);
 			btrfs_clear_opt(ctx->mount_opt, NODATASUM);
-		} else if (strncmp(param->string, "lzo", 3) == 0) {
+		} else if (strncmp(param->string, "lzo", 3) == 0 &&
+				(param->string[3] == ',' ||
+				 param->string[3] == '\0')) {
 			ctx->compress_type = BTRFS_COMPRESS_LZO;
 			ctx->compress_level = 0;
 			btrfs_set_opt(ctx->mount_opt, COMPRESS);
 			btrfs_clear_opt(ctx->mount_opt, NODATACOW);
 			btrfs_clear_opt(ctx->mount_opt, NODATASUM);
-		} else if (strncmp(param->string, "zstd", 4) == 0) {
+		} else if (strncmp(param->string, "zstd", 4) == 0 &&
+				(param->string[4] == ':' ||
+				 param->string[4] == ',' ||
+				 param->string[4] == '\0')) {
 			ctx->compress_type = BTRFS_COMPRESS_ZSTD;
 			ctx->compress_level =
 				btrfs_compress_str2level(BTRFS_COMPRESS_ZSTD,
@@ -376,7 +384,12 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
 			btrfs_set_opt(ctx->mount_opt, COMPRESS);
 			btrfs_clear_opt(ctx->mount_opt, NODATACOW);
 			btrfs_clear_opt(ctx->mount_opt, NODATASUM);
-		} else if (strncmp(param->string, "no", 2) == 0) {
+		} else if ((strncmp(param->string, "no", 2) == 0 &&
+				(param->string[2] == ',' ||
+				 param->string[2] == '\0')) ||
+			   (strncmp(param->string, "none", 4) == 0 &&
+				(param->string[4] == ',' ||
+				 param->string[4] == '\0'))) {
 			ctx->compress_level = 0;
 			ctx->compress_type = 0;
 			btrfs_clear_opt(ctx->mount_opt, COMPRESS);
-- 
2.47.2


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

end of thread, other threads:[~2025-05-28 23:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-23  7:33 [PATCH] btrfs: harden parsing of compress mount option Daniel Vacek
2025-04-23 10:24 ` David Sterba
2025-04-23 10:29 ` David Sterba
2025-04-23 13:22 ` [PATCH v2] " Daniel Vacek
2025-04-24 19:29   ` David Sterba
2025-05-28 23:28     ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®