summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJann Horn <jannh@google.com>2023-11-24 17:48:31 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-12-08 08:43:25 +0100
commit907f80604e4f9b209f7268864e4cec8038436bc4 (patch)
treea38b1e5f55061ec59d1ae34cfeebd52d07318428 /fs
parenta3baa90ab0548820dc66673d03ac8b143113c8ba (diff)
downloadlinux-stable-907f80604e4f9b209f7268864e4cec8038436bc4.tar.gz
linux-stable-907f80604e4f9b209f7268864e4cec8038436bc4.tar.bz2
linux-stable-907f80604e4f9b209f7268864e4cec8038436bc4.zip
btrfs: send: ensure send_fd is writable
commit 0ac1d13a55eb37d398b63e6ff6db4a09a2c9128c upstream. kernel_write() requires the caller to ensure that the file is writable. Let's do that directly after looking up the ->send_fd. We don't need a separate bailout path because the "out" path already does fput() if ->send_filp is non-NULL. This has no security impact for two reasons: - the ioctl requires CAP_SYS_ADMIN - __kernel_write() bails out on read-only files - but only since 5.8, see commit a01ac27be472 ("fs: check FMODE_WRITE in __kernel_write") Reported-and-tested-by: syzbot+12e098239d20385264d3@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=12e098239d20385264d3 Fixes: 31db9f7c23fb ("Btrfs: introduce BTRFS_IOC_SEND for btrfs send/receive") CC: stable@vger.kernel.org # 4.14+ Signed-off-by: Jann Horn <jannh@google.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/send.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 1f535cd990d3..cb584c044f8a 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -6860,7 +6860,7 @@ long btrfs_ioctl_send(struct file *mnt_file, struct btrfs_ioctl_send_args *arg)
sctx->flags = arg->flags;
sctx->send_filp = fget(arg->send_fd);
- if (!sctx->send_filp) {
+ if (!sctx->send_filp || !(sctx->send_filp->f_mode & FMODE_WRITE)) {
ret = -EBADF;
goto out;
}