lockd: nlmsvc_mark_resources(): avoid stack overflow
Subsystems (2)
PATCH 1/1 lockd: nlmsvc_mark_resources(): avoid stack overflow
Dynamically allocate the NLM host structure in order to avoid stack overflow. nlmsvc_mark_resources() is several call levels deep in a stack that has a number of large variables. 512 bytes seems like a lot on the stack at this point.
smatch analysis:
fs/lockd/svcsubs.c:366 nlmsvc_mark_resources() warn: 'hint' puts
512 bytes on stack
--- fs/lockd/svcsubs.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
fs/lockd/svcsubs.c +8 -4
@@ -363,11 +363,15 @@ nlmsvc_is_client(void *data, struct nlm_host *dummy)void nlmsvc_mark_resources (struct net *net) { -struct nlm_host hint; +struct nlm_host *hint =kzalloc (sizeof (*hint),GFP_KERNEL ); -dprintk ("lockd: nlmsvc_mark_resources for net %p\n" , net); - hint.net = net; -nlm_traverse_files (&hint, nlmsvc_mark_host,NULL ); +if (hint) { +dprintk ("lockd: nlmsvc_mark_resources for net %p\n" , net); + hint->net = net; +nlm_traverse_files (hint, nlmsvc_mark_host,NULL ); + } + +kfree (hint); }/*
Signature · 1 line
1.7.9.5
Quoted 27 lines · Tim Gardner
Dynamically allocate the NLM host structure in order to avoid stack overflow.
nlmsvc_mark_resources()is several call levels deep in a stack that has a number of large variables. 512 bytes seems like a lot on the stack at this point.smatch analysis:
fs/lockd/svcsubs.c:366nlmsvc_mark_resources()warn: 'hint' puts
512 bytes on stackCc Trond Myklebust <[email protected]>Cc "J. Bruce Fields" <[email protected]>Signed-off-by Tim Gardner <[email protected]>--- fs/lockd/svcsubs.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)fs/lockd/svcsubs.c +0
-1@@ -363,11 +363,15 @@ nlmsvc_is_client(void *data, struct nlm_host *dummy)void nlmsvc_mark_resources (struct net *net) { -struct nlm_host hint;
fs/lockd/svcsubs.c nlmsvc_is_client(void *data, struct nlm_host *dummy) · line 372
Quoted 10 lines
fs/lockd/svcsubs.c +6
-3+struct nlm_host *hint =kzalloc (sizeof (*hint),GFP_KERNEL ); -dprintk ("lockd: nlmsvc_mark_resources for net %p\n" , net); - hint.net = net; -nlm_traverse_files (&hint, nlmsvc_mark_host,NULL ); +if (hint) { +dprintk ("lockd: nlmsvc_mark_resources for net %p\n" , net); + hint->net = net; +nlm_traverse_files (hint, nlmsvc_mark_host,NULL ); + }
Silently neglecting to do this looks like a bad idea.
It's strange that we're passing in an nlm_host when all we actually use is the struct net*. Why not just change this to pass in the net instead?
--b.
Quoted 8 lines
fs/lockd/svcsubs.c +2
-0+ +kfree (hint); }/* Signature · 1 line
1.7.9.5
Quoted 41 lines · J. Bruce Fields
Quoted 27 lines · Tim Gardner
Dynamically allocate the NLM host structure in order to avoid stack overflow.
nlmsvc_mark_resources()is several call levels deep in a stack that has a number of large variables. 512 bytes seems like a lot on the stack at this point.smatch analysis:
fs/lockd/svcsubs.c:366nlmsvc_mark_resources()warn: 'hint' puts
512 bytes on stackCc Trond Myklebust <[email protected]>Cc "J. Bruce Fields" <[email protected]>Signed-off-by Tim Gardner <[email protected]>--- fs/lockd/svcsubs.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)fs/lockd/svcsubs.c +0
-1@@ -363,11 +363,15 @@ nlmsvc_is_client(void *data, struct nlm_host *dummy)void nlmsvc_mark_resources (struct net *net) { -struct nlm_host hint;fs/lockd/svcsubs.c nlmsvc_is_client(void *data, struct nlm_host *dummy) · line 372
Quoted 10 lines
fs/lockd/svcsubs.c +6
-3+struct nlm_host *hint =kzalloc (sizeof (*hint),GFP_KERNEL ); -dprintk ("lockd: nlmsvc_mark_resources for net %p\n" , net); - hint.net = net; -nlm_traverse_files (&hint, nlmsvc_mark_host,NULL ); +if (hint) { +dprintk ("lockd: nlmsvc_mark_resources for net %p\n" , net); + hint->net = net; +nlm_traverse_files (hint, nlmsvc_mark_host,NULL ); + }Silently neglecting to do this looks like a bad idea.
Quoted 6 lines
It's strange that we're passing in an
nlm_hostwhen all we actually use is the struct net*. Why not just change this to pass in the net instead?--b.
It won't really be silent. k[zm]alloc() dumps a stack trace on failure to allocate unless GFP_NOWARN is set in the flags. I think this is a bit better then possibly corrupting the stack.
Changing the prototype to just pass in 'net' has knock on effects that make this patch a whole lot bigger. You'd have to change the code within a bunch of functions which are difficult to verify at compile time because of the use of 'void *data' as the first parameter. Is there still a good reason for that parameter to be opaque ?
rtg
Signature · 1 line
Tim Gardner [email protected]