Commit 18f0a5d8 authored by Jann Horn's avatar Jann Horn Committed by Zheng Zengkai
Browse files

btrfs: send: ensure send_fd is writable

stable inclusion
from stable-v6.6.5
commit da2dbbb73e33d8326d7c0bd54810033706d4a3f2
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I8N21P

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=da2dbbb73e33d8326d7c0bd54810033706d4a3f2



--------------------------------

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 a01ac27b ("fs: check FMODE_WRITE in __kernel_write")

Reported-and-tested-by: default avatar <syzbot+12e098239d20385264d3@syzkaller.appspotmail.com>
Closes: https://syzkaller.appspot.com/bug?extid=12e098239d20385264d3


Fixes: 31db9f7c ("Btrfs: introduce BTRFS_IOC_SEND for btrfs send/receive")
CC: stable@vger.kernel.org # 4.14+
Signed-off-by: default avatarJann Horn <jannh@google.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 91202366
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment