~smcv/apparmor/connman-resolv

« back to all changes in this revision

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

  • Committer: Tyler Hicks
  • Date: 2016-05-28 16:58:41 UTC
  • Revision ID: tyhicks@canonical.com-20160528165841-czsdd5f5vc91hhc7
tests: Regression tests to verify AT_SECURE across exec transitions

The AT_SECURE value in the kernel's per-process auxiliary vector is what
signals to libc that the process' environment should be scrubbed. This
new set of regression tests checks the AT_SECURE value after performing
the various types of exec transitions that AppArmor supports (file rules
with different exec access modes and change_profile rules).

Different versions of the kernel handle AT_SECURE differently with
respect to change_profile rules. This change in behavior was introduced
in the AppArmor profile stacking kernel support and the tests are
conditionalized to account for this change.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright (C) 2016 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of version 2 of the GNU General Public
 
6
 * License published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program; if not, contact Canonical Ltd.
 
15
 */
 
16
 
 
17
#include <errno.h>
 
18
#include <stdio.h>
 
19
#include <stdlib.h>
 
20
#include <sys/auxv.h>
 
21
 
 
22
int check_at_secure(unsigned long expected)
 
23
{
 
24
        unsigned long at_secure;
 
25
 
 
26
        errno = 0;
 
27
        at_secure = getauxval(AT_SECURE);
 
28
        if (at_secure == 0 && errno != 0) {
 
29
                perror("FAIL - getauxval");
 
30
                return 1;
 
31
        }
 
32
 
 
33
        if (at_secure != expected) {
 
34
                fprintf(stderr,
 
35
                        "FAIL - AT_SECURE value (%lu) did not match the expected value (%lu)\n",
 
36
                        at_secure, expected);
 
37
                return 1;
 
38
        }
 
39
 
 
40
        printf("PASS\n");
 
41
        return 0;
 
42
}
 
43
 
 
44
int main(int argc, char **argv)
 
45
{
 
46
        unsigned long expected;
 
47
 
 
48
        if (argc != 2) {
 
49
                fprintf(stderr, "usage: %s EXPECTED_AT_SECURE\n", argv[0]);
 
50
                return 1;
 
51
        }
 
52
 
 
53
        expected = strtoul(argv[1], NULL, 10);
 
54
        return check_at_secure(expected);
 
55
}