From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62D85C433FE for ; Wed, 30 Nov 2022 17:29:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229497AbiK3R3v (ORCPT ); Wed, 30 Nov 2022 12:29:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbiK3R3v (ORCPT ); Wed, 30 Nov 2022 12:29:51 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AD7823E99 for ; Wed, 30 Nov 2022 09:29:50 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CF1DBB81BE4 for ; Wed, 30 Nov 2022 17:29:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16A28C433D6; Wed, 30 Nov 2022 17:29:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1669829387; bh=Se/TC8jGwx1Q4vMg/Yue2z42QsGe8Z6rbqxs+lft5BA=; h=Subject:To:Cc:From:Date:From; b=jnyxa4tfPEy6HJwDVYfHUjppteBHhY7ZnwDvgG2vjpTr2ssB+ASSRCQpCzA1aMx31 wFB3s9jllBL2NocL9VZqtj5zWQl3LfLriZGhpVAcCAJo+PrmwIwO9cvG/yuaqXq68S cae4HdV47PoO5b2iUY/y27YaZUvWSejCl8i7EM/w= Subject: FAILED: patch "[PATCH] btrfs: free btrfs_path before copying inodes to userspace" failed to apply to 5.15-stable tree To: anand.jain@oracle.com, dsterba@suse.com Cc: From: Date: Wed, 30 Nov 2022 18:29:44 +0100 Message-ID: <1669829384107223@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch below does not apply to the 5.15-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . Possible dependencies: 418ffb9e3cf6 ("btrfs: free btrfs_path before copying inodes to userspace") e3059ec06b9f ("btrfs: sink iterator parameter to btrfs_ioctl_logical_to_ino") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 418ffb9e3cf6c4e2574d3a732b724916684bd133 Mon Sep 17 00:00:00 2001 From: Anand Jain Date: Thu, 10 Nov 2022 11:36:28 +0530 Subject: [PATCH] btrfs: free btrfs_path before copying inodes to userspace btrfs_ioctl_logical_to_ino() frees the search path after the userspace copy from the temp buffer @inodes. Which potentially can lead to a lock splat. Fix this by freeing the path before we copy @inodes to userspace. CC: stable@vger.kernel.org # 4.19+ Signed-off-by: Anand Jain Reviewed-by: David Sterba Signed-off-by: David Sterba diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 89b8d14cb68c..b595f2c6dfc9 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4282,21 +4282,20 @@ static long btrfs_ioctl_logical_to_ino(struct btrfs_fs_info *fs_info, size = min_t(u32, loi->size, SZ_16M); } - path = btrfs_alloc_path(); - if (!path) { - ret = -ENOMEM; - goto out; - } - inodes = init_data_container(size); if (IS_ERR(inodes)) { ret = PTR_ERR(inodes); - inodes = NULL; - goto out; + goto out_loi; } + path = btrfs_alloc_path(); + if (!path) { + ret = -ENOMEM; + goto out; + } ret = iterate_inodes_from_logical(loi->logical, fs_info, path, inodes, ignore_offset); + btrfs_free_path(path); if (ret == -EINVAL) ret = -ENOENT; if (ret < 0) @@ -4308,7 +4307,6 @@ static long btrfs_ioctl_logical_to_ino(struct btrfs_fs_info *fs_info, ret = -EFAULT; out: - btrfs_free_path(path); kvfree(inodes); out_loi: kfree(loi);