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 9786A3BBC5 for ; Wed, 19 Jun 2024 14:54:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718808883; cv=none; b=d6Fh07+8Nb7UCllyJqEB5VaPL2gff+fgbBy5bjOZh0Bn3ceuM7HLoVSSYvC1OBU42DkrbgAZeBvsRVKgiLyvo2CTv1PgR8vm6BpBGagCFk4w07MJd014jDmx5CzBcZdoPWx2yiTO2OqlPyEVqbbgnEYyqrQoL3oti0qrMS4FLZQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718808883; c=relaxed/simple; bh=TOV6NSYfu38YPaAmBvT1W7wFPDoUbSZFbtIW0v7pEDE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Qbl1eubYjKF+fV5wid+RzuePmg0P1zwufZLkgn6dCzZSNhmeWEvjFY+I6Y80gXF8Zbf1d9Vg/T47JsHg+n2s+sUg9WbhF/YvsGMAdBZBRuHY8yNcAfIc964jKxVUUlHe/E0YUCPC6abaglEDLwEzsaTSq/x+wHMclcP+eICZymg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=r/rBXGtB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="r/rBXGtB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 976CDC4AF09; Wed, 19 Jun 2024 14:54:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1718808883; bh=TOV6NSYfu38YPaAmBvT1W7wFPDoUbSZFbtIW0v7pEDE=; h=From:To:Cc:Subject:Date:Reply-to:From; b=r/rBXGtBoq90ZUvb7yunBuENVJQdXysT9Il3WzlWIJGaw1rflxpwo24neQJXakKNb I8mI3xrr8Ww59Sx2D4FKxrshkxabrRwTogcEW+JuFxd+RoLkeeIv/Hvo5UiJIwy9XM Ur1Of5o2WaBRqevuhdTHT0ByCf8U7Lm1vd7a+jMw= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2021-47585: btrfs: fix memory leak in __add_inode_ref() Date: Wed, 19 Jun 2024 16:54:24 +0200 Message-ID: <2024061917-CVE-2021-47585-0a6a@gregkh> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=3507; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=TOV6NSYfu38YPaAmBvT1W7wFPDoUbSZFbtIW0v7pEDE=; b=owGbwMvMwCRo6H6F97bub03G02pJDGlFHyUrLm+VEGNf/GBpnPSyspdaWSbs7/aWnsvsXPjWu i5/R4JMRywLgyATg6yYIsuXbTxH91ccUvQytD0NM4eVCWQIAxenAEzE8BDD/Ogn/wt2xt/Imnzj Ri/TvL/Xq9YFTmeY72Sxpe7dvrnzr64o2j1j6633C3LygwA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Description =========== In the Linux kernel, the following vulnerability has been resolved: btrfs: fix memory leak in __add_inode_ref() Line 1169 (#3) allocates a memory chunk for victim_name by kmalloc(), but when the function returns in line 1184 (#4) victim_name allocated by line 1169 (#3) is not freed, which will lead to a memory leak. There is a similar snippet of code in this function as allocating a memory chunk for victim_name in line 1104 (#1) as well as releasing the memory in line 1116 (#2). We should kfree() victim_name when the return value of backref_in_log() is less than zero and before the function returns in line 1184 (#4). 1057 static inline int __add_inode_ref(struct btrfs_trans_handle *trans, 1058 struct btrfs_root *root, 1059 struct btrfs_path *path, 1060 struct btrfs_root *log_root, 1061 struct btrfs_inode *dir, 1062 struct btrfs_inode *inode, 1063 u64 inode_objectid, u64 parent_objectid, 1064 u64 ref_index, char *name, int namelen, 1065 int *search_done) 1066 { 1104 victim_name = kmalloc(victim_name_len, GFP_NOFS); // #1: kmalloc (victim_name-1) 1105 if (!victim_name) 1106 return -ENOMEM; 1112 ret = backref_in_log(log_root, &search_key, 1113 parent_objectid, victim_name, 1114 victim_name_len); 1115 if (ret < 0) { 1116 kfree(victim_name); // #2: kfree (victim_name-1) 1117 return ret; 1118 } else if (!ret) { 1169 victim_name = kmalloc(victim_name_len, GFP_NOFS); // #3: kmalloc (victim_name-2) 1170 if (!victim_name) 1171 return -ENOMEM; 1180 ret = backref_in_log(log_root, &search_key, 1181 parent_objectid, victim_name, 1182 victim_name_len); 1183 if (ret < 0) { 1184 return ret; // #4: missing kfree (victim_name-2) 1185 } else if (!ret) { 1241 return 0; 1242 } The Linux kernel CVE team has assigned CVE-2021-47585 to this issue. Affected and fixed versions =========================== Issue introduced in 5.5 with commit d3316c8233bb and fixed in 5.10.88 with commit 005d9292b5b2 Issue introduced in 5.5 with commit d3316c8233bb and fixed in 5.15.11 with commit 493ff661d434 Issue introduced in 5.5 with commit d3316c8233bb and fixed in 5.16 with commit f35838a69302 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2021-47585 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: fs/btrfs/tree-log.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/005d9292b5b2e71a009f911bd85d755009b37242 https://git.kernel.org/stable/c/493ff661d434d6bdf02e3a21adae04d7a0b4265d https://git.kernel.org/stable/c/f35838a6930296fc1988764cfa54cb3f705c0665