From mboxrd@z Thu Jan 1 00:00:00 1970 Message-id: <1438335805.2081.11.camel@samsung.com> Subject: Re: [PATCH v3 04/11] lsm: inode_pre_setxattr hook From: Lukasz Pawelczyk To: "Serge E. Hallyn" Date: Fri, 31 Jul 2015 11:43:25 +0200 In-reply-to: <20150730215648.GD13589@mail.hallyn.com> References: <1437732285-11524-1-git-send-email-l.pawelczyk@samsung.com> <1437732285-11524-5-git-send-email-l.pawelczyk@samsung.com> <20150730215648.GD13589@mail.hallyn.com> Content-type: text/plain; charset=UTF-8 MIME-version: 1.0 Cc: linux-doc@vger.kernel.org, NeilBrown , linux-kernel@vger.kernel.org, David Howells , Eric Dumazet , selinux@tycho.nsa.gov, Jonathan Corbet , havner@gmail.com, Tetsuo Handa , Jiri Slaby , Stephen Smalley , Alexey Dobriyan , Kees Cook , Arnd Bergmann , Mauro Carvalho Chehab , Fabian Frederick , Al Viro , James Morris , John Johansen , Greg KH , Oleg Nesterov , Andy Lutomirski , linux-security-module@vger.kernel.org, Zefan Li , Joe Perches , linux-fsdevel@vger.kernel.org, Andrew Morton List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: On czw, 2015-07-30 at 16:56 -0500, Serge E. Hallyn wrote: > On Fri, Jul 24, 2015 at 12:04:38PM +0200, 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 > > Could get confusing if userspace passes in 1 char and gets ENOSPC > because > the unmapped label is too long :) I would consider such a case a bug in LSM module. If there exists a mapping "very_very_long_label" -> "l" the module needs to know that the very long label is possible to get written. After all it would be written on the host directly. Smack has a limit for max label name and importing longer label (which also means creating a mapping with a longer label) will get refused. At least that's my understanding, but thanks, that's an interesting remark :-) > > > --- > > 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 1751864..0aeed91 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 f0d2914..24f91e0 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 88a3b78..e1d2c6f 100644 > > --- a/security/security.c > > +++ b/security/security.c > > @@ -649,6 +649,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) > > { > > @@ -1666,6 +1676,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_setxa > > ttr), > > .inode_post_setxattr = > > LIST_HEAD_INIT(security_hook_heads.inode_post_setx > > attr), > > .inode_getxattr = -- Lukasz Pawelczyk Samsung R&D Institute Poland Samsung Electronics From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lukasz Pawelczyk Subject: Re: [PATCH v3 04/11] lsm: inode_pre_setxattr hook Date: Fri, 31 Jul 2015 11:43:25 +0200 Message-ID: <1438335805.2081.11.camel@samsung.com> References: <1437732285-11524-1-git-send-email-l.pawelczyk@samsung.com> <1437732285-11524-5-git-send-email-l.pawelczyk@samsung.com> <20150730215648.GD13589@mail.hallyn.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: "Eric W. Biederman" , Al Viro , Alexey Dobriyan , Andrew Morton , Andy Lutomirski , Arnd Bergmann , Casey Schaufler , David Howells , Eric Dumazet , Eric Paris , Fabian Frederick , Greg KH , James Morris , Jiri Slaby , Joe Perches , John Johansen , Jonathan Corbet , Kees Cook , Mauro Carvalho Chehab , NeilBrown , Oleg Nesterov , Paul Moore , Stephen Smalley , Tetsuo Handa Return-path: In-reply-to: <20150730215648.GD13589@mail.hallyn.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On czw, 2015-07-30 at 16:56 -0500, Serge E. Hallyn wrote: > On Fri, Jul 24, 2015 at 12:04:38PM +0200, 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 > > Could get confusing if userspace passes in 1 char and gets ENOSPC > because > the unmapped label is too long :) I would consider such a case a bug in LSM module. If there exists a mapping "very_very_long_label" -> "l" the module needs to know that the very long label is possible to get written. After all it would be written on the host directly. Smack has a limit for max label name and importing longer label (which also means creating a mapping with a longer label) will get refused. At least that's my understanding, but thanks, that's an interesting remark :-) > > > --- > > 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 1751864..0aeed91 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 f0d2914..24f91e0 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 88a3b78..e1d2c6f 100644 > > --- a/security/security.c > > +++ b/security/security.c > > @@ -649,6 +649,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) > > { > > @@ -1666,6 +1676,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_setxa > > ttr), > > .inode_post_setxattr = > > LIST_HEAD_INIT(security_hook_heads.inode_post_setx > > attr), > > .inode_getxattr = -- Lukasz Pawelczyk Samsung R&D Institute Poland Samsung Electronics From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752850AbbGaJne (ORCPT ); Fri, 31 Jul 2015 05:43:34 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:52468 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751072AbbGaJna (ORCPT ); Fri, 31 Jul 2015 05:43:30 -0400 X-AuditID: cbfec7f5-f794b6d000001495-1c-55bb433e462a Message-id: <1438335805.2081.11.camel@samsung.com> Subject: Re: [PATCH v3 04/11] lsm: inode_pre_setxattr hook From: Lukasz Pawelczyk To: "Serge E. Hallyn" Cc: "Eric W. Biederman" , Al Viro , Alexey Dobriyan , Andrew Morton , Andy Lutomirski , Arnd Bergmann , Casey Schaufler , David Howells , Eric Dumazet , Eric Paris , Fabian Frederick , Greg KH , James Morris , Jiri Slaby , Joe Perches , John Johansen , Jonathan Corbet , Kees Cook , Mauro Carvalho Chehab , NeilBrown , Oleg Nesterov , Paul Moore , Stephen Smalley , Tetsuo Handa , Zefan Li , 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, havner@gmail.com Date: Fri, 31 Jul 2015 11:43:25 +0200 In-reply-to: <20150730215648.GD13589@mail.hallyn.com> References: <1437732285-11524-1-git-send-email-l.pawelczyk@samsung.com> <1437732285-11524-5-git-send-email-l.pawelczyk@samsung.com> <20150730215648.GD13589@mail.hallyn.com> Content-type: text/plain; charset=UTF-8 X-Mailer: Evolution 3.16.4 (3.16.4-2.fc22) MIME-version: 1.0 Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA02Se0hTcRTH+e3+du9VGt6W5S8jikEvK1MpO0VZEOSlEkLyj6TIpRfTnMpu mvXXqvm6vmIG2Walqf2RW75STBvKNCtquh4WPVR8heAyxSRrLHNa4H+fw/l8zzl/HJZS5sj9 2YTkC4I2WZ2kor3xyz/P3m4PO9QaFeTs3Q03rxyB0hozDW5DFwP9Tb9pGGnPRjBx1YVhrknP wGjXEAO5g3YKJNcvGq5V1NAwN74NCocjwTQwjOH5j0wabtROyuBVngbKsyoxPLG+wPC2pZSG yfwhGgw5BQxUW3RyqP6aAda7OgyNbZkIPhtuYjDpJ+TQ0VpBQfGIDUOPo5uBHvcz+cH1/IDT jXnXbwPijboCmjfpXmP+sbGP4cvq0/j3rSd5fec3Of/Y8kDGPy9xYb7ttpnhKwqL5fzU6CfM PyqaV+0z0bzFOoaO+0d774sTkhLSBe2OsBjvc1KflUltC80wmSSkQwUBEmJZwu0k40UyCXnN 4yri6K+hJeTNKrkqRKSCjn/FNCKOQT3yWAouhDQUv8MeXsHtJSWuKcrDNBdEfjqsC+zLbSbl ztmFMMVNsaTqyxztaWBuAxnPNywM8uJ2EXOdfmG1kqtFpNmm8DDFbSKGO/eoxesCSJYzcXHv cjJb3I8XlXWkwfyNuo4445KEcYlmXKKVIeoBWimkxaaKZ+M1IYGiWiOmJccHxqZo6tHif8w0 o6quvTbEsUi1TMFVtEQp5ep08ZLGhghLqXwVAxtbo5SKOPWly4I25Yw2LUkQbWgNi1V+ilst 308ouXj1BeG8IKQK2v9dGevlr0OOlrDT+xufOn07j302x2YdGH0ozh1Od/dKrmzJ8vBUcJzF N1H86JM7EmX3Uyvko4WZKbPNeSl7ytfm9UZstc3cYY6++ZIQXH3bvjoxcv8Hv/t/6F3NrE/c rP90T3j3FnN4aTscTQ9lRFmj+3tM9aqqMQNVOTDWGVJXYm+6+DFChcVz6uAASiuq/wKm0SgB GwMAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On czw, 2015-07-30 at 16:56 -0500, Serge E. Hallyn wrote: > On Fri, Jul 24, 2015 at 12:04:38PM +0200, 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 > > Could get confusing if userspace passes in 1 char and gets ENOSPC > because > the unmapped label is too long :) I would consider such a case a bug in LSM module. If there exists a mapping "very_very_long_label" -> "l" the module needs to know that the very long label is possible to get written. After all it would be written on the host directly. Smack has a limit for max label name and importing longer label (which also means creating a mapping with a longer label) will get refused. At least that's my understanding, but thanks, that's an interesting remark :-) > > > --- > > 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 1751864..0aeed91 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 f0d2914..24f91e0 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 88a3b78..e1d2c6f 100644 > > --- a/security/security.c > > +++ b/security/security.c > > @@ -649,6 +649,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) > > { > > @@ -1666,6 +1676,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_setxa > > ttr), > > .inode_post_setxattr = > > LIST_HEAD_INIT(security_hook_heads.inode_post_setx > > attr), > > .inode_getxattr = -- Lukasz Pawelczyk Samsung R&D Institute Poland Samsung Electronics