From patchwork Mon Sep 12 19:29:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9327875 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B628760231 for ; Mon, 12 Sep 2016 19:33:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8A3C28E59 for ; Mon, 12 Sep 2016 19:33:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D92B28E6F; Mon, 12 Sep 2016 19:33:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5464F28E59 for ; Mon, 12 Sep 2016 19:33:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753104AbcILTdF (ORCPT ); Mon, 12 Sep 2016 15:33:05 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:36137 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753113AbcILT3g (ORCPT ); Mon, 12 Sep 2016 15:29:36 -0400 Received: by mail-wm0-f46.google.com with SMTP id b187so152080853wme.1 for ; Mon, 12 Sep 2016 12:29:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tA/Zzrws9x4hkY9lTx1BuEm6wHkjS2l4s+LI7A/WBBY=; b=VlZIBFl1omO3qTWuBFUoJGoOVXnuauQxREw7fBrJ9lhs1nSb8xcr+PlIzRsQOYowlt WRpCa3NXvRdi4Ym0tMJL/dZF+omIem821Mcm71iQskTKY8tTZDqxWoYoU8DViGZBwykZ zUe+xF7bYTeP3WwDxW4yDZcdSiyiURBo++4Ed3wnKQgIzuDZgmUn4pgHAbMYGWwOB2t1 FYUUmYPNhZdlgO/VQifCzmksY0n1OGJaklRxlXsNtQbt1XzOMZT1W3sQEdp/F4CgETPE 341SoESZWZ71qqGT9top42tg4l83Qu4sAo6dwgdseeiDj4az8orTuts+0BDpbvtHxPl2 Tb4A== X-Gm-Message-State: AE9vXwMNnXTzWVh5q+uIs0V8bG/lU2699UuX/uCKoHmXdtflA9h7rh74UgApLlqKXy9+Ulqx X-Received: by 10.194.228.98 with SMTP id sh2mr16609441wjc.127.1473708575143; Mon, 12 Sep 2016 12:29:35 -0700 (PDT) Received: from veci.piliscsaba.szeredi.hu (pool-dsl-2c-0018.externet.hu. [217.173.44.24]) by smtp.gmail.com with ESMTPSA id f8sm19250418wjh.45.2016.09.12.12.29.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Sep 2016 12:29:34 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Al Viro Subject: [PATCH 09/17] proc: merge proc_ns_readlink() into proc_ns_get_link() Date: Mon, 12 Sep 2016 21:29:11 +0200 Message-Id: <1473708559-12714-10-git-send-email-mszeredi@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1473708559-12714-1-git-send-email-mszeredi@redhat.com> References: <1473708559-12714-1-git-send-email-mszeredi@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This will allow us to move the generic readlink logic into the VFS and get rid of the readlink method. Signed-off-by: Miklos Szeredi --- fs/proc/namespaces.c | 56 +++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/fs/proc/namespaces.c b/fs/proc/namespaces.c index 51b8b0a8ad91..9c9a1683791a 100644 --- a/fs/proc/namespaces.c +++ b/fs/proc/namespaces.c @@ -33,6 +33,8 @@ static const struct proc_ns_operations *ns_entries[] = { #endif }; +#define PROC_NS_LINK_MAX 50 + static const char *proc_ns_get_link(struct dentry *dentry, struct inode *inode, struct delayed_call *done) @@ -40,47 +42,47 @@ static const char *proc_ns_get_link(struct dentry *dentry, const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops; struct task_struct *task; struct path ns_path; - void *error = ERR_PTR(-EACCES); + char *res = ERR_PTR(-EACCES); if (!dentry) return ERR_PTR(-ECHILD); task = get_proc_task(inode); if (!task) - return error; - - if (ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) { - error = ns_get_path(&ns_path, task, ns_ops); - if (!error) - nd_jump_link(&ns_path); - } - put_task_struct(task); - return error; -} - -static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int buflen) -{ - struct inode *inode = d_inode(dentry); - const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops; - struct task_struct *task; - char name[50]; - int res = -EACCES; + goto out; - task = get_proc_task(inode); - if (!task) - return res; + if (!ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) + goto out_put; - if (ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) { - res = ns_get_name(name, sizeof(name), task, ns_ops); - if (res >= 0) - res = readlink_copy(buffer, buflen, name); + if (is_following_link()) { + res = ns_get_path(&ns_path, task, ns_ops); + if (!res) + nd_jump_link(&ns_path); + } else { + char *name = kmalloc(PROC_NS_LINK_MAX, GFP_KERNEL); + int err; + + res = ERR_PTR(-ENOMEM); + if (!name) + goto out_put; + + err = ns_get_name(name, PROC_NS_LINK_MAX, task, ns_ops); + if (err < 0) { + kfree(name); + res = ERR_PTR(err); + goto out_put; + } + set_delayed_call(done, kfree_link, name); + res = name; } +out_put: put_task_struct(task); +out: return res; } static const struct inode_operations proc_ns_link_inode_operations = { - .readlink = proc_ns_readlink, + .readlink = generic_readlink, .get_link = proc_ns_get_link, .setattr = proc_setattr, };