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 <neilb@xxxxxxx> --- 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); -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html