Bug 11652

Summary: mkfs.ext4 changes folder permissions when creating image
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Alessio Moscatello <a.m.mm.work>
Component: devtools / tool chainAssignee: Robert Yang <liezhi.yang>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: Medium+ CC: meta.mr.watcher, meta.watcher, randy.macleod
Version: 2.1.2   
Target Milestone: 2.4 M4   
Hardware: Other   
OS: Multiple   
Whiteboard: Backport to 2.3.1 & 2.2.2
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Don't know

Description Alessio Moscatello 2017-06-13 10:04:01 UTC
I'm using Yocto 2.1.1 and I've noticed that files/folders permissions are changed when creating ext4 image.

Steps to reproduce:
1) in pkg_postinst task set wanted file permissions:
---> chmod -R 521 "$D/opt/my_folder"
2) generate the rootfs image

Results:
1)my_folder has correct permissions on rootfs: I can verify it from devshell (so pseudo is correctly handling them)
2)my_folder has correct permissions in rootfs archive
3)my_folder hasn't correct permissions on rootfs ext4 image -> permissions are changed to 751


I think that the cause is in mkfs itself

see line 119 on https://github.com/tytso/e2fsprogs/blob/master/misc/create_inode.c

    inode.i_mode |= st->st_mode;


I've also opened a discussion on e2fsprogs:
https://sourceforge.net/p/e2fsprogs/discussion/7053/thread/33e8a603/#a89f


I'd like to have a feedback from Yocto community to understand if this a bug or rather a misconfiguration of my set up. Can anyone reproduce this issue?

Thanks,
Alessio
Comment 1 Alessio Moscatello 2017-06-14 07:25:17 UTC
Just an update: I've cross-checked and only folder permissions are wrong, file are correct.
It seems that mkfs.ext4 forces rwx for user permission on folders and that permissions for group and other is the one specified in the recipe.
Comment 2 Alessio Moscatello 2017-06-27 10:03:46 UTC
Hello,
I've found the rootcause in lib/ext2fs/mkdir.c, function ext2fs_mkdir:
inode for folder is being created using a default umask

 inode.i_mode = LINUX_S_IFDIR | (0777 & ~fs->umask);

this is ok when creating a filesystem from scratch, but causes permission changes when creating an image starting from a folder.

I've a quick patch to fix the issue, but I think that the best solution is to add a parameter to mkfs in order to select if using or not the default umask when using -d option as well.

BR,
Alessio