From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753837AbbHUJaR (ORCPT ); Fri, 21 Aug 2015 05:30:17 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:61327 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753709AbbHUJaL (ORCPT ); Fri, 21 Aug 2015 05:30:11 -0400 MIME-version: 1.0 Content-type: text/plain; charset=UTF-8 X-AuditID: cbfec7f5-f794b6d000001495-a8-55d6efa01977 Content-transfer-encoding: 8BIT Message-id: <1440149407.2227.5.camel@samsung.com> Subject: Re: [PATCH v3 02/11] lsm: /proc/$PID/attr/label_map file and getprocattr_seq hook From: Lukasz Pawelczyk To: Paul Moore Cc: "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 , Mauro Carvalho Chehab , NeilBrown , Oleg Nesterov , 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, 21 Aug 2015 11:30:07 +0200 In-reply-to: References: <1437732285-11524-1-git-send-email-l.pawelczyk@samsung.com> <1437732285-11524-3-git-send-email-l.pawelczyk@samsung.com> X-Mailer: Evolution 3.16.4 (3.16.4-2.fc22) X-Brightmail-Tracker: H4sIAAAAAAAAA02Sa0iTURzGO3vP3r0uB6+mdjAiGUlgF2dKniyiDwaHKAhLQitq2YvaNieb mvZplpppWm6Juk1TpwRTWYmKqUNZplbeyjQyVPJSZt66SHnPaVHffjzP8+d5PvwZyjmF785E RsVwqiipXEwL4cuV1p69RTN9wRKDEuckHsdGSzmNl7UtAjxYs0Dj0aZbAE/fWIR4tSZJgMda hgX49ocOCqctztP4pslC49Uve3DmSBA2DI1A3PYjmcb3H83ycHu6AhellEDcYH0OcU+dkcaz d4ZprE3NEOCyCg0fl32Mx9YHGoirG5MBfq/NgdiQNM3HT+tNFNaN2iDu6u4U4K7lVv5RDzI0 uQzJ4oIWEL0mgyYGzStInugHBKSwMpb01YeQpOYpPnlSYeaRttxFSBrzywXElKnjk69j/ZBU 3V2LdsyFkgrrODjlHio8fIWTR8ZxKu8jl4QRORMldPT89viH8z9pDch3SQMODGL90EDWNL3B bqh70LLGQsaZLQUoMz9x3RCxTuiXbhCmAYah2B2o+bXMLlPsLqQtKKY28t8BSq/6DDfyPiij V7fOW9jzaLZ3gLIzzUrQz27rOruwO5FpzALsxxQ7x6Ce/gKevQCynuhbxnqvA3sadU0t/Clo B2giu46yZxDrhVImr94DrP6/efp/8/T/zSsElBm4crFh0erL4Yr9+9RShTo2KnxfmFJRCTa+ Y64WlLYE2ADLALGjKDekL9iZL41TJyhsADGU2EV0aHxNEl2RJlznVMqLqlg5p7aBbQwUbxXl 1c2ccWbDpTGcjOOiOdVfl8c4uGvASc7s6heV7d2Q6auQmYnm08GInVpuIPXN6Dmlx1XXdx4B Nacdb17/sRJ4Q1stm/MQdroavUWKZ/7RQbs3XXBy8nTLkryYWc2CZ5dqc5eKAw8O6VrKEwez TgRc25t24K1c+cI4qtnsL/V1nLgj8+UFxZA4Y17SY0lT4LGxZvmKUgzVEVIfL0qllv4GSBK6 BBkDAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On piÄ…, 2015-08-21 at 01:14 -0400, Paul Moore wrote: > On Fri, Jul 24, 2015 at 6:04 AM, Lukasz Pawelczyk > wrote: > > This commit adds a new proc attribute, label_map that is required > > by an > > upcoming Smack namespace. In general it can be used to hold a map > > of > > labels, e.g. to be used in namespaces. > > > > Due to the nature of this file, the standard getprocattr hook might > > not > > be enough to handle it. The map's output can in principle be > > greater > > than page size to which the aforementioned hook is limited. > > To handle this properly a getprocattr_seq LSM hook has been added > > that > > makes it possible to handle any chosen proc attr by seq operations. > > > > See the documentation in the patch below for the details about how > > to > > use the hook. > > > > Signed-off-by: Lukasz Pawelczyk > > --- > > fs/proc/base.c | 81 > > +++++++++++++++++++++++++++++++++++++++++++---- > > include/linux/lsm_hooks.h | 15 +++++++++ > > include/linux/security.h | 9 ++++++ > > security/security.c | 8 +++++ > > 4 files changed, 107 insertions(+), 6 deletions(-) > > > > diff --git a/fs/proc/base.c b/fs/proc/base.c > > index aa50d1a..e5ac827 100644 > > --- a/fs/proc/base.c > > +++ b/fs/proc/base.c > > @@ -2338,20 +2338,77 @@ out: > > } > > > > #ifdef CONFIG_SECURITY > > +static int proc_pid_attr_open(struct inode *inode, struct file > > *file) > > +{ > > + const char *name = file->f_path.dentry->d_name.name; > > + const struct seq_operations *ops; > > + struct task_struct *task; > > + struct seq_file *seq; > > + int ret; > > + > > + file->private_data = NULL; > > + > > + task = get_proc_task(inode); > > + if (!task) > > + return -ESRCH; > > + > > + /* don't use seq_ops if they are not provided by LSM */ > > + ret = security_getprocattr_seq(task, name, &ops); > > + if (ret == -EOPNOTSUPP) { > > + put_task_struct(task); > > + return 0; > > + } > > + if (ret) { > > + put_task_struct(task); > > + return ret; > > + } > > + > > + ret = seq_open(file, ops); > > + if (ret) { > > + put_task_struct(task); > > + return ret; > > + } > > + > > + seq = file->private_data; > > + seq->private = task; > > + > > + return 0; > > +} > > If you end up having to respin this patchset, you might consider > moving the "put_task_struct(...); return X;" code into a block at the > end of the function to simplify things a bit, for example: I will do so, thanks. > > static int proc_pid_attr_open(struct inode *inode, struct file *file) > { > const char *name = file->f_path.dentry->d_name.name; > const struct seq_operations *ops; > struct task_struct *task; > struct seq_file *seq; > int ret; > > file->private_data = NULL; > > task = get_proc_task(inode); > if (!task) > return -ESRCH; > > /* don't use seq_ops if they are not provided by LSM */ > ret = security_getprocattr_seq(task, name, &ops); > if (ret == -EOPNOTSUPP) { > ret = 0; > goto put_task; > } > if (ret) > goto put_task; > > ret = seq_open(file, ops); > if (ret) > goto put_task; > > seq = file->private_data; > seq->private = task; > > return 0; > > put_task: > put_task_struct(task); > return ret; > } > -- Lukasz Pawelczyk Samsung R&D Institute Poland Samsung Electronics