mincore returning -ENOMEM instead of -EFAULT
Subsystems (2)
Linus,
Your fix in commit 2f77d107050abc14bc393b34bdb7b91cf670c250
modifies sys_mincore() to return -ENOMEM instead of -EFAULT on a totally bogus address. Was this intentional, or is it something that should be fixed up?
- /* check the output buffer whilst holding the lock */ - error = -EFAULT; - down_read(¤t->mm->mmap_sem); + /* ..and we need to be passed a valid user-space range */ + if (!access_ok(VERIFY_READ, (void __user *) start, len))
+ return -ENOMEM;
Joel
Signature · 10 lines
"Nobody loves me, Nobody seems to care. Troubles and worries, people, You know I've had my share." Joel Becker Principal Software Developer Oracle E-mail: [email protected] Phone: (650) 506-8127
PATCH 1/1 mm/mincore: Return EFAULT when passed an invalid address.
The locking fix to sys_mincore in commit2f77d107050abc14bc393b34bdb7b91cf670c250 returns -ENOMEM when given a bad userspace address. It should return -EFAULT.
mm/mincore.c +1 -1
@@ -122,7 +122,7 @@ asmlinkage long sys_mincore(unsigned long start, size_t len,/* ..and we need to be passed a valid user-space range */ if (!access_ok (VERIFY_READ , (void __user *) start, len)) -return -ENOMEM ; +return -EFAULT ;/* This also avoids any overflows on PAGE_CACHE_ALIGN */ pages = len >>PAGE_SHIFT ;
Signature · 12 lines
"But then she looks me in the eye And says, 'We're going to last forever,' And man you know I can't begin to doubt it. Cause it just feels so good and so free and so right, I know we ain't never going to change our minds about it, Hey! Here comes my girl." Joel Becker Principal Software Developer Oracle E-mail: [email protected] Phone: (650) 506-8127
Re: [PATCH] mm/mincore: Return EFAULT when passed an invalid address.
Quoted 3 lines · Joel Becker
The locking fix to
sys_mincorein commit2f77d107050abc14bc393b34bdb7b91cf670c250returns-ENOMEMwhen given a bad userspace address. It should return-EFAULT.
No, I think you're getting confused by the way Linus uses access_ok on the address range given with the access_ok on the vector address.
Before and after, an access_ok failure on the output vector address gives -EFAULT. Before and after, an invalid address in the range to be inspected gives -ENOMEM.
Which is consistent with the other m* system calls: -EFAULT if arguments are inaccessible, -ENOMEM if address range is invalid.
Hugh
Re: [PATCH] mm/mincore: Return EFAULT when passed an invalid address.
Quoted 2 lines · Hugh Dickins
No, I think you're getting confused by the way Linus uses
access_okon the address range given with theaccess_okon the vector address.
Whoops. Sorry for the noise.
Joel
Signature · 9 lines
Life's Little Instruction Book #451 "Don't be afraid to say, 'I'm sorry.'" Joel Becker Principal Software Developer Oracle E-mail: [email protected] Phone: (650) 506-8127
Quoted 5 lines · Joel Becker
Your fix in commit 2f77d107050abc14bc393b34bdb7b91cf670c250modifies
sys_mincore()to return-ENOMEMinstead of-EFAULTon a totally bogus address. Was this intentional, or is it something that should be fixed up?
It was intentional, and I don't actually think it was even a change. The access_ok() in question is not done on the actual array that we fill up with the result of the operation, but on the address range that is being queried, and if the queried address range is bogus, we should return ENOMEM.
It's even mentioned in the man-page..
We *do* return -EFAULT for the case where the "vec" array itself is not mapped.
Linus