* [PATCH] btrfs: send: Ensure send_fd is writable
@ 2023-11-24 16:48 Jann Horn
2023-11-24 17:43 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Jann Horn @ 2023-11-24 16:48 UTC (permalink / raw)
To: Chris Mason, Josef Bacik, David Sterba
Cc: Alex Lyakas, Alexander Block, linux-btrfs, linux-kernel, syzkaller-bugs
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
Signed-off-by: Jann Horn <jannh@google.com>
---
fs/btrfs/send.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 3b929f0e8f04..4e36550618e5 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -8158,7 +8158,7 @@ long btrfs_ioctl_send(struct inode *inode, struct btrfs_ioctl_send_args *arg)
}
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;
}
base-commit: 98b1cc82c4affc16f5598d4fa14b1858671b2263
--
2.43.0.rc1.413.gea7ed67945-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs: send: Ensure send_fd is writable
2023-11-24 16:48 [PATCH] btrfs: send: Ensure send_fd is writable Jann Horn
@ 2023-11-24 17:43 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2023-11-24 17:43 UTC (permalink / raw)
To: Jann Horn
Cc: Chris Mason, Josef Bacik, David Sterba, Alex Lyakas,
Alexander Block, linux-btrfs, linux-kernel, syzkaller-bugs
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@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
> Signed-off-by: Jann Horn <jannh@google.com>
Added to misc-next, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-24 17:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-24 16:48 [PATCH] btrfs: send: Ensure send_fd is writable Jann Horn
2023-11-24 17:43 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).