Skip to contentSkip to conversation

proc: use vmalloc for our kernel buffer

PATCH Superseded Josef Bacik 5 participants 16 messages Aug 13, 2020

Subsystems (6)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 proc: use vmalloc for our kernel buffer

Since

sysctl: pass kernel pointers to ->proc_handler

we have been pre-allocating a buffer to copy the data from the proc handlers into, and then copying that to userspace. The problem is this just blind kmalloc()'s the buffer size passed in from the read, which in the case of our 'cat' binary was 64kib. Order-4 allocations are not awesome, and since we can potentially allocate up to our maximum order, use vmalloc for these buffers.

Fixes 32927393dc1c ("sysctl: pass kernel pointers to ->proc_handler")
---
 fs/proc/proc_sysctl.c  |  6 +++---
 include/linux/string.h |  1 +
 mm/util.c              | 26 ++++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 3 deletions(-)
fs/proc/proc_sysctl.c +3 -3
index 6c1166ccdaea..207ac6e6e028 100644
@@ -571,13 +571,13 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
 		goto out;
 
 	if (write) {
-		kbuf = memdup_user_nul(ubuf, count);
+		kbuf = vmemdup_user_nul(ubuf, count);
 		if (IS_ERR(kbuf)) {
 			error = PTR_ERR(kbuf);
 			goto out;
 		}
 	} else {
-		kbuf = kzalloc(count, GFP_KERNEL);
+		kbuf = kvzalloc(count, GFP_KERNEL);
 		if (!kbuf)
 			goto out;
 	}
@@ -600,7 +600,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
 
 	error = count;
 out_free_buf:
-	kfree(kbuf);
+	kvfree(kbuf);
 out:
 	sysctl_head_finish(head);
 
include/linux/string.h +1 -0
index 9b7a0632e87a..aee3689fb865 100644
@@ -12,6 +12,7 @@
 extern char *strndup_user(const char __user *, long);
 extern void *memdup_user(const void __user *, size_t);
 extern void *vmemdup_user(const void __user *, size_t);
+extern void *vmemdup_user_nul(const void __user *, size_t);
 extern void *memdup_user_nul(const void __user *, size_t);
 
 /*
mm/util.c +26 -0
index 5ef378a2a038..4de3b4b0f358 100644
@@ -208,6 +208,32 @@ void *vmemdup_user(const void __user *src, size_t len)
 }
 EXPORT_SYMBOL(vmemdup_user);
 
+/**
+ * vmemdup_user - duplicate memory region from user space and NUL-terminate
+ *
+ * @src: source address in user space
+ * @len: number of bytes to copy
+ *
+ * Return: an ERR_PTR() on failure.  Result may be not
+ * physically contiguous.  Use kvfree() to free.
+ */
+void *vmemdup_user_nul(const void __user *src, size_t len)
+{
+	void *p;
+
+	p = kvmalloc(len, GFP_USER);
+	if (!p)
+		return ERR_PTR(-ENOMEM);
+
+	if (copy_from_user(p, src, len)) {
+		kvfree(p);
+		return ERR_PTR(-EFAULT);
+	}
+
+	return p;
+}
+EXPORT_SYMBOL(vmemdup_user_nul);
+
 /**
  * strndup_user - duplicate an existing string from user space
  * @s: The string to duplicate
Signature · 1 line
2.24.1
#1 lore raw
Quoted 2 lines · Josef Bacik

+/**
+ * vmemdup_user - duplicate memory region from user space and NUL-terminate

vmemdup_user_nul()

mm/util.c void *vmemdup_user(const void __user *src, size_t len) · line 224

Quoted 5 lines
mm/util.c +5 -0
+void *vmemdup_user_nul(const void __user *src, size_t len)
+{
+	void *p;
+
+	p = kvmalloc(len, GFP_USER);

len+1, shirley?

mm/util.c void *vmemdup_user(const void __user *src, size_t len) · line 231

Quoted 7 lines
mm/util.c +7 -0
+	if (!p)
+		return ERR_PTR(-ENOMEM);
+
+	if (copy_from_user(p, src, len)) {
+		kvfree(p);
+		return ERR_PTR(-EFAULT);
+	}

I think you forgot

        p[len] = '\0';
Quoted 10 lines
mm/util.c +4 -0
+	return p;
+}
+EXPORT_SYMBOL(vmemdup_user_nul);
+
 /**
  * strndup_user - duplicate an existing string from user space
  * @s: The string to duplicate
Signature · 1 line
2.24.1
#2 lore raw
Quoted 24 lines · Matthew Wilcox
Quoted 2 lines · Josef Bacik

+/**
+ * vmemdup_user - duplicate memory region from user space and NUL-terminate

vmemdup_user_nul()

mm/util.c void *vmemdup_user(const void __user *src, size_t len) · line 224

Quoted 5 lines
mm/util.c +5 -0
+void *vmemdup_user_nul(const void __user *src, size_t len)
+{
+	void *p;
+
+	p = kvmalloc(len, GFP_USER);

len+1, shirley?

mm/util.c void *vmemdup_user(const void __user *src, size_t len) · line 231

Quoted 7 lines
mm/util.c +7 -0
+	if (!p)
+		return ERR_PTR(-ENOMEM);
+
+	if (copy_from_user(p, src, len)) {
+		kvfree(p);
+		return ERR_PTR(-EFAULT);
+	}

I think you forgot

Quoted 2 lines
         p[len] = '\0';

Sweet lord I need more sleep, my bad. Thanks,

Josef

#3 lore raw

PATCH v2 1/1 proc: use vmalloc for our kernel buffer

In reply to Josef Bacik

Since

sysctl: pass kernel pointers to ->proc_handler

we have been pre-allocating a buffer to copy the data from the proc handlers into, and then copying that to userspace. The problem is this just blind kmalloc()'s the buffer size passed in from the read, which in the case of our 'cat' binary was 64kib. Order-4 allocations are not awesome, and since we can potentially allocate up to our maximum order, use vmalloc for these buffers.

Fixes 32927393dc1c ("sysctl: pass kernel pointers to ->proc_handler")

---
v1->v2:
- Make vmemdup_user_nul actually do the right thing...sorry about that.

 fs/proc/proc_sysctl.c  |  6 +++---
 include/linux/string.h |  1 +
 mm/util.c              | 27 +++++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 3 deletions(-)
fs/proc/proc_sysctl.c +3 -3
index 6c1166ccdaea..207ac6e6e028 100644
@@ -571,13 +571,13 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
 		goto out;
 
 	if (write) {
-		kbuf = memdup_user_nul(ubuf, count);
+		kbuf = vmemdup_user_nul(ubuf, count);
 		if (IS_ERR(kbuf)) {
 			error = PTR_ERR(kbuf);
 			goto out;
 		}
 	} else {
-		kbuf = kzalloc(count, GFP_KERNEL);
+		kbuf = kvzalloc(count, GFP_KERNEL);
 		if (!kbuf)
 			goto out;
 	}
@@ -600,7 +600,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
 
 	error = count;
 out_free_buf:
-	kfree(kbuf);
+	kvfree(kbuf);
 out:
 	sysctl_head_finish(head);
 
include/linux/string.h +1 -0
index 9b7a0632e87a..aee3689fb865 100644
@@ -12,6 +12,7 @@
 extern char *strndup_user(const char __user *, long);
 extern void *memdup_user(const void __user *, size_t);
 extern void *vmemdup_user(const void __user *, size_t);
+extern void *vmemdup_user_nul(const void __user *, size_t);
 extern void *memdup_user_nul(const void __user *, size_t);
 
 /*
mm/util.c +27 -0
index 5ef378a2a038..9d0ad7aafc27 100644
@@ -208,6 +208,33 @@ void *vmemdup_user(const void __user *src, size_t len)
 }
 EXPORT_SYMBOL(vmemdup_user);
 
+/**
+ * vmemdup_user_nul - duplicate memory region from user space and NUL-terminate
+ *
+ * @src: source address in user space
+ * @len: number of bytes to copy
+ *
+ * Return: an ERR_PTR() on failure.  Result may be not
+ * physically contiguous.  Use kvfree() to free.
+ */
+void *vmemdup_user_nul(const void __user *src, size_t len)
+{
+	char *p;
+
+	p = kvmalloc(len + 1, GFP_USER);
+	if (!p)
+		return ERR_PTR(-ENOMEM);
+
+	if (copy_from_user(p, src, len)) {
+		kvfree(p);
+		return ERR_PTR(-EFAULT);
+	}
+	p[len] = '\0';
+
+	return p;
+}
+EXPORT_SYMBOL(vmemdup_user_nul);
+
 /**
  * strndup_user - duplicate an existing string from user space
  * @s: The string to duplicate
Signature · 1 line
2.24.1
#4 lore raw
Quoted 27 lines · Josef Bacik

Since

sysctl: pass kernel pointers to ->proc_handler

we have been pre-allocating a buffer to copy the data from the proc handlers into, and then copying that to userspace. The problem is this just blind kmalloc()'s the buffer size passed in from the read, which in the case of our 'cat' binary was 64kib. Order-4 allocations are not awesome, and since we can potentially allocate up to our maximum order, use vmalloc for these buffers.

Fixes 32927393dc1c ("sysctl: pass kernel pointers to ->proc_handler")

---
v1->v2:
- Make vmemdup_user_nul actually do the right thing...sorry about that.

 fs/proc/proc_sysctl.c  |  6 +++---
 include/linux/string.h |  1 +
 mm/util.c              | 27 +++++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 3 deletions(-)
fs/proc/proc_sysctl.c +0 -0
index 6c1166ccdaea..207ac6e6e028 100644

fs/proc/proc_sysctl.c static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, · line 574

Quoted 5 lines
fs/proc/proc_sysctl.c +1 -1
@@ -571,13 +571,13 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
 		goto out;
 
 	if (write) {
-		kbuf = memdup_user_nul(ubuf, count);
+		kbuf = vmemdup_user_nul(ubuf, count);

Given that this can also do a kmalloc and thus needs to be paired with kvfree shouldn't it be kvmemdup_user_nul?

#5 lore raw
Quoted 30 lines · Christoph Hellwig
Quoted 29 lines · Josef Bacik

Since

sysctl: pass kernel pointers to ->proc_handler

we have been pre-allocating a buffer to copy the data from the proc handlers into, and then copying that to userspace. The problem is this just blind kmalloc()'s the buffer size passed in from the read, which in the case of our 'cat' binary was 64kib. Order-4 allocations are not awesome, and since we can potentially allocate up to our maximum order, use vmalloc for these buffers.

Fixes 32927393dc1c ("sysctl: pass kernel pointers to ->proc_handler")

---
v1->v2:
- Make vmemdup_user_nul actually do the right thing...sorry about that.

  fs/proc/proc_sysctl.c  |  6 +++---
  include/linux/string.h |  1 +
  mm/util.c              | 27 +++++++++++++++++++++++++++
  3 files changed, 31 insertions(+), 3 deletions(-)
fs/proc/proc_sysctl.c +0 -0
index 6c1166ccdaea..207ac6e6e028 100644
@@ -571,13 +571,13 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
  		goto out;
 
Quoted 7 lines

fs/proc/proc_sysctl.c static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, · line 574

Quoted 3 lines
fs/proc/proc_sysctl.c +1 -1
  	if (write) {
-		kbuf = memdup_user_nul(ubuf, count);
+		kbuf = vmemdup_user_nul(ubuf, count);

Given that this can also do a kmalloc and thus needs to be paired with kvfree shouldn't it be kvmemdup_user_nul?

There's an existing vmemdup_user that does kvmalloc, so I followed the existing naming convention. Do you want me to change them both? Thanks,

Josef

#6 lore raw
Quoted 38 lines · Josef Bacik
Quoted 23 lines · Christoph Hellwig
Quoted 22 lines · Josef Bacik

Since

sysctl: pass kernel pointers to ->proc_handler

we have been pre-allocating a buffer to copy the data from the proc handlers into, and then copying that to userspace. The problem is this just blind kmalloc()'s the buffer size passed in from the read, which in the case of our 'cat' binary was 64kib. Order-4 allocations are not awesome, and since we can potentially allocate up to our maximum order, use vmalloc for these buffers.

Fixes 32927393dc1c ("sysctl: pass kernel pointers to ->proc_handler")

---
v1->v2:
- Make vmemdup_user_nul actually do the right thing...sorry about that.

  fs/proc/proc_sysctl.c  |  6 +++---
  include/linux/string.h |  1 +
  mm/util.c              | 27 +++++++++++++++++++++++++++
  3 files changed, 31 insertions(+), 3 deletions(-)
Quoted 13 lines

fs/proc/proc_sysctl.c static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, · line 573

Quoted 9 lines
fs/proc/proc_sysctl.c +1 -1
index 6c1166ccdaea..207ac6e6e028 100644
@@ -571,13 +571,13 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
  		goto out;
    	if (write) {
-		kbuf = memdup_user_nul(ubuf, count);
+		kbuf = vmemdup_user_nul(ubuf, count);

Given that this can also do a kmalloc and thus needs to be paired with kvfree shouldn't it be kvmemdup_user_nul?

Quoted 2 lines

There's an existing vmemdup_user that does kvmalloc, so I followed the existing naming convention. Do you want me to change them both? Thanks,

I personally would, and given that it only has a few users it might even be feasible.

maintainer
#7 lore raw
Quoted 39 lines · Christoph Hellwig
Quoted 38 lines · Josef Bacik
Quoted 36 lines · Christoph Hellwig
Quoted 27 lines · Josef Bacik

Since

sysctl: pass kernel pointers to ->proc_handler

we have been pre-allocating a buffer to copy the data from the proc handlers into, and then copying that to userspace. The problem is this just blind kmalloc()'s the buffer size passed in from the read, which in the case of our 'cat' binary was 64kib. Order-4 allocations are not awesome, and since we can potentially allocate up to our maximum order, use vmalloc for these buffers.

Fixes 32927393dc1c ("sysctl: pass kernel pointers to ->proc_handler")

---
v1->v2:
- Make vmemdup_user_nul actually do the right thing...sorry about that.

  fs/proc/proc_sysctl.c  |  6 +++---
  include/linux/string.h |  1 +
  mm/util.c              | 27 +++++++++++++++++++++++++++
  3 files changed, 31 insertions(+), 3 deletions(-)
fs/proc/proc_sysctl.c +0 -0
index 6c1166ccdaea..207ac6e6e028 100644

fs/proc/proc_sysctl.c static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, · line 573

Quoted 4 lines
fs/proc/proc_sysctl.c +1 -1
@@ -571,13 +571,13 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
  		goto out;
    	if (write) {
-		kbuf = memdup_user_nul(ubuf, count);
+		kbuf = vmemdup_user_nul(ubuf, count);

Given that this can also do a kmalloc and thus needs to be paired with kvfree shouldn't it be kvmemdup_user_nul?

Quoted 5 lines
Quoted 2 lines

There's an existing vmemdup_user that does kvmalloc, so I followed the existing naming convention. Do you want me to change them both? Thanks,

I personally would, and given that it only has a few users it might even be feasible.

FWIW, how about following or combining that with "allocate count + 1 bytes on the read side"? Allows some nice cleanups - e.g.

                len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data);
                if (len > left)
                        len = left;
                memcpy(buffer, tmpbuf, len);
                if ((left -= len) > 0) {
                        *((char *)buffer + len) = '\n';
                        left--;
                }
in sunrpc proc_dodebug() turns into
		left -= snprintf(buffer, left, "0x%04x\n",
				 *(unsigned int *) table->data);

and that's not the only example.

#8 lore raw
Quoted 59 lines · Al Viro
Quoted 39 lines · Christoph Hellwig
Quoted 38 lines · Josef Bacik
Quoted 36 lines · Christoph Hellwig
Quoted 27 lines · Josef Bacik

Since

    sysctl: pass kernel pointers to ->proc_handler

we have been pre-allocating a buffer to copy the data from the proc handlers into, and then copying that to userspace. The problem is this just blind kmalloc()'s the buffer size passed in from the read, which in the case of our 'cat' binary was 64kib. Order-4 allocations are not awesome, and since we can potentially allocate up to our maximum order, use vmalloc for these buffers.

Fixes 32927393dc1c ("sysctl: pass kernel pointers to ->proc_handler")

---
v1->v2:
- Make vmemdup_user_nul actually do the right thing...sorry about that.

   fs/proc/proc_sysctl.c  |  6 +++---
   include/linux/string.h |  1 +
   mm/util.c              | 27 +++++++++++++++++++++++++++
   3 files changed, 31 insertions(+), 3 deletions(-)
fs/proc/proc_sysctl.c +0 -0
index 6c1166ccdaea..207ac6e6e028 100644

fs/proc/proc_sysctl.c static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, · line 573

Quoted 4 lines
fs/proc/proc_sysctl.c +1 -1
@@ -571,13 +571,13 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
   		goto out;
     	if (write) {
-		kbuf = memdup_user_nul(ubuf, count);
+		kbuf = vmemdup_user_nul(ubuf, count);

Given that this can also do a kmalloc and thus needs to be paired with kvfree shouldn't it be kvmemdup_user_nul?

Quoted 5 lines
Quoted 2 lines

There's an existing vmemdup_user that does kvmalloc, so I followed the existing naming convention. Do you want me to change them both? Thanks,

I personally would, and given that it only has a few users it might even be feasible.

FWIW, how about following or combining that with "allocate count + 1 bytes on the read side"? Allows some nice cleanups - e.g.

                 len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data);
                 if (len > left)
                         len = left;
                 memcpy(buffer, tmpbuf, len);
                 if ((left -= len) > 0) {
                         *((char *)buffer + len) = '\n';
                         left--;
                 }
in sunrpc proc_dodebug() turns into
		left -= snprintf(buffer, left, "0x%04x\n",
				 *(unsigned int *) table->data);
Quoted 2 lines

and that's not the only example.

We wouldn't even need the extra +1 part, since we're only copying in how much the user wants anyway, we could just go ahead and convert this to

left -= snprintf(buffer, left, "0x%04x\n", *(unsigned int *) table->data);

and be fine, right? Or am I misunderstanding what you're looking for? Thanks,

Josef

maintainer
#9 lore raw
Quoted 2 lines · Josef Bacik
Quoted 2 lines

in sunrpc proc_dodebug() turns into

		left -= snprintf(buffer, left, "0x%04x\n",
					 ^^^^
					 left + 1, that is.
Quoted 10 lines
Quoted 3 lines
				 *(unsigned int *) table->data);

and that's not the only example.

We wouldn't even need the extra +1 part, since we're only copying in how much the user wants anyway, we could just go ahead and convert this to

left -= snprintf(buffer, left, "0x%04x\n", *(unsigned int *) table->data);

and be fine, right? Or am I misunderstanding what you're looking for? Thanks,

snprintf() always produces a NUL-terminated string. And if you are passing 7 as len, you want 0xf0ad\n to be copied to user. For that you need 8 passed to snprintf, and 8-byte buffer given to it.

#10 lore raw
Quoted 14 lines · Al Viro
Quoted 2 lines · Josef Bacik
Quoted 2 lines

in sunrpc proc_dodebug() turns into

		left -= snprintf(buffer, left, "0x%04x\n",
					 ^^^^
					 left + 1, that is.
Quoted 7 lines
Quoted 3 lines
				 *(unsigned int *) table->data);

and that's not the only example.

We wouldn't even need the extra +1 part, since we're only copying in how much the user wants anyway, we could just go ahead and convert this to

Quoted 8 lines
Quoted 3 lines

left -= snprintf(buffer, left, "0x%04x\n", *(unsigned int *) table->data);

and be fine, right? Or am I misunderstanding what you're looking for? Thanks,

snprintf() always produces a NUL-terminated string. And if you are passing 7 as len, you want 0xf0ad\n to be copied to user. For that you need 8 passed to snprintf, and 8-byte buffer given to it.

Right, gotcha. I'll rig that up and see how it looks. I'd recommend looking through what I do with a fine tooth comb, I'm obviously not batting 1000 today. Thanks,

Josef

#11 lore raw
In reply to Josef Bacik

From: Josef Bacik

Quoted 1 line

Sent: 13 August 2020 18:19

...

Quoted 6 lines

We wouldn't even need the extra +1 part, since we're only copying in how much the user wants anyway, we could just go ahead and convert this to

left -= snprintf(buffer, left, "0x%04x\n", *(unsigned int *) table->data);

and be fine, right? Or am I misunderstanding what you're looking for? Thanks,

Doesn't that need to be scnprintf()?
IIRC snprintf() returns the number of bytes that would have been written were the buffer infinite size?
(I suspect this is an 'accidental' return value from the original SYSV? userspace implementation that just dumped characters that wouldn't fit in the buffer somewhere.)

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#12 lore raw
Quoted 8 lines · David Laight

From: Josef Bacik

Quoted 1 line

Sent: 13 August 2020 18:19

...

Quoted 5 lines

We wouldn't even need the extra +1 part, since we're only copying in how much the user wants anyway, we could just go ahead and convert this to

left -= snprintf(buffer, left, "0x%04x\n", *(unsigned int *) table->data);

Quoted 9 lines
Quoted 1 line

and be fine, right? Or am I misunderstanding what you're looking for? Thanks,

Doesn't that need to be scnprintf()?
IIRC snprintf() returns the number of bytes that would have been written were the buffer infinite size?
(I suspect this is an 'accidental' return value from the original SYSV? userspace implementation that just dumped characters that wouldn't fit in the buffer somewhere.)

Yeah, if you look at the patches I just sent you'll notice I used scnprintf() everywhere. Thanks,

Josef

#13 lore raw
In reply to Josef Bacik

From: Josef Bacik

Quoted 10 lines

Sent: 13 August 2020 15:53

sysctl: pass kernel pointers to ->proc_handler

we have been pre-allocating a buffer to copy the data from the proc handlers into, and then copying that to userspace. The problem is this just blind kmalloc()'s the buffer size passed in from the read, which in the case of our 'cat' binary was 64kib. Order-4 allocations are not awesome, and since we can potentially allocate up to our maximum order, use vmalloc for these buffers.

What happens if I run 'dd bs=16M ...' ?

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

maintainer
#14 lore raw
Quoted 5 lines · David Laight

From: Josef Bacik

Quoted 4 lines

Sent: 13 August 2020 15:53

sysctl: pass kernel pointers to ->proc_handler

Quoted 8 lines
Quoted 6 lines

we have been pre-allocating a buffer to copy the data from the proc handlers into, and then copying that to userspace. The problem is this just blind kmalloc()'s the buffer size passed in from the read, which in the case of our 'cat' binary was 64kib. Order-4 allocations are not awesome, and since we can potentially allocate up to our maximum order, use vmalloc for these buffers.

What happens if I run 'dd bs=16M ...' ?

Try it.

#15 lore raw
In reply to David Laight
Quoted 12 lines · David Laight

From: Josef Bacik

Quoted 10 lines

Sent: 13 August 2020 15:53

sysctl: pass kernel pointers to ->proc_handler

we have been pre-allocating a buffer to copy the data from the proc handlers into, and then copying that to userspace. The problem is this just blind kmalloc()'s the buffer size passed in from the read, which in the case of our 'cat' binary was 64kib. Order-4 allocations are not awesome, and since we can potentially allocate up to our maximum order, use vmalloc for these buffers.

Quoted 4 lines

What happens if I run 'dd bs=16M ...' ?

David

        /* don't even try if the size is too large */
        error = -ENOMEM;
        if (count >= KMALLOC_MAX_SIZE)
                goto out;

is above this code, thanks,

Josef