Skip to contentSkip to conversation

dump/fsck: convert encrypted file name

PATCH In review Sheng Yong 2 participants 4 messages Oct 24, 2016 – Oct 26, 2016

lore
Share & tools
lore

Sheng Yong

author
#0 lore raw

PATCH 1/2 dump/fsck: convert encrypted file name

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.

---
 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(-)
fsck/dump.c +4 -2
index befffd7..8e7c85c 100644
@@ -353,9 +353,10 @@ static void dump_file(struct f2fs_sb_info *sbi, struct node_info *ni,
 	struct f2fs_inode *inode = &node_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);
 
fsck/fsck.c +32 -14

115 lines not on this page · raw message

fsck/fsck.h +1 -0
index 438d29b..0aab55e 100644
@@ -130,6 +130,7 @@ extern int fsck_chk_dentry_blk(struct f2fs_sb_info *, u32, struct child_info *,
 int fsck_chk_inline_dentries(struct f2fs_sb_info *, struct f2fs_node *,
 		struct child_info *);
 int fsck_chk_meta(struct f2fs_sb_info *sbi);
+int convert_encrypted_name(unsigned char *, int, unsigned char *, int);
 
 extern void update_free_segments(struct f2fs_sb_info *);
 void print_cp_state(u32);
fsck/mount.c +7 -3
index f343718..ca7f6dd 100644
@@ -37,12 +37,17 @@ void update_free_segments(struct f2fs_sb_info *sbi)
 
 void print_inode_info(struct f2fs_inode *inode, int name)
 {
+	unsigned char en[F2FS_NAME_LEN + 1];
 	unsigned int i = 0;
 	int namelen = le32_to_cpu(inode->i_namelen);
+	int is_encrypt = file_is_encrypt(inode);
 
+	namelen = convert_encrypted_name(inode->i_name, namelen, en, is_encrypt);
+	en[namelen] = '\0';
 	if (name && namelen) {
 		inode->i_name[namelen] = '\0';
-		MSG(0, " - File name         : %s\n", inode->i_name);
+		MSG(0, " - File name         : %s%s\n", en,
+				is_encrypt ? " <encrypted>" : "");
 		setlocale(LC_ALL, "");
 		MSG(0, " - File size         : %'llu (bytes)\n",
 				le64_to_cpu(inode->i_size));
@@ -74,8 +79,7 @@ void print_inode_info(struct f2fs_inode *inode, int name)
 
 	if (namelen) {
 		DISP_u32(inode, i_namelen);
-		inode->i_name[namelen] = '\0';
-		DISP_utf(inode, i_name);
+		printf("%-30s\t\t[%s]\n", "i_name", en);
 	}
 
 	printf("i_ext: fofs:%x blkaddr:%x len:%x\n",
include/f2fs_fs.h +1 -1
index bfe9b3f..56cdcab 100644
@@ -606,7 +606,7 @@ struct f2fs_extent {
 #define FADVISE_LOST_PINO_BIT  0x02
 #define FADVISE_ENCRYPT_BIT    0x04
 
-#define file_is_encrypt(i_advise)      ((i_advise) & FADVISE_ENCRYPT_BIT)
+#define file_is_encrypt(fi)      ((fi)->i_advise & FADVISE_ENCRYPT_BIT)
 
 struct f2fs_inode {
 	__le16 i_mode;			/* file mode */
Signature · 6 lines
2.10.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
author
#1 lore raw

PATCH 2/2 fsck.f2fs: do not check the first seg in a sec in find_next_free_block

The first segment is already checked, so there is no need to check it again if we want to make sure the whole section is freed.

---
 fsck/mount.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fsck/mount.c +1 -1
index ca7f6dd..0a47bf7 100644
@@ -1573,7 +1573,7 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
 			struct seg_entry *se2;
 			unsigned int i;
 
-			for (i = 0; i < sbi->segs_per_sec; i++) {
+			for (i = 1; i < sbi->segs_per_sec; i++) {
 				se2 = get_seg_entry(sbi, segno + i);
 				if (se2->valid_blocks)
 					break;
Signature · 6 lines
2.10.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
author
#2 lore raw
In reply to Sheng Yong

Hi, Jaegeuk,

Quoted 5 lines · 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.

[...]

Quoted 4 lines
fsck/fsck.c +1 -1
-static void convert_encrypted_name(unsigned char *name, int len,
+int convert_encrypted_name(unsigned char *name, int len,
 				unsigned char *new, int encrypted)
 {

fsck/fsck.c static int digest_encode(const char *src, int len, char *dst) · line 1037

Quoted 10 lines
fsck/fsck.c +2 -2
 	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

Quoted 1 line

}

[...]

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

#3 lore raw

Hi,

Quoted 20 lines · Sheng Yong

Hi, Jaegeuk,

Quoted 5 lines · 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.

[...]

Quoted 11 lines
fsck/fsck.c +2 -2
-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;
 	}
Quoted 5 lines

fsck/fsck.c static int digest_encode(const char *src, int len, char *dst) · line 1037

Quoted 3 lines
fsck/fsck.c +1 -1
 	*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.

Quoted 7 lines

thanks,
Sheng

Quoted 1 line

}

[...]

Quoted 7 lines

------------------------------------------------------------------------------
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 [email protected]
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