mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mkfs.f2fs: enforce alias_filename to match device name
@ 2026-08-26 18:11 Daeho Jeong
  2026-09-07  2:20 ` [f2fs-dev] " Chao Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Daeho Jeong @ 2026-08-26 18:11 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel, kernel-team
  Cc: Daeho Jeong, Wenjie Qi, stable

From: Daeho Jeong <daehojeong@google.com>

The kernel expects the device alias file in the root directory to match
the device basename (strrchr(path, '/') + 1) to identify the target device
both during mount in f2fs_restore_device_alias() and during reserve in
f2fs_ioc_reserve_dev_alias().

If a custom alias filename that differs from the device name is used,
the kernel fails to match the alias file at mount time (leaving
FDEV(i).has_alias unset and allowing pinned files to allocate in that
range) and subsequently fails to reserve the device range when requested.

Enforce that if an alias filename is specified, it must match the device
name. Also allow specifying just '-c <device>@' as a shorthand so users
do not have to redundantly type the device basename twice.

Reported-by: Wenjie Qi <qiwenjie@xiaomi.com>
Fixes: 8cc4e257ec20 ("mkfs.f2fs: add device aliasing feature")
Cc: stable@vger.kernel.org
Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
 man/mkfs.f2fs.8         |  4 +++-
 mkfs/f2fs_format_main.c | 27 +++++++++++++++------------
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/man/mkfs.f2fs.8 b/man/mkfs.f2fs.8
index 9096646..430d180 100644
--- a/man/mkfs.f2fs.8
+++ b/man/mkfs.f2fs.8
@@ -121,10 +121,12 @@ Currently, the kernel is only able to mount f2fs filesystems where the
 block size matches the page size.
 The default value is 4096.
 .TP
-.BI \-c " device-list"
+.BI \-c " device_name[@alias_filename]"
 Build f2fs with these additional devices, so that the user can
 see all the devices as one big volume.
 Supports up to 7 devices except meta device.
+If '@' or '@alias_filename' is given, the device is configured as a device alias.
+Note that alias_filename must match the device name.
 .TP
 .BI \-d " debug-level"
 Specify the level of debugging options.
diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index 8d44a9b..99d92c5 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -191,6 +191,7 @@ static void f2fs_parse_options(int argc, char *argv[])
 	int32_t option=0;
 	int val;
 	char *token;
+	bool is_alias;
 	int dev_num;
 
 	while ((option = getopt_long(argc,argv,option_string,long_opts,NULL)) != EOF) {
@@ -218,6 +219,8 @@ static void f2fs_parse_options(int argc, char *argv[])
 				mkfs_usage();
 			}
 
+			is_alias = (strchr(optarg, '@') != NULL);
+
 			token = strtok(optarg, "@");
 			if (strlen(token) > MAX_PATH_LEN) {
 				MSG(0, "Error: device path should be equal or "
@@ -226,21 +229,21 @@ static void f2fs_parse_options(int argc, char *argv[])
 				mkfs_usage();
 			}
 			c.devices[dev_num].path = strdup(token);
-			token = strtok(NULL, "");
-			if (token) {
-				if (strlen(token) > MAX_PATH_LEN) {
-					MSG(0, "Error: alias_filename should "
-						"be equal or less than %d "
-						"characters\n", MAX_PATH_LEN);
-					mkfs_usage();
-				}
-				if (strchr(token, '/')) {
-					MSG(0, "Error: alias_filename has "
-						"invalid '/' character\n");
+
+			if (is_alias) {
+				char *dev_name = strrchr(token, '/');
+
+				dev_name = dev_name ? dev_name + 1 : token;
+
+				token = strtok(NULL, "");
+				if (token && strcmp(token, dev_name)) {
+					MSG(0,
+						"Error: alias_filename (\"%s\") must match device name (\"%s\")\n",
+						token, dev_name);
 					mkfs_usage();
 				}
 				c.devices[dev_num].alias_filename =
-					strdup(token);
+					strdup(dev_name);
 				if (!c.aliased_devices)
 					c.feature |= F2FS_FEATURE_DEVICE_ALIAS;
 				c.aliased_devices++;
-- 
2.55.0.887.g758fc8c411-goog


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

* Re: [f2fs-dev] [PATCH] mkfs.f2fs: enforce alias_filename to match device name
  2026-08-26 18:11 [PATCH] mkfs.f2fs: enforce alias_filename to match device name Daeho Jeong
@ 2026-09-07  2:20 ` Chao Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2026-09-07  2:20 UTC (permalink / raw)
  To: Daeho Jeong, linux-kernel, linux-f2fs-devel, kernel-team
  Cc: chao, Daeho Jeong, stable, Wenjie Qi

On 8/26/26 18:11, Daeho Jeong wrote:
> From: Daeho Jeong <daehojeong@google.com>
> 
> The kernel expects the device alias file in the root directory to match
> the device basename (strrchr(path, '/') + 1) to identify the target device
> both during mount in f2fs_restore_device_alias() and during reserve in
> f2fs_ioc_reserve_dev_alias().
> 
> If a custom alias filename that differs from the device name is used,
> the kernel fails to match the alias file at mount time (leaving
> FDEV(i).has_alias unset and allowing pinned files to allocate in that
> range) and subsequently fails to reserve the device range when requested.
> 
> Enforce that if an alias filename is specified, it must match the device
> name. Also allow specifying just '-c <device>@' as a shorthand so users
> do not have to redundantly type the device basename twice.

Do we need to add a sanity check in kernel side as well, show warning info
if device name doesn't match device alias file name?

> 
> Reported-by: Wenjie Qi <qiwenjie@xiaomi.com>
> Fixes: 8cc4e257ec20 ("mkfs.f2fs: add device aliasing feature")
> Cc: stable@vger.kernel.org
> Signed-off-by: Daeho Jeong <daehojeong@google.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

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

end of thread, other threads:[~2026-09-07  2:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-26 18:11 [PATCH] mkfs.f2fs: enforce alias_filename to match device name Daeho Jeong
2026-09-07  2:20 ` [f2fs-dev] " Chao Yu

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®