From patchwork Mon Sep 12 19:29:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9327871 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 C84EA60231 for ; Mon, 12 Sep 2016 19:33:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BAEC228E59 for ; Mon, 12 Sep 2016 19:33:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AFA7328E6F; Mon, 12 Sep 2016 19:33:08 +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=ham 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 8F1BC28E59 for ; Mon, 12 Sep 2016 19:33:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758167AbcILT3g (ORCPT ); Mon, 12 Sep 2016 15:29:36 -0400 Received: from mail-wm0-f53.google.com ([74.125.82.53]:37063 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932468AbcILT3d (ORCPT ); Mon, 12 Sep 2016 15:29:33 -0400 Received: by mail-wm0-f53.google.com with SMTP id c131so75117572wmh.0 for ; Mon, 12 Sep 2016 12:29:33 -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=lRQok3pW4xlEfWb3AYKnnVqGrs2cGD9OQ5QaE6lyOjw=; b=lT0f87wqBA6lP9gZy+gR/9uVNLcdEH6HKMWTCryfdLixmG0/uSNRYiFMajh2nfTW22 PH5VKFngbZZgNFhrILuR3nxfZ9dqOV78HqyytjBkvqWq4u4TBlpCq5jQcCQ0SEAkOpVr bRi8+YOaM+AB++Fo4uS7IhxOvr2hyW6TnbzLBSkpTZu3lEJDCcgGSLBKSv23gSSS/FoM 38cPkuxR5W8u45Q2lsAi1mZP9GljjHGY3ZfXY6O90slorfg8RsDKi/uV5i9BQAZplfed H75Wrh1VrpNJwjZ401qHnrxkPAJZ2dc7Ws73EemY1+fpZnqtQcUr4Gv1zRZBM9un1RLZ 4vBg== X-Gm-Message-State: AE9vXwPkpIiVy3dhn1dtXNMvzixVbc1yHFHQz3q8sgpSO05Dsfaa4PREZZlnIBLnepZOxD77 X-Received: by 10.194.145.101 with SMTP id st5mr19754251wjb.94.1473708571993; Mon, 12 Sep 2016 12:29:31 -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.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Sep 2016 12:29:30 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Al Viro Subject: [PATCH 07/17] vfs: add is_following_link() helper Date: Mon, 12 Sep 2016 21:29:09 +0200 Message-Id: <1473708559-12714-8-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 The remainging instances of ->readlink that don't use generic_readlink are /proc/$$/fd/N, /proc/$$/map_files/A and /proc/$$/ns/X. The reason is that these have special get_link() implementations is that they "jump" to locations not indicated by the symlink contents. Since there are so few of these (the fd and map_files ones are essentially the same), it doesn't make sense to create a separate i_op method for them. This patch adds a helper: is_following_link() by which the two different modes of operation can be differentiated by the special get_link() implementations. Also add a WARN_ON_ONCE() in generic_readlink() to prevent misuse. Signed-off-by: Miklos Szeredi --- fs/namei.c | 9 +++++++++ include/linux/namei.h | 1 + 2 files changed, 10 insertions(+) diff --git a/fs/namei.c b/fs/namei.c index c06a68b82088..f72c405d1a27 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -880,6 +880,11 @@ void nd_jump_link(struct path *path) nd->flags |= LOOKUP_JUMPED; } +bool is_following_link(void) +{ + return current->nameidata; +} + static inline void put_link(struct nameidata *nd) { struct saved *last = nd->stack + --nd->depth; @@ -4670,6 +4675,10 @@ int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen) link = inode->i_op->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/namei.h b/include/linux/namei.h index f29abda31e6d..ec7b8ccfe064 100644 --- a/include/linux/namei.h +++ b/include/linux/namei.h @@ -90,6 +90,7 @@ extern struct dentry *lock_rename(struct dentry *, struct dentry *); extern void unlock_rename(struct dentry *, struct dentry *); extern void nd_jump_link(struct path *path); +extern bool is_following_link(void); static inline void nd_terminate_link(void *name, size_t len, size_t maxlen) {