From patchwork Fri May 20 03:45:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Borowski X-Patchwork-Id: 9128603 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 2743160221 for ; Fri, 20 May 2016 04:08:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FF931FEDE for ; Fri, 20 May 2016 04:08:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 049A8256D1; Fri, 20 May 2016 04:08:43 +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.9 required=2.0 tests=BAYES_00,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 8AC3F1FEDE for ; Fri, 20 May 2016 04:08:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753643AbcETEIk (ORCPT ); Fri, 20 May 2016 00:08:40 -0400 Received: from tartarus.angband.pl ([89.206.35.136]:49404 "EHLO tartarus.angband.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751903AbcETEIk (ORCPT ); Fri, 20 May 2016 00:08:40 -0400 X-Greylist: delayed 1383 seconds by postgrey-1.27 at vger.kernel.org; Fri, 20 May 2016 00:08:39 EDT Received: from umbar.angband.pl ([2001:6a0:118::6]) by tartarus.angband.pl with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1b3bNK-0001KJ-4c; Fri, 20 May 2016 05:45:24 +0200 Received: from kilobyte by umbar.angband.pl with local (Exim 4.87) (envelope-from ) id 1b3bNJ-00025p-Mw; Fri, 20 May 2016 05:45:21 +0200 From: Adam Borowski To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Adam Borowski Date: Fri, 20 May 2016 05:45:12 +0200 Message-Id: <1463715912-8005-1-git-send-email-kilobyte@angband.pl> X-Mailer: git-send-email 2.8.1 X-SA-Exim-Connect-IP: 2001:6a0:118::6 X-SA-Exim-Mail-From: kilobyte@angband.pl Subject: [PATCH] btrfs,vfs: allow FILE_EXTENT_SAME on a file opened ro X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on tartarus.angband.pl) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP (Only btrfs currently implements dedupe_file_range.) Instead of checking the mode of the file descriptor, let's check whether it could have been opened rw. This allows fixing failures when deduping a live system: anyone trying to exec a file currently being deduped gets ETXTBSY. Issuing this ioctl on a ro file was already allowed for root/cap. Signed-off-by: Adam Borowski --- fs/read_write.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/read_write.c b/fs/read_write.c index cf377cf..6c414d8 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1736,7 +1736,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) if (info->reserved) { info->status = -EINVAL; - } else if (!(is_admin || (dst_file->f_mode & FMODE_WRITE))) { + } else if (!(is_admin || !inode_permission(dst, MAY_WRITE))) { info->status = -EINVAL; } else if (file->f_path.mnt != dst_file->f_path.mnt) { info->status = -EXDEV;