public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix out-of-bounds access in xfs_bmapi_allocate by validating whichfork
@ 2024-10-27 19:35 MottiKumar Babu
  2024-10-27 20:32 ` [PATCH] Follow-up on Submitted Patch: Fix out-of-bounds access in xfs_bmapi_allocate MottiKumar Babu
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: MottiKumar Babu @ 2024-10-27 19:35 UTC (permalink / raw)
  To: cem, djwong, chandanbabu, dchinner, zhangjiachen.jaycee,
	linux-xfs, linux-kernel
  Cc: linux-kernel-mentees, anupnewsmail, skhan

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@gmail.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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-11-01  3:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-27 19:35 [PATCH] Fix out-of-bounds access in xfs_bmapi_allocate by validating whichfork MottiKumar Babu
2024-10-27 20:32 ` [PATCH] Follow-up on Submitted Patch: Fix out-of-bounds access in xfs_bmapi_allocate MottiKumar Babu
2024-10-27 22:53 ` [PATCH] Fix out-of-bounds access in xfs_bmapi_allocate by validating whichfork Dave Chinner
2024-10-28  8:46 ` Christoph Hellwig
2024-11-01  3:36 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox