Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752841AbbEKXnh (ORCPT ); Mon, 11 May 2015 19:43:37 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:49420 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751330AbbEKXng (ORCPT ); Mon, 11 May 2015 19:43:36 -0400 Date: Tue, 12 May 2015 00:43:33 +0100 From: Al Viro To: Linus Torvalds Cc: Neil Brown , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v3 105/110] namei: make unlazy_walk and terminate_walk handle nd->stack, add unlazy_link Message-ID: <20150511234333.GA7232@ZenIV.linux.org.uk> References: <20150511180650.GA4147@ZenIV.linux.org.uk> <1431367690-5223-105-git-send-email-viro@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1431367690-5223-105-git-send-email-viro@ZenIV.linux.org.uk> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1557 Lines: 33 On Mon, May 11, 2015 at 07:08:05PM +0100, Al Viro wrote: > +static bool legitimize_links(struct nameidata *nd) > +{ > + int i; > + for (i = 0; i < nd->depth; i++) { > + struct saved *last = nd->stack + i; > + if (unlikely(!legitimize_path(nd, &last->link, last->seq))) { > + drop_links(nd); > + nd->depth = i; Broken, actually - it should be i + 1. What happens is that we attempt to grab references on nd->stack[...].link; if everything succeeds, we'd won. If legitimizing nd->stack[i].link fails (e.g. ->d_seq has changed on us), we * put_link everything in stack and clear nd->stack[...].cookie, making sure that nobody will call ->put_link() on it later. * leave the things for terminate_walk() so that it would do path_put() on everything we have grabbed and ignored everything we hadn't even got around to. But this failed legitimize_path() requires path_put() - we *can't* block there (we wouldn't be able to do ->put_link() afterwards if we did), so we just zero what we didn't grab and leave what we had for subsequent path_put(). Which may be anything from "nothing" (mount_lock has been touched) to "both vfsmount and dentry" (->d_seq mismatch). So we need to set nd->depth to i + 1 here, not i. As it is, we are risking a vfsmount (and possibly dentry) leak. Fixed and force-pushed... -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/