Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1210867

Re: [PATCH v3 02/11] lsm: /proc/$PID/attr/label_map file and getprocattr_seq hook

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From Paul Moore <paul@paul-moore.com>
Newsgroups linux.kernel
Subject Re: [PATCH v3 02/11] lsm: /proc/$PID/attr/label_map file and getprocattr_seq hook
Date Fri, 21 Aug 2015 07:20:02 +0200
Message-ID <pZMUa-2nf-3@gated-at.bofh.it> (permalink)
References <pPI5r-2BZ-7@gated-at.bofh.it> <pPI5s-2BZ-29@gated-at.bofh.it>
X-Original-To Lukasz Pawelczyk <l.pawelczyk@samsung.com>
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=kEcJkyMYYGlGOZioHjiObJvAv9EyuJNWRNsYxbbGFTA=; b=cweYyMPPVBHfR6oy9fAaF+Iqm6X6uIodUBuJwPa4GvGXrSNhzktU5v5LXojyez1ATg fUgssbx2HjJ1iISE5J1tIGC3wf9BA8RjpofeQk2OKnoFg8/gohpvTAOm7Td7doA/efKi NN20Ei/NZaFAaC514A6DysQiuE7xNVPXfZSDx8nH9ZK3YKo7aTt/sxGzktemG8zLJYSQ vR9CnZLIf0lVtsx6tNLD0uaCp87G9iBqQUpC9coLb/uEZjb+en6L/vQ2XyVt5zQr0qK5 QqlQjxRerwwN0AvHR3RzidfLctVga+ksqNgv6dK636sjU+Ze9nNgV7j1TpgHOog2pnIk iBog==
X-Gm-Message-State ALoCoQnNNqJ2i4xmSdQ4mp/5jfdPNeYEoXLLMehdNUFb+ymPomrzs87hBYJI+BNYr6L5nDwm+JiU
MIME-Version 1.0
X-Received by 10.60.74.193 with SMTP id w1mr6070780oev.33.1440134091497; Thu, 20 Aug 2015 22:14:51 -0700 (PDT)
X-Originating-IP [70.96.146.23]
Content-Type text/plain; charset=UTF-8
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 117
Organization linux.* mail to news gateway
X-Original-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
X-Original-Date Fri, 21 Aug 2015 01:14:51 -0400
X-Original-Message-ID <CAHC9VhQy+qH09O1u6ZJPF226hx03j6h-dpuxHdykJjiiV6obbg@mail.gmail.com>
X-Original-References <1437732285-11524-1-git-send-email-l.pawelczyk@samsung.com> <1437732285-11524-3-git-send-email-l.pawelczyk@samsung.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1210867

Show key headers only | View raw


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:

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;
}

-- 
paul moore
www.paul-moore.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH v3 02/11] lsm: /proc/$PID/attr/label_map file and  getprocattr_seq hook Paul Moore <paul@paul-moore.com> - 2015-08-21 07:20 +0200
  Re: [PATCH v3 02/11] lsm: /proc/$PID/attr/label_map file and  getprocattr_seq hook Lukasz Pawelczyk <l.pawelczyk@samsung.com> - 2015-08-21 11:40 +0200

csiph-web