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=-10.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 DD599C2D0FA for ; Tue, 12 May 2020 21:31:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC32220747 for ; Tue, 12 May 2020 21:31:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731358AbgELVbn (ORCPT ); Tue, 12 May 2020 17:31:43 -0400 Received: from mx2.suse.de ([195.135.220.15]:53672 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728362AbgELVbn (ORCPT ); Tue, 12 May 2020 17:31:43 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BD606ACCE; Tue, 12 May 2020 21:31:43 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id CB639DA70B; Tue, 12 May 2020 23:30:49 +0200 (CEST) Date: Tue, 12 May 2020 23:30:49 +0200 From: David Sterba To: Marcos Paulo de Souza Cc: dsterba@suse.com, linux-btrfs@vger.kernel.org, wqu@suse.com, fdmanana@suse.com, Marcos Paulo de Souza , stable@vger.kernel.org Subject: Re: [PATCH v4] btrfs: send: Emit file capabilities after chown Message-ID: <20200512213049.GD18421@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Marcos Paulo de Souza , dsterba@suse.com, linux-btrfs@vger.kernel.org, wqu@suse.com, fdmanana@suse.com, Marcos Paulo de Souza , stable@vger.kernel.org References: <20200512144038.29498-1-marcos@mpdesouza.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200512144038.29498-1-marcos@mpdesouza.com> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On Tue, May 12, 2020 at 11:40:38AM -0300, Marcos Paulo de Souza wrote: > From: Marcos Paulo de Souza > > [PROBLEM] > Whenever a chown is executed, all capabilities of the file being touched are > lost. When doing incremental send with a file with capabilities, there is a > situation where the capability can be lost in the receiving side. The > sequence of actions bellow shows the problem: > > $ mount /dev/sda fs1 > $ mount /dev/sdb fs2 > > $ touch fs1/foo.bar > $ setcap cap_sys_nice+ep fs1/foo.bar > $ btrfs subvol snap -r fs1 fs1/snap_init > $ btrfs send fs1/snap_init | btrfs receive fs2 > > $ chgrp adm fs1/foo.bar > $ setcap cap_sys_nice+ep fs1/foo.bar > > $ btrfs subvol snap -r fs1 fs1/snap_complete > $ btrfs subvol snap -r fs1 fs1/snap_incremental > > $ btrfs send fs1/snap_complete | btrfs receive fs2 > $ btrfs send -p fs1/snap_init fs1/snap_incremental | btrfs receive fs2 > > At this point, only a chown was emitted by "btrfs send" since only the group > was changed. This makes the cap_sys_nice capability to be dropped from > fs2/snap_incremental/foo.bar > > [FIX] > Only emit capabilities after chown is emitted. The current code > first checks for xattrs that are new/changed, emits them, and later emit > the chown. Now, __process_new_xattr skips capabilities, letting only > finish_inode_if_needed to emit them, if they exist, for the inode being > processed. > > This behavior was being worked around in "btrfs receive" > side by caching the capability and only applying it after chown. Now, > xattrs are only emmited _after_ chown, making that hack not needed > anymore. > > Link: https://github.com/kdave/btrfs-progs/issues/202 > CC: stable@vger.kernel.org > Suggested-by: Filipe Manana > Reviewed-by: Filipe Manana > Signed-off-by: Marcos Paulo de Souza Added to misc-next, thanks.