Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp647577rwe; Thu, 1 Sep 2022 05:45:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR4yAuBSZLgdkp32d59ohRbgzKQhOYCQ0A/ymOQrF3os+FuExtk8YvIlVbEYzgfCJ6QlK0MB X-Received: by 2002:a63:b250:0:b0:422:e3a6:47f2 with SMTP id t16-20020a63b250000000b00422e3a647f2mr3540707pgo.478.1662036351096; Thu, 01 Sep 2022 05:45:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662036351; cv=none; d=google.com; s=arc-20160816; b=Pg3ioEe92DH1sZJvjiT/cb7osnx3U5rGRnd1OjLsa0JmNKrRUwfKcHbAcmcFY1u22S 4hLkH5fHj9BB51QkWeNL0rWP5vT4j3FJonWCJGS8yddbeYiHB3gTKsRobGHfny6MhYUQ fk9r6qIxQKw8nUDiYVi+3Vm/gHnURMfbz481wmQZXzskSomoisy9SXX85DuSRKNf2C4G saCJ4LPoskMf86N6O0JQ7P5VthN8hkFvpjR9nTRyztI8F2uq5LE0P8SWDQMx5TAsG0Ii OZqWkq2wsgKKkLVquSN0WRbVApwx0+9FZSBXgEu5UDW+lnqqTXBnlANoz9nhyGovFHtT K+gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3ENh2U53TvjlM9X8Sp5YP8hJNn8JQYvBM5MEptUdlEs=; b=cGQRqyNenXAuxQtcZiO1/hO2hChntwRSNI84qelICyvt+DMuUR3Ly7T72HQZeOxOSf IX6lVWxj0CCnlXykEQNRihUGH0vvJ8261LFdHq9pcK9titSeQFeddhxJ+WxBiFgybkEw r19e3ZLBfzsDp7GPfXZHyGBzBWGoxf+5kcv54ZAUXKk+jQkqfvnbR6S5WjlJGU2zD1Ee uxWCW083xi5TZxHJdBPUPTwHX5/8e/p3tFKMdSV95AkmCa/HbZzzEddfepHxn2/N+t63 lwvCK4r8nOH7DNXJHYM/SmSfixZqVJrsGFBKJ3ZQwX7MiK22X0JJu4hVL5iVDcXXCoyk eY3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Xvc/T3sC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qi9-20020a17090b274900b001fbbc5960b1si4542967pjb.136.2022.09.01.05.45.38; Thu, 01 Sep 2022 05:45:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Xvc/T3sC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232787AbiIAMeD (ORCPT + 99 others); Thu, 1 Sep 2022 08:34:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232879AbiIAMd7 (ORCPT ); Thu, 1 Sep 2022 08:33:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2965CD112; Thu, 1 Sep 2022 05:33:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AED4961DF4; Thu, 1 Sep 2022 12:33:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8291AC433D6; Thu, 1 Sep 2022 12:33:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662035635; bh=9UIyfyyALoM0eBslsP+U76/M/W3Lbw5Q0719KJ6vMKU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Xvc/T3sCjwdDiqe3jU5SB+YjvT4jAnI6vmPeoP1OYgLt8fw9cBnmEDwC6xL3Sa3VL 1RizMwJ36Apxl/q0v7NGjPx2eFF2c6l7kT/0xYGs3J2M73VoXT3cyF1MwtVzpfSzwJ rHRwtbtkw37e1xv+4v85vr/3QkTQyqhJCxEivyzMjl4xVaS7Ot+weuI3fX1zEUGQnq ku4y0O9hpmMEz1HvIc9YDmAjoOid8IwX8KxAgbFltvVNXHyDuz9Eev/Ix8GHfzrabC k0avvOm7M6MHs7I4/t3GJDtzlFwkNDrYHGI9iYGnGswMx9U4w2E5epMG6VU003Pht2 WWGt+VVqOD5aw== Date: Thu, 1 Sep 2022 14:33:50 +0200 From: Christian Brauner To: Zhang Tianci Cc: miklos@szeredi.hu, linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org, amir73il@gmail.com, Jiachen Zhang Subject: Re: [PATCH v3] ovl: Use ovl mounter's fsuid and fsgid in ovl_link() Message-ID: <20220901123350.wak7yjbvddtcnwfb@wittgenstein> References: <20220901082929.66831-1-zhangtianci.1997@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220901082929.66831-1-zhangtianci.1997@bytedance.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Thu, Sep 01, 2022 at 04:29:29PM +0800, Zhang Tianci wrote: > There is a wrong case of link() on overlay: > $ mkdir /lower /fuse /merge > $ mount -t fuse /fuse > $ mkdir /fuse/upper /fuse/work > $ mount -t overlay /merge -o lowerdir=/lower,upperdir=/fuse/upper,\ > workdir=work > $ touch /merge/file > $ chown bin.bin /merge/file // the file's caller becomes "bin" > $ ln /merge/file /merge/lnkfile > > Then we will get an error(EACCES) because fuse daemon checks the link()'s > caller is "bin", it denied this request. > > In the changing history of ovl_link(), there are two key commits: > > The first is commit bb0d2b8ad296 ("ovl: fix sgid on directory") which > overrides the cred's fsuid/fsgid using the new inode. The new inode's > owner is initialized by inode_init_owner(), and inode->fsuid is > assigned to the current user. So the override fsuid becomes the > current user. We know link() is actually modifying the directory, so > the caller must have the MAY_WRITE permission on the directory. The > current caller may should have this permission. This is acceptable > to use the caller's fsuid. > > The second is commit 51f7e52dc943 ("ovl: share inode for hard link") > which removed the inode creation in ovl_link(). This commit move > inode_init_owner() into ovl_create_object(), so the ovl_link() just > give the old inode to ovl_create_or_link(). Then the override fsuid > becomes the old inode's fsuid, neither the caller nor the overlay's > mounter! So this is incorrect. > > Fix this bug by using ovl mounter's fsuid/fsgid to do underlying > fs's link(). > > v1: https://lore.kernel.org/all/20220817102952.xnvesg3a7rbv576x@wittgenstein/T > v2: https://lore.kernel.org/lkml/20220825130552.29587-1-zhangtianci.1997@bytedance.com/t > > Signed-off-by: Zhang Tianci > Signed-off-by: Jiachen Zhang > --- Looks good to me, Reviewed-by: Christian Brauner (Microsoft)