[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241027193541.14212-1-mottikumarbabu@gmail.com>
Date: Mon, 28 Oct 2024 01:05:27 +0530
From: MottiKumar Babu <mottikumarbabu@...il.com>
To: cem@...nel.org,
djwong@...nel.org,
chandanbabu@...nel.org,
dchinner@...hat.com,
zhangjiachen.jaycee@...edance.com,
linux-xfs@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: linux-kernel-mentees@...ts.linux.dev,
anupnewsmail@...il.com,
skhan@...uxfoundation.org
Subject: [PATCH] Fix out-of-bounds access in xfs_bmapi_allocate by validating whichfork
This issue was reported by Coverity Scan.
Report:
CID 1633175 Out-of-bounds access - Access of memory not owned by this buffer may cause crashes or incorrect computations.
In xfs_bmapi_allocate: Out-of-bounds access to a buffer (CWE-119)
Signed-off-by: MottiKumar Babu <mottikumarbabu@...il.com>
---
fs/xfs/libxfs/xfs_bmap.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 36dd08d13293..6ff378d2d3d9 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -4169,6 +4169,10 @@ xfs_bmapi_allocate(
* is not on the busy list.
*/
bma->datatype = XFS_ALLOC_NOBUSY;
+ // Ensure whichfork is valid (0 or 1) before further checks
+ if (whichfork < 0 || whichfork > 1) {
+ return -EINVAL; // Invalid fork
+ }
if (whichfork == XFS_DATA_FORK || whichfork == XFS_COW_FORK) {
bma->datatype |= XFS_ALLOC_USERDATA;
if (bma->offset == 0)
--
2.43.0
Powered by blists - more mailing lists