Skip to content

Commit 1da9277

Browse files
author
Al Viro
committed
aio: sanitize the limit checking in io_submit(2)
as it is, the logics in native io_submit(2) is "if asked for more than LONG_MAX/sizeof(pointer) iocbs to submit, don't bother with more than LONG_MAX/sizeof(pointer)" (i.e. 512M requests on 32bit and 1E requests on 64bit) while compat io_submit(2) goes with "stop after the first PAGE_SIZE/sizeof(pointer) iocbs", i.e. 1K or so. Which is * inconsistent * *way* too much in native case * possibly too little in compat one and * wrong anyway, since the natural point where we ought to stop bothering is ctx->nr_events Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 67ba049 commit 1da9277

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

fs/aio.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,15 +1841,15 @@ SYSCALL_DEFINE3(io_submit, aio_context_t, ctx_id, long, nr,
18411841
if (unlikely(nr < 0))
18421842
return -EINVAL;
18431843

1844-
if (unlikely(nr > LONG_MAX/sizeof(*iocbpp)))
1845-
nr = LONG_MAX/sizeof(*iocbpp);
1846-
18471844
ctx = lookup_ioctx(ctx_id);
18481845
if (unlikely(!ctx)) {
18491846
pr_debug("EINVAL: invalid context id\n");
18501847
return -EINVAL;
18511848
}
18521849

1850+
if (nr > ctx->nr_events)
1851+
nr = ctx->nr_events;
1852+
18531853
blk_start_plug(&plug);
18541854
for (i = 0; i < nr; i++) {
18551855
struct iocb __user *user_iocb;
@@ -1870,8 +1870,6 @@ SYSCALL_DEFINE3(io_submit, aio_context_t, ctx_id, long, nr,
18701870
}
18711871

18721872
#ifdef CONFIG_COMPAT
1873-
#define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
1874-
18751873
COMPAT_SYSCALL_DEFINE3(io_submit, compat_aio_context_t, ctx_id,
18761874
int, nr, compat_uptr_t __user *, iocbpp)
18771875
{
@@ -1883,15 +1881,15 @@ COMPAT_SYSCALL_DEFINE3(io_submit, compat_aio_context_t, ctx_id,
18831881
if (unlikely(nr < 0))
18841882
return -EINVAL;
18851883

1886-
if (nr > MAX_AIO_SUBMITS)
1887-
nr = MAX_AIO_SUBMITS;
1888-
18891884
ctx = lookup_ioctx(ctx_id);
18901885
if (unlikely(!ctx)) {
18911886
pr_debug("EINVAL: invalid context id\n");
18921887
return -EINVAL;
18931888
}
18941889

1890+
if (nr > ctx->nr_events)
1891+
nr = ctx->nr_events;
1892+
18951893
blk_start_plug(&plug);
18961894
for (i = 0; i < nr; i++) {
18971895
compat_uptr_t user_iocb;

0 commit comments

Comments
 (0)