Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754315AbcJEPHZ (ORCPT ); Wed, 5 Oct 2016 11:07:25 -0400 Received: from tartarus.angband.pl ([89.206.35.136]:57391 "EHLO tartarus.angband.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753007AbcJEPHY (ORCPT ); Wed, 5 Oct 2016 11:07:24 -0400 X-Greylist: delayed 1682 seconds by postgrey-1.27 at vger.kernel.org; Wed, 05 Oct 2016 11:07:24 EDT From: Adam Borowski To: Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Adam Borowski Date: Wed, 5 Oct 2016 16:38:54 +0200 Message-Id: <20161005143854.17133-1-kilobyte@angband.pl> X-Mailer: git-send-email 2.9.3 X-SA-Exim-Connect-IP: 2001:6a0:118::6 X-SA-Exim-Mail-From: kilobyte@angband.pl Subject: [PATCH resend] vfs: allow FILE_EXTENT_SAME (dedupe_file_range) 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-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1089 Lines: 30 Instead of checking the mode of the file descriptor, let's check whether it could have been opened rw. This allows fixing intermittent exec 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. Tested on btrfs and not-yet-merged xfs, as only them implement this ioctl. Signed-off-by: Adam Borowski Reviewed-by: Mark Fasheh --- 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 66215a7..8ea5297 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1741,7 +1741,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; -- 2.9.3