From mboxrd@z Thu Jan 1 00:00:00 1970 From: Casey Schaufler Subject: Re: [PATCH v4 03/11] lsm: add file opener's cred to a setprocattr arguments Date: Thu, 29 Oct 2015 15:49:59 -0700 Message-ID: <5632A297.5050608@schaufler-ca.com> References: <1444826525-9758-1-git-send-email-l.pawelczyk@samsung.com> <1444826525-9758-4-git-send-email-l.pawelczyk@samsung.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1444826525-9758-4-git-send-email-l.pawelczyk-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org 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 Cc: Lukasz Pawelczyk List-Id: containers.vger.kernel.org On 10/14/2015 5:41 AM, Lukasz Pawelczyk wrote: > setprocattr hook for Smack's label_map attribute needs to know the > capabilities of file opener. Add those credentials to the hook's > arguments. > > While at it add documentation on get/setprocattr hooks. > > Signed-off-by: Lukasz Pawelczyk > Acked-by: Serge Hallyn Acked-by: Casey Schaufler > --- > fs/proc/base.c | 2 +- > include/linux/lsm_hooks.h | 18 ++++++++++++++++-- > include/linux/security.h | 7 +++++-- > security/apparmor/lsm.c | 5 +++-- > security/security.c | 6 ++++-- > security/selinux/hooks.c | 2 +- > security/smack/smack_lsm.c | 4 ++-- > 7 files changed, 32 insertions(+), 12 deletions(-) > > diff --git a/fs/proc/base.c b/fs/proc/base.c > index 9ec88b8..2b38969 100644 > --- a/fs/proc/base.c > +++ b/fs/proc/base.c > @@ -2447,7 +2447,7 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, > if (length < 0) > goto out_free; > > - length = security_setprocattr(task, > + length = security_setprocattr(task, file->f_cred, > (char*)file->f_path.dentry->d_name.name, > (void*)page, count); > mutex_unlock(&task->signal->cred_guard_mutex); > diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h > index 7049db0..4f16640 100644 > --- a/include/linux/lsm_hooks.h > +++ b/include/linux/lsm_hooks.h > @@ -1220,6 +1220,20 @@ > * Return 0 if @name is to be handled by seq, EOPNOTSUPP if getprocattr() > * should be used. Other errors will be passed to user-space. > * > + * @getprocattr: > + * Get a value of a proc security attribute in /proc/$PID/attr/. > + * @p a task associated with the proc file. > + * @name a name of the file in question. > + * @value a pointer where to return the attribute's value. > + * > + * @setprocattr: > + * Set a value of a proc security attribute in /proc/$PID/attr/. > + * @p a task associated with the proc file. > + * @f_cred credentials of a file's opener. > + * @name a name of the file in question. > + * @value a pointer where a value to set is kept. > + * @size a number of bytes to read from the @value pointer. > + * > * @secid_to_secctx: > * Convert secid to security context. If secdata is NULL the length of > * the result will be returned in seclen, but no secdata will be returned. > @@ -1540,8 +1554,8 @@ union security_list_options { > int (*getprocattr_seq)(struct task_struct *p, const char *name, > const struct seq_operations **ops); > int (*getprocattr)(struct task_struct *p, char *name, char **value); > - int (*setprocattr)(struct task_struct *p, char *name, void *value, > - size_t size); > + int (*setprocattr)(struct task_struct *p, const struct cred *f_cred, > + char *name, void *value, size_t size); > int (*ismaclabel)(const char *name); > int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen); > int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid); > diff --git a/include/linux/security.h b/include/linux/security.h > index dddea2f..12bd011 100644 > --- a/include/linux/security.h > +++ b/include/linux/security.h > @@ -348,7 +348,8 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode); > int security_getprocattr_seq(struct task_struct *p, const char *name, > const struct seq_operations **ops); > int security_getprocattr(struct task_struct *p, char *name, char **value); > -int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size); > +int security_setprocattr(struct task_struct *p, const struct cred *f_cred, > + char *name, void *value, size_t size); > int security_netlink_send(struct sock *sk, struct sk_buff *skb); > int security_ismaclabel(const char *name); > int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen); > @@ -1071,7 +1072,9 @@ static inline int security_getprocattr(struct task_struct *p, char *name, char * > return -EINVAL; > } > > -static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size) > +static inline int security_setprocattr(struct task_struct *p, > + const struct cred *f_cred, > + char *name, void *value, size_t size) > { > return -EINVAL; > } > diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c > index dec607c..1212927 100644 > --- a/security/apparmor/lsm.c > +++ b/security/apparmor/lsm.c > @@ -518,8 +518,9 @@ static int apparmor_getprocattr(struct task_struct *task, char *name, > return error; > } > > -static int apparmor_setprocattr(struct task_struct *task, char *name, > - void *value, size_t size) > +static int apparmor_setprocattr(struct task_struct *task, > + const struct cred *f_cred, > + char *name, void *value, size_t size) > { > struct common_audit_data sa; > struct apparmor_audit_data aad = {0,}; > diff --git a/security/security.c b/security/security.c > index da2bcd4..abfc207 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -1132,9 +1132,11 @@ int security_getprocattr(struct task_struct *p, char *name, char **value) > return call_int_hook(getprocattr, -EINVAL, p, name, value); > } > > -int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size) > +int security_setprocattr(struct task_struct *p, const struct cred *f_cred, > + char *name, void *value, size_t size) > { > - return call_int_hook(setprocattr, -EINVAL, p, name, value, size); > + return call_int_hook(setprocattr, -EINVAL, p, f_cred, > + name, value, size); > } > > int security_netlink_send(struct sock *sk, struct sk_buff *skb) > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c > index e4369d8..470eff8 100644 > --- a/security/selinux/hooks.c > +++ b/security/selinux/hooks.c > @@ -5603,7 +5603,7 @@ invalid: > return -EINVAL; > } > > -static int selinux_setprocattr(struct task_struct *p, > +static int selinux_setprocattr(struct task_struct *p, const struct cred *f_cred, > char *name, void *value, size_t size) > { > struct task_security_struct *tsec; > diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c > index c2d66ca..c439370 100644 > --- a/security/smack/smack_lsm.c > +++ b/security/smack/smack_lsm.c > @@ -3549,8 +3549,8 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value) > * > * Returns the length of the smack label or an error code > */ > -static int smack_setprocattr(struct task_struct *p, char *name, > - void *value, size_t size) > +static int smack_setprocattr(struct task_struct *p, const struct cred *f_cred, > + char *name, void *value, size_t size) > { > struct task_smack *tsp; > struct cred *new; From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758158AbbJ2WuJ (ORCPT ); Thu, 29 Oct 2015 18:50:09 -0400 Received: from smtp106.biz.mail.bf1.yahoo.com ([98.139.244.54]:28640 "EHLO smtp106.biz.mail.bf1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757610AbbJ2WuE (ORCPT ); Thu, 29 Oct 2015 18:50:04 -0400 X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: eYUohmMVM1kv_Anq1tnV7Xc0.lSzXKTBfG0ETtSR_VHNH6h wDv_CK43QQbovvlAhbgn8yjie3GMGktZ2LZwsqEGodUttJkcCSbvughjkT77 orszdVGkyGIRPGlTti5J_4R4v1LCkeUoeFaiFIYEVp3vPs1J21KvhfmZPzxQ o05KzSIDiMDFPsbZPOSswprGEf5aWguyBxpfbnLEBaYOS9Whlq04SAGTC9s5 l2qb_xG.Vzt0JtbisRkcpmM26PzMOpus1EvURDnxFNc90nL.55lX1pWjf7zI X8WlxiYSUkzzhP1g7hUIZnl.kBDBOEnuGpwut4wMGd4c.7C1XxXZngNOwLZT Ixp5OJ8QKmn9ZEhYMedldvrBmzWUVuYuu4rawpUvH211iilE6NfG6Jb3Zlcu xAJ.8w85HRWsG83nUpZgY_pdUEizUu2kY9eP_MMpYW9RcFPYpADfWqpjRy0L bS8gKS_RnQzR1I46xnADlKZh8gH6pfbWRJSetHwO9pe7eHzIFSMD8rCNcuFG vn0s- X-Yahoo-SMTP: OIJXglSswBDfgLtXluJ6wiAYv6_cnw-- Subject: Re: [PATCH v4 03/11] lsm: add file opener's cred to a setprocattr arguments 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-4-git-send-email-l.pawelczyk@samsung.com> Cc: Lukasz Pawelczyk From: Casey Schaufler Message-ID: <5632A297.5050608@schaufler-ca.com> Date: Thu, 29 Oct 2015 15:49:59 -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-4-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: > setprocattr hook for Smack's label_map attribute needs to know the > capabilities of file opener. Add those credentials to the hook's > arguments. > > While at it add documentation on get/setprocattr hooks. > > Signed-off-by: Lukasz Pawelczyk > Acked-by: Serge Hallyn Acked-by: Casey Schaufler > --- > fs/proc/base.c | 2 +- > include/linux/lsm_hooks.h | 18 ++++++++++++++++-- > include/linux/security.h | 7 +++++-- > security/apparmor/lsm.c | 5 +++-- > security/security.c | 6 ++++-- > security/selinux/hooks.c | 2 +- > security/smack/smack_lsm.c | 4 ++-- > 7 files changed, 32 insertions(+), 12 deletions(-) > > diff --git a/fs/proc/base.c b/fs/proc/base.c > index 9ec88b8..2b38969 100644 > --- a/fs/proc/base.c > +++ b/fs/proc/base.c > @@ -2447,7 +2447,7 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, > if (length < 0) > goto out_free; > > - length = security_setprocattr(task, > + length = security_setprocattr(task, file->f_cred, > (char*)file->f_path.dentry->d_name.name, > (void*)page, count); > mutex_unlock(&task->signal->cred_guard_mutex); > diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h > index 7049db0..4f16640 100644 > --- a/include/linux/lsm_hooks.h > +++ b/include/linux/lsm_hooks.h > @@ -1220,6 +1220,20 @@ > * Return 0 if @name is to be handled by seq, EOPNOTSUPP if getprocattr() > * should be used. Other errors will be passed to user-space. > * > + * @getprocattr: > + * Get a value of a proc security attribute in /proc/$PID/attr/. > + * @p a task associated with the proc file. > + * @name a name of the file in question. > + * @value a pointer where to return the attribute's value. > + * > + * @setprocattr: > + * Set a value of a proc security attribute in /proc/$PID/attr/. > + * @p a task associated with the proc file. > + * @f_cred credentials of a file's opener. > + * @name a name of the file in question. > + * @value a pointer where a value to set is kept. > + * @size a number of bytes to read from the @value pointer. > + * > * @secid_to_secctx: > * Convert secid to security context. If secdata is NULL the length of > * the result will be returned in seclen, but no secdata will be returned. > @@ -1540,8 +1554,8 @@ union security_list_options { > int (*getprocattr_seq)(struct task_struct *p, const char *name, > const struct seq_operations **ops); > int (*getprocattr)(struct task_struct *p, char *name, char **value); > - int (*setprocattr)(struct task_struct *p, char *name, void *value, > - size_t size); > + int (*setprocattr)(struct task_struct *p, const struct cred *f_cred, > + char *name, void *value, size_t size); > int (*ismaclabel)(const char *name); > int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen); > int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid); > diff --git a/include/linux/security.h b/include/linux/security.h > index dddea2f..12bd011 100644 > --- a/include/linux/security.h > +++ b/include/linux/security.h > @@ -348,7 +348,8 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode); > int security_getprocattr_seq(struct task_struct *p, const char *name, > const struct seq_operations **ops); > int security_getprocattr(struct task_struct *p, char *name, char **value); > -int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size); > +int security_setprocattr(struct task_struct *p, const struct cred *f_cred, > + char *name, void *value, size_t size); > int security_netlink_send(struct sock *sk, struct sk_buff *skb); > int security_ismaclabel(const char *name); > int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen); > @@ -1071,7 +1072,9 @@ static inline int security_getprocattr(struct task_struct *p, char *name, char * > return -EINVAL; > } > > -static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size) > +static inline int security_setprocattr(struct task_struct *p, > + const struct cred *f_cred, > + char *name, void *value, size_t size) > { > return -EINVAL; > } > diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c > index dec607c..1212927 100644 > --- a/security/apparmor/lsm.c > +++ b/security/apparmor/lsm.c > @@ -518,8 +518,9 @@ static int apparmor_getprocattr(struct task_struct *task, char *name, > return error; > } > > -static int apparmor_setprocattr(struct task_struct *task, char *name, > - void *value, size_t size) > +static int apparmor_setprocattr(struct task_struct *task, > + const struct cred *f_cred, > + char *name, void *value, size_t size) > { > struct common_audit_data sa; > struct apparmor_audit_data aad = {0,}; > diff --git a/security/security.c b/security/security.c > index da2bcd4..abfc207 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -1132,9 +1132,11 @@ int security_getprocattr(struct task_struct *p, char *name, char **value) > return call_int_hook(getprocattr, -EINVAL, p, name, value); > } > > -int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size) > +int security_setprocattr(struct task_struct *p, const struct cred *f_cred, > + char *name, void *value, size_t size) > { > - return call_int_hook(setprocattr, -EINVAL, p, name, value, size); > + return call_int_hook(setprocattr, -EINVAL, p, f_cred, > + name, value, size); > } > > int security_netlink_send(struct sock *sk, struct sk_buff *skb) > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c > index e4369d8..470eff8 100644 > --- a/security/selinux/hooks.c > +++ b/security/selinux/hooks.c > @@ -5603,7 +5603,7 @@ invalid: > return -EINVAL; > } > > -static int selinux_setprocattr(struct task_struct *p, > +static int selinux_setprocattr(struct task_struct *p, const struct cred *f_cred, > char *name, void *value, size_t size) > { > struct task_security_struct *tsec; > diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c > index c2d66ca..c439370 100644 > --- a/security/smack/smack_lsm.c > +++ b/security/smack/smack_lsm.c > @@ -3549,8 +3549,8 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value) > * > * Returns the length of the smack label or an error code > */ > -static int smack_setprocattr(struct task_struct *p, char *name, > - void *value, size_t size) > +static int smack_setprocattr(struct task_struct *p, const struct cred *f_cred, > + char *name, void *value, size_t size) > { > struct task_smack *tsp; > struct cred *new;