All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mkfs.ubifs: Allow root entry in device table
@ 2017-06-06 13:31 David Engraf
  2017-06-06 13:46 ` David Engraf
  0 siblings, 1 reply; 4+ messages in thread
From: David Engraf @ 2017-06-06 13:31 UTC (permalink / raw)
  To: linux-mtd; +Cc: David Engraf

When using a local root folder the permissions, user and group settings
are taken from the local folder. These permissions might be incorrect if
the folder has been created for the local user. Creating an UBIFS image
on my local system resulted in the following output on the target:

drwx------   17 1000     1000   1264 Jan  1 00:00 .
drwx------   17 1000     1000   1264 Jan  1 00:00 ..
drwxr-xr-x    2 root     root   9104 May 30  2017 bin
drwxr-xr-x    7 root     root   2760 Jan  1 00:00 dev
...

mkfs.ubifs aborts with an error message when the device table contains
a root entry. This patch allows setting the root folder permissions,
user and group to overwrite local configurations.
---
 ubifs-utils/mkfs.ubifs/devtable.c   |  8 ++++----
 ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 13 +++++++++++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/ubifs-utils/mkfs.ubifs/devtable.c b/ubifs-utils/mkfs.ubifs/devtable.c
index 3b46abc..10faaca 100644
--- a/ubifs-utils/mkfs.ubifs/devtable.c
+++ b/ubifs-utils/mkfs.ubifs/devtable.c
@@ -146,16 +146,16 @@ static int interpret_table_entry(const char *line)
 		increment, count);
 
 	len = strnlen(buf, 1024);
+	if (len == 0)
+		return err_msg("empty path");
 	if (len == 1024)
 		return err_msg("too long path");
 
-	if (!strcmp(buf, "/"))
+	if (buf[0] != '/')
 		return err_msg("device table entries require absolute paths");
-	if (buf[1] == '\0')
-		return err_msg("root directory cannot be created");
 	if (strstr(buf, "//"))
 		return err_msg("'//' cannot be used in the path");
-	if (buf[len - 1] == '/')
+	if (len > 1 && buf[len - 1] == '/')
 		return err_msg("do not put '/' at the end");
 
 	if (strstr(buf, "/./") || strstr(buf, "/../") ||
diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
index a60052d..52ed511 100644
--- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
+++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
@@ -1823,6 +1823,8 @@ static int write_data(void)
 {
 	int err;
 	mode_t mode = S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
+	struct path_htbl_element *ph_elt;
+	struct name_htbl_element *nh_elt;
 
 	if (root) {
 		err = stat(root, &root_st);
@@ -1835,6 +1837,17 @@ static int write_data(void)
 		root_st.st_mode = mode;
 	}
 
+	/*
+	 * Check for root entry and update permissions if it exists. This will
+	 * also remove the entry from the device table list.
+	 */
+	ph_elt = devtbl_find_path("/");
+	if (ph_elt) {
+		nh_elt = devtbl_find_name(ph_elt, "");
+		if (nh_elt && override_attributes(&root_st, ph_elt, nh_elt))
+			return -1;
+	}
+
 	head_flags = 0;
 
 	err = create_inum_attr(UBIFS_ROOT_INO, root);
-- 
2.11.0

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

* Re: [PATCH] mkfs.ubifs: Allow root entry in device table
  2017-06-06 13:31 [PATCH] mkfs.ubifs: Allow root entry in device table David Engraf
@ 2017-06-06 13:46 ` David Engraf
  2018-03-06  8:13   ` [PATCH RESEND] " David Engraf
  0 siblings, 1 reply; 4+ messages in thread
From: David Engraf @ 2017-06-06 13:46 UTC (permalink / raw)
  To: linux-mtd

Am 06.06.2017 um 15:31 schrieb David Engraf:
> When using a local root folder the permissions, user and group settings
> are taken from the local folder. These permissions might be incorrect if
> the folder has been created for the local user. Creating an UBIFS image
> on my local system resulted in the following output on the target:
> 
> drwx------   17 1000     1000   1264 Jan  1 00:00 .
> drwx------   17 1000     1000   1264 Jan  1 00:00 ..
> drwxr-xr-x    2 root     root   9104 May 30  2017 bin
> drwxr-xr-x    7 root     root   2760 Jan  1 00:00 dev
> ...
> 
> mkfs.ubifs aborts with an error message when the device table contains
> a root entry. This patch allows setting the root folder permissions,
> user and group to overwrite local configurations.

Signed-off-by: David Engraf <david.engraf@sysgo.com>

> ---
>   ubifs-utils/mkfs.ubifs/devtable.c   |  8 ++++----
>   ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 13 +++++++++++++
>   2 files changed, 17 insertions(+), 4 deletions(-)
> 
> diff --git a/ubifs-utils/mkfs.ubifs/devtable.c b/ubifs-utils/mkfs.ubifs/devtable.c
> index 3b46abc..10faaca 100644
> --- a/ubifs-utils/mkfs.ubifs/devtable.c
> +++ b/ubifs-utils/mkfs.ubifs/devtable.c
> @@ -146,16 +146,16 @@ static int interpret_table_entry(const char *line)
>   		increment, count);
>   
>   	len = strnlen(buf, 1024);
> +	if (len == 0)
> +		return err_msg("empty path");
>   	if (len == 1024)
>   		return err_msg("too long path");
>   
> -	if (!strcmp(buf, "/"))
> +	if (buf[0] != '/')
>   		return err_msg("device table entries require absolute paths");
> -	if (buf[1] == '\0')
> -		return err_msg("root directory cannot be created");
>   	if (strstr(buf, "//"))
>   		return err_msg("'//' cannot be used in the path");
> -	if (buf[len - 1] == '/')
> +	if (len > 1 && buf[len - 1] == '/')
>   		return err_msg("do not put '/' at the end");
>   
>   	if (strstr(buf, "/./") || strstr(buf, "/../") ||
> diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
> index a60052d..52ed511 100644
> --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
> +++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
> @@ -1823,6 +1823,8 @@ static int write_data(void)
>   {
>   	int err;
>   	mode_t mode = S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
> +	struct path_htbl_element *ph_elt;
> +	struct name_htbl_element *nh_elt;
>   
>   	if (root) {
>   		err = stat(root, &root_st);
> @@ -1835,6 +1837,17 @@ static int write_data(void)
>   		root_st.st_mode = mode;
>   	}
>   
> +	/*
> +	 * Check for root entry and update permissions if it exists. This will
> +	 * also remove the entry from the device table list.
> +	 */
> +	ph_elt = devtbl_find_path("/");
> +	if (ph_elt) {
> +		nh_elt = devtbl_find_name(ph_elt, "");
> +		if (nh_elt && override_attributes(&root_st, ph_elt, nh_elt))
> +			return -1;
> +	}
> +
>   	head_flags = 0;
>   
>   	err = create_inum_attr(UBIFS_ROOT_INO, root);
> 

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

* [PATCH RESEND] mkfs.ubifs: Allow root entry in device table
  2017-06-06 13:46 ` David Engraf
@ 2018-03-06  8:13   ` David Engraf
  2018-03-07 23:23     ` David Oberhollenzer
  0 siblings, 1 reply; 4+ messages in thread
From: David Engraf @ 2018-03-06  8:13 UTC (permalink / raw)
  To: linux-mtd; +Cc: David Engraf

When using a local root folder the permissions, user and group settings
are taken from the local folder. These permissions might be incorrect if
the folder has been created for the local user. Creating an UBIFS image
on my local system resulted in the following output on the target:

drwx------   17 1000     1000   1264 Jan  1 00:00 .
drwx------   17 1000     1000   1264 Jan  1 00:00 ..
drwxr-xr-x    2 root     root   9104 May 30  2017 bin
drwxr-xr-x    7 root     root   2760 Jan  1 00:00 dev
...

mkfs.ubifs aborts with an error message when the device table contains
a root entry. This patch allows setting the root folder permissions,
user and group to overwrite local configurations.

Signed-off-by: David Engraf <david.engraf@sysgo.com>
---
 ubifs-utils/mkfs.ubifs/devtable.c   |  8 ++++----
 ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 13 +++++++++++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/ubifs-utils/mkfs.ubifs/devtable.c b/ubifs-utils/mkfs.ubifs/devtable.c
index 3b46abc..10faaca 100644
--- a/ubifs-utils/mkfs.ubifs/devtable.c
+++ b/ubifs-utils/mkfs.ubifs/devtable.c
@@ -146,16 +146,16 @@ static int interpret_table_entry(const char *line)
 		increment, count);
 
 	len = strnlen(buf, 1024);
+	if (len == 0)
+		return err_msg("empty path");
 	if (len == 1024)
 		return err_msg("too long path");
 
-	if (!strcmp(buf, "/"))
+	if (buf[0] != '/')
 		return err_msg("device table entries require absolute paths");
-	if (buf[1] == '\0')
-		return err_msg("root directory cannot be created");
 	if (strstr(buf, "//"))
 		return err_msg("'//' cannot be used in the path");
-	if (buf[len - 1] == '/')
+	if (len > 1 && buf[len - 1] == '/')
 		return err_msg("do not put '/' at the end");
 
 	if (strstr(buf, "/./") || strstr(buf, "/../") ||
diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
index c916f48..2e18fdc 100644
--- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
+++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
@@ -1825,6 +1825,8 @@ static int write_data(void)
 {
 	int err;
 	mode_t mode = S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
+	struct path_htbl_element *ph_elt;
+	struct name_htbl_element *nh_elt;
 
 	if (root) {
 		err = stat(root, &root_st);
@@ -1839,6 +1841,17 @@ static int write_data(void)
 		root_st.st_mode = mode;
 	}
 
+	/*
+	 * Check for root entry and update permissions if it exists. This will
+	 * also remove the entry from the device table list.
+	 */
+	ph_elt = devtbl_find_path("/");
+	if (ph_elt) {
+		nh_elt = devtbl_find_name(ph_elt, "");
+		if (nh_elt && override_attributes(&root_st, ph_elt, nh_elt))
+			return -1;
+	}
+
 	head_flags = 0;
 
 	err = create_inum_attr(UBIFS_ROOT_INO, root);
-- 
2.14.1

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

* Re: [PATCH RESEND] mkfs.ubifs: Allow root entry in device table
  2018-03-06  8:13   ` [PATCH RESEND] " David Engraf
@ 2018-03-07 23:23     ` David Oberhollenzer
  0 siblings, 0 replies; 4+ messages in thread
From: David Oberhollenzer @ 2018-03-07 23:23 UTC (permalink / raw)
  To: David Engraf, linux-mtd

Applied to mtd-utils.git

Thanks,

David

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

end of thread, other threads:[~2018-03-07 23:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-06 13:31 [PATCH] mkfs.ubifs: Allow root entry in device table David Engraf
2017-06-06 13:46 ` David Engraf
2018-03-06  8:13   ` [PATCH RESEND] " David Engraf
2018-03-07 23:23     ` David Oberhollenzer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.