From patchwork Fri Jul 24 10:04:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Pawelczyk X-Patchwork-Id: 6859031 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 88CC59F380 for ; Fri, 24 Jul 2015 10:09:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 81E5420609 for ; Fri, 24 Jul 2015 10:09:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 32DBB2063D for ; Fri, 24 Jul 2015 10:09:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753969AbbGXKJ2 (ORCPT ); Fri, 24 Jul 2015 06:09:28 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:32269 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752134AbbGXKF3 (ORCPT ); Fri, 24 Jul 2015 06:05:29 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NRZ00LDJLD3BF90@mailout1.w1.samsung.com>; Fri, 24 Jul 2015 11:05:27 +0100 (BST) X-AuditID: cbfec7f5-f794b6d000001495-44-55b20de672ab Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id F9.2D.05269.6ED02B55; Fri, 24 Jul 2015 11:05:26 +0100 (BST) Received: from amdc2143.DIGITAL.local ([106.120.53.33]) by eusync2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NRZ00EPNLC23A60@eusync2.samsung.com>; Fri, 24 Jul 2015 11:05:26 +0100 (BST) From: Lukasz Pawelczyk To: "Eric W. Biederman" , "Serge E. Hallyn" , 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 , Lukasz Pawelczyk , 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 Cc: havner@gmail.com Subject: [PATCH v3 03/11] lsm: add file opener's cred to a setprocattr arguments Date: Fri, 24 Jul 2015 12:04:37 +0200 Message-id: <1437732285-11524-4-git-send-email-l.pawelczyk@samsung.com> X-Mailer: git-send-email 2.4.3 In-reply-to: <1437732285-11524-1-git-send-email-l.pawelczyk@samsung.com> References: <1437732285-11524-1-git-send-email-l.pawelczyk@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrKIsWRmVeSWpSXmKPExsVy+t/xK7rPeDeFGrzu0LGY3uhlMWf9GjaL v5OOsVvc2/aLzeLJgXZGi3dNv1ks/m9rYbd4euwRu0Xnw7PMFl2/f7JZNC9ez2bx/7WORd/j IIvZ9x+zWJz40spmMWXDByaLM925FmcmLWSyWNi2hMViz96TLBaXd81hs/jQ84jNYlJHL7vF 6rUNrBarn1VY7J3fwGKxdX8ro8XtSdNZLGa3vGO1OLx7MbPF5CeHWCzOXzjHbnH+73FWB0WP +2/+snj8/jWJ0WNWQy+bx+yGiyweO2fdZfdYsKnU49ruSI+WI29ZPXauXcXkcWLGbxaP/XPX sHss7pvM6vHx6S0Wjy39QKVnv0Z5rN37gjFAOorLJiU1J7MstUjfLoEro/FneMFHo4qTG7Ma GG9odjFyckgImEgse/WFEcIWk7hwbz1bFyMXh5DAUkaJW7fns0M4jUwSTa+ngFWxCRhIfL+w lxkkISKwlVNiwoa1YAlmARGJP+8+soPYwgIBEq8/HmAGsVkEVCV6JrWygdi8Au4Sr6a8YoJY Jydxbv0XFhCbU8BD4vTlT2C9QkA13bPmsE9g5F3AyLCKUTS1NLmgOCk910ivODG3uDQvXS85 P3cTIyRyv+5gXHrM6hCjAAejEg/vgUkbQ4VYE8uKK3MPMUpwMCuJ8DIcAwrxpiRWVqUW5ccX leakFh9ilOZgURLnnbnrfYiQQHpiSWp2ampBahFMlomDU6qBUb10StrkN0LhWnHiz16piZqE VtsxT17VY2yS5nstI2+uTTRTzInY2Zwn7ZSZTZ/uyOxMD/invpCjw3jrxFNS/PPzufNvLrQO rmEK1Jx1n/H0y4C1F+/5CFVtdvWQOx24v/y4VzXPrL9qW2aYX5lyZ7rC1usJ15JCPA01/H56 7VjSuXpS6GxvJZbijERDLeai4kQAEsqIv9gCAAA= Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 e5ac827..775372c 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2458,7 +2458,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 d347e66..1751864 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 3090bb2..f0d2914 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 e348e38..88a3b78 100644 --- a/security/security.c +++ b/security/security.c @@ -1137,9 +1137,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 564079c..3e1b9f7 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -5556,7 +5556,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 d962f88..cdcabf4 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -3450,8 +3450,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;