From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A17DAC433E3 for ; Tue, 21 Jul 2020 18:26:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8AD42206E9 for ; Tue, 21 Jul 2020 18:26:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726404AbgGUS0M (ORCPT ); Tue, 21 Jul 2020 14:26:12 -0400 Received: from verein.lst.de ([213.95.11.211]:53384 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726029AbgGUS0M (ORCPT ); Tue, 21 Jul 2020 14:26:12 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 209F968B05; Tue, 21 Jul 2020 20:26:08 +0200 (CEST) Date: Tue, 21 Jul 2020 20:26:07 +0200 From: Christoph Hellwig To: Al Viro Cc: Linus Torvalds , Christoph Hellwig , Greg Kroah-Hartman , "Rafael J. Wysocki" , Linux Kernel Mailing List , linux-raid@vger.kernel.org, linux-fsdevel , Linux API Subject: Re: [PATCH 05/24] devtmpfs: open code ksys_chdir and ksys_chroot Message-ID: <20200721182607.GA14450@lst.de> References: <20200721162818.197315-1-hch@lst.de> <20200721162818.197315-6-hch@lst.de> <20200721171627.GZ2786714@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200721171627.GZ2786714@ZenIV.linux.org.uk> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-api-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Tue, Jul 21, 2020 at 06:16:27PM +0100, Al Viro wrote: > On Tue, Jul 21, 2020 at 09:49:17AM -0700, Linus Torvalds wrote: > > On Tue, Jul 21, 2020 at 9:28 AM Christoph Hellwig wrote: > > > > > > + > > > + /* traverse into overmounted root and then chroot to it */ > > > + if (!kern_path("/..", LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path) && > > > + !inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHDIR) && > > > + ns_capable(current_user_ns(), CAP_SYS_CHROOT) && > > > + !security_path_chroot(&path)) { > > > + set_fs_pwd(current->fs, &path); > > > + set_fs_root(current->fs, &path); > > > + } > > > + path_put(&path); > > > > This looks wrong. > > It is wrong. kern_path() leaves *path unmodified in case of error, and > that struct path is uninitialized here. Yep. Only saving grace is that the error just doesn't happen during early init.