Skip to contentSkip to conversation

fs: aio: use correct integer overflow checks when creation aio ctx

PATCH In review Sasha Levin 2 participants 3 messages May 17, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: aio: use correct integer overflow checks when creation aio ctx

Commit "aio: percpu reqs_available" added some math to the nr_requests calculation, but didn't correct the overflow calculations to handle that.

This means that this:

	#include <linux/aio_abi.h>
	void main(void)
	{
	        aio_context_t ctx_idp;
	        io_setup(0x80000001, &ctx_idp);
	}

Would trigger the newly added BUG() couple of lines after the overflow checks.

---
 fs/aio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/aio.c +2 -1
index 5b7ed78..0ae450a 100644
@@ -411,7 +411,8 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
 
 	/* Prevent overflows */
 	if ((nr_events > (0x10000000U / sizeof(struct io_event))) ||
-	    (nr_events > (0x10000000U / sizeof(struct kiocb)))) {
+	    (nr_events > (0x10000000U / sizeof(struct kiocb))) ||
+	    (nr_events < num_possible_cpus() * 4)) {
 		pr_debug("ENOMEM: nr_events too high\n");
 		return ERR_PTR(-EINVAL);
 	}
Signature · 7 lines
1.8.2.1

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to [email protected].  For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"[email protected]">[email protected]</a>
maintainer
#1 lore raw
Quoted 12 lines · Sasha Levin

Commit "aio: percpu reqs_available" added some math to the nr_requests calculation, but didn't correct the overflow calculations to handle that.

This means that this:

	#include <linux/aio_abi.h>
	void main(void)
	{
	        aio_context_t ctx_idp;
	        io_setup(0x80000001, &ctx_idp);
	}
Quoted 2 lines

Would trigger the newly added BUG() couple of lines after the overflow checks.

This BUG() isn't in Linus' tree, and probably should be removed before it gets there.

Quoted 10 lines
---
 fs/aio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/aio.c +0 -0
index 5b7ed78..0ae450a 100644

fs/aio.c static struct kioctx *ioctx_alloc(unsigned nr_events) · line 417

Quoted 8 lines
fs/aio.c +2 -1
@@ -411,7 +411,8 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
 
 	/* Prevent overflows */
 	if ((nr_events > (0x10000000U / sizeof(struct io_event))) ||
-	    (nr_events > (0x10000000U / sizeof(struct kiocb)))) {
+	    (nr_events > (0x10000000U / sizeof(struct kiocb))) ||
+	    (nr_events < num_possible_cpus() * 4)) {
 		pr_debug("ENOMEM: nr_events too high\n");
 		return ERR_PTR(-EINVAL);

This is completely wrong. Enforcing a minimum needs to be done in a way that doesn't fail for existing users that potentially use a minimum smaller than what is newly required. That is: an existing userland program that only requests 16 events must not fail because of changes to the kernel that increase the minimum number of requests. So I have to NACK this patch as it stands.

-ben

Quoted 3 lines
fs/aio.c +0 -0
 	}
Signature · 1 line
1.8.2.1
Signature · 7 lines
"Thought is the essence of where you are now."

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to [email protected].  For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"[email protected]">[email protected]</a>
#2 lore raw
Quoted 13 lines · Benjamin LaHaise
Quoted 12 lines · Sasha Levin

Commit "aio: percpu reqs_available" added some math to the nr_requests calculation, but didn't correct the overflow calculations to handle that.

This means that this:

	#include <linux/aio_abi.h>
	void main(void)
	{
	        aio_context_t ctx_idp;
	        io_setup(0x80000001, &ctx_idp);
	}
Quoted 5 lines
Quoted 2 lines

Would trigger the newly added BUG() couple of lines after the overflow checks.

This BUG() isn't in Linus' tree, and probably should be removed before it gets there.

It's not, it's in -next though.

Quoted 11 lines
Quoted 11 lines
---
 fs/aio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/aio.c +0 -0
index 5b7ed78..0ae450a 100644
@@ -411,7 +411,8 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
 
Quoted 14 lines

fs/aio.c static struct kioctx *ioctx_alloc(unsigned nr_events) · line 417

Quoted 7 lines
fs/aio.c +2 -1
 	/* Prevent overflows */
 	if ((nr_events > (0x10000000U / sizeof(struct io_event))) ||
-	    (nr_events > (0x10000000U / sizeof(struct kiocb)))) {
+	    (nr_events > (0x10000000U / sizeof(struct kiocb))) ||
+	    (nr_events < num_possible_cpus() * 4)) {
 		pr_debug("ENOMEM: nr_events too high\n");
 		return ERR_PTR(-EINVAL);

This is completely wrong. Enforcing a minimum needs to be done in a way that doesn't fail for existing users that potentially use a minimum smaller than what is newly required. That is: an existing userland program that only requests 16 events must not fail because of changes to the kernel that increase the minimum number of requests. So I have to NACK this patch as it stands.

You didn't look around the context of the patch.

Couple of lines before that check, this happens:

        nr_events = max(nr_events, num_possible_cpus() * 4);
        nr_events *= 2;

The check I've added would only make sense if nr_events wrapped around, not if nr_events was originally smaller than (num_possible_cpus() * 4).

Thanks,
Sasha

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in the body to [email protected]. For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"[email protected]">[email protected]</a>