From patchwork Sat Jul 29 00:26:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ernesto_A=2E_Fern=C3=A1ndez?= X-Patchwork-Id: 9869691 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6B7366038C for ; Sat, 29 Jul 2017 00:26:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D0CD28865 for ; Sat, 29 Jul 2017 00:26:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61AF828901; Sat, 29 Jul 2017 00:26:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC78028865 for ; Sat, 29 Jul 2017 00:26:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753234AbdG2A0f (ORCPT ); Fri, 28 Jul 2017 20:26:35 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:38121 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752987AbdG2A0f (ORCPT ); Fri, 28 Jul 2017 20:26:35 -0400 Received: by mail-qt0-f193.google.com with SMTP id p3so14122654qtg.5 for ; Fri, 28 Jul 2017 17:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding; bh=sabenUQsoHFFMPGzdTvhaoOow7wqkiIMIuv6obSXnxg=; b=on9xbrvPDvhnagJnAKTTFPE8cd7DVqYeagXhcm8o9kdvQdS3VHiYFhMRW8BHUVyb+c bBbT/+lDL0TOYTuSkfGbN2cZV8xNyuZhB5NR0clEblaR1EBMU8TsDY3NBKTxoJmtFW3k F/wM7L5wQBP1PzFqvcW1+1dhlGoJIXLoxdJWzV84rhd6UjN5Nk4gNX9q9PAA51TOTyix FBXeeqIY7RF9opaCfkz72CLYw+MGnLQpBZNFOM50xWKsAiKBpcR8ahKP728UpKg+5xOH Km86MHpxc/Ffmgu8/vtMl9d1ziAPcwdkUPT/SVq5H26qbkuiGbf32W6zOi5rw6OX7O0d Xgyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding; bh=sabenUQsoHFFMPGzdTvhaoOow7wqkiIMIuv6obSXnxg=; b=NwlLuAVna4KnueRfKYrod2Pv7hlzZumNwEn9Rs3zdOvHsyW+pKRtmBCPfaIdDZcGzH C39/OCHblPXvvcIWneUk8Fr5ZaAj2gIaU6prcRST8wz5k/GF1t1reBML5OBDZEtDSNlf atkjHN1ZKH5NLh10hIgmzUsVLsVHx5hY1XTFFCLH1l4X/zlGA2mb3kO1w6akSlamf7cs Q7v0Y9516x0UrtQgxwv1tvxcugABvt6cvJ+oefdmlKe+QwJ1p9MhAWJRoaUwTPP7/kCh fpoodEGePSDUeS7sDBv0gLZ08QUsm5OwAhtQqx/sfLT3RrjYBQWukG6uY6dX2olu4+W4 joIQ== X-Gm-Message-State: AIVw113uPHY/eauIyEjIS9fYv4QaplefHoiTrWw9DCmL8GgQ2UYmyUmi kUn7Fg8vOOH4jJYn X-Received: by 10.200.35.188 with SMTP id q57mr12495524qtq.238.1501287994132; Fri, 28 Jul 2017 17:26:34 -0700 (PDT) Received: from debian.home ([181.164.84.213]) by smtp.gmail.com with ESMTPSA id 33sm17178731qtv.76.2017.07.28.17.26.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Jul 2017 17:26:33 -0700 (PDT) Date: Fri, 28 Jul 2017 21:26:29 -0300 From: Ernesto =?utf-8?Q?A=2E_Fern=C3=A1ndez?= To: linux-btrfs@vger.kernel.org Cc: Chris Mason , Josef Bacik , David Sterba , Ernesto =?utf-8?Q?A=2E_Fern=C3=A1ndez?= Subject: [PATCH] btrfs: preserve i_mode if __btrfs_set_acl() fails Message-ID: <20170729002626.GA6759@debian.home> MIME-Version: 1.0 Content-Disposition: inline Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When changing a file's acl mask, btrfs_set_acl() will first set the group bits of i_mode to the value of the mask, and only then set the actual extended attribute representing the new acl. If the second part fails (due to lack of space, for example) and the file had no acl attribute to begin with, the system will from now on assume that the mask permission bits are actual group permission bits, potentially granting access to the wrong users. Prevent this by starting the journal transaction before calling __btrfs_set_acl and only changing the inode mode after it returns successfully. Signed-off-by: Ernesto A. Fernández --- This issue is covered by generic/449 in xfstests. Several filesystems are affected; some of them have already applied patches: - fe26569 ext2: preserve i_mode if ext2_set_acl() fails - f070e5a jfs: preserve i_mode if __jfs_set_acl() fails - fcea8ae reiserfs: preserve i_mode if __reiserfs_set_acl() fails fs/btrfs/acl.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c index 8d8370d..d041526 100644 --- a/fs/btrfs/acl.c +++ b/fs/btrfs/acl.c @@ -27,6 +27,7 @@ #include "ctree.h" #include "btrfs_inode.h" #include "xattr.h" +#include "transaction.h" struct posix_acl *btrfs_get_acl(struct inode *inode, int type) { @@ -113,14 +114,36 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans, int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) { + struct btrfs_root *root = BTRFS_I(inode)->root; + struct btrfs_trans_handle *trans; int ret; + umode_t mode = inode->i_mode; + + if (btrfs_root_readonly(root)) + return -EROFS; + + trans = btrfs_start_transaction(root, 2); + if (IS_ERR(trans)) + return PTR_ERR(trans); if (type == ACL_TYPE_ACCESS && acl) { - ret = posix_acl_update_mode(inode, &inode->i_mode, &acl); + ret = posix_acl_update_mode(inode, &mode, &acl); if (ret) - return ret; + goto out; } - return __btrfs_set_acl(NULL, inode, acl, type); + ret = __btrfs_set_acl(trans, inode, acl, type); + if (ret) + goto out; + + inode->i_mode = mode; + inode_inc_iversion(inode); + inode->i_ctime = current_time(inode); + set_bit(BTRFS_INODE_COPY_EVERYTHING, &BTRFS_I(inode)->runtime_flags); + ret = btrfs_update_inode(trans, root, inode); + BUG_ON(ret); +out: + btrfs_end_transaction(trans); + return ret; } /*