Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2637323iof; Wed, 8 Jun 2022 08:59:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTXnmEFyF2pym5EG4lpnnlNptdxO0MJI3MA/3eI5nStnCIcUFnlHjbdAaUrloROo3QHQs6 X-Received: by 2002:aa7:9e9c:0:b0:51b:e1b8:271c with SMTP id p28-20020aa79e9c000000b0051be1b8271cmr28090374pfq.73.1654703965094; Wed, 08 Jun 2022 08:59:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654703965; cv=none; d=google.com; s=arc-20160816; b=VwmiaTSUQ/NlpeY54qB9WYYvvXK1WzJk/efsRQO/YiiMHJIdto0DHw0Wjmef5GCM3t jI7jMXwQfhTghVKFtUFpNpw0sWUBf685mupIIUclaiaD/bDSBZuqRAlYmRwMFaSSet5k PvExeYKD898Z0PxyGowOvnpPSUDKIdRHNO1+sNNcnOCkdC+P7WXUfCulR8RMiO4yHDbj f0fAIQTXGuCOZot85gx0363MeFqmYox/g+RxD58BCdDrRxPIIo6YEUC5aYJizi7446Tw VYgy0nFm4GiuyC+trNP7lu92FeCRv9k4BDqHq/fsSmmoIUGFFQGKCPHaHh/SQELMTbqd zgLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=WG94p2edkIKDcgGBWYikbRM1gTNO7+P3Sh2LbeXDfqU=; b=IVvhJ/rZ7teXQMMXB+dCvDj64K0k/jDufn2mVxIhH6lFKvWyKUmREkRr1rvekxVb3A uppokB18jQgVLsWc4T8i8uKUN1CXPGkR6c9mpU/rgri/tPngxkjwHnATPRVeaSQCcNOb Hi6eeuntZ0z8YYfrxw99EHB+9AzuuI0Nsla/K+cn3Wxkq71uIPrIvthfDqjzhSf1r1O6 O/nAXt4RQCE2TGSBWhhEfvGsd89LhPnn5kCzbIrrlUqw9gUiRXOdnrOm9cvH22wtE7VB Y9xbgEg0an/LNeYvuhGuAON9aAgMjiK6X7RLZieEjPK5uyJfJ654w1cl0m03zSvT+ETd 6pFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="pOfM/2EU"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m12-20020a170902db0c00b001640a9436b9si20787216plx.414.2022.06.08.08.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 08:59:25 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="pOfM/2EU"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C9F9B39B80; Wed, 8 Jun 2022 08:31:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244280AbiFHPRq (ORCPT + 99 others); Wed, 8 Jun 2022 11:17:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244404AbiFHPQI (ORCPT ); Wed, 8 Jun 2022 11:16:08 -0400 Received: from mail-ua1-x936.google.com (mail-ua1-x936.google.com [IPv6:2607:f8b0:4864:20::936]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 224CD10A9; Wed, 8 Jun 2022 08:12:42 -0700 (PDT) Received: by mail-ua1-x936.google.com with SMTP id p3so7015367uam.12; Wed, 08 Jun 2022 08:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=WG94p2edkIKDcgGBWYikbRM1gTNO7+P3Sh2LbeXDfqU=; b=pOfM/2EUVDmuVQ7A91fzp3O+W/p+wb1GKzUYWJ/bT/oWdW2QM8uYD0H4pYI/Bv9Y69 nBsBQJSXR8CntPJwIGvC2XkJiTtXNnrbOFtsLhpxgoXV/2OSvpP9upgEp8/iq5e53gU8 jYylvrzcCksi8nH3mND+M8xqZ5l+LhvrIeAwYzqywUyXNWuOp+MAxGJl5g2BW401lOWz Rsz5w3kvDZBM4Z+mBZB8BGr2++PJgbt1ZL7H36AriDmtP1j3srwz9Jb/YiXj1qgcLN7w e/TzmG2Qq2t8Yvu3ldbll8ld/jiEfkCoI7phj+G9QtW1cYyWV9oCZq2uhIWb57QAuUuD M86Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=WG94p2edkIKDcgGBWYikbRM1gTNO7+P3Sh2LbeXDfqU=; b=cfdu5FvEBCvOmInqDkDf5ZVZBuoNiXY/UFS60XjsNtgk2tEO4s358Y/81ylvMbUKzv uNEBJMVSL5TPYB/VQBnHF6y/Sfe8MKd/HW5YMoktrMHzGj4nXsBjB5XeTCEl/4eKI9U/ fPohpban7KBIvmMkF9BlMQURzDhKiobZmqDNs4SJ2ndxPlGucTl8aA2PsfcFRARZ27NX /Emg4DnhPGJindxHFU4x1O/OZgSwAl90Jj//0GmjG0oBv3iKf/sDvqK26wZeVIO++Mzb HRR/DVpCp03mjV1llq4ebmTO5+n+fJojVsGjJZQ97yt5QxcFA2bcjvbpaP22zugcyYb4 wgUA== X-Gm-Message-State: AOAM532/uDJU30O3CbypSYsntytBx0M3f47GeBBnoebJLPVojLuKKlEc jnBqzW60klgQMgRNtdoAWHFjqSVBW87YQYbbNRE= X-Received: by 2002:ab0:2315:0:b0:378:cc65:f798 with SMTP id a21-20020ab02315000000b00378cc65f798mr8801120uao.60.1654701161087; Wed, 08 Jun 2022 08:12:41 -0700 (PDT) MIME-Version: 1.0 References: <20220607153139.35588-1-cgzones@googlemail.com> <20220608112728.b4xrdppxqmyqmtwf@wittgenstein> <20220608124808.uylo5lntzfgxxmns@wittgenstein> In-Reply-To: <20220608124808.uylo5lntzfgxxmns@wittgenstein> From: Amir Goldstein Date: Wed, 8 Jun 2022 18:12:29 +0300 Message-ID: Subject: Re: [RFC PATCH] f*xattr: allow O_PATH descriptors To: Christian Brauner Cc: =?UTF-8?Q?Christian_G=C3=B6ttsche?= , selinux@vger.kernel.org, Miklos Szeredi , Linux API , linux-man , Alexander Viro , linux-fsdevel , linux-kernel , Aleksa Sarai Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 8, 2022 at 3:48 PM Christian Brauner wrote= : > > On Wed, Jun 08, 2022 at 03:28:52PM +0300, Amir Goldstein wrote: > > On Wed, Jun 8, 2022 at 2:57 PM Christian Brauner w= rote: > > > > > > On Tue, Jun 07, 2022 at 05:31:39PM +0200, Christian G=C3=B6ttsche wro= te: > > > > From: Miklos Szeredi > > > > > > > > Support file descriptors obtained via O_PATH for extended attribute > > > > operations. > > > > > > > > Extended attributes are for example used by SELinux for the securit= y > > > > context of file objects. To avoid time-of-check-time-of-use issues = while > > > > setting those contexts it is advisable to pin the file in question = and > > > > operate on a file descriptor instead of the path name. This can be > > > > emulated in userspace via /proc/self/fd/NN [1] but requires a procf= s, > > > > which might not be mounted e.g. inside of chroots, see[2]. > > > > > > > > [1]: https://github.com/SELinuxProject/selinux/commit/7e979b56fd2ce= e28f647376a7233d2ac2d12ca50 > > > > [2]: https://github.com/SELinuxProject/selinux/commit/de285252a1801= 397306032e070793889c9466845 > > > > > > > > Original patch by Miklos Szeredi > > > > https://patchwork.kernel.org/project/linux-fsdevel/patch/2020050509= 5915.11275-6-mszeredi@redhat.com/ > > > > > > > > > While this carries a minute risk of someone relying on the proper= ty of > > > > > xattr syscalls rejecting O_PATH descriptors, it saves the trouble= of > > > > > introducing another set of syscalls. > > > > > > > > > > Only file->f_path and file->f_inode are accessed in these functio= ns. > > > > > > > > > > Current versions return EBADF, hence easy to detect the presense = of > > > > > this feature and fall back in case it's missing. > > > > > > > > CC: linux-api@vger.kernel.org > > > > CC: linux-man@vger.kernel.org > > > > Signed-off-by: Christian G=C3=B6ttsche > > > > --- > > > > > > I'd be somewhat fine with getxattr and listxattr but I'm worried that > > > setxattr/removexattr waters down O_PATH semantics even more. I don't > > > want O_PATH fds to be useable for operations which are semantically > > > equivalent to a write. > > > > It is not really semantically equivalent to a write if it works on a > > O_RDONLY fd already. > > The fact that it works on a O_RDONLY fd has always been weird. And is > probably a bug. If you look at xattr_permission() you can see that it Bug or no bug, this is the UAPI. It is not fixable anymore. > checks for MAY_WRITE for set operations... setxattr() writes to disk for > real filesystems. I don't know how much closer to a write this can get. > > In general, one semantic aberration doesn't justify piling another one > on top. > > (And one thing that speaks for O_RDONLY is at least that it actually > opens the file wheres O_PATH doesn't.) Ok. I care mostly about consistent UAPI, so if you want to set the rule that modify f*() operations are not allowed to use O_PATH fd, I can live with that, although fcntl(2) may be breaking that rule, but fine by me. It's good to have consistent rules and it's good to add a new UAPI for new behavior. However... > > > > > > > > > In sensitive environments such as service management/container runtim= es > > > we often send O_PATH fds around precisely because it is restricted wh= at > > > they can be used for. I'd prefer to not to plug at this string. > > > > But unless I am mistaken, path_setxattr() and syscall_fsetxattr() > > are almost identical w.r.t permission checks and everything else. > > > > So this change introduces nothing new that a user in said environment > > cannot already accomplish with setxattr(). > > > > Besides, as the commit message said, doing setxattr() on an O_PATH > > fd is already possible with setxattr("/proc/self/$fd"), so whatever sec= urity > > hole you are trying to prevent is already wide open. > > That is very much a something that we're trying to restrict for this > exact reason and is one of the main motivator for upgrade mask in > openat2(). If I want to send a O_PATH around I want it to not be > upgradable. Aleksa is working on upgrade masks with openat2() (see [1] > and part of the original patchset in [2]. O_PATH semantics don't need to > become weird. > > [1]: https://lore.kernel.org/all/20220526130355.fo6gzbst455fxywy@senku > [2]: https://patchwork.ozlabs.org/project/linuxppc-dev/patch/201907280102= 07.9781-8-cyphar@cyphar.com ... thinking forward, if this patch is going to be rejected, the patch that will follow is *xattrat() syscalls. What will you be able to argue then? There are several *at() syscalls that modify metadata. fchownat(.., AT_EMPTY_PATH) is intentionally designed for this. Do you intend to try and block setxattrat()? Just try and block setxattrat(.., AT_EMPTY_PATH)? those *at() syscalls have real use cases to avoid TOCTOU races. Do you propose that applications will have to use fsetxattr() on an open file to avert races? I completely understand the idea behind upgrade masks for limiting f_mode, but I don't know if trying to retroactively change semantics of setxattr() in the move to setxattrat() is going to be a good idea. And forgive me if I am failing to see the big picture. It is certainly a possibility. Thanks, Amir.