Skip to contentSkip to conversation

mkfs.ubifs: Also encrypt multi linked files

PATCH In review Christian Eggers 2 participants 2 messages Jan 6, 2020 – Jan 8, 2020 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs.ubifs: Also encrypt multi linked files

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.

---
 ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +9 -4
index 4247270..519c982 100644
@@ -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();

--
2.16.4

________________________________
[http://assets.arri.com/media/sign/2019-12-13a-ARRI-E-mail-Signatur-Parkstadt.jpg] <https://www.google.com/maps/place/Herbert-Bayer-Stra%C3%9Fe+10,+80807+M%C3%BCnchen/data=!4m2!3m1!1s0x479e74379489f045:0x4bbf0c7a9e893d66?sa=X&ved=2ahUKEwjjvdSlh8TmAhWIp4sKHe3vDlQQ8gEwAHoECAsQAQ>

Get all the latest information from www.arri.com<https://www.arri.com/>, Facebook<https://www.facebook.com/TeamARRI>, Twitter<https://twitter.com/ARRIChannel>, Instagram<https://instagram.com/arri> and YouTube<https://www.youtube.com/user/ARRIChannel>.

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: M�nchen - Registergericht: Amtsgericht M�nchen - Handelsregisternummer: HRA 57918 Pers�nlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: M�nchen - Registergericht: Amtsgericht M�nchen - Handelsregisternummer: HRB 54477 Gesch�ftsf�hrer: Dr. Michael Neuh�user; Stephan Schenk; Walter Trauninger; Markus Zeiler

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#1 lore raw
Quoted 9 lines · Christian Eggers

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!

Quoted 38 lines
---
 ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +8 -3
index 4247270..519c982 100644
@@ -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;

ubifs-utils/mkfs.ubifs/mkfs.ubifs.c static int write_data(void) · line 2298

Quoted 5 lines
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +1 -1
@@ -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.

Signature · 6 lines
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/