[CRIU] [PATCH] x86/kdat: Check PTRACE_TRACEME return value
Andrei Vagin
avagin at virtuozzo.com
Wed Feb 28 22:55:08 MSK 2018
Applied, thanks!
On Tue, Feb 27, 2018 at 01:42:55PM +0000, Dmitry Safonov wrote:
> Coverity has informed:
>
> *** CID 188251: Error handling issues (CHECKED_RETURN)
> /criu/arch/x86/crtools.c: 196 in kdat_x86_has_ptrace_fpu_xsave_bug_child()
> 190 return 0;
> 191 }
> 192 #endif
> 193
> 194 static int kdat_x86_has_ptrace_fpu_xsave_bug_child(void *arg)
> 195 {
> >>> CID 188251: Error handling issues (CHECKED_RETURN)
> >>> Calling "ptrace" without checking return value (as is done elsewhere 46 out of 51 times).
> 196 ptrace(PTRACE_TRACEME, 0, 0, 0);
> 197 kill(getpid(), SIGSTOP);
> 198 pr_err("Continue after SIGSTOP.. Urr what?\n");
> 199 _exit(1);
> 200 }
> 201
>
> Also added checks for kill() and waitpid().
>
> Signed-off-by: Dmitry Safonov <dima at arista.com>
> ---
> criu/arch/x86/kerndat.c | 17 +++++++++++++----
> 1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/criu/arch/x86/kerndat.c b/criu/arch/x86/kerndat.c
> index a67017d3456e..006196829c89 100644
> --- a/criu/arch/x86/kerndat.c
> +++ b/criu/arch/x86/kerndat.c
> @@ -178,8 +178,14 @@ int kdat_compatible_cr(void)
>
> static int kdat_x86_has_ptrace_fpu_xsave_bug_child(void *arg)
> {
> - ptrace(PTRACE_TRACEME, 0, 0, 0);
> - kill(getpid(), SIGSTOP);
> + if (ptrace(PTRACE_TRACEME, 0, 0, 0)) {
> + pr_perror("%d: ptrace(PTRACE_TRACEME) failed", getpid());
> + _exit(1);
> + }
> +
> + if (kill(getpid(), SIGSTOP))
> + pr_perror("%d: failed to kill myself", getpid());
> +
> pr_err("Continue after SIGSTOP.. Urr what?\n");
> _exit(1);
> }
> @@ -243,7 +249,10 @@ int kdat_x86_has_ptrace_fpu_xsave_bug(void)
> ret = !xsave.i387.mxcsr;
>
> out_kill:
> - kill(child, SIGKILL);
> - waitpid(child, &stat, 0);
> + if (kill(child, SIGKILL))
> + pr_perror("Failed to kill my own child");
> + if (waitpid(child, &stat, 0) < 0)
> + pr_perror("Failed wait for a dead child");
> +
> return ret;
> }
> --
> 2.13.6
>
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
More information about the CRIU
mailing list