~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to tests/regression/apparmor/syscall_ptrace.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      Copyright (C) 2002-2005 Novell/SUSE
 
3
 *
 
4
 *      This program is free software; you can redistribute it and/or
 
5
 *      modify it under the terms of the GNU General Public License as
 
6
 *      published by the Free Software Foundation, version 2 of the
 
7
 *      License.
 
8
 */
 
9
 
 
10
#include <stdio.h>
 
11
#include <unistd.h>
 
12
#include <errno.h>
 
13
#include <sys/types.h>
 
14
#include <sys/stat.h>
 
15
#include <sys/wait.h>
 
16
#include <sys/ptrace.h>
 
17
#include <signal.h>
 
18
#include <fcntl.h>
 
19
#include <limits.h>
 
20
#include <string.h>
 
21
 
 
22
#include "changehat.h"
 
23
 
 
24
#define FALSE 0
 
25
#define TRUE !FALSE
 
26
 
 
27
int main(int argc, char *argv[])
 
28
{
 
29
        pid_t pid;
 
30
        int retval = 0;
 
31
 
 
32
        if (argc != 2){
 
33
                fprintf(stderr, "usage: %s\n", argv[0]);
 
34
                return 1;
 
35
        }
 
36
 
 
37
 
 
38
        pid=fork();
 
39
 
 
40
        if (pid){       /* parent */
 
41
                int status;
 
42
 
 
43
                while (wait(&status) != pid);
 
44
                retval = WEXITSTATUS(status);
 
45
        }else{
 
46
                /* change profile so that ptrace can fail */
 
47
                if (change_hat(argv[1], SD_ID_MAGIC + 1) == -1 &&
 
48
                    errno != EPERM) {
 
49
                        /* confined process failed to change_hat */
 
50
                        fprintf(stderr, "FAIL: changehat %s failed - %s\n",
 
51
                                argv[1], strerror(errno));
 
52
                        return errno;
 
53
                }
 
54
                if (ptrace(PTRACE_TRACEME, 0, 0, 0) == -1){
 
55
                        fprintf(stderr, "FAIL: ptrace failed - %s\n",
 
56
                                strerror(errno));
 
57
                        retval = errno;
 
58
                }else{
 
59
                        printf("PASS\n");
 
60
                }
 
61
        }
 
62
 
 
63
        return retval;
 
64
}