Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp25897lqn; Thu, 11 Apr 2024 12:35:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/Kn4fdyqk4+ggWIPmYeX+3CwtyYORcnqsFeEs6lncZMLZYI98MOy/2DTC3zz1XZ7sI3C8jMX28DJ+bVeVP0m5dBv0ptpWet4QHC8qOQ== X-Google-Smtp-Source: AGHT+IHhHlFsq5kyjRxTgXYpVoAq4Zr9mwoY1RcMdB6H3Vf8XHECjnun+Hcq+pHCmD+dMrZeqO68 X-Received: by 2002:a05:6a00:1390:b0:6ea:bb00:dbb6 with SMTP id t16-20020a056a00139000b006eabb00dbb6mr762898pfg.8.1712864123025; Thu, 11 Apr 2024 12:35:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712864123; cv=pass; d=google.com; s=arc-20160816; b=lb3U0542CT1AYJXv5zHVcbSV5BhmrYb7e3SzySt0U3ERQMCiXH8CmF8NAWQi4p+XTP CfG5FSCXXGYWaaD95h3BwHhkyv82nIfRE3gU0lGm6C25QbZFY3jwc6s2TQsF/dssmwXg p0fq5ZgzO7raaLP76cPRjk3SllKaba5VeMrbPkTbqCXXqPHd6oWj9ClnjO5a9eaAhwGm pMyZyCP1TxfNkFeX9nIUCxuRN1RnGj02bNF72u9gSh3bATnqr4H3KS6IRwLchz/CQIdp sOY7XN+HvNKlGVyuMENeQmKeYjUwSLhrrKDJupFg5Fw/vaHDjEIdUsk25pwAdmWQJCMo O1Ww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=qhujaawioP0edqzESewC5qrutyIfvYKamEof/gouabc=; fh=9mSALxaQY6r5KgbUrCM4MedkFzFtUEVCRV49hKA9NRU=; b=yrIPMPN1GfM0e92uPZFEyw2Vv3TET+8p5GW9VATvK9qeuZzRuXUTAaTiigjtKHUCQu BD9S/Z0Z2s4SeJcNulum/fRmwkaS5oAfsEypPWCxvpr7DDh9XVQU9bof+XYr8QA2ysEE RSs3G0tVOqIK/4iFAksTVuhhN1jUXLxaK90NBFo1qxcf9q/QUAYRbjRR7I5y8fJwOodT hujw5bcTzYALQYt1QAz6nABMcExcRZOeiHaQcbctfiijaENLxNT9zeYu/haIxzuXrNZd 07Eif24UkMkejBHOkdVcWpYcuy3EZb9PPxolKYvjpLU0NpIQpoI44rspZPtdcN7Gz28P ipgg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=WTzaXJlO; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-141540-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141540-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s5-20020aa78d45000000b006eb3c44c83csi1846695pfe.310.2024.04.11.12.35.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 12:35:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141540-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=WTzaXJlO; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-141540-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141540-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A5DF528640C for ; Thu, 11 Apr 2024 19:35:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A2D71759E; Thu, 11 Apr 2024 19:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="WTzaXJlO" Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77CA313AE2 for ; Thu, 11 Apr 2024 19:35:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712864114; cv=none; b=KFD+SrW9iueLBXv2KOdpDa9GYebtM3ihdDVI4AvrmzMj0MH4UxGMweRY9tyxAXfBWx0LgfvfVGjXS2bAPkNMcLcyO+buwGu0v7XaXRvBKI50NTRPTugxbG4t1128sPSs1KgPlWGmIeFHDRVinVCfil03/KZFn0xS/Iui4zXYviE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712864114; c=relaxed/simple; bh=5KVFeFerRH8GLwfSRDO//pTmkAv+uv/gwR3NCKN8Cdg=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=WyutQgUxwfsXhpSzP8RUZdr2iw1qDYQMB+OCDvT765lkOtRTvREkM3HUg5Hdf+QQsoajJY1UBnyDQgZSjNOIP9V4ukH3aE0vc0gdnpevy2EAH2qR0JQ43dACvCW0Q+plDNxw8IFH12vK+5KC9sXCSLTeEJi35Mis7STcxTMHIWY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=WTzaXJlO; arc=none smtp.client-ip=209.85.208.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2d8129797fcso1409181fa.1 for ; Thu, 11 Apr 2024 12:35:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1712864110; x=1713468910; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=qhujaawioP0edqzESewC5qrutyIfvYKamEof/gouabc=; b=WTzaXJlOO/kVxxr1UkWojPQ/xwlyFTzOJSP5b0jR/awylRo5f1TXq5e9VoMDDY3kO2 FFLH/bUak6hUenp9hECToGe5ICfRIfzKfk90FANs+DTVMzj3e0K5xRZ7x080OufLuOAP z6rlyTv541da48Ok+wcK3uaiY64r9X/GDlcuY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712864110; x=1713468910; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qhujaawioP0edqzESewC5qrutyIfvYKamEof/gouabc=; b=HS2SoQFUyUh1r03He6h8svjUmrHD2gjl3YbVDCcPAxrXsf0PjvCWoscnuHBxKiFUm8 yCIbqTf8Ni5fAMTdULxy2ncM5e3MF6pZCiUNgnFiToBMCS0Y6VgNs/oPpLAnLLQEyWjx 276pZfHKvtUUdNZulEvOlrr2B2AtjR3stg2xOpUOUtKccEwq14MlMqm5sWoUVKf5S85g o4CkHpZncczorkF2FQemQOPOymO92yGji2+WwtaNmGBdOri0z32DyzGhOvN8S3RRlBxP qwZdCzxs5sPBOqVKOAH/UfS+9iu1+P5boMTCJU3sU39C+l4V6Nc1uQaKC7Xdd+GbMbM7 UhVg== X-Forwarded-Encrypted: i=1; AJvYcCWf+Jjeqvg+ryC9y061oCeUFmg0F0cgCC3pCMS+Zd9PTicPz8/saM6+ayJijrkdkHU29jiXiXQSrbxy/wRGEued0HELQwNOgyEo9iRz X-Gm-Message-State: AOJu0YxTeXrhPDMqmqSLeLXRRuxtSroekFiTCUoZWDzWseYXR6cgw193 G3enFnHNQmJchuqDFnQ6VXZ3gdPBiN6nWv+1n6bpySrLtGGjlebq9hvmBy9zbJ7MkhhHoW9BvUV 6FufrtA== X-Received: by 2002:a2e:be86:0:b0:2d8:d472:581e with SMTP id a6-20020a2ebe86000000b002d8d472581emr528389ljr.37.1712864110364; Thu, 11 Apr 2024 12:35:10 -0700 (PDT) Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com. [209.85.167.49]) by smtp.gmail.com with ESMTPSA id f15-20020a2e6a0f000000b002d868f2939bsm276785ljc.103.2024.04.11.12.35.09 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Apr 2024 12:35:09 -0700 (PDT) Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-516d2600569so275958e87.0 for ; Thu, 11 Apr 2024 12:35:09 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCVPwyMcBgDMERRSML1YVdLwHvKFfMwV0Vas0boYuD90S3dq+RdYUj9p4RtXpoWpksJ9Y74NTqGoIYJ15h2nu7TwJAvcI8DVWOxLw5KT X-Received: by 2002:a19:3855:0:b0:516:d11b:5532 with SMTP id d21-20020a193855000000b00516d11b5532mr402271lfj.23.1712864109199; Thu, 11 Apr 2024 12:35:09 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240411001012.12513-1-torvalds@linux-foundation.org> <20240411-alben-kocht-219170e9dc99@brauner> In-Reply-To: From: Linus Torvalds Date: Thu, 11 Apr 2024 12:34:52 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] vfs: relax linkat() AT_EMPTY_PATH - aka flink() - requirements To: Charles Mirabile Cc: Christian Brauner , Alexander Viro , Jan Kara , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Lutomirski , Peter Anvin Content-Type: text/plain; charset="UTF-8" On Thu, 11 Apr 2024 at 11:13, Linus Torvalds wrote: > > So while I understand your motivation, I actually think it's actively > wrong to special-case __O_TMPFILE, because it encourages a pattern > that is bad. Just to clarify: I think the ns_capable() change is a good idea and makes sense. The whole "limited to global root" makes no sense if the file was opened within a namespace, and I think it always just came from the better check not being obvious at the point where AT_EMPTY_PATH was checked for. Similarly, while the FMODE_PATH test _looks_ very similar to an O_TMPFILE check, I think it's fundamentally different in a conceptual sense: not only is FMODE_PATH filesystem-agnostic, a FMODE_PATH file is *only* useful as a pathname (ie no read/write semantics). And so if a FMODE_PATH file descriptor is passed in from the outside, I feel like the "you cannot use this to create a path" is kind of a fundamentally nonsensical rule. IOW, whoever is passing that FMODE_PATH file descriptor around must have actually thought about it, and must have opened it with O_PATH, and it isn't useful for anything else than as a starting point for a path lookup. So while I don't think the __O_TMPFILE exception would necessarily be wrong per se, I am afraid that it would result in people writing convenient code that "appears to work" in testing, but then fails when run in an environment where the directory is mounted over NFS (or any other filesystem that doesn't do ->tmpfile()). I am certainly open to be convinced otherwise, but I really think that the real pattern to aim for should just be "look, I opened the file myself, then filled in the detail, and now I'm doing a linkat() to expose it" and that the real protection issue should be that "my credentials are the same for open and linkat". The other rules (ie the capability check or the FMODE_PATH case) would be literally about situations where you *want* to pass things around between protection domains. In that context, the ns_capable() and the FMODE_PATH check make sense to me. In contrast, the __O_TMPFILE check just feels like a random detail. Hmm? Anyway, end result of that is that this is what that part of the patch looks like for me right now: + if (flags & LOOKUP_DFD_MATCH_CREDS) { + const struct cred *cred = f.file->f_cred; + if (!(f.file->f_mode & FMODE_PATH) && + cred != current_cred() && + !ns_capable(cred->user_ns, CAP_DAC_READ_SEARCH)) { + fdput(f); + return ERR_PTR(-ENOENT); + } + } and that _seems_ sensible to me. But yes, this all has been something that we have failed to do right for at least a quarter of a century so far, so this needs a *lot* of thought, even if the patch itself is rather small and looks relatively obvious. Linus