[PATCH 2/2] mount: -T OTHERTAB support

walter harms wharms at bfs.de
Wed Mar 11 09:21:26 UTC 2015



Am 11.03.2015 06:35, schrieb Isaac Dunham:
> +0 bytes disabled, +56 enabled when DESKTOP is enabled (glibc/i386):
> function                                             old     new   delta
> .rodata                                           144949  144971     +22
> packed_usage                                       30236   30256     +20
> mount_main                                          1200    1214     +14
> ------------------------------------------------------------------------------
> (add/remove: 0/0 grow/shrink: 3/0 up/down: 56/0)               Total: 56 bytes
>    text	   data	    bss	    dec	    hex	filename
>  757557	   2068	   9044	 768669	  bba9d	busybox_old
>  757593	   2068	   9044	 768705	  bbac1	busybox_unstripped
> 
> Making fstabname always char* was tidier than the alternatives.
> Should be +47 bytes without DESKTOP.
> ---
>  util-linux/mount.c | 22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/util-linux/mount.c b/util-linux/mount.c
> index 1e6a2c8..6e62882 100644
> --- a/util-linux/mount.c
> +++ b/util-linux/mount.c
> @@ -105,6 +105,12 @@
>  //config:	help
>  //config:	  Support mount all and looking for files in /etc/fstab.
>  //config:
> +//config:config FEATURE_MOUNT_OTHERTAB
> +//config:	depends on FEATURE_MOUNT_FSTAB
> +//config:	bool "Support -T <alt_fstab>"
> +//config:	default n
> +//config:	help
> +//config:	  Support mount -T (specifying an alternate fstab)
>  //usage:#define mount_trivial_usage
>  //usage:       "[OPTIONS] [-o OPTS] DEVICE NODE"
>  //usage:#define mount_full_usage "\n\n"
> @@ -131,6 +137,9 @@
>  //usage:     "\n	-r		Read-only mount"
>  //usage:     "\n	-w		Read-write mount (default)"
>  //usage:     "\n	-t FSTYPE[,...]	Filesystem type(s)"
> +//usage:	IF_FEATURE_MOUNT_OTHERTAB(
> +//usage:     "\n	-T FSTAB	Read FSTAB instead of /etc/fstab"
> +//usage:	)
>  //usage:     "\n	-O OPT		Mount only filesystems with option OPT (-a only)"
>  //usage:     "\n-o OPT:"
>  //usage:	IF_FEATURE_MOUNT_LOOP(
> @@ -255,7 +264,7 @@ enum {
>  };
>  
>  
> -#define OPTION_STR "o:t:rwanfvsiO:"
> +#define OPTION_STR "o:t:rwanfvsiO:" IF_FEATURE_MOUNT_OTHERTAB("T:")
>  enum {
>  	OPT_o = (1 << 0),
>  	OPT_t = (1 << 1),
> @@ -268,6 +277,7 @@ enum {
>  	OPT_s = (1 << 8),
>  	OPT_i = (1 << 9),
>  	OPT_O = (1 << 10),
> +	OPT_T = (1 << 11),
>  };
>  
>  #if ENABLE_FEATURE_MTAB_SUPPORT
> @@ -2122,7 +2132,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
>  	char *O_optmatch = NULL;
>  	char *storage_path;
>  	llist_t *lst_o = NULL;
> -	const char *fstabname;
> +	char *fstabname = (char*)"/etc/fstab";

i am curious why (char *) ?

re
 wh


>  	FILE *fstab;
>  	int i, j;
>  	int rc = EXIT_SUCCESS;
> @@ -2149,12 +2159,17 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
>  	// Max 2 params; -o is a list, -v is a counter
>  	opt_complementary = "?2o::" IF_FEATURE_MOUNT_VERBOSE("vv");
>  	opt = getopt32(argv, OPTION_STR, &lst_o, &fstype, &O_optmatch
> +			IF_FEATURE_MOUNT_OTHERTAB(, &fstabname)
>  			IF_FEATURE_MOUNT_VERBOSE(, &verbose));
>  	while (lst_o) append_mount_options(&cmdopts, llist_pop(&lst_o)); // -o
>  	if (opt & OPT_r) append_mount_options(&cmdopts, "ro"); // -r
>  	if (opt & OPT_w) append_mount_options(&cmdopts, "rw"); // -w
>  	argv += optind;
>  
> +	// A malicious user could overmount /usr without this.
> +	if (ENABLE_FEATURE_MOUNT_OTHERTAB && nonroot)
> +		fstabname = (char*)"/etc/fstab";
> +
>  	// If we have no arguments, show currently mounted filesystems
>  	if (!argv[0]) {
>  		if (!(opt & OPT_a)) {
> @@ -2217,12 +2232,11 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
>  	}
>  
>  	// Open either fstab or mtab
> -	fstabname = "/etc/fstab";
>  	if (cmdopt_flags & MS_REMOUNT) {
>  		// WARNING. I am not sure this matches util-linux's
>  		// behavior. It's possible util-linux does not
>  		// take -o opts from mtab (takes only mount source).
> -		fstabname = bb_path_mtab_file;
> +		fstabname = (char*)bb_path_mtab_file;
>  	}
>  	fstab = setmntent(fstabname, "r");
>  	if (!fstab)


More information about the busybox mailing list