From patchwork Mon Mar 23 02:37:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 6068991 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 865C09F350 for ; Mon, 23 Mar 2015 02:43:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AD83520219 for ; Mon, 23 Mar 2015 02:43:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D688120211 for ; Mon, 23 Mar 2015 02:43:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752132AbbCWCiH (ORCPT ); Sun, 22 Mar 2015 22:38:07 -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 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 311DFAD28; Mon, 23 Mar 2015 02:38:02 +0000 (UTC) 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 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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);