From patchwork Mon Sep 12 19:29:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9327847 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 365D460231 for ; Mon, 12 Sep 2016 19:31:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28AE728E59 for ; Mon, 12 Sep 2016 19:31:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D71828E6F; Mon, 12 Sep 2016 19:31:34 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 E180028E59 for ; Mon, 12 Sep 2016 19:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757186AbcILTbP (ORCPT ); Mon, 12 Sep 2016 15:31:15 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:36283 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932633AbcILT3r (ORCPT ); Mon, 12 Sep 2016 15:29:47 -0400 Received: by mail-wm0-f41.google.com with SMTP id b187so152088735wme.1 for ; Mon, 12 Sep 2016 12:29:46 -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=aNH7lwNHiFKYTQzWc9AWGAQeCQVLBShvHkXUdrs4Wz0=; b=WzH7/2HB0yFBuevO20GORtbBdjldjPfWGGbiFi5x8otyIENNfV/MAfQVCGU/idHsUA hJDhSgU8LEF8Y6m6DNSiiXpWXnWk1AKgIVQsWsdQ1uV+6zfjoBaFiZVH7kkhZ3TbVh2b a4YHlP6fXlSDQZe/PVHx0JbrCsh13o13IVwsCB78B0hUykvJ8k1es+3HaZHcxKJSRaB8 7r6jBOK7qOIM91EOEIlrs9MHk+rik49u8zRatCp/iMeVfqZjUWAMPZ7wojs5GxrnwPlH BVwEtngEzSl1YnL5zr0OA6OINgSCC0KBe0s1WXOc31l8pA5LMO0kz7ptTG0UdmA06cJu wDZg== X-Gm-Message-State: AE9vXwP7nqOcqwaz039vesfhpWcG5xRW5IEvfvCp1c9r+g6hQX4KlSkk0r7flLcING81R6kG X-Received: by 10.28.203.141 with SMTP id b135mr11661038wmg.36.1473708585968; Mon, 12 Sep 2016 12:29:45 -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.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Sep 2016 12:29:44 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Al Viro Subject: [PATCH 16/17] ovl: use vfs_get_link() Date: Mon, 12 Sep 2016 21:29:18 +0200 Message-Id: <1473708559-12714-17-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 Resulting in a complete removal of a function basically implementing the inverse of vfs_readlink(). As a bonus, now the proper security hook is also called. Signed-off-by: Miklos Szeredi --- fs/overlayfs/copy_up.c | 45 ++++++--------------------------------------- fs/overlayfs/inode.c | 5 +---- 2 files changed, 7 insertions(+), 43 deletions(-) diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c index a2d4c10dd74d..c3371d62d931 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -167,39 +167,6 @@ out_fput: return error; } -static char *ovl_read_symlink(struct dentry *realdentry) -{ - int res; - char *buf; - struct inode *inode = realdentry->d_inode; - mm_segment_t old_fs; - - res = -EINVAL; - if (!inode->i_op->get_link) - goto err; - - res = -ENOMEM; - buf = (char *) __get_free_page(GFP_KERNEL); - if (!buf) - goto err; - - old_fs = get_fs(); - set_fs(get_ds()); - /* The cast to a user pointer is valid due to the set_fs() */ - res = vfs_readlink(realdentry, (char __user *)buf, PAGE_SIZE - 1); - set_fs(old_fs); - if (res < 0) { - free_page((unsigned long) buf); - goto err; - } - buf[res] = '\0'; - - return buf; - -err: - return ERR_PTR(res); -} - static int ovl_set_timestamps(struct dentry *upperdentry, struct kstat *stat) { struct iattr attr = { @@ -331,19 +298,21 @@ out_cleanup: int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry, struct path *lowerpath, struct kstat *stat) { + DEFINE_DELAYED_CALL(done); struct dentry *workdir = ovl_workdir(dentry); int err; struct kstat pstat; struct path parentpath; + struct dentry *lowerdentry = lowerpath->dentry; struct dentry *upperdir; struct dentry *upperdentry; const struct cred *old_cred; - char *link = NULL; + const char *link = NULL; if (WARN_ON(!workdir)) return -EROFS; - ovl_do_check_copy_up(lowerpath->dentry); + ovl_do_check_copy_up(lowerdentry); ovl_path_upper(parent, &parentpath); upperdir = parentpath.dentry; @@ -353,7 +322,7 @@ int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry, return err; if (S_ISLNK(stat->mode)) { - link = ovl_read_symlink(lowerpath->dentry); + link = vfs_get_link(lowerdentry, d_inode(lowerdentry), &done); if (IS_ERR(link)) return PTR_ERR(link); } @@ -381,9 +350,7 @@ int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry, out_unlock: unlock_rename(workdir, upperdir); revert_creds(old_cred); - - if (link) - free_page((unsigned long) link); + do_delayed_call(&done); return err; } diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c index db8975f59021..6be9bb470fd9 100644 --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c @@ -164,11 +164,8 @@ static const char *ovl_get_link(struct dentry *dentry, realdentry = ovl_dentry_real(dentry); realinode = realdentry->d_inode; - if (WARN_ON(!realinode->i_op->get_link)) - return ERR_PTR(-EPERM); - old_cred = ovl_override_creds(dentry->d_sb); - p = realinode->i_op->get_link(realdentry, realinode, done); + p = vfs_get_link(realdentry, realinode, done); revert_creds(old_cred); return p; }