Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp443382pxb; Wed, 1 Sep 2021 02:22:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5oh788k3zmYF1fmR7abatT6Tj0I+thQ4czBfTXcrN54cyDBaHW1E6eR6P+stkuu2aNKPO X-Received: by 2002:a17:906:5e4b:: with SMTP id b11mr16989688eju.472.1630488158001; Wed, 01 Sep 2021 02:22:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630488157; cv=none; d=google.com; s=arc-20160816; b=WoeLA0rvrkN/jhxPXKXWXxDM1bvPGcUFM/V/GIGXFa4+QsAHlsTYPeR91JIMTN0I8Z okB4RbgiA0XnlwgRDJ9035FmzDm71biJgvw9wXcHEJ6Lbqyy3icrcjzFnCHn9V6n2raH MdPVqaSJOKHgCPp2DRl0IUZM+cvUG5jCkiuyTSvN3B6VScEewmmjUGnlQBmC5v4pfzE1 l55/t81OF86xymc3Nbbc+bbai/IClDzzC5n5cMJtKkX1N9elt40WPn98qTDZHBDGA2Yq U3sM3JtVEoGP4Y3bwB3YNRw6axUnx+zt8G+vCg0pfsCN8MAd6zEr1AtIjua01ey5y7Zg kdwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=kkri7tT4fIBDPfIQhCUKK7u4nuQgtfBcg/qedosEIiw=; b=CBLsX4e3splDrxaIg0tMXzoiZYEFXslHTpRfJxiNy0JYMu+zSZPplIEQhvuCOZOwrJ 2HHmk33XaEJTy60IoPnRwQxFxzj340cVD15We1lmnH0l0GeSZ3mrL3WRcohRhflFbfmk Sfzc0OuZWsvjf5dn8Ms6gmXw8yQTCsbALrFvdw51rS6XZoqdtKdUHlBWSDXDzNwMxzW+ rTFfOzFYqEGLzhPr/CJphdTaOLT8e3UjeBC7t8gcSG2gkdAXqXMIRbG+fRUVWCdYb0F3 vIPl4kpsgydAAWtpSPSjxNV/EXYQDjPeExGWuTDOIUDGxcoj0ommHSmd9w/F0CoLrZSL FdnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=eG14zmp6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e10si22464340edz.215.2021.09.01.02.21.57; Wed, 01 Sep 2021 02:22:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=eG14zmp6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243466AbhIAJOk (ORCPT + 99 others); Wed, 1 Sep 2021 05:14:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243285AbhIAJOj (ORCPT ); Wed, 1 Sep 2021 05:14:39 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62D5AC061575; Wed, 1 Sep 2021 02:13:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=kkri7tT4fIBDPfIQhCUKK7u4nuQgtfBcg/qedosEIiw=; b=eG14zmp6Kro2k7a7jO1uyoWiU+ n8Cw/wj2cIFmXIqZZV0e56pLJ8hCGxMEz1F6P6Y9uSwXhT/xhlPG60ppbnfn9BN4lJkyObTdtsyYK LmrSYhIhJTzsf7m8ryNIQZbO8xrIFPAYw+zgb10xMkiHCW+xn6i4/fuYNqQOzBEewR/dMNKnfrO0F uSY5nBB7K64btU/rKlHuVn2+FAUxPGjruNVVuF5PIj8G3rF2qsmwxrmEeEkk5COYdJr3kAyWrZc19 rgxJmZQbblDO5wmBRzlIVQ77I7SUnbtv2Tr8vZRKvxh/+q2BkfpQREUQFlPINsxK+QlfAbhvTWuwP 5zNGXJnA==; Received: from hch by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mLMHo-00256D-3O; Wed, 01 Sep 2021 09:12:15 +0000 Date: Wed, 1 Sep 2021 10:12:00 +0100 From: Christoph Hellwig To: Dmitry Kadashev Cc: Stephen Brennan , Alexander Viro , Jens Axboe , linux-fsdevel , linux-kernel@vger.kernel.org Subject: Re: [PATCH] namei: Fix use after free in kern_path_locked Message-ID: References: <20210901001341.79887-1-stephen.s.brennan@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 01, 2021 at 02:35:08PM +0700, Dmitry Kadashev wrote: > On Wed, Sep 1, 2021 at 7:13 AM Stephen Brennan > wrote: > > > > In 0ee50b47532a ("namei: change filename_parentat() calling > > conventions"), filename_parentat() was made to always put the struct > > filename before returning, and kern_path_locked() was migrated to this > > calling convention. However, kern_path_locked() uses the "last" > > parameter to lookup and potentially create a new dentry. The last > > parameter contains the last component of the path and points within the > > filename, which was recently freed at the end of filename_parentat(). > > Thus, when kern_path_locked() calls __lookup_hash(), it is using the > > filename after it has already been freed. > > > > To avoid this, switch back to __filename_parentat() and place a putname > > at the end of the function, once all uses are completed. > > Ouch. Thanks for taking care of this, Stephen. I guess > filename_parentat() should be killed, since kern_path_locked() was the > only place it's used in and it always results in danging "last", > provoking bugs just like this one. I can send a patch on top of this if > you prefer. Yes. And then rename __filename_parentat to filename_parentat, please.