From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758192AbbJ2Wu2 (ORCPT ); Thu, 29 Oct 2015 18:50:28 -0400 Received: from smtp106.biz.mail.bf1.yahoo.com ([98.139.244.54]:28764 "EHLO smtp106.biz.mail.bf1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758177AbbJ2WuX (ORCPT ); Thu, 29 Oct 2015 18:50:23 -0400 X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: XzlDY4sVM1ljHqZRODEuqGaJ5b729BIgZOFskAVJlI.APhG 3QCByOXzKY27fqMr4VT0aB_XxDTJXF.40_m4WXK5kaUgs1_96H4F8wtE9O.b 3Nnq7ywCtHo8By69KEHSraZHWaMJ6ltKr4kryJEfGUjYAM1eNo_YiuDx2FK1 CtO2elz7sAOpuRNNWT1aB4HWJalfIKkgq8TAMOM_axmFtQG.VTzHSgqpu1iL VD.37i7mUFRjnXYyK7XEU.mv5snGH2xO78D.xX7auqQjxOnM5k6jugWrwug. nG.05hkSNJ6zV4vHUwgb9bbr8NR05Z4hnFt6qEPlE96cmE28KddeUZaHmbPa nSypJtBVLAw_v7134j7Of7Rr_HtG6TZc16u_o6GZnoQOtS13YAHRhFlwEM2T raJENWsjNMQwRsMIIrUAbMlMcbTwVsG00fAicnucazxEMa3BT5lwuOtahiLd NDU7KGXsbvkLaAAalekHYF8FWq3NIj5XJkaKM6EioKzh22_wX_3hJBa_tmqM Zmq8- X-Yahoo-SMTP: OIJXglSswBDfgLtXluJ6wiAYv6_cnw-- Subject: Re: [PATCH v4 04/11] lsm: inode_pre_setxattr hook To: Lukasz Pawelczyk , "David S. Miller" , "Eric W. Biederman" , "Serge E. Hallyn" , Al Viro , Alexey Dobriyan , Andrew Morton , Andy Lutomirski , Calvin Owens , David Howells , Eric Dumazet , Eric Paris , Greg Kroah-Hartman , James Morris , Jann Horn , Jiri Slaby , Joe Perches , John Johansen , Jonathan Corbet , Kees Cook , Mauro Carvalho Chehab , NeilBrown , Paul Moore , Serge Hallyn , Stephen Smalley , Tejun Heo , Tetsuo Handa , containers@lists.linuxfoundation.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov References: <1444826525-9758-1-git-send-email-l.pawelczyk@samsung.com> <1444826525-9758-5-git-send-email-l.pawelczyk@samsung.com> Cc: Lukasz Pawelczyk From: Casey Schaufler Message-ID: <5632A2AA.7010202@schaufler-ca.com> Date: Thu, 29 Oct 2015 15:50:18 -0700 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <1444826525-9758-5-git-send-email-l.pawelczyk@samsung.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/14/2015 5:41 AM, Lukasz Pawelczyk wrote: > Add a new LSM hook called before inode's setxattr. It is required for > LSM to be able to reliably replace the xattr's value to be set to > filesystem in __vfs_setxattr_noperm(). Useful for mapped values, like in > the upcoming Smack namespace patches. > > Signed-off-by: Lukasz Pawelczyk > Acked-by: Serge Hallyn Acked-by: Casey Schaufler > --- > fs/xattr.c | 10 ++++++++++ > include/linux/lsm_hooks.h | 9 +++++++++ > include/linux/security.h | 10 ++++++++++ > security/security.c | 12 ++++++++++++ > 4 files changed, 41 insertions(+) > > diff --git a/fs/xattr.c b/fs/xattr.c > index 072fee1..cbc8d19 100644 > --- a/fs/xattr.c > +++ b/fs/xattr.c > @@ -100,12 +100,22 @@ int __vfs_setxattr_noperm(struct dentry *dentry, const char *name, > if (issec) > inode->i_flags &= ~S_NOSEC; > if (inode->i_op->setxattr) { > + bool alloc = false; > + > + error = security_inode_pre_setxattr(dentry, name, &value, > + &size, flags, &alloc); > + if (error) > + return error; > + > error = inode->i_op->setxattr(dentry, name, value, size, flags); > if (!error) { > fsnotify_xattr(dentry); > security_inode_post_setxattr(dentry, name, value, > size, flags); > } > + > + if (alloc) > + kfree(value); > } else if (issec) { > const char *suffix = name + XATTR_SECURITY_PREFIX_LEN; > error = security_inode_setsecurity(inode, suffix, value, > diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h > index 4f16640..85bfdde 100644 > --- a/include/linux/lsm_hooks.h > +++ b/include/linux/lsm_hooks.h > @@ -349,6 +349,11 @@ > * Check permission before setting the extended attributes > * @value identified by @name for @dentry. > * Return 0 if permission is granted. > + * @inode_pre_setxattr: > + * Be able to do some operation before setting the @value identified > + * by @name on the filesystem. Replacing the @value and its @size is > + * possible. Useful for mapped values. Set @alloc to true if @value > + * needs to be kfreed afterwards. > * @inode_post_setxattr: > * Update inode security field after successful setxattr operation. > * @value identified by @name for @dentry. > @@ -1448,6 +1453,9 @@ union security_list_options { > int (*inode_getattr)(const struct path *path); > int (*inode_setxattr)(struct dentry *dentry, const char *name, > const void *value, size_t size, int flags); > + int (*inode_pre_setxattr)(struct dentry *dentry, const char *name, > + const void **value, size_t *size, > + int flags, bool *alloc); > void (*inode_post_setxattr)(struct dentry *dentry, const char *name, > const void *value, size_t size, > int flags); > @@ -1730,6 +1738,7 @@ struct security_hook_heads { > struct list_head inode_setattr; > struct list_head inode_getattr; > struct list_head inode_setxattr; > + struct list_head inode_pre_setxattr; > struct list_head inode_post_setxattr; > struct list_head inode_getxattr; > struct list_head inode_listxattr; > diff --git a/include/linux/security.h b/include/linux/security.h > index 12bd011..4de4865 100644 > --- a/include/linux/security.h > +++ b/include/linux/security.h > @@ -263,6 +263,9 @@ int security_inode_setattr(struct dentry *dentry, struct iattr *attr); > int security_inode_getattr(const struct path *path); > int security_inode_setxattr(struct dentry *dentry, const char *name, > const void *value, size_t size, int flags); > +int security_inode_pre_setxattr(struct dentry *dentry, const char *name, > + const void **value, size_t *size, int flags, > + bool *alloc); > void security_inode_post_setxattr(struct dentry *dentry, const char *name, > const void *value, size_t size, int flags); > int security_inode_getxattr(struct dentry *dentry, const char *name); > @@ -691,6 +694,13 @@ static inline int security_inode_setxattr(struct dentry *dentry, > return cap_inode_setxattr(dentry, name, value, size, flags); > } > > +static inline int security_inode_pre_setxattr(struct dentry *dentry, > + const char *name, const void **value, > + size_t *size, int flags, bool *alloc) > +{ > + return 0; > +} > + > static inline void security_inode_post_setxattr(struct dentry *dentry, > const char *name, const void *value, size_t size, int flags) > { } > diff --git a/security/security.c b/security/security.c > index abfc207..75d46b6 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -644,6 +644,16 @@ int security_inode_setxattr(struct dentry *dentry, const char *name, > return evm_inode_setxattr(dentry, name, value, size); > } > > +int security_inode_pre_setxattr(struct dentry *dentry, const char *name, > + const void **value, size_t *size, int flags, > + bool *alloc) > +{ > + if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) > + return 0; > + return call_int_hook(inode_pre_setxattr, 0, dentry, name, value, size, > + flags, alloc); > +} > + > void security_inode_post_setxattr(struct dentry *dentry, const char *name, > const void *value, size_t size, int flags) > { > @@ -1662,6 +1672,8 @@ struct security_hook_heads security_hook_heads = { > LIST_HEAD_INIT(security_hook_heads.inode_getattr), > .inode_setxattr = > LIST_HEAD_INIT(security_hook_heads.inode_setxattr), > + .inode_pre_setxattr = > + LIST_HEAD_INIT(security_hook_heads.inode_pre_setxattr), > .inode_post_setxattr = > LIST_HEAD_INIT(security_hook_heads.inode_post_setxattr), > .inode_getxattr =