Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs: reject unknown mount options early
@ 2023-09-27  1:13 Qu Wenruo
  2023-09-27 15:32 ` David Sterba
  2023-09-27 22:56 ` Anand Jain
  0 siblings, 2 replies; 5+ messages in thread
From: Qu Wenruo @ 2023-09-27  1:13 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Anand Jain

[BUG]
The following script would allow invalid mount options to be specified
(although such invalid options would just be ignored):

 # mkfs.btrfs -f $dev
 # mount $dev $mnt1		<<< Successful mount expected
 # mount $dev $mnt2 -o junk	<<< Failed mount expected
 # echo $?
 0

[CAUSE]
For the 2nd mount, since the fs is already mounted, we won't go through
open_ctree() thus no btrfs_parse_options(), but only through
btrfs_parse_subvol_options().

However we do not treat unrecognized options from valid but irrelevant
options, thus those invalid options would just be ignored by
btrfs_parse_subvol_options().

[FIX]
Add the handling for Opt_error to handle invalid options and error out,
while still ignore other valid options inside
btrfs_parse_subvol_options().

Reported-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/super.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 5c6054f0552b..574fcff0822f 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -911,6 +911,10 @@ static int btrfs_parse_subvol_options(const char *options, char **subvol_name,
 
 			*subvol_objectid = subvolid;
 			break;
+		case Opt_err:
+			btrfs_err(NULL, "unrecognized mount option '%s'", p);
+			error = -EINVAL;
+			goto out;
 		default:
 			break;
 		}
-- 
2.42.0


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

end of thread, other threads:[~2023-09-29 14:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-27  1:13 [PATCH] btrfs: reject unknown mount options early Qu Wenruo
2023-09-27 15:32 ` David Sterba
2023-09-27 22:56 ` Anand Jain
2023-09-27 23:12   ` Qu Wenruo
2023-09-29 14:13     ` David Sterba

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