overlayfs: copyup security inode field
Subsystems (2)
PATCH 1/1 overlayfs: copyup security inode field
SELinux (and maybe other security frameworks) relies on inode->i_security field to perform audit of security contexts.
I think this field must be the same as the underlying filesystem, instead of creating new fresh one at ovl_new_inode() which give an UNLABELED sid.
The issue rised when certain process (for instance Zygote) fails to perform some actions (for instance getxattr) on Android using SEAndroid and overlyafs with empty uppdir mounted on /system, but it succeeds in case there is not overlayfs.
--- fs/overlayfs/overlayfs.h | 3 +++ 1 file changed, 3 insertions(+)
fs/overlayfs/overlayfs.h +3 -0
@@ -60,6 +60,9 @@ static inline void ovl_copyattr(struct inode *from, struct inode *to) { to->i_uid = from->i_uid; to->i_gid = from->i_gid; +#ifdef CONFIG_SECURITY + to->i_security = from->i_security; +#endif }/* dir.c */
Signature · 1 line
1.7.9.5
Zakaria ElQotbi:
Quoted 2 lines
I think this field must be the same as the underlying filesystem, instead of creating new fresh one at
ovl_new_inode()which give an UNLABELED sid.
When two inodes refers to a single inode_security_struct (i_security), won't it cause a "double free" problem?
J. R. Okajima
Quoted 4 lines · J. R. Okajima
When two inodes refers to a single
inode_security_struct(i_security), won't it cause a "double free" problem?
Thanks for your feedback. Below another patch that set the inode_security_struct correctly with help of security API.
Your review are welcome.
Best Regards,
Zakaria ElQotbi
Quoted 1 line
From
934602df4e9d26e77cf04f8514079c02fe592d4aMon Sep 17 00:00:00 2001
From: Zakaria ElQotbi <[email protected]>
Date: Wed, 19 Mar 2014 11:59:09 +0100
Subject: [PATCH] overlayfs: copyup security inode field
SELinux (and maybe other security frameworks) relies on inode->i_security field to perform audit of security contexts.
I think this field must be the same as the underlying filesystem, instead of creating new fresh one at ovl_new_inode() which give an UNLABELED sid.
The issue rised when certain process (for instance Zygote) fails to perform some actions (for instance getxattr) on Android using SEAndroid and overlyafs with empty uppdir mounted on /system, but it succeeds in case there is not overlayfs.
--- fs/overlayfs/inode.c | 25 +++++++++++++++++++++++++ fs/overlayfs/overlayfs.h | 7 ++----- 2 files changed, 27 insertions(+), 5 deletions(-)
fs/overlayfs/inode.c +25 -0
@@ -11,6 +11,7 @@#include <linux/slab.h> #include <linux/xattr.h> #include "overlayfs.h" +#include <linux/security.h> int ovl_setattr (struct dentry *dentry,struct iattr *attr) {
@@ -332,6 +333,30 @@ static const struct inode_operations ovl_symlink_inode_operations = { .removexattr = ovl_removexattr, }; +void ovl_copyattr (struct inode *from,struct inode *to) +{ +#ifdef CONFIG_SECURITY +void *secctx; +size_t ctxlen; +int err =-1 ; + + err =security_inode_getsecctx (from, &secctx, &ctxlen); +if (!err) { +/* +* replace the fresh inode_security_struct because it should be +* the same as the real underlying inode. +*/ + err =security_inode_notifysecctx (to, secctx, ctxlen); +security_release_secctx (secctx, ctxlen); + } +if (err) { +WARN (1 ,"cannot set security context err:%d \n" , err); + } +#endif + to->i_uid = from->i_uid; + to->i_gid = from->i_gid; +} +struct inode *ovl_new_inode (struct super_block *sb,umode_t mode,struct ovl_entry *oe) {
fs/overlayfs/overlayfs.h +2 -5
@@ -56,11 +56,8 @@ int ovl_removexattr(struct dentry *dentry, const char *name);struct inode *ovl_new_inode (struct super_block *sb,umode_t mode,struct ovl_entry *oe); -static inline void ovl_copyattr (struct inode *from,struct inode *to) -{ - to->i_uid = from->i_uid; - to->i_gid = from->i_gid; -} + +void ovl_copyattr (struct inode *from,struct inode *to);/* dir.c */ extern const struct inode_operations ovl_dir_inode_operations;
Signature · 1 line
1.7.9.5
Zakaria ElQotbi:
Quoted 2 lines
Thanks for your feedback. Below another patch that set the
inode_security_structcorrectly with help of security API.
I don't know much about LSM, but don't we need to acquire i_mutex to get/set (actually notify) i_security?
J. R. Okajima
I omitted the lock because i assumed that is wasn't necessary at inode creation, but the ovl_copyattr() can be called from elsewhere.
Below yet another patch.
Thanks,
Zakaria
---
Quoted 1 line
From
33ca41ec2a1b9e1ff295fb4d99be958b0c7a12dbMon Sep 17 00:00:00 2001
From: Zakaria ElQotbi <[email protected]>
Date: Wed, 19 Mar 2014 11:59:09 +0100
Subject: [PATCH] overlayfs: copyup security inode field
SELinux (and maybe other security frameworks) relies on inode->i_security field to perform audit of security contexts.
I think this field must be the same as the underlying filesystem, instead of creating new fresh one at ovl_new_inode() which give an UNLABELED sid.
The issue rised when certain process (for instance Zygote) fails to perform some actions (for instance getxattr) on Android using SEAndroid and overlyafs with empty uppdir mounted on /system, but it succeeds in case there is not overlayfs.
--- fs/overlayfs/inode.c | 27 +++++++++++++++++++++++++++ fs/overlayfs/overlayfs.h | 7 ++----- 2 files changed, 29 insertions(+), 5 deletions(-)
fs/overlayfs/inode.c +27 -0
@@ -11,6 +11,7 @@#include <linux/slab.h> #include <linux/xattr.h> #include "overlayfs.h" +#include <linux/security.h> int ovl_setattr (struct dentry *dentry,struct iattr *attr) {
@@ -332,6 +333,32 @@ static const struct inode_operations ovl_symlink_inode_operations = { .removexattr = ovl_removexattr, }; +void ovl_copyattr (struct inode *from,struct inode *to) +{ +#ifdef CONFIG_SECURITY +void *secctx; +size_t ctxlen; +int err =-1 ; + + err =security_inode_getsecctx (from, &secctx, &ctxlen); +if (!err) { +/* +* replace the fresh inode_security_struct because it should be +* the same as the real underlying inode. +*/ +mutex_lock (&to->i_mutex); + err =security_inode_notifysecctx (to, secctx, ctxlen); +mutex_unlock (&to->i_mutex); +security_release_secctx (secctx, ctxlen); + } +if (err) +WARN (1 ,"cannot copy up security context err:%d\n" , err); + +#endif + to->i_uid = from->i_uid; + to->i_gid = from->i_gid; +} +struct inode *ovl_new_inode (struct super_block *sb,umode_t mode,struct ovl_entry *oe) {
fs/overlayfs/overlayfs.h +2 -5
@@ -56,11 +56,8 @@ int ovl_removexattr(struct dentry *dentry, const char *name);struct inode *ovl_new_inode (struct super_block *sb,umode_t mode,struct ovl_entry *oe); -static inline void ovl_copyattr (struct inode *from,struct inode *to) -{ - to->i_uid = from->i_uid; - to->i_gid = from->i_gid; -} + +void ovl_copyattr (struct inode *from,struct inode *to);/* dir.c */ extern const struct inode_operations ovl_dir_inode_operations;
Signature · 1 line
1.7.9.5