LCOV - code coverage report
Current view: top level - strace_git - clone.c (source / functions) Hit Total Coverage
Test: strace-4.16.0.69.f1ea-dirty Code Coverage Lines: 26 39 66.7 %
Date: 2017-03-18 00:38:52 Functions: 3 5 60.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 24 41.7 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 1999-2000 Wichert Akkerman <wichert@cistron.nl>
       3                 :            :  * Copyright (c) 2002-2005 Roland McGrath <roland@redhat.com>
       4                 :            :  * Copyright (c) 2008 Jan Kratochvil <jan.kratochvil@redhat.com>
       5                 :            :  * Copyright (c) 2009-2013 Denys Vlasenko <dvlasenk@redhat.com>
       6                 :            :  * Copyright (c) 2006-2015 Dmitry V. Levin <ldv@altlinux.org>
       7                 :            :  * All rights reserved.
       8                 :            :  *
       9                 :            :  * Redistribution and use in source and binary forms, with or without
      10                 :            :  * modification, are permitted provided that the following conditions
      11                 :            :  * are met:
      12                 :            :  * 1. Redistributions of source code must retain the above copyright
      13                 :            :  *    notice, this list of conditions and the following disclaimer.
      14                 :            :  * 2. Redistributions in binary form must reproduce the above copyright
      15                 :            :  *    notice, this list of conditions and the following disclaimer in the
      16                 :            :  *    documentation and/or other materials provided with the distribution.
      17                 :            :  * 3. The name of the author may not be used to endorse or promote products
      18                 :            :  *    derived from this software without specific prior written permission.
      19                 :            :  *
      20                 :            :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
      21                 :            :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      22                 :            :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      23                 :            :  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
      24                 :            :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      25                 :            :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      26                 :            :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      27                 :            :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      28                 :            :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      29                 :            :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      30                 :            :  */
      31                 :            : 
      32                 :            : #include "defs.h"
      33                 :            : #include <sched.h>
      34                 :            : #include <asm/unistd.h>
      35                 :            : 
      36                 :            : #ifndef CSIGNAL
      37                 :            : # define CSIGNAL 0x000000ff
      38                 :            : #endif
      39                 :            : 
      40                 :            : #include "xlat/clone_flags.h"
      41                 :            : #include "xlat/setns_types.h"
      42                 :            : #include "xlat/unshare_flags.h"
      43                 :            : 
      44                 :            : #if defined IA64
      45                 :            : # define ARG_FLAGS      0
      46                 :            : # define ARG_STACK      1
      47                 :            : # define ARG_STACKSIZE  (tcp->scno == __NR_clone2 ? 2 : -1)
      48                 :            : # define ARG_PTID       (tcp->scno == __NR_clone2 ? 3 : 2)
      49                 :            : # define ARG_CTID       (tcp->scno == __NR_clone2 ? 4 : 3)
      50                 :            : # define ARG_TLS        (tcp->scno == __NR_clone2 ? 5 : 4)
      51                 :            : #elif defined S390 || defined S390X || defined CRISV10 || defined CRISV32
      52                 :            : # define ARG_STACK      0
      53                 :            : # define ARG_FLAGS      1
      54                 :            : # define ARG_PTID       2
      55                 :            : # define ARG_CTID       3
      56                 :            : # define ARG_TLS        4
      57                 :            : #elif defined X86_64 || defined X32
      58                 :            : /* x86 personality processes have the last two arguments flipped. */
      59                 :            : # define ARG_FLAGS      0
      60                 :            : # define ARG_STACK      1
      61                 :            : # define ARG_PTID       2
      62                 :            : # define ARG_CTID       ((current_personality != 1) ? 3 : 4)
      63                 :            : # define ARG_TLS        ((current_personality != 1) ? 4 : 3)
      64                 :            : #elif defined ALPHA || defined TILE || defined OR1K || defined RISCV
      65                 :            : # define ARG_FLAGS      0
      66                 :            : # define ARG_STACK      1
      67                 :            : # define ARG_PTID       2
      68                 :            : # define ARG_CTID       3
      69                 :            : # define ARG_TLS        4
      70                 :            : #else
      71                 :            : # define ARG_FLAGS      0
      72                 :            : # define ARG_STACK      1
      73                 :            : # define ARG_PTID       2
      74                 :            : # define ARG_TLS        3
      75                 :            : # define ARG_CTID       4
      76                 :            : #endif
      77                 :            : 
      78                 :            : static void
      79                 :          0 : print_tls_arg(struct tcb *const tcp, const kernel_ulong_t addr)
      80                 :            : {
      81                 :            : #ifdef HAVE_STRUCT_USER_DESC
      82                 :            : # if SUPPORTED_PERSONALITIES > 1
      83         [ #  # ]:          0 :         if (current_personality == 1)
      84                 :            : # endif
      85                 :            :         {
      86         [ #  # ]:          0 :                 print_user_desc(tcp, tcp->u_arg[ARG_TLS]);
      87                 :            :         }
      88                 :            : # if SUPPORTED_PERSONALITIES > 1
      89                 :            :         else
      90                 :            : # endif
      91                 :            : #endif /* HAVE_STRUCT_USER_DESC */
      92                 :            :         {
      93         [ #  # ]:          0 :                 printaddr(tcp->u_arg[ARG_TLS]);
      94                 :            :         }
      95                 :          0 : }
      96                 :            : 
      97                 :         12 : SYS_FUNC(clone)
      98                 :            : {
      99         [ +  + ]:         12 :         if (exiting(tcp)) {
     100                 :          6 :                 const char *sep = "|";
     101                 :          6 :                 kernel_ulong_t flags = tcp->u_arg[ARG_FLAGS];
     102                 :          6 :                 tprints("child_stack=");
     103                 :          6 :                 printaddr(tcp->u_arg[ARG_STACK]);
     104                 :          6 :                 tprints(", ");
     105                 :            : #ifdef ARG_STACKSIZE
     106                 :            :                 if (ARG_STACKSIZE != -1)
     107                 :            :                         tprintf("stack_size=%#" PRI_klx ", ",
     108                 :            :                                 tcp->u_arg[ARG_STACKSIZE]);
     109                 :            : #endif
     110                 :          6 :                 tprints("flags=");
     111         [ -  + ]:          6 :                 if (!printflags64(clone_flags, flags &~ CSIGNAL, NULL))
     112                 :          0 :                         sep = "";
     113         [ +  - ]:          6 :                 if ((flags & CSIGNAL) != 0)
     114                 :          6 :                         tprintf("%s%s", sep, signame(flags & CSIGNAL));
     115         [ -  + ]:          6 :                 if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID
     116                 :            :                               |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
     117                 :          0 :                         return 0;
     118         [ -  + ]:          6 :                 if (flags & CLONE_PARENT_SETTID) {
     119                 :          0 :                         tprints(", parent_tidptr=");
     120                 :          0 :                         printaddr(tcp->u_arg[ARG_PTID]);
     121                 :            :                 }
     122         [ -  + ]:          6 :                 if (flags & CLONE_SETTLS) {
     123                 :          0 :                         tprints(", tls=");
     124         [ #  # ]:          0 :                         print_tls_arg(tcp, tcp->u_arg[ARG_TLS]);
     125                 :            :                 }
     126         [ +  - ]:          6 :                 if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID)) {
     127                 :          6 :                         tprints(", child_tidptr=");
     128         [ +  + ]:          6 :                         printaddr(tcp->u_arg[ARG_CTID]);
     129                 :            :                 }
     130                 :            :         }
     131                 :            :         /* TODO on syscall entry:
     132                 :            :          * We can clear CLONE_PTRACE here since it is an ancient hack
     133                 :            :          * to allow us to catch children, and we use another hack for that.
     134                 :            :          * But CLONE_PTRACE can conceivably be used by malicious programs
     135                 :            :          * to subvert us. By clearing this bit, we can defend against it:
     136                 :            :          * in untraced execution, CLONE_PTRACE should have no effect.
     137                 :            :          *
     138                 :            :          * We can also clear CLONE_UNTRACED, since it allows to start
     139                 :            :          * children outside of our control. At the moment
     140                 :            :          * I'm trying to figure out whether there is a *legitimate*
     141                 :            :          * use of this flag which we should respect.
     142                 :            :          */
     143                 :         12 :         return 0;
     144                 :            : }
     145                 :            : 
     146                 :         18 : SYS_FUNC(setns)
     147                 :            : {
     148                 :         18 :         printfd(tcp, tcp->u_arg[0]);
     149                 :         18 :         tprints(", ");
     150                 :         18 :         printxval(setns_types, tcp->u_arg[1], "CLONE_NEW???");
     151                 :            : 
     152                 :         18 :         return RVAL_DECODED;
     153                 :            : }
     154                 :            : 
     155                 :         30 : SYS_FUNC(unshare)
     156                 :            : {
     157                 :         30 :         printflags64(unshare_flags, tcp->u_arg[0], "CLONE_???");
     158                 :         30 :         return RVAL_DECODED;
     159                 :            : }
     160                 :            : 
     161                 :          0 : SYS_FUNC(fork)
     162                 :            : {
     163                 :          0 :         return RVAL_DECODED | RVAL_UDECIMAL;
     164                 :            : }

Generated by: LCOV version 1.12