From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF6176FAF; Tue, 5 Dec 2023 03:28:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="c0HChaKY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52D27C433C8; Tue, 5 Dec 2023 03:28:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1701746924; bh=+1MUob8ygWwmnx118yVM1SsXO/lHvoOkHDCT6nAfndc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c0HChaKYW9pUQldlf+5pQQ/54mtYrykPyhcRA1Fxa14yF1SjEEd5lZmISmxgB0Sed BTlHe0SW5tXeS4eGvARFiQ0mvRL0eToBQqC5izuKhJdQ3wm3grkx7Lfq1X1GqyDg7z UCw5aPBKUCp+qfuPIiuK1KmQm9boq9DEwdO5BFJ0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jann Horn , David Sterba , syzbot+12e098239d20385264d3@syzkaller.appspotmail.com Subject: [PATCH 4.19 44/71] btrfs: send: ensure send_fd is writable Date: Tue, 5 Dec 2023 12:16:42 +0900 Message-ID: <20231205031520.385739861@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231205031517.859409664@linuxfoundation.org> References: <20231205031517.859409664@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jann Horn 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 Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -6860,7 +6860,7 @@ long btrfs_ioctl_send(struct file *mnt_f 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; }