coredump: fix pipe coredump when core limit is 0
Subsystems (2)
PATCH 1/1 coredump: fix pipe coredump when core limit is 0
From: Jovi Zhang <[email protected]>
Regressing from 2.6.35
In pipe coredump case, normally core limits are irrelevant, since we're not writing to the file system, but core limit 0 is a special value, kernel should skip the dump when limit is 0.
Note that most Linux distribution set default core file limit as 0, because many user don't want to get core file even process crash, wahtever pipe coredump pattern used or not.
This error intruduced by commit c71354 in 2.6.35, that commit put core limit zero check into non-pipe code branch.
commit c713541125002b8bc9e681af3b09118e771e2d8a
Author: Oleg Nesterov <[email protected]>
Date: Wed May 26 14:43:05 2010 -0700
coredump: factor out the not-ispipe file checks
For non-pipe case, limit 0 also means drop the coredump, so just put the zero limit check at do_coredump function begining.
--- fs/exec.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
fs/exec.c +4 -0
@@ -2119,6 +2119,10 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)if (!__get_dumpable (cprm.mm_flags)) goto fail; +/* Core limit as 0 should skip the dump */ +if (cprm.limit ==0 ) + goto fail; + cred =prepare_creds ();if (!cred) goto fail;
Signature · 1 line
1.7.2.3
Quoted 4 lines · On 08/21, [email protected] wrote:
From: Jovi Zhang <[email protected]>
Regressing from 2.6.35
Hmm. Thanks Jovi.
Quoted 3 lines
In pipe coredump case, normally core limits are irrelevant, since we're not writing to the file system, but core limit 0 is a special value, kernel should skip the dump when limit is 0.
Hmm. probably yes... although I'd say I do not really know. iirc, previously RLIMIT_CORE was simply ignored if ispipe. But then we changed the rules many time.
Yes. See 725eae32df7754044809973034429a47e6035158. This is where we changed the "limit == 0 && ispipe" behaviour.
Quoted 8 lines
This error intruduced by commit c71354 in 2.6.35, that commit put core limit zero check into non-pipe code branch.
commit
c713541125002b8bc9e681af3b09118e771e2d8a
Author: Oleg Nesterov <[email protected]>
Date: Wed May 26 14:43:05 2010 -0700coredump: factor out the not-ispipe file checks
Cough. I don't think so ;)
Yes, that patch moves the check, but please note that before the patch we did
if ((!ispipe) && (cprm.limit < binfmt->min_coredump)) goto fail;
so I do not think this patch can make any difference.
I think this was changed by 898b374af6f71041bd3bceebe257e564f3f1d458.
Quoted 2 lines
For non-pipe case, limit 0 also means drop the coredump, so just put the zero limit check at
do_coredumpfunction begining.
Neil, what do you think? Should we change the code or the comment?
As for the patch, it is not exactly right in any case,
fs/exec.c void do_coredump(long signr, int exit_code, struct pt_regs *regs) · line 2124
Quoted 9 lines
fs/exec.c +3
-0@@ -2119,6 +2119,10 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)if (!__get_dumpable (cprm.mm_flags)) goto fail; +/* Core limit as 0 should skip the dump */ +if (cprm.limit ==0 ) + goto fail;
Even if we do not dump, we should kill all tasks/threads which use this ->mm. We shouldn't miss coredump_wait().
To clarify, I don't really know _why_, and probably it makes sense to change this behaviour. But this needs a separate patch plus discussion.
Oleg.
Quoted 7 lines · Oleg Nesterov
Quoted 3 lines · On 08/21, [email protected] wrote:
For non-pipe case, limit 0 also means drop the coredump, so just put the zero limit check at
do_coredumpfunction begining.Neil, what do you think? Should we change the code or the comment?
Personally I think we should fix the comment. I think RLIMIT_CORE doesn't apply in this case, limit == 1 check is very special. And this is what linux always did, except between 725eae32 and 898b374a.
Oleg.