Skip to content

Commit 0ac1d13

Browse files
thejhkdave
authored andcommitted
btrfs: send: ensure send_fd is writable
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 a01ac27 ("fs: check FMODE_WRITE in __kernel_write") Reported-and-tested-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=12e098239d20385264d3 Fixes: 31db9f7 ("Btrfs: introduce BTRFS_IOC_SEND for btrfs send/receive") CC: [email protected] # 4.14+ Signed-off-by: Jann Horn <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 94dbf7c commit 0ac1d13

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/btrfs/send.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8158,7 +8158,7 @@ long btrfs_ioctl_send(struct inode *inode, struct btrfs_ioctl_send_args *arg)
81588158
}
81598159

81608160
sctx->send_filp = fget(arg->send_fd);
8161-
if (!sctx->send_filp) {
8161+
if (!sctx->send_filp || !(sctx->send_filp->f_mode & FMODE_WRITE)) {
81628162
ret = -EBADF;
81638163
goto out;
81648164
}

0 commit comments

Comments
 (0)