Commit d5bf4c4f5f9dcc90b7e25dbb2f7c4436cf6e7ed0
Committed by
Linus Torvalds
1 parent
c713541125
coredump: cleanup "ispipe" code
- kill "int dump_count", argv_split(argcp) accepts argcp == NULL. - move "int dump_count" under " if (ispipe)" branch, fail_dropcount can check ispipe. - move "char **helper_argv" as well, change the code to do argv_free() right after call_usermodehelper_fns(). - If call_usermodehelper_fns() fails goto close_fail label instead of closing the file by hand. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: David Howells <dhowells@redhat.com> Cc: Neil Horman <nhorman@tuxdriver.com> Cc: Roland McGrath <roland@redhat.com> Cc: Andi Kleen <andi@firstfloor.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 17 additions and 22 deletions Side-by-side Diff
fs/exec.c
... | ... | @@ -1841,10 +1841,7 @@ |
1841 | 1841 | struct cred *cred; |
1842 | 1842 | int retval = 0; |
1843 | 1843 | int flag = 0; |
1844 | - int ispipe = 0; | |
1845 | - char **helper_argv = NULL; | |
1846 | - int helper_argc = 0; | |
1847 | - int dump_count = 0; | |
1844 | + int ispipe; | |
1848 | 1845 | static atomic_t core_dump_count = ATOMIC_INIT(0); |
1849 | 1846 | struct coredump_params cprm = { |
1850 | 1847 | .signr = signr, |
... | ... | @@ -1914,6 +1911,9 @@ |
1914 | 1911 | unlock_kernel(); |
1915 | 1912 | |
1916 | 1913 | if (ispipe) { |
1914 | + int dump_count; | |
1915 | + char **helper_argv; | |
1916 | + | |
1917 | 1917 | if (cprm.limit == 1) { |
1918 | 1918 | /* |
1919 | 1919 | * Normally core limits are irrelevant to pipes, since |
... | ... | @@ -1935,6 +1935,7 @@ |
1935 | 1935 | printk(KERN_WARNING "Aborting core\n"); |
1936 | 1936 | goto fail_unlock; |
1937 | 1937 | } |
1938 | + cprm.limit = RLIM_INFINITY; | |
1938 | 1939 | |
1939 | 1940 | dump_count = atomic_inc_return(&core_dump_count); |
1940 | 1941 | if (core_pipe_limit && (core_pipe_limit < dump_count)) { |
1941 | 1942 | |
1942 | 1943 | |
... | ... | @@ -1944,26 +1945,21 @@ |
1944 | 1945 | goto fail_dropcount; |
1945 | 1946 | } |
1946 | 1947 | |
1947 | - helper_argv = argv_split(GFP_KERNEL, corename+1, &helper_argc); | |
1948 | + helper_argv = argv_split(GFP_KERNEL, corename+1, NULL); | |
1948 | 1949 | if (!helper_argv) { |
1949 | 1950 | printk(KERN_WARNING "%s failed to allocate memory\n", |
1950 | 1951 | __func__); |
1951 | 1952 | goto fail_dropcount; |
1952 | 1953 | } |
1953 | 1954 | |
1954 | - cprm.limit = RLIM_INFINITY; | |
1955 | - | |
1956 | - /* SIGPIPE can happen, but it's just never processed */ | |
1957 | - cprm.file = NULL; | |
1958 | - if (call_usermodehelper_fns(helper_argv[0], helper_argv, NULL, | |
1959 | - UMH_WAIT_EXEC, umh_pipe_setup, | |
1960 | - NULL, &cprm)) { | |
1961 | - if (cprm.file) | |
1962 | - filp_close(cprm.file, NULL); | |
1963 | - | |
1955 | + retval = call_usermodehelper_fns(helper_argv[0], helper_argv, | |
1956 | + NULL, UMH_WAIT_EXEC, umh_pipe_setup, | |
1957 | + NULL, &cprm); | |
1958 | + argv_free(helper_argv); | |
1959 | + if (retval) { | |
1964 | 1960 | printk(KERN_INFO "Core dump to %s pipe failed\n", |
1965 | 1961 | corename); |
1966 | - goto fail_dropcount; | |
1962 | + goto close_fail; | |
1967 | 1963 | } |
1968 | 1964 | } else { |
1969 | 1965 | struct inode *inode; |
1970 | 1966 | |
1971 | 1967 | |
1972 | 1968 | |
... | ... | @@ -2003,17 +1999,16 @@ |
2003 | 1999 | retval = binfmt->core_dump(&cprm); |
2004 | 2000 | if (retval) |
2005 | 2001 | current->signal->group_exit_code |= 0x80; |
2006 | -close_fail: | |
2002 | + | |
2007 | 2003 | if (ispipe && core_pipe_limit) |
2008 | 2004 | wait_for_dump_helpers(cprm.file); |
2009 | - filp_close(cprm.file, NULL); | |
2005 | +close_fail: | |
2006 | + if (cprm.file) | |
2007 | + filp_close(cprm.file, NULL); | |
2010 | 2008 | fail_dropcount: |
2011 | - if (dump_count) | |
2009 | + if (ispipe) | |
2012 | 2010 | atomic_dec(&core_dump_count); |
2013 | 2011 | fail_unlock: |
2014 | - if (helper_argv) | |
2015 | - argv_free(helper_argv); | |
2016 | - | |
2017 | 2012 | revert_creds(old_cred); |
2018 | 2013 | put_cred(cred); |
2019 | 2014 | coredump_finish(mm); |