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=-0.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 949FFC3A5A9 for ; Wed, 4 Sep 2019 21:15:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 67B5921726 for ; Wed, 4 Sep 2019 21:15:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567631748; bh=LuUtzpYz+SszjJS1ASCTqLWs6NSw/g3zdJ1//DUUYJs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=ErHk/3+VGO/rAt9mHm0Tu4wd6usKco5V1o1iVjJ8II3TMykb6l+1CebgWFFRgQnCC WA+/6D+/31qRLcy3PaW3wOZvXLJP4ZeA9NnL4GchbMsQx1h1atOACgsCcWV26HFceR 2H0pKyjYVlzNAYDqlEzgmO3tH3dNL65pIyd30o7E= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729597AbfIDVPr (ORCPT ); Wed, 4 Sep 2019 17:15:47 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:34790 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726495AbfIDVPr (ORCPT ); Wed, 4 Sep 2019 17:15:47 -0400 Received: by mail-lj1-f195.google.com with SMTP id x18so203036ljh.1 for ; Wed, 04 Sep 2019 14:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hgF2nRVhP2Z9Hk/CZOFcXhAAs++h0MvE3fMY8xcOeYw=; b=V0fXrvG/y6fw7T3tD/KUlmTDsOhByRFRgMw+QxPA9hiU5TDgpngn7HfopRM+i/LJMb k2AA+nRMkFxYb/ldSeHBR5el3bmmhNNCMxw9ToB+OOlkWRR6wchZHlLiKsQK9TmfmvjP dVvrUijYkfU5Fh9X3uECYhU3OGmtsUJMmdGfk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hgF2nRVhP2Z9Hk/CZOFcXhAAs++h0MvE3fMY8xcOeYw=; b=ljOvbdorKyFs431Z3OruROqXe0kFCI+IwZ2QlXorLZxB/u+onN0IDc3XNr6LDioTAI vIulGyV87g/aFg1Uub4U98fRGh9bgGLwVj2Psbp252P8a1dHtLTakmEvokhomxAg1lTg snEtXi3lRX6tI95rw7RxtIsdiWoPfry4dy0LzCjrIX2/VWmpadU+AZVYIGIGld0neIfG GK2htoQQ7t957PJ99l+So1CGNPx02rga1zNwYTyOxSUbbbgTkvkE8yIgtfjVeaUJV+cD wUI1Z0ygwhGtUIETWhSMRzVEkSVqQf494hyfccKNZIurmnxPWPmYrK+EdUotrdygLjv7 0jrg== X-Gm-Message-State: APjAAAXGLYQILtdPudKNaWdrQAuTp2b08WvKmt3mqMOrBry0ZMW5B5F4 Of1djZD50Qyhl0ZSon22HUvhEYyZEFY= X-Google-Smtp-Source: APXvYqwiVNBTDS8K95CXE7bJQcUZbYKKfl/TPALNqTJGCMuVKQ19E/gTU4xebvV444kAEAV/NSFfaQ== X-Received: by 2002:a2e:5c45:: with SMTP id q66mr23430993ljb.197.1567631744879; Wed, 04 Sep 2019 14:15:44 -0700 (PDT) Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com. [209.85.208.180]) by smtp.gmail.com with ESMTPSA id y10sm3552591ljk.5.2019.09.04.14.15.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Sep 2019 14:15:44 -0700 (PDT) Received: by mail-lj1-f180.google.com with SMTP id x18so202983ljh.1 for ; Wed, 04 Sep 2019 14:15:44 -0700 (PDT) X-Received: by 2002:a2e:8507:: with SMTP id j7mr10579330lji.156.1567631404184; Wed, 04 Sep 2019 14:10:04 -0700 (PDT) MIME-Version: 1.0 References: <20190904201933.10736-1-cyphar@cyphar.com> <20190904201933.10736-11-cyphar@cyphar.com> In-Reply-To: <20190904201933.10736-11-cyphar@cyphar.com> From: Linus Torvalds Date: Wed, 4 Sep 2019 14:09:48 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v12 10/12] namei: aggressively check for nd->root escape on ".." resolution To: Aleksa Sarai Cc: Al Viro , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , David Howells , Shuah Khan , Shuah Khan , Ingo Molnar , Peter Zijlstra , Christian Brauner , Jann Horn , Kees Cook , Eric Biederman , Andy Lutomirski , Andrew Morton , Alexei Starovoitov , Tycho Andersen , David Drysdale , Chanho Min , Oleg Nesterov , Rasmus Villemoes , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Aleksa Sarai , Linux Containers , alpha , Linux API , linux-arch , Linux ARM , linux-fsdevel , linux-ia64@vger.kernel.org, Linux List Kernel Mailing , "open list:KERNEL SELFTEST FRAMEWORK" , linux-m68k , linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390 , Linux-sh list , linux-xtensa@linux-xtensa.org, sparclinux@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Wed, Sep 4, 2019 at 1:23 PM Aleksa Sarai wrote: > > This patch allows for LOOKUP_BENEATH and LOOKUP_IN_ROOT to safely permit > ".." resolution (in the case of LOOKUP_BENEATH the resolution will still > fail if ".." resolution would resolve a path outside of the root -- > while LOOKUP_IN_ROOT will chroot(2)-style scope it). Magic-link jumps > are still disallowed entirely because now they could result in > inconsistent behaviour if resolution encounters a subsequent ".."[*]. This is the only patch in the series that makes me go "umm". Why is it ok to re-initialize m_seq, which is used by other things too? I think it's because we're out of RCU lookup, but there's no comment about it, and it looks iffy to me. I'd rather have a separate sequence count that doesn't have two users with different lifetime rules. But even apart from that, I think from a "patch continuity" standpoint it would be better to introduce the sequence counts as just an error condition first - iow, not have the "path_is_under()" check, but just return -EXDEV if the sequence number doesn't match. So you'd have three stages: 1) ".." always returns -EXDEV 2) ".." returns -EXDEV if there was a concurrent rename/mount 3) ".." returns -EXDEV if there was a concurrent rename/mount and we reset the sequence numbers and check if you escaped. becasue the sequence number reset really does make me go "hmm", plus I get this nagging little feeling in the back of my head that you can cause nasty O(n^2) lookup cost behavior with deep paths, lots of "..", and repeated path_is_under() calls. So (1) sounds safe. (2) sounds simple. And (3) is where I think subtle things start happening. Also, I'm not 100% convinced that (3) is needed at all. I think the retry could be done in user space instead, which needs to have a fallback anyway. Yes? No? Linus