From patchwork Mon Sep 12 19:29:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9327845 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 880BB60231 for ; Mon, 12 Sep 2016 19:31:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A69628E6E for ; Mon, 12 Sep 2016 19:31:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F00728E98; Mon, 12 Sep 2016 19:31:33 +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 0E93A28E6E for ; Mon, 12 Sep 2016 19:31:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757574AbcILTbQ (ORCPT ); Mon, 12 Sep 2016 15:31:16 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:36262 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932586AbcILT3p (ORCPT ); Mon, 12 Sep 2016 15:29:45 -0400 Received: by mail-wm0-f48.google.com with SMTP id b187so152087689wme.1 for ; Mon, 12 Sep 2016 12:29:45 -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=ZVqHUKz2RarzjBp9nsV7pTAeR+bnVPgRfCHW45kQvtw=; b=C+s8TrtrNBCvbvUr3VnhXUbxiNCvGOqxYBIIlFn/Pvphz/TAPec7UEw5Z4CHBy7UYY 3MzyJcwnldBNz1FcaKwX5GcMhqtdlOXVdPfsx8NevCL/m34cixWRo1S0h1dGb+iMWr4o O788nYM0KwgCXB1hqTypIuYT3rV/xVoRO/K9+NgG7bYrr3k8nMQLJkYR/rQZOylmFjTm PrUAEC8yeEe8oF1Y5TEd5056C2hB1oNdMhredkKfWl/2/WPQD0u4KGYtj56HL0dAlzdi SNKIdcnTXoy8VDu0Z89MPNMezP51YWfTp319lvsWXefufZ+Ktpp5W/N4MZm0wmFYqFwd dENQ== X-Gm-Message-State: AE9vXwN57TUEeyts6fBuXRavanQC9UlQ/6mJXqIHmlOKcnA7fx0lQMDMIO1qoB7pbzTnVjI9 X-Received: by 10.28.48.71 with SMTP id w68mr13207215wmw.4.1473708584514; Mon, 12 Sep 2016 12:29:44 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Sep 2016 12:29:43 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Al Viro Subject: [PATCH 15/17] vfs: add vfs_get_link() helper Date: Mon, 12 Sep 2016 21:29:17 +0200 Message-Id: <1473708559-12714-16-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 helper is for filesystems that want to read the symlink and are better off with the get_link() interface (returning a char *) rather than the readlink() interface (copy into a userspace buffer). Also call the LSM hook for readlink (not get_link) since this is for symlink reading not following. Signed-off-by: Miklos Szeredi --- fs/namei.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- include/linux/fs.h | 2 ++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 76d1f061de3c..23c3fb8cec0a 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4659,6 +4659,47 @@ out: return len; } +static const char *do_get_link(struct dentry *dentry, struct inode *inode, + struct delayed_call *done) +{ + const char *link = inode->i_op->get_link(dentry, inode, done); + + /* "jumping" is unacceptable, warn and return error */ + if (!IS_ERR(link) && WARN_ON_ONCE(!link)) + link = ERR_PTR(-EIO); + + return link; +} + +/** + * vfs_get_link - get symbolic link + * @dentry: dentry + * @inode: inode on which to get symbolic link + * @done: caller needs to free returned data with this + * + * Calls security hook and i_op->get_link() on the supplied inode. + * + * It does not touch atime. That's up to the caller if necessary. + * + * Don't call this from RCU lookup mode (yet) + */ +const char *vfs_get_link(struct dentry *dentry, struct inode *inode, + struct delayed_call *done) +{ + const char *res = ERR_PTR(-EINVAL); + + if (inode->i_op->get_link) { + int error = security_inode_readlink(dentry); + + res = ERR_PTR(error); + if (!error) + res = do_get_link(dentry, inode, done); + } + + return res; +} +EXPORT_SYMBOL(vfs_get_link); + /** * vfs_readlink - read symlink body * @dentry: read symlink from this dentry @@ -4682,13 +4723,9 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen) int res; if (!link) { - link = inode->i_op->get_link(dentry, inode, &done); + link = do_get_link(dentry, inode, &done); if (IS_ERR(link)) return PTR_ERR(link); - - /* "jumping" is unacceptable, warn and return error */ - if (WARN_ON_ONCE(!link)) - return -EIO; } res = readlink_copy(buffer, buflen, link); do_delayed_call(&done); diff --git a/include/linux/fs.h b/include/linux/fs.h index f71e70e3017b..58f42e979b12 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2916,6 +2916,8 @@ extern int vfs_fstat(unsigned int, struct kstat *); extern int vfs_fstatat(int , const char __user *, struct kstat *, int); extern int vfs_readlink(struct dentry *, char __user *, int); +extern const char *vfs_get_link(struct dentry *, struct inode *, + struct delayed_call *); extern int __generic_block_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,