Skip to contentSkip to conversation

Revert "dlm: check the maximum size of a request from user"

GIT PULL David Teigland 2 participants 4 messages Feb 4, 2013 Distributed lock manager (DLM)

lore
Share & tools
lore

David Teigland

author maintainer
#0 lore raw

Hi Linus,

Please pull the following fix from branch:

git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm.git for-linus

This reverts commit 2b75bc9121e54e22537207b47b71373bcb0be41c.

There is something wrong with the CONFIG_COMPAT max size check in ioctl write. There is a report of a case where this breaks userland (clvmd) when maximum resource name lengths are used. I am still sorting out exactly which combinations of kernel and userland libs are a problem.

---
 fs/dlm/user.c | 7 -------
 1 file changed, 7 deletions(-)
fs/dlm/user.c +0 -7
index 7ff4985..eb4ed9b 100644
@@ -503,13 +503,6 @@ static ssize_t device_write(struct file *file, const char __user *buf,
 #endif
 		return -EINVAL;
 
-#ifdef CONFIG_COMPAT
-	if (count > sizeof(struct dlm_write_request32) + DLM_RESNAME_MAXLEN)
-#else
-	if (count > sizeof(struct dlm_write_request) + DLM_RESNAME_MAXLEN)
-#endif
-		return -EINVAL;
-
 	kbuf = kzalloc(count + 1, GFP_NOFS);
 	if (!kbuf)
 		return -ENOMEM;
Signature · 1 line
1.8.1.rc1.5.g7e0651a
#1 lore raw

Hi David,

This opens up a hole for userspace to force the kernel to allocate huge chunks of memory, triggering oom killing spree and such.

It should probably be fixed instead of just reverted.

I'll look into it.

Thanks,
Sasha

Quoted 42 lines · David Teigland

Hi Linus,

Please pull the following fix from branch:

git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm.git for-linus

This reverts commit 2b75bc9121e54e22537207b47b71373bcb0be41c.

There is something wrong with the CONFIG_COMPAT max size check in ioctl write. There is a report of a case where this breaks userland (clvmd) when maximum resource name lengths are used. I am still sorting out exactly which combinations of kernel and userland libs are a problem.

---
 fs/dlm/user.c | 7 -------
 1 file changed, 7 deletions(-)
fs/dlm/user.c +0 -8
index 7ff4985..eb4ed9b 100644
@@ -503,13 +503,6 @@ static ssize_t device_write(struct file *file, const char __user *buf,
 #endif
                return -EINVAL;
 
-#ifdef CONFIG_COMPAT
-       if (count > sizeof(struct dlm_write_request32) + DLM_RESNAME_MAXLEN)
-#else
-       if (count > sizeof(struct dlm_write_request) + DLM_RESNAME_MAXLEN)
-#endif
-               return -EINVAL;
-
        kbuf = kzalloc(count + 1, GFP_NOFS);
        if (!kbuf)
                return -ENOMEM;
--

1.8.1.rc1.5.g7e0651a

author maintainer
#2 lore raw
Quoted 8 lines · Sasha Levin

Hi David,

This opens up a hole for userspace to force the kernel to allocate huge chunks of memory, triggering oom killing spree and such.

It should probably be fixed instead of just reverted.

I'll look into it.

Here is the patch I'm planning to put in the queue for the next merge window, once it's been tested.

Subject: [PATCH] dlm: check the write size from user

Return EINVAL from write if the size is larger than allowed. Do this before allocating kernel memory for the bogus size, which could lead to OOM.

---
 fs/dlm/user.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/dlm/user.c +7 -0
index eb4ed9b..911649a 100644
@@ -503,6 +503,13 @@ static ssize_t device_write(struct file *file, const char __user *buf,
 #endif
 		return -EINVAL;
 
+	/*
+	 * can't compare against COMPAT/dlm_write_request32 because
+	 * we don't yet know if is64bit is zero
+	 */
+	if (count > sizeof(struct dlm_write_request) + DLM_RESNAME_MAXLEN)
+		return -EINVAL;
+
 	kbuf = kzalloc(count + 1, GFP_NOFS);
 	if (!kbuf)
 		return -ENOMEM;
Signature · 1 line
1.8.1.rc1.5.g7e0651a
author maintainer Tested-by Jana Saout
#3 lore raw
In reply to David Teigland
Quoted 5 lines · David Teigland

Please pull the following fix from branch:

git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm.git for-linus

This reverts commit 2b75bc9121e54e22537207b47b71373bcb0be41c.

Hi Linus,

You can choose to pull that revert, or you can alternatively pull this fix to the original patch from this branch:

git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm.git fix-max-write

Thanks to Jana who reported the problem and was able to test this fix so quickly.

Subject: [PATCH] dlm: check the write size from user

Return EINVAL from write if the size is larger than allowed. Do this before allocating kernel memory for the bogus size, which could lead to OOM.

---
 fs/dlm/user.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/dlm/user.c +4 -4
index 7ff4985..911649a 100644
@@ -503,11 +503,11 @@ static ssize_t device_write(struct file *file, const char __user *buf,
 #endif
 		return -EINVAL;
 
-#ifdef CONFIG_COMPAT
-	if (count > sizeof(struct dlm_write_request32) + DLM_RESNAME_MAXLEN)
-#else
+	/*
+	 * can't compare against COMPAT/dlm_write_request32 because
+	 * we don't yet know if is64bit is zero
+	 */
 	if (count > sizeof(struct dlm_write_request) + DLM_RESNAME_MAXLEN)
-#endif
 		return -EINVAL;
 
 	kbuf = kzalloc(count + 1, GFP_NOFS);
Signature · 1 line
1.8.1.rc1.5.g7e0651a