Re: [PATCH] btrfs: send: Ensure send_fd is writable

From: David Sterba
Date: Fri Nov 24 2023 - 12:51:28 EST


On Fri, Nov 24, 2023 at 05:48:31PM +0100, Jann Horn wrote:
> 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@xxxxxxxxxxxxxxxxxxxxxxxxx
> Closes: https://syzkaller.appspot.com/bug?extid=12e098239d20385264d3
> Fixes: 31db9f7c23fb ("Btrfs: introduce BTRFS_IOC_SEND for btrfs send/receive")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Jann Horn <jannh@xxxxxxxxxx>

Added to misc-next, thanks.