This is a sync and squash to the apparmor 3 RC 1 development snapshot. The set of patches in this squash are available at the apparmor-3.RC1 tag in git://kernel.ubuntu.com/jj/ubuntu-utopic.git. This cleans up several functions over the alpha6 sync, and includes multiple bug fixes. In addition it picks up - new network mediation - fine grained mediation of all unix socket types In addition to the apparmor 3 RC 1 sync this contains the backport patch series for the 3.4 goldfish kernel - apparmor: 3.4 backport alias file_open 83d49856 - apparmor: 3.4 backport fake no_new_privs 259e5e6c - apparmor: 3.4 backport cap_mmap_addr d007794a - apparmor: 3.4 backport revert file_mmap e5467859 - apparmor: 3.5 backport dentry_open params 765927b2 - apparmor: 3.6 backport provide replace_fd 8280d161 - apparmor: 3.6 backport provide iterate_fd c3c073f8 - apparmor: 3.6 backport remove const from sb_mount 808d4e3c - apparmor: 3.6 backport kuid_t support for audit 2db81452 - apparmor: 3.6 backport define kuid_t d2b31ca64 - apparmor: 3.6 backport revert uapi for resnames 8a1ab315 - apparmor: 3.6 backport revert uapi for capnames 43c422ed - apparmor: 3.8 backport provide file_inode helper 496ad9aa - apparmor: 3.10 backport revert no delay vfree() - apparmor: 3.11 backport revert module/lsm: Have apparm 5265fc62 - apparmor: 3.12 backport mtd: Move major number f83c3838 - apparmor: 3.15 backport revert nick kvfree() from apparmor - apparmor: backport setup base backport files BugLink: http://bugs.launchpad.net/bugs/1362199 Signed-off-by: John Johansen <john.johansen@canonical.com> Signed-off-by: Tyler Hicks <tyhicks@canonical.com> Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
146 lines
4.0 KiB
C
146 lines
4.0 KiB
C
/*
|
|
* AppArmor security module
|
|
*
|
|
* This file contains AppArmor /proc/<pid>/attr/ interface functions
|
|
*
|
|
* Copyright (C) 1998-2008 Novell/SUSE
|
|
* Copyright 2009-2010 Canonical Ltd.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License as
|
|
* published by the Free Software Foundation, version 2 of the
|
|
* License.
|
|
*/
|
|
|
|
#include "include/apparmor.h"
|
|
#include "include/context.h"
|
|
#include "include/policy.h"
|
|
#include "include/domain.h"
|
|
#include "include/procattr.h"
|
|
|
|
|
|
/**
|
|
* aa_getprocattr - Return the profile information for @profile
|
|
* @profile: the profile to print profile info about (NOT NULL)
|
|
* @string: Returns - string containing the profile info (NOT NULL)
|
|
*
|
|
* Returns: length of @string on success else error on failure
|
|
*
|
|
* Requires: profile != NULL
|
|
*
|
|
* Creates a string containing the namespace_name://profile_name for
|
|
* @profile.
|
|
*
|
|
* Returns: size of string placed in @string else error code on failure
|
|
*/
|
|
int aa_getprocattr(struct aa_label *label, char **string)
|
|
{
|
|
struct aa_namespace *ns = labels_ns(label);
|
|
struct aa_namespace *current_ns = labels_ns(aa_current_label());
|
|
int len;
|
|
|
|
if (!aa_ns_visible(current_ns, ns))
|
|
return -EACCES;
|
|
|
|
len = aa_label_snprint(NULL, 0, current_ns, label, true);
|
|
AA_BUG(len < 0);
|
|
|
|
*string = kmalloc(len + 2, GFP_KERNEL);
|
|
if (!*string)
|
|
return -ENOMEM;
|
|
|
|
len = aa_label_snprint(*string, len + 2, current_ns, label, true);
|
|
if (len < 0)
|
|
return len;
|
|
(*string)[len] = '\n';
|
|
(*string)[len + 1] = 0;
|
|
|
|
return len + 1;
|
|
}
|
|
|
|
/**
|
|
* split_token_from_name - separate a string of form <token>^<name>
|
|
* @op: operation being checked
|
|
* @args: string to parse (NOT NULL)
|
|
* @token: stores returned parsed token value (NOT NULL)
|
|
*
|
|
* Returns: start position of name after token else NULL on failure
|
|
*/
|
|
static char *split_token_from_name(int op, char *args, u64 * token)
|
|
{
|
|
char *name;
|
|
|
|
*token = simple_strtoull(args, &name, 16);
|
|
if ((name == args) || *name != '^') {
|
|
AA_ERROR("%s: Invalid input '%s'", op_table[op], args);
|
|
return ERR_PTR(-EINVAL);
|
|
}
|
|
|
|
name++; /* skip ^ */
|
|
if (!*name)
|
|
name = NULL;
|
|
return name;
|
|
}
|
|
|
|
/**
|
|
* aa_setprocattr_chagnehat - handle procattr interface to change_hat
|
|
* @args: args received from writing to /proc/<pid>/attr/current (NOT NULL)
|
|
* @size: size of the args
|
|
* @test: true if this is a test of change_hat permissions
|
|
*
|
|
* Returns: %0 or error code if change_hat fails
|
|
*/
|
|
int aa_setprocattr_changehat(char *args, size_t size, int test)
|
|
{
|
|
char *hat;
|
|
u64 token;
|
|
const char *hats[16]; /* current hard limit on # of names */
|
|
int count = 0;
|
|
|
|
hat = split_token_from_name(OP_CHANGE_HAT, args, &token);
|
|
if (IS_ERR(hat))
|
|
return PTR_ERR(hat);
|
|
|
|
if (!hat && !token) {
|
|
AA_ERROR("change_hat: Invalid input, NULL hat and NULL magic");
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (hat) {
|
|
/* set up hat name vector, args guaranteed null terminated
|
|
* at args[size] by setprocattr.
|
|
*
|
|
* If there are multiple hat names in the buffer each is
|
|
* separated by a \0. Ie. userspace writes them pre tokenized
|
|
*/
|
|
char *end = args + size;
|
|
for (count = 0; (hat < end) && count < 16; ++count) {
|
|
char *next = hat + strlen(hat) + 1;
|
|
hats[count] = hat;
|
|
AA_DEBUG("%s: (pid %d) Magic 0x%llx count %d hat '%s'\n"
|
|
, __func__, current->pid, token, count, hat);
|
|
hat = next;
|
|
}
|
|
} else
|
|
AA_DEBUG("%s: (pid %d) Magic 0x%llx count %d Hat '%s'\n",
|
|
__func__, current->pid, token, count, "<NULL>");
|
|
|
|
return aa_change_hat(hats, count, token, test);
|
|
}
|
|
|
|
/**
|
|
* aa_setprocattr_changeprofile - handle procattr interface to changeprofile
|
|
* @fqname: args received from writting to /proc/<pid>/attr/current (NOT NULL)
|
|
* @onexec: true if change_profile should be delayed until exec
|
|
* @test: true if this is a test of change_profile permissions
|
|
*
|
|
* Returns: %0 or error code if change_profile fails
|
|
*/
|
|
int aa_setprocattr_changeprofile(char *fqname, bool onexec, int test)
|
|
{
|
|
char *name, *ns_name;
|
|
|
|
name = aa_split_fqname(fqname, &ns_name);
|
|
return aa_change_profile(ns_name, name, onexec, test);
|
|
}
|