public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Pawelczyk <l.pawelczyk@samsung.com>
To: Paul Moore <paul@paul-moore.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Arnd Bergmann <arnd@arndb.de>,
	Casey Schaufler <casey@schaufler-ca.com>,
	David Howells <dhowells@redhat.com>,
	Eric Dumazet <edumazet@google.com>,
	Eric Paris <eparis@parisplace.org>,
	Fabian Frederick <fabf@skynet.be>,
	Greg KH <gregkh@linuxfoundation.org>,
	James Morris <james.l.morris@oracle.com>,
	Jiri Slaby <jslaby@suse.com>, Joe Perches <joe@perches.com>,
	John Johansen <john.johansen@canonical.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Kees Cook <keescook@chromium.org>,
	Mauro Carvalho Chehab <mchehab@osg.samsung.com>,
	NeilBrown <neilb@suse.de>, Oleg Nesterov <oleg@redhat.com>,
	Stephen Smalley <sds@tycho.nsa.gov>,
	Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
	Zefan Li <lizefan@huawei.com>,
	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
Subject: Re: [PATCH v3 02/11] lsm: /proc/$PID/attr/label_map file and getprocattr_seq hook
Date: Fri, 21 Aug 2015 11:30:07 +0200	[thread overview]
Message-ID: <1440149407.2227.5.camel@samsung.com> (raw)
In-Reply-To: <CAHC9VhQy+qH09O1u6ZJPF226hx03j6h-dpuxHdykJjiiV6obbg@mail.gmail.com>

On pią, 2015-08-21 at 01:14 -0400, Paul Moore wrote:
> On Fri, Jul 24, 2015 at 6:04 AM, Lukasz Pawelczyk
> <l.pawelczyk@samsung.com> 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 <l.pawelczyk@samsung.com>
> > ---
> >  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




  reply	other threads:[~2015-08-21  9:30 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-24 10:04 [PATCH v3 00/11] Smack namespace Lukasz Pawelczyk
2015-07-24 10:04 ` [PATCH v3 01/11] user_ns: 3 new LSM hooks for user namespace operations Lukasz Pawelczyk
2015-07-30 21:30   ` Serge E. Hallyn
2015-07-31  9:28     ` Lukasz Pawelczyk
2015-08-01  3:48       ` Serge E. Hallyn
2015-08-03 11:34         ` Lukasz Pawelczyk
2015-08-04  1:38           ` Kees Cook
2015-08-21  5:04             ` Paul Moore
2015-08-21 15:56   ` Paul Moore
2015-07-24 10:04 ` [PATCH v3 02/11] lsm: /proc/$PID/attr/label_map file and getprocattr_seq hook Lukasz Pawelczyk
2015-07-30 21:49   ` Serge E. Hallyn
2015-08-21  5:14   ` Paul Moore
2015-08-21  9:30     ` Lukasz Pawelczyk [this message]
2015-07-24 10:04 ` [PATCH v3 03/11] lsm: add file opener's cred to a setprocattr arguments Lukasz Pawelczyk
2015-07-30 21:50   ` Serge E. Hallyn
2015-07-24 10:04 ` [PATCH v3 04/11] lsm: inode_pre_setxattr hook Lukasz Pawelczyk
2015-07-30 21:56   ` Serge E. Hallyn
2015-07-31  9:43     ` Lukasz Pawelczyk
2015-07-24 10:04 ` [PATCH v3 05/11] smack: extend capability functions and fix 2 checks Lukasz Pawelczyk
2015-07-30 22:10   ` Serge E. Hallyn
2015-07-24 10:04 ` [PATCH v3 06/11] smack: don't use implicit star to display smackfs/syslog Lukasz Pawelczyk
2015-07-30 22:42   ` Serge E. Hallyn
2015-07-24 10:04 ` [PATCH v3 07/11] smack: abstraction layer for 2 common Smack operations Lukasz Pawelczyk
2015-07-24 10:04 ` [PATCH v3 08/11] smack: misc cleanups in preparation for a namespace patch Lukasz Pawelczyk
2015-07-24 10:04 ` [PATCH v3 09/11] smack: namespace groundwork Lukasz Pawelczyk
2015-07-24 10:04 ` [PATCH v3 10/11] smack: namespace implementation Lukasz Pawelczyk
2015-07-24 10:04 ` [PATCH v3 11/11] smack: documentation for the Smack namespace Lukasz Pawelczyk
2015-07-29 15:25   ` Serge E. Hallyn
2015-07-29 16:13     ` Lukasz Pawelczyk
2015-07-29 16:24       ` Lukasz Pawelczyk
2015-07-29 16:37       ` Serge E. Hallyn
2015-07-29 17:05         ` Lukasz Pawelczyk
2015-07-30 19:11           ` Serge E. Hallyn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1440149407.2227.5.camel@samsung.com \
    --to=l.pawelczyk@samsung.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=casey@schaufler-ca.com \
    --cc=corbet@lwn.net \
    --cc=dhowells@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=edumazet@google.com \
    --cc=eparis@parisplace.org \
    --cc=fabf@skynet.be \
    --cc=gregkh@linuxfoundation.org \
    --cc=havner@gmail.com \
    --cc=james.l.morris@oracle.com \
    --cc=joe@perches.com \
    --cc=john.johansen@canonical.com \
    --cc=jslaby@suse.com \
    --cc=keescook@chromium.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=luto@amacapital.net \
    --cc=mchehab@osg.samsung.com \
    --cc=neilb@suse.de \
    --cc=oleg@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@tycho.nsa.gov \
    --cc=serge@hallyn.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox