IA64: virt_to_page() can be called with NULL arg
PATCH 3/3 IA64: virt_to_page() can be called with NULL arg
From: Kirill Korotaev <[email protected]>
It does not return NULL when arg is NULL.
---
include/asm-ia64/pgalloc.h | 3 ++- 1 files changed, 2 insertions(+), 1 deletion(-)
include/asm-ia64/pgalloc.h renamed from include/asm-ia64/pgalloc.h~ia64-virt_to_page-can-be-called-with-null-arg +2 -1
@@ -137,7 +137,8 @@ pmd_populate_kernel(struct mm_struct *mmstatic inline struct page *pte_alloc_one (struct mm_struct *mm,unsigned long addr) { -return virt_to_page (pgtable_quicklist_alloc ()); +void *pg =pgtable_quicklist_alloc (); +return pg ?virt_to_page (pg) :NULL ; } static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
_
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"akpm" = akpm <[email protected]> writes:
akpm> From: Kirill Korotaev <[email protected]> It does not return NULL akpm> when arg is NULL.
Shouldn't the real fix be to track down who calls virt_to_page() with a NULL pointer? IMHO it is bogus to do so.
Cheers,
Jes
Quoted 9 lines · Kirill Korotaev
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"akpm" = akpm <[email protected]> writes:
akpm> From: Kirill Korotaev <[email protected]> It does not return NULL akpm> when arg is NULL.
Shouldn't the real fix be to track down who calls
virt_to_page()with a NULL pointer? IMHO it is bogus to do so.what do you propose? to insert
BUG_ON(!kaddr)intovirt_to_page()? in this case caller in question should be still fixed.
If you hit this, yes I'd insert the BUG_ON in your test kernel and fix the code. Maybe add the BUG_ON in upstream for CONFIG_DEBUG or something.
Which callers did you see cause this? If it was a common problem I would expect a lot of data corruption or crashes on ia64 systems which I haven't heard of.
Cheers,
Jes
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"akpm" = akpm <[email protected]> writes:
akpm> From: Kirill Korotaev <[email protected]> It does not return NULL akpm> when arg is NULL.
Shouldn't the real fix be to track down who calls
virt_to_page()with a NULL pointer? IMHO it is bogus to do so.
what do you propose? to insert BUG_ON(!kaddr) into virt_to_page()? in this case caller in question should be still fixed.
Thanks,
Kirill
Quoted 7 lines · Kirill Korotaev
Quoted 3 lines · Jes Sorensen
If you hit this, yes I'd insert the
BUG_ONin your test kernel and fix the code. Maybe add theBUG_ONin upstream forCONFIG_DEBUGor something.I guess then all the platforms should be analyzed/patched carefully or all the callers of
virt_to_page().
Care to create debug patch?
Well you suggested a patch which just hides the problem. I suggest you change it to have the BUG_ON().
Quoted 11 lines
Quoted 3 lines
Which callers did you see cause this? If it was a common problem I would expect a lot of data corruption or crashes on ia64 systems which I haven't heard of.
from the patch:
pte_alloc_one()callspgtable_quicklist_alloc()which can return NULL in case of allocation failure.It was hit on OpenVZ where kernel memory is accounted and limited on per-container basis (it is possible to DoS using page tables allocations). In mainstream the bug can be hit if OOM killer
kills the process and__get_free_page()returns NULL which is rare, but still possible.
I see, since you have it tracked down, it would be good to fix it and push a patch upstream. Unless of course Andrew or Linus thinks this is the wrong approach.
Cheers,
Jes
Quoted 10 lines · Jes Sorensen
Quoted 8 lines · Kirill Korotaev
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"akpm" = akpm <[email protected]> writes:
akpm> From: Kirill Korotaev <[email protected]> It does not return NULL akpm> when arg is NULL.
Shouldn't the real fix be to track down who calls
virt_to_page()with a NULL pointer? IMHO it is bogus to do so.
Quoted 7 lines
Quoted 2 lines
what do you propose? to insert
BUG_ON(!kaddr)intovirt_to_page()? in this case caller in question should be still fixed.If you hit this, yes I'd insert the
BUG_ONin your test kernel and fix the code. Maybe add theBUG_ONin upstream forCONFIG_DEBUGor something.
I guess then all the platforms should be analyzed/patched carefully or all the callers of virt_to_page().
Care to create debug patch?
Quoted 3 lines
Which callers did you see cause this? If it was a common problem I would expect a lot of data corruption or crashes on ia64 systems which I haven't heard of.
from the patch:pte_alloc_one() calls pgtable_quicklist_alloc() which can return NULL in case of allocation failure.
It was hit on OpenVZ where kernel memory is accounted and limited on per-container basis (it is possible to DoS using page tables allocations). In mainstream the bug can be hit if OOM killer
kills the process and __get_free_page() returns NULL which is rare, but still possible.
Thanks,
Kirill
Quoted 5 lines · On Wed, 20 Dec 2006 11:14:53 +0100 Jes Sorensen <[email protected]> wrote:
Quoted 4 lines · Kirill Korotaev
Quoted 3 lines · Jes Sorensen
If you hit this, yes I'd insert the
BUG_ONin your test kernel and fix the code. Maybe add theBUG_ONin upstream forCONFIG_DEBUGor something.
Quoted 7 lines
Quoted 3 lines
I guess then all the platforms should be analyzed/patched carefully or all the callers of
virt_to_page().
Care to create debug patch?Well you suggested a patch which just hides the problem. I suggest you change it to have the
BUG_ON().
The patch doesn't hide any problems:
include/asm-ia64/pgalloc.h renamed from include/asm-ia64/pgalloc.h~ia64-virt_to_page-can-be-called-with-null-arg +2 -1
@@ -137,7 +137,8 @@ pmd_populate_kernel(struct mm_struct *mmstatic inline struct page *pte_alloc_one (struct mm_struct *mm,unsigned long addr) { -return virt_to_page (pgtable_quicklist_alloc ()); +void *pg =pgtable_quicklist_alloc (); +return pg ?virt_to_page (pg) :NULL ; }
if the memory allocation function fails, we propagate that failure back to callers. All very good.
From a quick look it seems that the pte_alloc() callers are all nicely handling the failures.
The patch looks good to me?
Quoted 1 line · Andrew Morton
The patch doesn't hide any problems:
[snip]
Quoted 2 lines
if the memory allocation function fails, we propagate that failure back to callers. All very good.
ARGH!
I somehow put it in my head that the patch was modifying virt_to_page() rather than the pte function.
My apologies, this was written by a stupid person who can't read :-(
Cheers,
Jes
Jes,
Quoted 2 lines
Well you suggested a patch which just hides the problem. I suggest you change it to have the
BUG_ON().
IMHO you are wrong.
the suggested patch *fixes* one particular place, which can be triggered on mainstream IA64 by a standard user and is actually a *SECURITY* bug which can be potentially exploited (when OOM killer is enabled).
It doesn't hide anything, It just doesn't help to catch other places.
Quoted 14 lines
Quoted 4 lines
Quoted 3 lines
Which callers did you see cause this? If it was a common problem I would expect a lot of data corruption or crashes on ia64 systems which I haven't heard of.
Quoted 8 lines
from the patch:
pte_alloc_one()callspgtable_quicklist_alloc()which can return NULL in case of allocation failure.It was hit on OpenVZ where kernel memory is accounted and limited on per-container basis (it is possible to DoS using page tables allocations). In mainstream the bug can be hit if OOM killer
kills the process and__get_free_page()returns NULL which is rare, but still possible.
Quoted 3 lines
I see, since you have it tracked down, it would be good to fix it and push a patch upstream. Unless of course Andrew or Linus thinks this is the wrong approach.
Maybe the fact that I came without an exploit to crash IA64 makes you think it should not be commited, ok, you can leave it as is then.
NOTE: I don't mind against the debug you proposed. It is quite a good idea.
Thanks,
Kirill
Quoted 9 lines · Kirill Korotaev
Jes,
Quoted 2 lines
Well you suggested a patch which just hides the problem. I suggest you change it to have the
BUG_ON().IMHO you are wrong.
the suggested patch *fixes* one particular place, which can be triggered on mainstream IA64 by a standard user and is actually a *SECURITY* bug which can be potentially exploited (when OOM killer is enabled).
It doesn't hide anything, It just doesn't help to catch other places.
Hi Kirill,
See my response to Andrew, you are indeed right.
I'll go back and hide in my corner in shame :-(
Cheers,
Jes