From patchwork Mon May 21 14:45:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Borowski X-Patchwork-Id: 10415579 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 540FB6053B for ; Mon, 21 May 2018 14:45:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 444862843B for ; Mon, 21 May 2018 14:45:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 386EC288AE; Mon, 21 May 2018 14:45:55 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 A66032843B for ; Mon, 21 May 2018 14:45:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752358AbeEUOpw (ORCPT ); Mon, 21 May 2018 10:45:52 -0400 Received: from tartarus.angband.pl ([89.206.35.136]:41982 "EHLO tartarus.angband.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751021AbeEUOpw (ORCPT ); Mon, 21 May 2018 10:45:52 -0400 Received: from 89-71-158-145.dynamic.chello.pl ([89.71.158.145] helo=umbar.angband.pl) by tartarus.angband.pl with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fKm4I-0004Yz-2z; Mon, 21 May 2018 16:45:48 +0200 Received: from kilobyte by umbar.angband.pl with local (Exim 4.91) (envelope-from ) id 1fKm4H-0004JI-4Z; Mon, 21 May 2018 16:45:45 +0200 From: Adam Borowski To: linux-btrfs@vger.kernel.org, David Sterba Cc: Adam Borowski Date: Mon, 21 May 2018 16:45:14 +0200 Message-Id: <20180521144515.16501-1-kilobyte@angband.pl> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180521144254.4zdxt6jtxoeca26o@angband.pl> References: <20180521144254.4zdxt6jtxoeca26o@angband.pl> X-SA-Exim-Connect-IP: 89.71.158.145 X-SA-Exim-Mail-From: kilobyte@angband.pl Subject: [PATCH 1/2] btrfs: allow defrag on a file opened ro that has rw permissions X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on tartarus.angband.pl) 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 Requiring a rw descriptor conflicts both ways with exec, returning ETXTBSY whenever you try to defrag a program that's currently being run, or causing intermittent exec failures on a live system being defragged. As defrag doesn't change the file's contents in any way, there's no reason to consider it a rw operation. Thus, let's check only whether the file could have been opened rw. Such access control is still needed as currently defrag can use extra disk space, and might trigger bugs. Signed-off-by: Adam Borowski --- fs/btrfs/ioctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 632e26d6f7ce..b75db9d72106 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2561,7 +2561,8 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) ret = btrfs_defrag_root(root); break; case S_IFREG: - if (!(file->f_mode & FMODE_WRITE)) { + if (!capable(CAP_SYS_ADMIN) && + inode_permission(inode, MAY_WRITE)) { ret = -EINVAL; goto out; }