From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752151AbbCWCiI (ORCPT ); Sun, 22 Mar 2015 22:38:08 -0400 Received: from cantor2.suse.de ([195.135.220.15]:34426 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752079AbbCWCiD (ORCPT ); Sun, 22 Mar 2015 22:38:03 -0400 From: NeilBrown To: Al Viro Date: Mon, 23 Mar 2015 13:37:38 +1100 Subject: [PATCH 02/20] STAGING/lustre: limit follow_link recursion using stack space. Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <20150323023738.8161.97062.stgit@notabene.brown> In-Reply-To: <20150323023258.8161.32467.stgit@notabene.brown> References: <20150323023258.8161.32467.stgit@notabene.brown> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org lustre's ->follow_link() uses a lot of stack space and so need to limit symlink recursion based on stack size. It currently tests current->link_count, but that will soon become private to fs/namei.c. So instead base on actual available stack space. This patch aborts recursive symlinks in less than 2K of space is available. This seems consistent with current code, but hasn't been tested. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/llite/symlink.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/staging/lustre/lustre/llite/symlink.c b/drivers/staging/lustre/lustre/llite/symlink.c index 686b6a574cc5..ba37eb6b29dc 100644 --- a/drivers/staging/lustre/lustre/llite/symlink.c +++ b/drivers/staging/lustre/lustre/llite/symlink.c @@ -120,20 +120,27 @@ failed: static void *ll_follow_link(struct dentry *dentry, struct nameidata *nd) { + unsigned long avail_space; struct inode *inode = dentry->d_inode; struct ptlrpc_request *request = NULL; int rc; char *symname = NULL; CDEBUG(D_VFSTRACE, "VFS Op\n"); - /* Limit the recursive symlink depth to 5 instead of default - * 8 links when kernel has 4k stack to prevent stack overflow. - * For 8k stacks we need to limit it to 7 for local servers. */ - if (THREAD_SIZE < 8192 && current->link_count >= 6) { - rc = -ELOOP; - } else if (THREAD_SIZE == 8192 && current->link_count >= 8) { + /* Limit the recursive symlink depth. + * Previously limited to 5 instead of default 8 links when + * kernel has 4k stack to prevent stack overflow. + * For 8k stacks, was limited to 7 for local servers. + * Now limited to ensure 2K of stack is available for lustre. + */ +#ifdef CONFIG_STACK_GROWSUP + avail_space = end_of_stack(current) - &avail_space; +#else + avail_space = &avail_space - end_of_stack(current); +#endif + if (avail_space < 2048) rc = -ELOOP; - } else { + else { ll_inode_size_lock(inode); rc = ll_readlink_internal(inode, &request, &symname); ll_inode_size_unlock(inode);