diff mbox series

mkfs.ubifs: Also encrypt multi linked files

Message ID 20200106192815.8902-1-ceggers@arri.de
State New
Delegated to: David Oberhollenzer
Headers show
Series mkfs.ubifs: Also encrypt multi linked files | expand

Commit Message

Christian Eggers Jan. 6, 2020, 7:28 p.m. UTC
Up to now, no fscrypt context has been passed when calling add_non_dir()
from add_multi_linked_files(). In consequence, files with multiple links
were not encrypted all.

The Linux ubifs file system detects this situation (file not encrypted,
but parent directory is) and refuses to open such files. Nevertheless,
these files are stored unencrypted in flash and could be accessed by
reading directly from the flash.

Signed-off-by: Christian Eggers <ceggers@arri.de>
---
 ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

--
2.16.4

Comments

Richard Weinberger Jan. 8, 2020, 10:26 p.m. UTC | #1
On Mon, Jan 6, 2020 at 8:28 PM Christian Eggers <ceggers@arri.de> wrote:
>
> Up to now, no fscrypt context has been passed when calling add_non_dir()
> from add_multi_linked_files(). In consequence, files with multiple links
> were not encrypted all.
>
> The Linux ubifs file system detects this situation (file not encrypted,
> but parent directory is) and refuses to open such files. Nevertheless,
> these files are stored unencrypted in flash and could be accessed by
> reading directly from the flash.

Thanks for pointing this out!

> Signed-off-by: Christian Eggers <ceggers@arri.de>
> ---
>  ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
> index 4247270..519c982 100644
> --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
> +++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
> @@ -2228,7 +2228,7 @@ out_free:
>  /**
>   * add_multi_linked_files - write all the files for which we counted links.
>   */
> -static int add_multi_linked_files(void)
> +static int add_multi_linked_files(struct fscrypt_context *fctx)
>  {
>         int i, err;
>
> @@ -2237,11 +2237,16 @@ static int add_multi_linked_files(void)
>                 unsigned char type = 0;
>
>                 for (im = hash_table[i]; im; im = im->next) {
> +                       struct fscrypt_context *new_fctx = inherit_fscrypt_context(fctx);
> +
>                         dbg_msg(2, "%s", im->path_name);
>                         err = add_non_dir(im->path_name, &im->use_inum,
> -                                         im->use_nlink, &type, &im->st, NULL);
> -                       if (err)
> +                                         im->use_nlink, &type, &im->st, new_fctx);
> +                       if (err) {
> +                               free_fscrypt_context(new_fctx);
>                                 return err;
> +                       }
> +                       free_fscrypt_context(new_fctx);
>                 }
>         }
>         return 0;
> @@ -2290,7 +2295,7 @@ static int write_data(void)
>         err = add_directory(root, UBIFS_ROOT_INO, &root_st, !!root, root_fctx);
>         if (err)
>                 return err;
> -       err = add_multi_linked_files();
> +       err = add_multi_linked_files(root_fctx);

Hmm, maybe I don't read the patch correctly but doesn't this
always inherit the the context from root?

This may work by chance right now but AFAICT the fscrypt model wants us
to inherit from the parent directory.
diff mbox series

Patch

diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
index 4247270..519c982 100644
--- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
+++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
@@ -2228,7 +2228,7 @@  out_free:
 /**
  * add_multi_linked_files - write all the files for which we counted links.
  */
-static int add_multi_linked_files(void)
+static int add_multi_linked_files(struct fscrypt_context *fctx)
 {
        int i, err;

@@ -2237,11 +2237,16 @@  static int add_multi_linked_files(void)
                unsigned char type = 0;

                for (im = hash_table[i]; im; im = im->next) {
+                       struct fscrypt_context *new_fctx = inherit_fscrypt_context(fctx);
+
                        dbg_msg(2, "%s", im->path_name);
                        err = add_non_dir(im->path_name, &im->use_inum,
-                                         im->use_nlink, &type, &im->st, NULL);
-                       if (err)
+                                         im->use_nlink, &type, &im->st, new_fctx);
+                       if (err) {
+                               free_fscrypt_context(new_fctx);
                                return err;
+                       }
+                       free_fscrypt_context(new_fctx);
                }
        }
        return 0;
@@ -2290,7 +2295,7 @@  static int write_data(void)
        err = add_directory(root, UBIFS_ROOT_INO, &root_st, !!root, root_fctx);
        if (err)
                return err;
-       err = add_multi_linked_files();
+       err = add_multi_linked_files(root_fctx);
        if (err)
                return err;
        return flush_nodes();