Re: [f2fs-dev] [PATCH 1/2] dump/fsck: convert encrypted file name

2016-10-25 Thread Jaegeuk Kim
Hi,

On Mon, Oct 24, 2016 at 11:47:06AM +0800, Sheng Yong wrote:
> Hi, Jaegeuk,
> 
> On 10/24/2016 10:16 AM, Sheng Yong wrote:
> > If fscrypt is enabled, we need to convert the encrypted file name before
> > printing it. So let's export convert_encrypted_name for other functions,
> > and make it returns the length of converted string.
> > This patch also changes the parameter of file_is_encrypt to f2fs_inode.
> > 
> [...]
> > -static void convert_encrypted_name(unsigned char *name, int len,
> > +int convert_encrypted_name(unsigned char *name, int len,
> > unsigned char *new, int encrypted)
> >  {
> > if (!encrypted) {
> > memcpy(new, name, len);
> > new[len] = 0;
> > -   return;
> > +   return len;
> > }
> >  
> > *new = '_';
> > -   digest_encode((const char *)name, 24, (char *)new + 1);
> > +   return digest_encode((const char *)name, 24, (char *)new + 1);
> I'm confused about the parameter "24" here. Why it is not the length of
> the cipher text?

It's just to sync with fscrypt_fname_disk_to_usr which uses 24 bytes for the
encrypted name without a key.

> 
> thanks,
> Sheng
> >  }
> [...]
> 
> 
> --
> Check out the vibrant tech community on one of the world's most 
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> ___
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

--
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive. 
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 1/2] dump/fsck: convert encrypted file name

2016-10-23 Thread Sheng Yong
Hi, Jaegeuk,

On 10/24/2016 10:16 AM, Sheng Yong wrote:
> If fscrypt is enabled, we need to convert the encrypted file name before
> printing it. So let's export convert_encrypted_name for other functions,
> and make it returns the length of converted string.
> This patch also changes the parameter of file_is_encrypt to f2fs_inode.
> 
[...]
> -static void convert_encrypted_name(unsigned char *name, int len,
> +int convert_encrypted_name(unsigned char *name, int len,
>   unsigned char *new, int encrypted)
>  {
>   if (!encrypted) {
>   memcpy(new, name, len);
>   new[len] = 0;
> - return;
> + return len;
>   }
>  
>   *new = '_';
> - digest_encode((const char *)name, 24, (char *)new + 1);
> + return digest_encode((const char *)name, 24, (char *)new + 1);
I'm confused about the parameter "24" here. Why it is not the length of
the cipher text?

thanks,
Sheng
>  }
[...]


--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH 1/2] dump/fsck: convert encrypted file name

2016-10-23 Thread Sheng Yong
If fscrypt is enabled, we need to convert the encrypted file name before
printing it. So let's export convert_encrypted_name for other functions,
and make it returns the length of converted string.
This patch also changes the parameter of file_is_encrypt to f2fs_inode.

Signed-off-by: Sheng Yong 
---
 fsck/dump.c   |  6 --
 fsck/fsck.c   | 46 --
 fsck/fsck.h   |  1 +
 fsck/mount.c  | 10 +++---
 include/f2fs_fs.h |  2 +-
 5 files changed, 45 insertions(+), 20 deletions(-)

diff --git a/fsck/dump.c b/fsck/dump.c
index befffd7..8e7c85c 100644
--- a/fsck/dump.c
+++ b/fsck/dump.c
@@ -353,9 +353,10 @@ static void dump_file(struct f2fs_sb_info *sbi, struct 
node_info *ni,
struct f2fs_inode *inode = _blk->i;
u32 imode = le32_to_cpu(inode->i_mode);
u32 namelen = le32_to_cpu(inode->i_namelen);
-   char name[255] = {0};
+   unsigned char name[F2FS_NAME_LEN + 1] = {0};
char path[1024] = {0};
char ans[255] = {0};
+   int is_encrypt = file_is_encrypt(inode);
int ret;
 
if (!S_ISREG(imode) || namelen == 0 || namelen > F2FS_NAME_LEN) {
@@ -375,7 +376,8 @@ dump:
ASSERT(ret >= 0);
 
/* make a file */
-   strncpy(name, (const char *)inode->i_name, namelen);
+   namelen = convert_encrypted_name(inode->i_name, namelen,
+   name, is_encrypt);
name[namelen] = 0;
sprintf(path, "./lost_found/%s", name);
 
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 7dd311f..d0392c3 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -426,8 +426,19 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 
nid,
if (ntype == TYPE_INODE && ftype == F2FS_FT_DIR) {
u32 len = le32_to_cpu(node_blk->i.i_namelen);
if (name && memcmp(name, node_blk->i.i_name, len)) {
-   ASSERT_MSG("mismatch name [0x%x] [%s vs. %s]",
-   nid, name, node_blk->i.i_name);
+   int is_encrypt = file_is_encrypt(_blk->i);
+   unsigned char en1[F2FS_NAME_LEN + 1];
+   unsigned char en2[F2FS_NAME_LEN + 1];
+   /* if file is encrypted, its parent must be encrypted */
+   int len1 = convert_encrypted_name(name, len, en1,
+   is_encrypt);
+   int len2 = convert_encrypted_name(node_blk->i.i_name,
+   len, en2, is_encrypt);
+   en1[len1] = '\0';
+   en2[len2] = '\0';
+   ASSERT_MSG("mismatch name [0x%x] [%s vs. %s]%s",
+   nid, en1, en2,
+   is_encrypt ? " " : "");
return -EINVAL;
}
}
@@ -607,6 +618,8 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
u32 i_links = le32_to_cpu(node_blk->i.i_links);
u64 i_size = le64_to_cpu(node_blk->i.i_size);
u64 i_blocks = le64_to_cpu(node_blk->i.i_blocks);
+   unsigned char en[F2FS_NAME_LEN + 1];
+   int namelen;
unsigned int idx = 0;
int need_fix = 0;
int ret;
@@ -727,7 +740,7 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
blkaddr,
, (i_blocks == *blk_cnt),
ftype, nid, idx, ni->version,
-   file_is_encrypt(node_blk->i.i_advise));
+   file_is_encrypt(_blk->i));
if (!ret) {
*blk_cnt = *blk_cnt + 1;
} else if (c.fix_on) {
@@ -798,16 +811,18 @@ check:
}
}
 skip_blkcnt_fix:
+   namelen = convert_encrypted_name(node_blk->i.i_name,
+   le32_to_cpu(node_blk->i.i_namelen),
+   en, file_is_encrypt(_blk->i));
+   en[namelen] = '\0';
if (ftype == F2FS_FT_ORPHAN)
DBG(1, "Orphan Inode: 0x%x [%s] i_blocks: %u\n\n",
le32_to_cpu(node_blk->footer.ino),
-   node_blk->i.i_name,
-   (u32)i_blocks);
+   en, (u32)i_blocks);
 
if (ftype == F2FS_FT_DIR) {
DBG(1, "Directory Inode: 0x%x [%s] depth: %d has %d files\n\n",
-   le32_to_cpu(node_blk->footer.ino),
-   node_blk->i.i_name,
+   le32_to_cpu(node_blk->footer.ino), en,
le32_to_cpu(node_blk->i.i_current_depth),