diff mbox series

[2/2] tune2fs: Warn if page size != blocksize when enabling encrypt

Message ID 20190821131813.9456-2-lczerner@redhat.com
State New
Headers show
Series [1/2] mke2fs: Warn if page size != blocksize when ecnrypt is enabled | expand

Commit Message

Lukas Czerner Aug. 21, 2019, 1:18 p.m. UTC
With encrypt feature enabled the file system block size must match
system page size. Currently tune2fs will not complain at all when we try
to enable encrypt on a file system that does not satisfy this
requirement for the system. Add a warning for this case.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 misc/tune2fs.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

Comments

Eric Sandeen Aug. 21, 2019, 3:17 p.m. UTC | #1
On 8/21/19 8:18 AM, Lukas Czerner wrote:
> With encrypt feature enabled the file system block size must match
> system page size. Currently tune2fs will not complain at all when we try
> to enable encrypt on a file system that does not satisfy this
> requirement for the system. Add a warning for this case.
> 
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> ---
>  misc/tune2fs.c | 38 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
> 
> diff --git a/misc/tune2fs.c b/misc/tune2fs.c
> index 7d2d38d7..26b1b1d0 100644
> --- a/misc/tune2fs.c
> +++ b/misc/tune2fs.c
> @@ -130,6 +130,8 @@ void do_findfs(int argc, char **argv);
>  int journal_enable_debug = -1;
>  #endif
>  
> +static int sys_page_size = 4096;
> +
>  static void usage(void)
>  {
>  	fprintf(stderr,
> @@ -1407,6 +1409,29 @@ mmp_error:
>  			      stderr);
>  			return 1;
>  		}
> +
> +		/*
> +		 * When encrypt feature is enabled, the file system blocksize
> +		 * needs to match system page size otherwise the file system
> +		 * won't mount.
> +		 */
> +		if (fs->blocksize != sys_page_size) {
> +			if (!f_flag) {
> +				com_err(program_name, 0,
> +					_("Block size (%dB) does not match "
> +					  "system page size (%dB). File "
> +					  "system won't be usable on this "
> +					  "system"),

I wonder if this message should explicitly mention the encryption option, right
now it doesn't give a lot of context as to why this is being printed.

Perhaps "Encryption feature requested, but block size (%dB) does not match ...?"

-Eric

> +					fs->blocksize, sys_page_size);
> +				proceed_question(-1);
> +			}
> +			fprintf(stderr,_("Warning: Encrypt feature enabled, "
> +					 "but block size (%dB) does not match "
> +					 "system page size (%dB), forced to "
> +					 "cointinue\n"),
> +				fs->blocksize, sys_page_size);
> +		}
> +
>  		fs->super->s_encrypt_algos[0] =
>  			EXT4_ENCRYPTION_MODE_AES_256_XTS;
>  		fs->super->s_encrypt_algos[1] =
> @@ -2844,6 +2869,7 @@ int main(int argc, char **argv)
>  int tune2fs_main(int argc, char **argv)
>  #endif  /* BUILD_AS_LIB */
>  {
> +	long sysval;
>  	errcode_t retval;
>  	ext2_filsys fs;
>  	struct ext2_super_block *sb;
> @@ -2879,6 +2905,18 @@ int tune2fs_main(int argc, char **argv)
>  #endif
>  		io_ptr = unix_io_manager;
>  
> +	/* Determine the system page size if possible */
> +#ifdef HAVE_SYSCONF
> +#if (!defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE))
> +#define _SC_PAGESIZE _SC_PAGE_SIZE
> +#endif
> +#ifdef _SC_PAGESIZE
> +	sysval = sysconf(_SC_PAGESIZE);
> +	if (sysval > 0)
> +		sys_page_size = sysval;
> +#endif /* _SC_PAGESIZE */
> +#endif /* HAVE_SYSCONF */
> +
>  retry_open:
>  	if ((open_flag & EXT2_FLAG_RW) == 0 || f_flag)
>  		open_flag |= EXT2_FLAG_SKIP_MMP;
>
Lukas Czerner Aug. 22, 2019, 9:48 a.m. UTC | #2
On Wed, Aug 21, 2019 at 10:17:09AM -0500, Eric Sandeen wrote:
> 
> 
> On 8/21/19 8:18 AM, Lukas Czerner wrote:
> > With encrypt feature enabled the file system block size must match
> > system page size. Currently tune2fs will not complain at all when we try
> > to enable encrypt on a file system that does not satisfy this
> > requirement for the system. Add a warning for this case.
> > 
> > Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> > ---
> >  misc/tune2fs.c | 38 ++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 38 insertions(+)
> > 
> > diff --git a/misc/tune2fs.c b/misc/tune2fs.c
> > index 7d2d38d7..26b1b1d0 100644
> > --- a/misc/tune2fs.c
> > +++ b/misc/tune2fs.c
> > @@ -130,6 +130,8 @@ void do_findfs(int argc, char **argv);
> >  int journal_enable_debug = -1;
> >  #endif
> >  
> > +static int sys_page_size = 4096;
> > +
> >  static void usage(void)
> >  {
> >  	fprintf(stderr,
> > @@ -1407,6 +1409,29 @@ mmp_error:
> >  			      stderr);
> >  			return 1;
> >  		}
> > +
> > +		/*
> > +		 * When encrypt feature is enabled, the file system blocksize
> > +		 * needs to match system page size otherwise the file system
> > +		 * won't mount.
> > +		 */
> > +		if (fs->blocksize != sys_page_size) {
> > +			if (!f_flag) {
> > +				com_err(program_name, 0,
> > +					_("Block size (%dB) does not match "
> > +					  "system page size (%dB). File "
> > +					  "system won't be usable on this "
> > +					  "system"),
> 
> I wonder if this message should explicitly mention the encryption option, right
> now it doesn't give a lot of context as to why this is being printed.

Ah right, I suppose people can change more things at once. I'll get it
fixed.

Thanks!
-Lukas

> 
> Perhaps "Encryption feature requested, but block size (%dB) does not match ...?"
> 
> -Eric
> 
> > +					fs->blocksize, sys_page_size);
> > +				proceed_question(-1);
> > +			}
> > +			fprintf(stderr,_("Warning: Encrypt feature enabled, "
> > +					 "but block size (%dB) does not match "
> > +					 "system page size (%dB), forced to "
> > +					 "cointinue\n"),
> > +				fs->blocksize, sys_page_size);
> > +		}
> > +
> >  		fs->super->s_encrypt_algos[0] =
> >  			EXT4_ENCRYPTION_MODE_AES_256_XTS;
> >  		fs->super->s_encrypt_algos[1] =
> > @@ -2844,6 +2869,7 @@ int main(int argc, char **argv)
> >  int tune2fs_main(int argc, char **argv)
> >  #endif  /* BUILD_AS_LIB */
> >  {
> > +	long sysval;
> >  	errcode_t retval;
> >  	ext2_filsys fs;
> >  	struct ext2_super_block *sb;
> > @@ -2879,6 +2905,18 @@ int tune2fs_main(int argc, char **argv)
> >  #endif
> >  		io_ptr = unix_io_manager;
> >  
> > +	/* Determine the system page size if possible */
> > +#ifdef HAVE_SYSCONF
> > +#if (!defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE))
> > +#define _SC_PAGESIZE _SC_PAGE_SIZE
> > +#endif
> > +#ifdef _SC_PAGESIZE
> > +	sysval = sysconf(_SC_PAGESIZE);
> > +	if (sysval > 0)
> > +		sys_page_size = sysval;
> > +#endif /* _SC_PAGESIZE */
> > +#endif /* HAVE_SYSCONF */
> > +
> >  retry_open:
> >  	if ((open_flag & EXT2_FLAG_RW) == 0 || f_flag)
> >  		open_flag |= EXT2_FLAG_SKIP_MMP;
> >
diff mbox series

Patch

diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 7d2d38d7..26b1b1d0 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -130,6 +130,8 @@  void do_findfs(int argc, char **argv);
 int journal_enable_debug = -1;
 #endif
 
+static int sys_page_size = 4096;
+
 static void usage(void)
 {
 	fprintf(stderr,
@@ -1407,6 +1409,29 @@  mmp_error:
 			      stderr);
 			return 1;
 		}
+
+		/*
+		 * When encrypt feature is enabled, the file system blocksize
+		 * needs to match system page size otherwise the file system
+		 * won't mount.
+		 */
+		if (fs->blocksize != sys_page_size) {
+			if (!f_flag) {
+				com_err(program_name, 0,
+					_("Block size (%dB) does not match "
+					  "system page size (%dB). File "
+					  "system won't be usable on this "
+					  "system"),
+					fs->blocksize, sys_page_size);
+				proceed_question(-1);
+			}
+			fprintf(stderr,_("Warning: Encrypt feature enabled, "
+					 "but block size (%dB) does not match "
+					 "system page size (%dB), forced to "
+					 "cointinue\n"),
+				fs->blocksize, sys_page_size);
+		}
+
 		fs->super->s_encrypt_algos[0] =
 			EXT4_ENCRYPTION_MODE_AES_256_XTS;
 		fs->super->s_encrypt_algos[1] =
@@ -2844,6 +2869,7 @@  int main(int argc, char **argv)
 int tune2fs_main(int argc, char **argv)
 #endif  /* BUILD_AS_LIB */
 {
+	long sysval;
 	errcode_t retval;
 	ext2_filsys fs;
 	struct ext2_super_block *sb;
@@ -2879,6 +2905,18 @@  int tune2fs_main(int argc, char **argv)
 #endif
 		io_ptr = unix_io_manager;
 
+	/* Determine the system page size if possible */
+#ifdef HAVE_SYSCONF
+#if (!defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE))
+#define _SC_PAGESIZE _SC_PAGE_SIZE
+#endif
+#ifdef _SC_PAGESIZE
+	sysval = sysconf(_SC_PAGESIZE);
+	if (sysval > 0)
+		sys_page_size = sysval;
+#endif /* _SC_PAGESIZE */
+#endif /* HAVE_SYSCONF */
+
 retry_open:
 	if ((open_flag & EXT2_FLAG_RW) == 0 || f_flag)
 		open_flag |= EXT2_FLAG_SKIP_MMP;