Skip to contentSkip to conversation

xfs: fix kernel memory exposure problems

PATCH In review Darrick J. Wong 3 participants 7 messages Apr 3, 2017 – Apr 4, 2017 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfs: fix kernel memory exposure problems

Fix a memory exposure problems in inumbers where we allocate an array of structures with holes, fail to zero the holes, then blindly copy the kernel memory contents (junk and all) into userspace.

---
v2: split patches

---
 fs/xfs/xfs_itable.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_itable.c +1 -1
index 2a6d9b1..26d67ce 100644
@@ -583,7 +583,7 @@ xfs_inumbers(
 		return error;
 
 	bcount = MIN(left, (int)(PAGE_SIZE / sizeof(*buffer)));
-	buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP);
+	buffer = kmem_zalloc(bcount * sizeof(*buffer), KM_SLEEP);
 	do {
 		struct xfs_inobt_rec_incore	r;
 		int				stat;
#1 lore raw

PATCH 1/1 xfs: fix over-copying of getbmap parameters from userspace

In xfs_ioc_getbmap, we should only copy the fields of struct getbmap from userspace, or else we end up copying random stack contents into the kernel. struct getbmap is a strict subset of getbmapx, so a partial structure copy should work fine.

---
 fs/xfs/xfs_ioctl.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
fs/xfs/xfs_ioctl.c +6 -2
index 2fd7fdf..e44dde7 100644
@@ -1543,10 +1543,14 @@ xfs_ioc_getbmap(
 	unsigned int		cmd,
 	void			__user *arg)
 {
-	struct getbmapx		bmx;
+	struct getbmapx		bmx = { 0 };
 	int			error;
 
-	if (copy_from_user(&bmx, arg, sizeof(struct getbmapx)))
+	/*
+	 * struct getbmap is a strict subset of struct getbmapx,
+	 * so using a straight memory copy should work fine.
+	 */
+	if (copy_from_user(&bmx, arg, offsetof(struct getbmapx, bmv_iflags)))
 		return -EFAULT;
 
 	if (bmx.bmv_count < 2)
Reviewed-by on v1 1/1
#2 lore raw

Re: [PATCH] xfs: fix over-copying of getbmap parameters from userspace

fs/xfs/xfs_ioctl.c xfs_ioc_getbmap( · line 1551

Quoted 1 line
fs/xfs/xfs_ioctl.c +1 -0
+	 * so using a straight memory copy should work fine.

I'd skip this half of the comment.

Otherwise looks fine:

#3 lore raw

Re: [PATCH] xfs: fix over-copying of getbmap parameters from userspace

Quoted 3 lines · Christoph Hellwig

fs/xfs/xfs_ioctl.c xfs_ioc_getbmap( · line 1551

Quoted 1 line
fs/xfs/xfs_ioctl.c +1 -0
+	 * so using a straight memory copy should work fine.

I'd skip this half of the comment.

Will do.

Quoted 7 lines

Otherwise looks fine:

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to Darrick J. Wong
Quoted 6 lines · Darrick J. Wong

Fix a memory exposure problems in inumbers where we allocate an array of structures with holes, fail to zero the holes, then blindly copy the kernel memory contents (junk and all) into userspace.

BTW, I intend to send this patch (though not the getbmap patch) for 4.11 since kernel memory exposure is usually treated as a security problem.

--D

Quoted 23 lines

---
v2: split patches

---
 fs/xfs/xfs_itable.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_itable.c +1 -2
index 2a6d9b1..26d67ce 100644
@@ -583,7 +583,7 @@ xfs_inumbers(
 		return error;
 
 	bcount = MIN(left, (int)(PAGE_SIZE / sizeof(*buffer)));
-	buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP);
+	buffer = kmem_zalloc(bcount * sizeof(*buffer), KM_SLEEP);
 	do {
 		struct xfs_inobt_rec_incore	r;
 		int				stat;
--

To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 10 lines · Darrick J. Wong
Quoted 6 lines · Darrick J. Wong

Fix a memory exposure problems in inumbers where we allocate an array of structures with holes, fail to zero the holes, then blindly copy the kernel memory contents (junk and all) into userspace.

BTW, I intend to send this patch (though not the getbmap patch) for 4.11 since kernel memory exposure is usually treated as a security problem.

I agree with that plan; if this change isn't safe I don't know what is ...

-Eric

Quoted 30 lines

--D

Quoted 20 lines

---
v2: split patches

---
 fs/xfs/xfs_itable.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_itable.c +1 -2
index 2a6d9b1..26d67ce 100644
@@ -583,7 +583,7 @@ xfs_inumbers(
 		return error;
 
 	bcount = MIN(left, (int)(PAGE_SIZE / sizeof(*buffer)));
-	buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP);
+	buffer = kmem_zalloc(bcount * sizeof(*buffer), KM_SLEEP);
 	do {
 		struct xfs_inobt_rec_incore	r;
 		int				stat;
--
Quoted 3 lines

To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
Quoted 6 lines · Eric Sandeen
Quoted 5 lines · Darrick J. Wong
Quoted 4 lines · Darrick J. Wong

Fix a memory exposure problems in inumbers where we allocate an array of structures with holes, fail to zero the holes, then blindly copy the kernel memory contents (junk and all) into userspace.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

BTW, I intend to send this patch (though not the getbmap patch) for 4.11 since kernel memory exposure is usually treated as a security problem.

I agree with that plan; if this change isn't safe I don't know what is ...

Yes. Please send this for 4.11-rc.