Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp14268ybe; Wed, 4 Sep 2019 14:12:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqxSimtCC3SvfUavaEcdRHrm6nm3yP5zJwkslMWbpkcDoj8IpP7j5mx/IDHiGa8+3NhP5PSg X-Received: by 2002:a62:7790:: with SMTP id s138mr46511519pfc.243.1567631571338; Wed, 04 Sep 2019 14:12:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567631571; cv=none; d=google.com; s=arc-20160816; b=YpD6NlVuWJMNjgj6E5mMsLlqQNSkEqrJIwO6a0eYUqQ7sBly8NsHMJBAbq59KeGPFD CfvDQpA6sDGsSFabDU/pDZW8d6N+R/e9TWNf0BKCFTt81h3PEOzdvCiqfgfR5dymMrTE wwpGrYSYfaAmfthSo+j3E17c1X4Q+veV79ombg1HYGwvxIc7579t74UfQS20/6jlD56x 2Hr68qMsqBNpY/oQBatxnc7+hMgiQEYqjBMXu8GSSGo1bZg+TRzX2Z5mad66Tk+n8XEl umRWD2myrb3951zkmCStP+hlaUV3hRufSxogzCo+K6evH5K1/E7BJnabnIe3sSM5JliD B8pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=hgF2nRVhP2Z9Hk/CZOFcXhAAs++h0MvE3fMY8xcOeYw=; b=CNFG+pMR34gBq3Plb3ayHczQ7UPyDdni3VV4eBRwwDaZS1HaUFxTXBiWecD7qJvaJA zBbS68FugkSDa99wRISeP1y3x+GzZ2htI8Hj9j1JE1vIQY1FULxkOPLv6/DT7+gOcNIh B4nL6FWkXskuBygfFaDqFz+vEnrnfn9j6jsVm9isVsu5mlJHVWFmGRgtKS2rnomOM8Hr VyPiuiMl0y9erR3ZxJmFduFPWOZv7lEVdC2jLzbVAK4NsN+NMh0AtARJgqkwM+EUFySV HBHoXJzC4kWwICIWajJy7uL52i9HXZLJTNl0Yw0q93qEo99FxctYaV++j7sC+9mSyMpt lGDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="V0fXrvG/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si17090plt.296.2019.09.04.14.12.34; Wed, 04 Sep 2019 14:12:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="V0fXrvG/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730214AbfIDVKM (ORCPT + 99 others); Wed, 4 Sep 2019 17:10:12 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:42348 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727900AbfIDVKL (ORCPT ); Wed, 4 Sep 2019 17:10:11 -0400 Received: by mail-lf1-f68.google.com with SMTP id u13so137657lfm.9 for ; Wed, 04 Sep 2019 14:10:10 -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=mw5JsjT4BrAO5WKG8JRb0pjdN01YeM+0G5P7W9xEM5qwuez2PrMCahVmTgGJRcZ6pN hNA0B0bC24zTyHNmqFnTqd9PnUCH6zVxmgK36rSdJy8r88NgSad6KhCJiY7r7t+fAp5X LS6WTe+XNudU6PY5U3yhgaR+GqQNXVAx6TNLuqUDxB8oNdDxctL1IPtDqOwBs5ynj93u BJv88gaMzMYRcZ+QXjBFbXLolit0vUk+7r32/YR9om7Da5zbVNcAVf25xO1zil6xoSAJ AzGlB+uMmdtCsw9r/ufC4eBSAQ4RuDcHBzsdcDuDDjHWW60RDWB6MC3IY27bCtJEVqHu nQAA== X-Gm-Message-State: APjAAAXecmYyjLmYgAXFl0Drl2QQ31rjCYfmBuPBYV6Ht3Dj1PK3W7op NtsbVh0TEXcV5eISQgw2CMTCWeN8vMI= X-Received: by 2002:ac2:4a70:: with SMTP id q16mr122256lfp.4.1567631408918; Wed, 04 Sep 2019 14:10:08 -0700 (PDT) Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com. [209.85.208.171]) by smtp.gmail.com with ESMTPSA id v1sm3717728lfa.87.2019.09.04.14.10.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Sep 2019 14:10:08 -0700 (PDT) Received: by mail-lj1-f171.google.com with SMTP id j16so160636ljg.6 for ; Wed, 04 Sep 2019 14:10:06 -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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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