Commit e24dd9ee authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security

Pull security layer updates from James Morris:

 - a major update for AppArmor. From JJ:

     * several bug fixes and cleanups

     * the patch to add symlink support to securityfs that was floated
       on the list earlier and the apparmorfs changes that make use of
       securityfs symlinks

     * it introduces the domain labeling base code that Ubuntu has been
       carrying for several years, with several cleanups applied. And it
       converts the current mediation over to using the domain labeling
       base, which brings domain stacking support with it. This finally
       will bring the base upstream code in line with Ubuntu and provide
       a base to upstream the new feature work that Ubuntu carries.

     * This does _not_ contain any of the newer apparmor mediation
       features/controls (mount, signals, network, keys, ...) that
       Ubuntu is currently carrying, all of which will be RFC'd on top
       of this.

 - Notable also is the Infiniband work in SELinux, and the new file:map
   permission. From Paul:

      "While we're down to 21 patches for v4.13 (it was 31 for v4.12),
       the diffstat jumps up tremendously with over 2k of line changes.

       Almost all of these changes are the SELinux/IB work done by
       Daniel Jurgens; some other noteworthy changes include a NFS v4.2
       labeling fix, a new file:map permission, and reporting of policy
       capabilities on policy load"

   There's also now genfscon labeling support for tracefs, which was
   lost in v4.1 with the separation from debugfs.

 - Smack incorporates a safer socket check in file_receive, and adds a
   cap_capable call in privilege check.

 - TPM as usual has a bunch of fixes and enhancements.

 - Multiple calls to security_add_hooks() can now be made for the same
   LSM, to allow LSMs to have hook declarations across multiple files.

 - IMA now supports different "ima_appraise=" modes (eg. log, fix) from
   the boot command line.

* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (126 commits)
  apparmor: put back designators in struct initialisers
  seccomp: Switch from atomic_t to recount_t
  seccomp: Adjust selftests to avoid double-join
  seccomp: Clean up core dump logic
  IMA: update IMA policy documentation to include pcr= option
  ima: Log the same audit cause whenever a file has no signature
  ima: Simplify policy_func_show.
  integrity: Small code improvements
  ima: fix get_binary_runtime_size()
  ima: use ima_parse_buf() to parse template data
  ima: use ima_parse_buf() to parse measurements headers
  ima: introduce ima_parse_buf()
  ima: Add cgroups2 to the defaults list
  ima: use memdup_user_nul
  ima: fix up #endif comments
  IMA: Correct Kconfig dependencies for hash selection
  ima: define is_ima_appraise_enabled()
  ima: define Kconfig IMA_APPRAISE_BOOTPARAM option
  ima: define a set of appraisal rules requiring file signatures
  ima: extend the "ima_policy" boot command line to support multiple policies
  ...
parents 7391786a c4758fa5
...@@ -34,9 +34,10 @@ Description: ...@@ -34,9 +34,10 @@ Description:
fsuuid:= file system UUID (e.g 8bcbe394-4f13-4144-be8e-5aa9ea2ce2f6) fsuuid:= file system UUID (e.g 8bcbe394-4f13-4144-be8e-5aa9ea2ce2f6)
uid:= decimal value uid:= decimal value
euid:= decimal value euid:= decimal value
fowner:=decimal value fowner:= decimal value
lsm: are LSM specific lsm: are LSM specific
option: appraise_type:= [imasig] option: appraise_type:= [imasig]
pcr:= decimal value
default policy: default policy:
# PROC_SUPER_MAGIC # PROC_SUPER_MAGIC
...@@ -96,3 +97,8 @@ Description: ...@@ -96,3 +97,8 @@ Description:
Smack: Smack:
measure subj_user=_ func=FILE_CHECK mask=MAY_READ measure subj_user=_ func=FILE_CHECK mask=MAY_READ
Example of measure rules using alternate PCRs:
measure func=KEXEC_KERNEL_CHECK pcr=4
measure func=KEXEC_INITRAMFS_CHECK pcr=5
...@@ -1501,12 +1501,21 @@ ...@@ -1501,12 +1501,21 @@
in crypto/hash_info.h. in crypto/hash_info.h.
ima_policy= [IMA] ima_policy= [IMA]
The builtin measurement policy to load during IMA The builtin policies to load during IMA setup.
setup. Specyfing "tcb" as the value, measures all Format: "tcb | appraise_tcb | secure_boot"
programs exec'd, files mmap'd for exec, and all files
opened with the read mode bit set by either the The "tcb" policy measures all programs exec'd, files
effective uid (euid=0) or uid=0. mmap'd for exec, and all files opened with the read
Format: "tcb" mode bit set by either the effective uid (euid=0) or
uid=0.
The "appraise_tcb" policy appraises the integrity of
all files owned by root. (This is the equivalent
of ima_appraise_tcb.)
The "secure_boot" policy appraises the integrity
of files (eg. kexec kernel image, kernel modules,
firmware, policy, etc) based on file signatures.
ima_tcb [IMA] Deprecated. Use ima_policy= instead. ima_tcb [IMA] Deprecated. Use ima_policy= instead.
Load a policy which meets the needs of the Trusted Load a policy which meets the needs of the Trusted
......
...@@ -127,7 +127,7 @@ static int st33zp24_i2c_acpi_request_resources(struct i2c_client *client) ...@@ -127,7 +127,7 @@ static int st33zp24_i2c_acpi_request_resources(struct i2c_client *client)
struct device *dev = &client->dev; struct device *dev = &client->dev;
int ret; int ret;
ret = acpi_dev_add_driver_gpios(ACPI_COMPANION(dev), acpi_st33zp24_gpios); ret = devm_acpi_dev_add_driver_gpios(dev, acpi_st33zp24_gpios);
if (ret) if (ret)
return ret; return ret;
...@@ -285,7 +285,6 @@ static int st33zp24_i2c_remove(struct i2c_client *client) ...@@ -285,7 +285,6 @@ static int st33zp24_i2c_remove(struct i2c_client *client)
if (ret) if (ret)
return ret; return ret;
acpi_dev_remove_driver_gpios(ACPI_COMPANION(&client->dev));
return 0; return 0;
} }
......
...@@ -246,7 +246,7 @@ static int st33zp24_spi_acpi_request_resources(struct spi_device *spi_dev) ...@@ -246,7 +246,7 @@ static int st33zp24_spi_acpi_request_resources(struct spi_device *spi_dev)
struct device *dev = &spi_dev->dev; struct device *dev = &spi_dev->dev;
int ret; int ret;
ret = acpi_dev_add_driver_gpios(ACPI_COMPANION(dev), acpi_st33zp24_gpios); ret = devm_acpi_dev_add_driver_gpios(dev, acpi_st33zp24_gpios);
if (ret) if (ret)
return ret; return ret;
...@@ -402,7 +402,6 @@ static int st33zp24_spi_remove(struct spi_device *dev) ...@@ -402,7 +402,6 @@ static int st33zp24_spi_remove(struct spi_device *dev)
if (ret) if (ret)
return ret; return ret;
acpi_dev_remove_driver_gpios(ACPI_COMPANION(&dev->dev));
return 0; return 0;
} }
......
...@@ -416,7 +416,8 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space, ...@@ -416,7 +416,8 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
/* Store the decision as chip->locality will be changed. */ /* Store the decision as chip->locality will be changed. */
need_locality = chip->locality == -1; need_locality = chip->locality == -1;
if (need_locality && chip->ops->request_locality) { if (!(flags & TPM_TRANSMIT_RAW) &&
need_locality && chip->ops->request_locality) {
rc = chip->ops->request_locality(chip, 0); rc = chip->ops->request_locality(chip, 0);
if (rc < 0) if (rc < 0)
goto out_no_locality; goto out_no_locality;
...@@ -429,8 +430,9 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space, ...@@ -429,8 +430,9 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
rc = chip->ops->send(chip, (u8 *) buf, count); rc = chip->ops->send(chip, (u8 *) buf, count);
if (rc < 0) { if (rc < 0) {
dev_err(&chip->dev, if (rc != -EPIPE)
"tpm_transmit: tpm_send: error %d\n", rc); dev_err(&chip->dev,
"%s: tpm_send: error %d\n", __func__, rc);
goto out; goto out;
} }
...@@ -536,59 +538,62 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space, ...@@ -536,59 +538,62 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space,
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(tpm_transmit_cmd);
#define TPM_DIGEST_SIZE 20 #define TPM_DIGEST_SIZE 20
#define TPM_RET_CODE_IDX 6 #define TPM_RET_CODE_IDX 6
#define TPM_INTERNAL_RESULT_SIZE 200 #define TPM_INTERNAL_RESULT_SIZE 200
#define TPM_ORD_GET_CAP cpu_to_be32(101) #define TPM_ORD_GET_CAP 101
#define TPM_ORD_GET_RANDOM cpu_to_be32(70) #define TPM_ORD_GET_RANDOM 70
static const struct tpm_input_header tpm_getcap_header = { static const struct tpm_input_header tpm_getcap_header = {
.tag = TPM_TAG_RQU_COMMAND, .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
.length = cpu_to_be32(22), .length = cpu_to_be32(22),
.ordinal = TPM_ORD_GET_CAP .ordinal = cpu_to_be32(TPM_ORD_GET_CAP)
}; };
ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
const char *desc, size_t min_cap_length) const char *desc, size_t min_cap_length)
{ {
struct tpm_cmd_t tpm_cmd; struct tpm_buf buf;
int rc; int rc;
tpm_cmd.header.in = tpm_getcap_header; rc = tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_GET_CAP);
if (rc)
return rc;
if (subcap_id == TPM_CAP_VERSION_1_1 || if (subcap_id == TPM_CAP_VERSION_1_1 ||
subcap_id == TPM_CAP_VERSION_1_2) { subcap_id == TPM_CAP_VERSION_1_2) {
tpm_cmd.params.getcap_in.cap = cpu_to_be32(subcap_id); tpm_buf_append_u32(&buf, subcap_id);
/*subcap field not necessary */ tpm_buf_append_u32(&buf, 0);
tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(0);
tpm_cmd.header.in.length -= cpu_to_be32(sizeof(__be32));
} else { } else {
if (subcap_id == TPM_CAP_FLAG_PERM || if (subcap_id == TPM_CAP_FLAG_PERM ||
subcap_id == TPM_CAP_FLAG_VOL) subcap_id == TPM_CAP_FLAG_VOL)
tpm_cmd.params.getcap_in.cap = tpm_buf_append_u32(&buf, TPM_CAP_FLAG);
cpu_to_be32(TPM_CAP_FLAG);
else else
tpm_cmd.params.getcap_in.cap = tpm_buf_append_u32(&buf, TPM_CAP_PROP);
cpu_to_be32(TPM_CAP_PROP);
tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); tpm_buf_append_u32(&buf, 4);
tpm_cmd.params.getcap_in.subcap = cpu_to_be32(subcap_id); tpm_buf_append_u32(&buf, subcap_id);
} }
rc = tpm_transmit_cmd(chip, NULL, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE,
min_cap_length, 0, desc); min_cap_length, 0, desc);
if (!rc) if (!rc)
*cap = tpm_cmd.params.getcap_out.cap; *cap = *(cap_t *)&buf.data[TPM_HEADER_SIZE + 4];
tpm_buf_destroy(&buf);
return rc; return rc;
} }
EXPORT_SYMBOL_GPL(tpm_getcap); EXPORT_SYMBOL_GPL(tpm_getcap);
#define TPM_ORD_STARTUP cpu_to_be32(153) #define TPM_ORD_STARTUP 153
#define TPM_ST_CLEAR cpu_to_be16(1) #define TPM_ST_CLEAR cpu_to_be16(1)
#define TPM_ST_STATE cpu_to_be16(2) #define TPM_ST_STATE cpu_to_be16(2)
#define TPM_ST_DEACTIVATED cpu_to_be16(3) #define TPM_ST_DEACTIVATED cpu_to_be16(3)
static const struct tpm_input_header tpm_startup_header = { static const struct tpm_input_header tpm_startup_header = {
.tag = TPM_TAG_RQU_COMMAND, .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
.length = cpu_to_be32(12), .length = cpu_to_be32(12),
.ordinal = TPM_ORD_STARTUP .ordinal = cpu_to_be32(TPM_ORD_STARTUP)
}; };
static int tpm_startup(struct tpm_chip *chip, __be16 startup_type) static int tpm_startup(struct tpm_chip *chip, __be16 startup_type)
...@@ -737,7 +742,7 @@ EXPORT_SYMBOL_GPL(tpm_get_timeouts); ...@@ -737,7 +742,7 @@ EXPORT_SYMBOL_GPL(tpm_get_timeouts);
#define CONTINUE_SELFTEST_RESULT_SIZE 10 #define CONTINUE_SELFTEST_RESULT_SIZE 10
static const struct tpm_input_header continue_selftest_header = { static const struct tpm_input_header continue_selftest_header = {
.tag = TPM_TAG_RQU_COMMAND, .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
.length = cpu_to_be32(10), .length = cpu_to_be32(10),
.ordinal = cpu_to_be32(TPM_ORD_CONTINUE_SELFTEST), .ordinal = cpu_to_be32(TPM_ORD_CONTINUE_SELFTEST),
}; };
...@@ -760,13 +765,13 @@ static int tpm_continue_selftest(struct tpm_chip *chip) ...@@ -760,13 +765,13 @@ static int tpm_continue_selftest(struct tpm_chip *chip)
return rc; return rc;
} }
#define TPM_ORDINAL_PCRREAD cpu_to_be32(21) #define TPM_ORDINAL_PCRREAD 21
#define READ_PCR_RESULT_SIZE 30 #define READ_PCR_RESULT_SIZE 30
#define READ_PCR_RESULT_BODY_SIZE 20 #define READ_PCR_RESULT_BODY_SIZE 20
static const struct tpm_input_header pcrread_header = { static const struct tpm_input_header pcrread_header = {
.tag = TPM_TAG_RQU_COMMAND, .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
.length = cpu_to_be32(14), .length = cpu_to_be32(14),
.ordinal = TPM_ORDINAL_PCRREAD .ordinal = cpu_to_be32(TPM_ORDINAL_PCRREAD)
}; };
int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf) int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
...@@ -838,15 +843,34 @@ int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf) ...@@ -838,15 +843,34 @@ int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf)
} }
EXPORT_SYMBOL_GPL(tpm_pcr_read); EXPORT_SYMBOL_GPL(tpm_pcr_read);
#define TPM_ORD_PCR_EXTEND cpu_to_be32(20) #define TPM_ORD_PCR_EXTEND 20
#define EXTEND_PCR_RESULT_SIZE 34 #define EXTEND_PCR_RESULT_SIZE 34
#define EXTEND_PCR_RESULT_BODY_SIZE 20 #define EXTEND_PCR_RESULT_BODY_SIZE 20
static const struct tpm_input_header pcrextend_header = { static const struct tpm_input_header pcrextend_header = {
.tag = TPM_TAG_RQU_COMMAND, .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
.length = cpu_to_be32(34), .length = cpu_to_be32(34),
.ordinal = TPM_ORD_PCR_EXTEND .ordinal = cpu_to_be32(TPM_ORD_PCR_EXTEND)
}; };
static int tpm1_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash,
char *log_msg)
{
struct tpm_buf buf;
int rc;
rc = tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_PCR_EXTEND);
if (rc)
return rc;
tpm_buf_append_u32(&buf, pcr_idx);
tpm_buf_append(&buf, hash, TPM_DIGEST_SIZE);
rc = tpm_transmit_cmd(chip, NULL, buf.data, EXTEND_PCR_RESULT_SIZE,
EXTEND_PCR_RESULT_BODY_SIZE, 0, log_msg);
tpm_buf_destroy(&buf);
return rc;
}
/** /**
* tpm_pcr_extend - extend pcr value with hash * tpm_pcr_extend - extend pcr value with hash
* @chip_num: tpm idx # or AN& * @chip_num: tpm idx # or AN&
...@@ -859,7 +883,6 @@ static const struct tpm_input_header pcrextend_header = { ...@@ -859,7 +883,6 @@ static const struct tpm_input_header pcrextend_header = {
*/ */
int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash) int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
{ {
struct tpm_cmd_t cmd;
int rc; int rc;
struct tpm_chip *chip; struct tpm_chip *chip;
struct tpm2_digest digest_list[ARRAY_SIZE(chip->active_banks)]; struct tpm2_digest digest_list[ARRAY_SIZE(chip->active_banks)];
...@@ -885,13 +908,8 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash) ...@@ -885,13 +908,8 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
return rc; return rc;
} }
cmd.header.in = pcrextend_header; rc = tpm1_pcr_extend(chip, pcr_idx, hash,
cmd.params.pcrextend_in.pcr_idx = cpu_to_be32(pcr_idx); "attempting extend a PCR value");
memcpy(cmd.params.pcrextend_in.hash, hash, TPM_DIGEST_SIZE);
rc = tpm_transmit_cmd(chip, NULL, &cmd, EXTEND_PCR_RESULT_SIZE,
EXTEND_PCR_RESULT_BODY_SIZE, 0,
"attempting extend a PCR value");
tpm_put_ops(chip); tpm_put_ops(chip);
return rc; return rc;
} }
...@@ -1060,13 +1078,13 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, ...@@ -1060,13 +1078,13 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
} }
EXPORT_SYMBOL_GPL(wait_for_tpm_stat); EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
#define TPM_ORD_SAVESTATE cpu_to_be32(152) #define TPM_ORD_SAVESTATE 152
#define SAVESTATE_RESULT_SIZE 10 #define SAVESTATE_RESULT_SIZE 10
static const struct tpm_input_header savestate_header = { static const struct tpm_input_header savestate_header = {
.tag = TPM_TAG_RQU_COMMAND, .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
.length = cpu_to_be32(10), .length = cpu_to_be32(10),
.ordinal = TPM_ORD_SAVESTATE .ordinal = cpu_to_be32(TPM_ORD_SAVESTATE)
}; };
/* /*
...@@ -1090,15 +1108,9 @@ int tpm_pm_suspend(struct device *dev) ...@@ -1090,15 +1108,9 @@ int tpm_pm_suspend(struct device *dev)
} }
/* for buggy tpm, flush pcrs with extend to selected dummy */ /* for buggy tpm, flush pcrs with extend to selected dummy */
if (tpm_suspend_pcr) { if (tpm_suspend_pcr)
cmd.header.in = pcrextend_header; rc = tpm1_pcr_extend(chip, tpm_suspend_pcr, dummy_hash,
cmd.params.pcrextend_in.pcr_idx = cpu_to_be32(tpm_suspend_pcr); "extending dummy pcr before suspend");
memcpy(cmd.params.pcrextend_in.hash, dummy_hash,
TPM_DIGEST_SIZE);
rc = tpm_transmit_cmd(chip, NULL, &cmd, EXTEND_PCR_RESULT_SIZE,
EXTEND_PCR_RESULT_BODY_SIZE, 0,
"extending dummy pcr before suspend");
}
/* now do the actual savestate */ /* now do the actual savestate */
for (try = 0; try < TPM_RETRY; try++) { for (try = 0; try < TPM_RETRY; try++) {
...@@ -1149,9 +1161,9 @@ EXPORT_SYMBOL_GPL(tpm_pm_resume); ...@@ -1149,9 +1161,9 @@ EXPORT_SYMBOL_GPL(tpm_pm_resume);
#define TPM_GETRANDOM_RESULT_SIZE 18 #define TPM_GETRANDOM_RESULT_SIZE 18
static const struct tpm_input_header tpm_getrandom_header = { static const struct tpm_input_header tpm_getrandom_header = {
.tag = TPM_TAG_RQU_COMMAND, .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
.length = cpu_to_be32(14), .length = cpu_to_be32(14),
.ordinal = TPM_ORD_GET_RANDOM .ordinal = cpu_to_be32(TPM_ORD_GET_RANDOM)
}; };
/** /**
......
...@@ -22,11 +22,11 @@ ...@@ -22,11 +22,11 @@
#define READ_PUBEK_RESULT_SIZE 314 #define READ_PUBEK_RESULT_SIZE 314
#define READ_PUBEK_RESULT_MIN_BODY_SIZE (28 + 256) #define READ_PUBEK_RESULT_MIN_BODY_SIZE (28 + 256)
#define TPM_ORD_READPUBEK cpu_to_be32(124) #define TPM_ORD_READPUBEK 124
static const struct tpm_input_header tpm_readpubek_header = { static const struct tpm_input_header tpm_readpubek_header = {
.tag = TPM_TAG_RQU_COMMAND, .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
.length = cpu_to_be32(30), .length = cpu_to_be32(30),
.ordinal = TPM_ORD_READPUBEK .ordinal = cpu_to_be32(TPM_ORD_READPUBEK)
}; };
static ssize_t pubek_show(struct device *dev, struct device_attribute *attr, static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
......
...@@ -247,7 +247,7 @@ struct tpm_output_header { ...@@ -247,7 +247,7 @@ struct tpm_output_header {
__be32 return_code; __be32 return_code;
} __packed; } __packed;
#define TPM_TAG_RQU_COMMAND cpu_to_be16(193) #define TPM_TAG_RQU_COMMAND 193
struct stclear_flags_t { struct stclear_flags_t {
__be16 tag; __be16 tag;
...@@ -339,17 +339,6 @@ enum tpm_sub_capabilities { ...@@ -339,17 +339,6 @@ enum tpm_sub_capabilities {
TPM_CAP_PROP_TIS_DURATION = 0x120, TPM_CAP_PROP_TIS_DURATION = 0x120,
}; };
struct tpm_getcap_params_in {
__be32 cap;
__be32 subcap_size;
__be32 subcap;
} __packed;
struct tpm_getcap_params_out {
__be32 cap_size;
cap_t cap;
} __packed;
struct tpm_readpubek_params_out { struct tpm_readpubek_params_out {
u8 algorithm[4]; u8 algorithm[4];
u8 encscheme[2]; u8 encscheme[2];
...@@ -374,11 +363,6 @@ struct tpm_pcrread_in { ...@@ -374,11 +363,6 @@ struct tpm_pcrread_in {
__be32 pcr_idx; __be32 pcr_idx;
} __packed; } __packed;
struct tpm_pcrextend_in {
__be32 pcr_idx;
u8 hash[TPM_DIGEST_SIZE];
} __packed;
/* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18 /* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18
* bytes, but 128 is still a relatively large number of random bytes and * bytes, but 128 is still a relatively large number of random bytes and
* anything much bigger causes users of struct tpm_cmd_t to start getting * anything much bigger causes users of struct tpm_cmd_t to start getting
...@@ -399,13 +383,10 @@ struct tpm_startup_in { ...@@ -399,13 +383,10 @@ struct tpm_startup_in {
} __packed; } __packed;
typedef union { typedef union {
struct tpm_getcap_params_out getcap_out;
struct tpm_readpubek_params_out readpubek_out; struct tpm_readpubek_params_out readpubek_out;
u8 readpubek_out_buffer[sizeof(struct tpm_readpubek_params_out)]; u8 readpubek_out_buffer[sizeof(struct tpm_readpubek_params_out)];
struct tpm_getcap_params_in getcap_in;
struct tpm_pcrread_in pcrread_in; struct tpm_pcrread_in pcrread_in;
struct tpm_pcrread_out pcrread_out; struct tpm_pcrread_out pcrread_out;
struct tpm_pcrextend_in pcrextend_in;
struct tpm_getrandom_in getrandom_in; struct tpm_getrandom_in getrandom_in;
struct tpm_getrandom_out getrandom_out; struct tpm_getrandom_out getrandom_out;
struct tpm_startup_in startup_in; struct tpm_startup_in startup_in;
...@@ -525,6 +506,7 @@ extern struct idr dev_nums_idr; ...@@ -525,6 +506,7 @@ extern struct idr dev_nums_idr;
enum tpm_transmit_flags { enum tpm_transmit_flags {
TPM_TRANSMIT_UNLOCKED = BIT(0), TPM_TRANSMIT_UNLOCKED = BIT(0),
TPM_TRANSMIT_RAW = BIT(1),
}; };
ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space, ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
......
...@@ -840,7 +840,7 @@ void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type) ...@@ -840,7 +840,7 @@ void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type)
/* In places where shutdown command is sent there's no much we can do /* In places where shutdown command is sent there's no much we can do
* except print the error code on a system failure. * except print the error code on a system failure.
*/ */
if (rc < 0) if (rc < 0 && rc != -EPIPE)
dev_warn(&chip->dev, "transmit returned %d while stopping the TPM", dev_warn(&chip->dev, "transmit returned %d while stopping the TPM",
rc); rc);
} }
......
...@@ -144,13 +144,11 @@ static void atml_plat_remove(void) ...@@ -144,13 +144,11 @@ static void atml_plat_remove(void)
struct tpm_chip *chip = dev_get_drvdata(&pdev->dev); struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
struct tpm_atmel_priv *priv = dev_get_drvdata(&chip->dev); struct tpm_atmel_priv *priv = dev_get_drvdata(&chip->dev);
if (chip) { tpm_chip_unregister(chip);
tpm_chip_unregister(chip); if (priv->have_region)
if (priv->have_region) atmel_release_region(priv->base, priv->region_size);
atmel_release_region(priv->base, priv->region_size); atmel_put_base_addr(priv->iobase);
atmel_put_base_addr(priv->iobase); platform_device_unregister(pdev);
platform_device_unregister(pdev);
}
} }
static SIMPLE_DEV_PM_OPS(tpm_atml_pm, tpm_pm_suspend, tpm_pm_resume); static SIMPLE_DEV_PM_OPS(tpm_atml_pm, tpm_pm_suspend, tpm_pm_resume);
......
...@@ -70,6 +70,7 @@ struct tpm_inf_dev { ...@@ -70,6 +70,7 @@ struct tpm_inf_dev {
u8 buf[TPM_BUFSIZE + sizeof(u8)]; /* max. buffer size + addr */ u8 buf[TPM_BUFSIZE + sizeof(u8)]; /* max. buffer size + addr */
struct tpm_chip *chip; struct tpm_chip *chip;
enum i2c_chip_type chip_type; enum i2c_chip_type chip_type;
unsigned int adapterlimit;
}; };
static struct tpm_inf_dev tpm_dev; static struct tpm_inf_dev tpm_dev;
...@@ -111,6 +112,7 @@ static int iic_tpm_read(u8 addr, u8 *buffer, size_t len) ...@@ -111,6 +112,7 @@ static int iic_tpm_read(u8 addr, u8 *buffer, size_t len)
int rc = 0; int rc = 0;
int count; int count;
unsigned int msglen = len;
/* Lock the adapter for the duration of the whole sequence. */ /* Lock the adapter for the duration of the whole sequence. */
if (!tpm_dev.client->adapter->algo->master_xfer) if (!tpm_dev.client->adapter->algo->master_xfer)
...@@ -131,27 +133,61 @@ static int iic_tpm_read(u8 addr, u8 *buffer, size_t len) ...@@ -131,27 +133,61 @@ static int iic_tpm_read(u8 addr, u8 *buffer, size_t len)
usleep_range(SLEEP_DURATION_LOW, SLEEP_DURATION_HI); usleep_range(SLEEP_DURATION_LOW, SLEEP_DURATION_HI);
} }
} else { } else {
/* slb9635 protocol should work in all cases */ /* Expect to send one command message and one data message, but
for (count = 0; count < MAX_COUNT; count++) { * support looping over each or both if necessary.
rc = __i2c_transfer(tpm_dev.client->adapter, &msg1, 1);
if (rc > 0)
break; /* break here to skip sleep */
usleep_range(SLEEP_DURATION_LOW, SLEEP_DURATION_HI);
}
if (rc <= 0)
goto out;
/* After the TPM has successfully received the register address
* it needs some time, thus we're sleeping here again, before
* retrieving the data
*/ */
for (count = 0; count < MAX_COUNT; count++) { while (len > 0) {
usleep_range(SLEEP_DURATION_LOW, SLEEP_DURATION_HI); /* slb9635 protocol should work in all cases */
rc = __i2c_transfer(tpm_dev.client->adapter, &msg2, 1); for (count = 0; count < MAX_COUNT; count++) {
if (rc > 0) rc = __i2c_transfer(tpm_dev.client->adapter,
break; &msg1, 1);
if (rc > 0)
break; /* break here to skip sleep */
usleep_range(SLEEP_DURATION_LOW,
SLEEP_DURATION_HI);
}
if (rc <= 0)
goto out;
/* After the TPM has successfully received the register
* address it needs some time, thus we're sleeping here
* again, before retrieving the data
*/
for (count = 0; count < MAX_COUNT; count++) {
if (tpm_dev.adapterlimit) {
msglen = min_t(unsigned int,
tpm_dev.adapterlimit,
len);
msg2.len = msglen;
}
usleep_range(SLEEP_DURATION_LOW,
SLEEP_DURATION_HI);
rc = __i2c_transfer(tpm_dev.client->adapter,
&msg2, 1);
if (rc > 0) {
/* Since len is unsigned, make doubly
* sure we do not underflow it.
*/
if (msglen > len)
len = 0;
else
len -= msglen;
msg2.buf += msglen;
break;
}
/* If the I2C adapter rejected the request (e.g
* when the quirk read_max_len < len) fall back
* to a sane minimum value and try again.
*/
if (rc == -EOPNOTSUPP)
tpm_dev.adapterlimit =
I2C_SMBUS_BLOCK_MAX;
}
if (rc <= 0)
goto out;
} }
} }
......
...@@ -397,7 +397,7 @@ static int tpm_inf_pnp_probe(struct pnp_dev *dev, ...@@ -397,7 +397,7 @@ static int tpm_inf_pnp_probe(struct pnp_dev *dev,
int vendorid[2]; int vendorid[2];
int version[2]; int version[2];
int productid[2]; int productid[2];
char chipname[20]; const char *chipname;
struct tpm_chip *chip; struct tpm_chip *chip;
/* read IO-ports through PnP */ /* read IO-ports through PnP */
...@@ -488,13 +488,13 @@ static int tpm_inf_pnp_probe(struct pnp_dev *dev, ...@@ -488,13 +488,13 @@ static int tpm_inf_pnp_probe(struct pnp_dev *dev,
switch ((productid[0] << 8) | productid[1]) { switch ((productid[0] << 8) | productid[1]) {
case 6: case 6:
snprintf(chipname, sizeof(chipname), " (SLD 9630 TT 1.1)"); chipname = " (SLD 9630 TT 1.1)";
break; break;
case 11: case 11:
snprintf(chipname, sizeof(chipname), " (SLB 9635 TT 1.2)"); chipname = " (SLB 9635 TT 1.2)";
break; break;
default: default:
snprintf(chipname, sizeof(chipname), " (unknown chip)"); chipname = " (unknown chip)";
break; break;
} }
......
...@@ -80,6 +80,8 @@ static int has_hid(struct acpi_device *dev, const char *hid) ...@@ -80,6 +80,8 @@ static int has_hid(struct acpi_device *dev, const char *hid)
static inline int is_itpm(struct acpi_device *dev) static inline int is_itpm(struct acpi_device *dev)
{ {
if (!dev)
return 0;
return has_hid(dev, "INTC0102"); return has_hid(dev, "INTC0102");
} }
#else #else
...@@ -89,6 +91,47 @@ static inline int is_itpm(struct acpi_device *dev) ...@@ -89,6 +91,47 @@ static inline int is_itpm(struct acpi_device *dev)
} }
#endif #endif
#if defined(CONFIG_ACPI)
#define DEVICE_IS_TPM2 1
static const struct acpi_device_id tpm_acpi_tbl[] = {
{"MSFT0101", DEVICE_IS_TPM2},
{},
};
MODULE_DEVICE_TABLE(acpi, tpm_acpi_tbl);
static int check_acpi_tpm2(struct device *dev)
{
const struct acpi_device_id *aid = acpi_match_device(tpm_acpi_tbl, dev);
struct acpi_table_tpm2 *tbl;
acpi_status st;
if (!aid || aid->driver_data != DEVICE_IS_TPM2)
return 0;
/* If the ACPI TPM2 signature is matched then a global ACPI_SIG_TPM2
* table is mandatory
*/
st =
acpi_get_table(ACPI_SIG_TPM2, 1, (struct acpi_table_header **)&tbl);
if (ACPI_FAILURE(st) || tbl->header.length < sizeof(*tbl)) {
dev_err(dev, FW_BUG "failed to get TPM2 ACPI table\n");
return -EINVAL;
}
/* The tpm2_crb driver handles this device */
if (tbl->start_method != ACPI_TPM2_MEMORY_MAPPED)
return -ENODEV;
return 0;
}
#else
static int check_acpi_tpm2(struct device *dev)
{
return 0;
}
#endif
static int tpm_tcg_read_bytes(struct tpm_tis_data *data, u32 addr, u16 len, static int tpm_tcg_read_bytes(struct tpm_tis_data *data, u32 addr, u16 len,
u8 *result) u8 *result)
{ {
...@@ -141,11 +184,15 @@ static const struct tpm_tis_phy_ops tpm_tcg = { ...@@ -141,11 +184,15 @@ static const struct tpm_tis_phy_ops tpm_tcg = {
.write32 = tpm_tcg_write32, .write32 = tpm_tcg_write32,
}; };
static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info, static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info)
acpi_handle acpi_dev_handle)
{ {
struct tpm_tis_tcg_phy *phy; struct tpm_tis_tcg_phy *phy;
int irq = -1; int irq = -1;
int rc;
rc = check_acpi_tpm2(dev);
if (rc)
return rc;
phy = devm_kzalloc(dev, sizeof(struct tpm_tis_tcg_phy), GFP_KERNEL); phy = devm_kzalloc(dev, sizeof(struct tpm_tis_tcg_phy), GFP_KERNEL);
if (phy == NULL) if (phy == NULL)
...@@ -158,11 +205,11 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info, ...@@ -158,11 +205,11 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
if (interrupts) if (interrupts)
irq = tpm_info->irq; irq = tpm_info->irq;
if (itpm) if (itpm || is_itpm(ACPI_COMPANION(dev)))
phy->priv.flags |= TPM_TIS_ITPM_WORKAROUND; phy->priv.flags |= TPM_TIS_ITPM_WORKAROUND;
return tpm_tis_core_init(dev, &phy->priv, irq, &tpm_tcg, return tpm_tis_core_init(dev, &phy->priv, irq, &tpm_tcg,
acpi_dev_handle); ACPI_HANDLE(dev));
} }
static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume); static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume);
...@@ -171,7 +218,6 @@ static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev, ...@@ -171,7 +218,6 @@ static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
const struct pnp_device_id *pnp_id) const struct pnp_device_id *pnp_id)
{ {
struct tpm_info tpm_info = {}; struct tpm_info tpm_info = {};
acpi_handle acpi_dev_handle = NULL;
struct resource *res; struct resource *res;
res = pnp_get_resource(pnp_dev, IORESOURCE_MEM, 0); res = pnp_get_resource(pnp_dev, IORESOURCE_MEM, 0);
...@@ -184,14 +230,7 @@ static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev, ...@@ -184,14 +230,7 @@ static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
else else
tpm_info.irq = -1; tpm_info.irq = -1;
if (pnp_acpi_device(pnp_dev)) { return tpm_tis_init(&pnp_dev->dev, &tpm_info);
if (is_itpm(pnp_acpi_device(pnp_dev)))
itpm = true;
acpi_dev_handle = ACPI_HANDLE(&pnp_dev->dev);
}
return tpm_tis_init(&pnp_dev->dev, &tpm_info, acpi_dev_handle);
} }
static struct pnp_device_id tpm_pnp_tbl[] = { static struct pnp_device_id tpm_pnp_tbl[] = {
...@@ -231,93 +270,6 @@ module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id, ...@@ -231,93 +270,6 @@ module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444); sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe"); MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
#ifdef CONFIG_ACPI
static int tpm_check_resource(struct acpi_resource *ares, void *data)
{
struct tpm_info *tpm_info = (struct tpm_info *) data;
struct resource res;
if (acpi_dev_resource_interrupt(ares, 0, &res))
tpm_info->irq = res.start;
else if (acpi_dev_resource_memory(ares, &res)) {
tpm_info->res = res;
tpm_info->res.name = NULL;
}
return 1;
}
static int tpm_tis_acpi_init(struct acpi_device *acpi_dev)
{
struct acpi_table_tpm2 *tbl;
acpi_status st;
struct list_head resources;
struct tpm_info tpm_info = {};
int ret;
st = acpi_get_table(ACPI_SIG_TPM2, 1,
(struct acpi_table_header **) &tbl);
if (ACPI_FAILURE(st) || tbl->header.length < sizeof(*tbl)) {
dev_err(&acpi_dev->dev,
FW_BUG "failed to get TPM2 ACPI table\n");
return -EINVAL;
}
if (tbl->start_method != ACPI_TPM2_MEMORY_MAPPED)
return -ENODEV;
INIT_LIST_HEAD(&resources);
tpm_info.irq = -1;
ret = acpi_dev_get_resources(acpi_dev, &resources, tpm_check_resource,
&tpm_info);
if (ret < 0)
return ret;
acpi_dev_free_resource_list(&resources);
if (resource_type(&tpm_info.res) != IORESOURCE_MEM) {
dev_err(&acpi_dev->dev,
FW_BUG "TPM2 ACPI table does not define a memory resource\n");
return -EINVAL;
}
if (is_itpm(acpi_dev))
itpm = true;
return tpm_tis_init(&acpi_dev->dev, &tpm_info, acpi_dev->handle);
}
static int tpm_tis_acpi_remove(struct acpi_device *dev)
{
struct tpm_chip *chip = dev_get_drvdata(&dev->dev);
tpm_chip_unregister(chip);
tpm_tis_remove(chip);
return 0;
}
static struct acpi_device_id tpm_acpi_tbl[] = {
{"MSFT0101", 0}, /* TPM 2.0 */
/* Add new here */
{"", 0}, /* User Specified */
{"", 0} /* Terminator */
};
MODULE_DEVICE_TABLE(acpi, tpm_acpi_tbl);
static struct acpi_driver tis_acpi_driver = {
.name = "tpm_tis",
.ids = tpm_acpi_tbl,
.ops = {
.add = tpm_tis_acpi_init,
.remove = tpm_tis_acpi_remove,
},
.drv = {
.pm = &tpm_tis_pm,
},
};
#endif
static struct platform_device *force_pdev; static struct platform_device *force_pdev;
static int tpm_tis_plat_probe(struct platform_device *pdev) static int tpm_tis_plat_probe(struct platform_device *pdev)
...@@ -332,18 +284,16 @@ static int tpm_tis_plat_probe(struct platform_device *pdev) ...@@ -332,18 +284,16 @@ static int tpm_tis_plat_probe(struct platform_device *pdev)
} }
tpm_info.res = *res; tpm_info.res = *res;
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); tpm_info.irq = platform_get_irq(pdev, 0);
if (res) { if (tpm_info.irq <= 0) {
tpm_info.irq = res->start; if (pdev != force_pdev)
} else {
if (pdev == force_pdev)
tpm_info.irq = -1; tpm_info.irq = -1;
else else
/* When forcing auto probe the IRQ */ /* When forcing auto probe the IRQ */
tpm_info.irq = 0; tpm_info.irq = 0;
} }
return tpm_tis_init(&pdev->dev, &tpm_info, NULL); return tpm_tis_init(&pdev->dev, &tpm_info);
} }
static int tpm_tis_plat_remove(struct platform_device *pdev) static int tpm_tis_plat_remove(struct platform_device *pdev)
...@@ -371,6 +321,7 @@ static struct platform_driver tis_drv = { ...@@ -371,6 +321,7 @@ static struct platform_driver tis_drv = {
.name = "tpm_tis", .name = "tpm_tis",
.pm = &tpm_tis_pm, .pm = &tpm_tis_pm,
.of_match_table = of_match_ptr(tis_of_platform_match), .of_match_table = of_match_ptr(tis_of_platform_match),
.acpi_match_table = ACPI_PTR(tpm_acpi_tbl),
}, },
}; };
...@@ -413,11 +364,6 @@ static int __init init_tis(void) ...@@ -413,11 +364,6 @@ static int __init init_tis(void)
if (rc) if (rc)
goto err_platform; goto err_platform;
#ifdef CONFIG_ACPI
rc = acpi_bus_register_driver(&tis_acpi_driver);
if (rc)
goto err_acpi;
#endif
if (IS_ENABLED(CONFIG_PNP)) { if (IS_ENABLED(CONFIG_PNP)) {
rc = pnp_register_driver(&tis_pnp_driver); rc = pnp_register_driver(&tis_pnp_driver);
...@@ -428,10 +374,6 @@ static int __init init_tis(void) ...@@ -428,10 +374,6 @@ static int __init init_tis(void)
return 0; return 0;
err_pnp: err_pnp:
#ifdef CONFIG_ACPI
acpi_bus_unregister_driver(&tis_acpi_driver);
err_acpi:
#endif
platform_driver_unregister(&tis_drv); platform_driver_unregister(&tis_drv);
err_platform: err_platform:
if (force_pdev) if (force_pdev)
...@@ -443,9 +385,6 @@ static int __init init_tis(void) ...@@ -443,9 +385,6 @@ static int __init init_tis(void)
static void __exit cleanup_tis(void) static void __exit cleanup_tis(void)
{ {
pnp_unregister_driver(&tis_pnp_driver); pnp_unregister_driver(&tis_pnp_driver);
#ifdef CONFIG_ACPI
acpi_bus_unregister_driver(&tis_acpi_driver);
#endif
platform_driver_unregister(&tis_drv); platform_driver_unregister(&tis_drv);
if (force_pdev) if (force_pdev)
......
...@@ -43,6 +43,7 @@ struct proxy_dev { ...@@ -43,6 +43,7 @@ struct proxy_dev {
#define STATE_OPENED_FLAG BIT(0) #define STATE_OPENED_FLAG BIT(0)
#define STATE_WAIT_RESPONSE_FLAG BIT(1) /* waiting for emulator response */ #define STATE_WAIT_RESPONSE_FLAG BIT(1) /* waiting for emulator response */
#define STATE_REGISTERED_FLAG BIT(2) #define STATE_REGISTERED_FLAG BIT(2)
#define STATE_DRIVER_COMMAND BIT(3) /* sending a driver specific command */
size_t req_len; /* length of queued TPM request */ size_t req_len; /* length of queued TPM request */
size_t resp_len; /* length of queued TPM response */ size_t resp_len; /* length of queued TPM response */
...@@ -299,6 +300,28 @@ static int vtpm_proxy_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t count) ...@@ -299,6 +300,28 @@ static int vtpm_proxy_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t count)
return len; return len;
} }
static int vtpm_proxy_is_driver_command(struct tpm_chip *chip,
u8 *buf, size_t count)
{
struct tpm_input_header *hdr = (struct tpm_input_header *)buf;
if (count < sizeof(struct tpm_input_header))
return 0;
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
switch (be32_to_cpu(hdr->ordinal)) {
case TPM2_CC_SET_LOCALITY:
return 1;
}
} else {
switch (be32_to_cpu(hdr->ordinal)) {
case TPM_ORD_SET_LOCALITY:
return 1;
}
}
return 0;
}
/* /*
* Called when core TPM driver forwards TPM requests to 'server side'. * Called when core TPM driver forwards TPM requests to 'server side'.
* *
...@@ -321,6 +344,10 @@ static int vtpm_proxy_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t count) ...@@ -321,6 +344,10 @@ static int vtpm_proxy_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t count)
return -EIO; return -EIO;
} }
if (!(proxy_dev->state & STATE_DRIVER_COMMAND) &&
vtpm_proxy_is_driver_command(chip, buf, count))
return -EFAULT;
mutex_lock(&proxy_dev->buf_lock); mutex_lock(&proxy_dev->buf_lock);
if (!(proxy_dev->state & STATE_OPENED_FLAG)) { if (!(proxy_dev->state & STATE_OPENED_FLAG)) {
...@@ -371,6 +398,47 @@ static bool vtpm_proxy_tpm_req_canceled(struct tpm_chip *chip, u8 status) ...@@ -371,6 +398,47 @@ static bool vtpm_proxy_tpm_req_canceled(struct tpm_chip *chip, u8 status)
return ret; return ret;
} }
static int vtpm_proxy_request_locality(struct tpm_chip *chip, int locality)
{
struct tpm_buf buf;
int rc;
const struct tpm_output_header *header;
struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev);
if (chip->flags & TPM_CHIP_FLAG_TPM2)
rc = tpm_buf_init(&buf, TPM2_ST_SESSIONS,
TPM2_CC_SET_LOCALITY);
else
rc = tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND,
TPM_ORD_SET_LOCALITY);
if (rc)
return rc;
tpm_buf_append_u8(&buf, locality);
proxy_dev->state |= STATE_DRIVER_COMMAND;
rc = tpm_transmit_cmd(chip, NULL, buf.data, tpm_buf_length(&buf), 0,
TPM_TRANSMIT_UNLOCKED | TPM_TRANSMIT_RAW,
"attempting to set locality");
proxy_dev->state &= ~STATE_DRIVER_COMMAND;
if (rc < 0) {
locality = rc;
goto out;
}
header = (const struct tpm_output_header *)buf.data;
rc = be32_to_cpu(header->return_code);
if (rc)
locality = -1;
out:
tpm_buf_destroy(&buf);
return locality;
}
static const struct tpm_class_ops vtpm_proxy_tpm_ops = { static const struct tpm_class_ops vtpm_proxy_tpm_ops = {
.flags = TPM_OPS_AUTO_STARTUP, .flags = TPM_OPS_AUTO_STARTUP,
.recv = vtpm_proxy_tpm_op_recv, .recv = vtpm_proxy_tpm_op_recv,
...@@ -380,6 +448,7 @@ static const struct tpm_class_ops vtpm_proxy_tpm_ops = { ...@@ -380,6 +448,7 @@ static const struct tpm_class_ops vtpm_proxy_tpm_ops = {
.req_complete_mask = VTPM_PROXY_REQ_COMPLETE_FLAG, .req_complete_mask = VTPM_PROXY_REQ_COMPLETE_FLAG,
.req_complete_val = VTPM_PROXY_REQ_COMPLETE_FLAG, .req_complete_val = VTPM_PROXY_REQ_COMPLETE_FLAG,
.req_canceled = vtpm_proxy_tpm_req_canceled, .req_canceled = vtpm_proxy_tpm_req_canceled,
.request_locality = vtpm_proxy_request_locality,
}; };
/* /*
......
...@@ -45,7 +45,7 @@ static int tpmrm_release(struct inode *inode, struct file *file) ...@@ -45,7 +45,7 @@ static int tpmrm_release(struct inode *inode, struct file *file)
return 0; return 0;
} }
ssize_t tpmrm_write(struct file *file, const char __user *buf, static ssize_t tpmrm_write(struct file *file, const char __user *buf,
size_t size, loff_t *off) size_t size, loff_t *off)
{ {
struct file_priv *fpriv = file->private_data; struct file_priv *fpriv = file->private_data;
......
...@@ -10,7 +10,8 @@ obj-$(CONFIG_INFINIBAND_USER_ACCESS) += ib_uverbs.o ib_ucm.o \ ...@@ -10,7 +10,8 @@ obj-$(CONFIG_INFINIBAND_USER_ACCESS) += ib_uverbs.o ib_ucm.o \
ib_core-y := packer.o ud_header.o verbs.o cq.o rw.o sysfs.o \ ib_core-y := packer.o ud_header.o verbs.o cq.o rw.o sysfs.o \
device.o fmr_pool.o cache.o netlink.o \ device.o fmr_pool.o cache.o netlink.o \
roce_gid_mgmt.o mr_pool.o addr.o sa_query.o \ roce_gid_mgmt.o mr_pool.o addr.o sa_query.o \
multicast.o mad.o smi.o agent.o mad_rmpp.o multicast.o mad.o smi.o agent.o mad_rmpp.o \
security.o
ib_core-$(CONFIG_INFINIBAND_USER_MEM) += umem.o ib_core-$(CONFIG_INFINIBAND_USER_MEM) += umem.o
ib_core-$(CONFIG_INFINIBAND_ON_DEMAND_PAGING) += umem_odp.o umem_rbtree.o ib_core-$(CONFIG_INFINIBAND_ON_DEMAND_PAGING) += umem_odp.o umem_rbtree.o
ib_core-$(CONFIG_CGROUP_RDMA) += cgroup.o ib_core-$(CONFIG_CGROUP_RDMA) += cgroup.o
......
...@@ -53,6 +53,7 @@ struct ib_update_work { ...@@ -53,6 +53,7 @@ struct ib_update_work {
struct work_struct work; struct work_struct work;
struct ib_device *device; struct ib_device *device;
u8 port_num; u8 port_num;
bool enforce_security;
}; };
union ib_gid zgid; union ib_gid zgid;
...@@ -911,6 +912,26 @@ int ib_get_cached_pkey(struct ib_device *device, ...@@ -911,6 +912,26 @@ int ib_get_cached_pkey(struct ib_device *device,
} }
EXPORT_SYMBOL(ib_get_cached_pkey); EXPORT_SYMBOL(ib_get_cached_pkey);
int ib_get_cached_subnet_prefix(struct ib_device *device,
u8 port_num,
u64 *sn_pfx)
{
unsigned long flags;
int p;
if (port_num < rdma_start_port(device) ||
port_num > rdma_end_port(device))
return -EINVAL;
p = port_num - rdma_start_port(device);
read_lock_irqsave(&device->cache.lock, flags);
*sn_pfx = device->cache.ports[p].subnet_prefix;
read_unlock_irqrestore(&device->cache.lock, flags);
return 0;
}
EXPORT_SYMBOL(ib_get_cached_subnet_prefix);
int ib_find_cached_pkey(struct ib_device *device, int ib_find_cached_pkey(struct ib_device *device,
u8 port_num, u8 port_num,
u16 pkey, u16 pkey,
...@@ -1022,7 +1043,8 @@ int ib_get_cached_port_state(struct ib_device *device, ...@@ -1022,7 +1043,8 @@ int ib_get_cached_port_state(struct ib_device *device,
EXPORT_SYMBOL(ib_get_cached_port_state); EXPORT_SYMBOL(ib_get_cached_port_state);
static void ib_cache_update(struct ib_device *device, static void ib_cache_update(struct ib_device *device,
u8 port) u8 port,
bool enforce_security)
{ {
struct ib_port_attr *tprops = NULL; struct ib_port_attr *tprops = NULL;
struct ib_pkey_cache *pkey_cache = NULL, *old_pkey_cache; struct ib_pkey_cache *pkey_cache = NULL, *old_pkey_cache;
...@@ -1108,8 +1130,15 @@ static void ib_cache_update(struct ib_device *device, ...@@ -1108,8 +1130,15 @@ static void ib_cache_update(struct ib_device *device,
device->cache.ports[port - rdma_start_port(device)].port_state = device->cache.ports[port - rdma_start_port(device)].port_state =
tprops->state; tprops->state;
device->cache.ports[port - rdma_start_port(device)].subnet_prefix =
tprops->subnet_prefix;
write_unlock_irq(&device->cache.lock); write_unlock_irq(&device->cache.lock);
if (enforce_security)
ib_security_cache_change(device,
port,
tprops->subnet_prefix);
kfree(gid_cache); kfree(gid_cache);
kfree(old_pkey_cache); kfree(old_pkey_cache);
kfree(tprops); kfree(tprops);
...@@ -1126,7 +1155,9 @@ static void ib_cache_task(struct work_struct *_work) ...@@ -1126,7 +1155,9 @@ static void ib_cache_task(struct work_struct *_work)
struct ib_update_work *work = struct ib_update_work *work =
container_of(_work, struct ib_update_work, work); container_of(_work, struct ib_update_work, work);
ib_cache_update(work->device, work->port_num); ib_cache_update(work->device,
work->port_num,
work->enforce_security);
kfree(work); kfree(work);
} }
...@@ -1147,6 +1178,12 @@ static void ib_cache_event(struct ib_event_handler *handler, ...@@ -1147,6 +1178,12 @@ static void ib_cache_event(struct ib_event_handler *handler,
INIT_WORK(&work->work, ib_cache_task); INIT_WORK(&work->work, ib_cache_task);
work->device = event->device; work->device = event->device;
work->port_num = event->element.port_num; work->port_num = event->element.port_num;
if (event->event == IB_EVENT_PKEY_CHANGE ||
event->event == IB_EVENT_GID_CHANGE)
work->enforce_security = true;
else
work->enforce_security = false;
queue_work(ib_wq, &work->work); queue_work(ib_wq, &work->work);
} }
} }
...@@ -1172,7 +1209,7 @@ int ib_cache_setup_one(struct ib_device *device) ...@@ -1172,7 +1209,7 @@ int ib_cache_setup_one(struct ib_device *device)
goto out; goto out;
for (p = 0; p <= rdma_end_port(device) - rdma_start_port(device); ++p) for (p = 0; p <= rdma_end_port(device) - rdma_start_port(device); ++p)
ib_cache_update(device, p + rdma_start_port(device)); ib_cache_update(device, p + rdma_start_port(device), true);
INIT_IB_EVENT_HANDLER(&device->cache.event_handler, INIT_IB_EVENT_HANDLER(&device->cache.event_handler,
device, ib_cache_event); device, ib_cache_event);
......
...@@ -38,6 +38,16 @@ ...@@ -38,6 +38,16 @@
#include <linux/cgroup_rdma.h> #include <linux/cgroup_rdma.h>
#include <rdma/ib_verbs.h> #include <rdma/ib_verbs.h>
#include <rdma/ib_mad.h>
#include "mad_priv.h"
struct pkey_index_qp_list {
struct list_head pkey_index_list;
u16 pkey_index;
/* Lock to hold while iterating the qp_list. */
spinlock_t qp_list_lock;
struct list_head qp_list;
};
#if IS_ENABLED(CONFIG_INFINIBAND_ADDR_TRANS_CONFIGFS) #if IS_ENABLED(CONFIG_INFINIBAND_ADDR_TRANS_CONFIGFS)
int cma_configfs_init(void); int cma_configfs_init(void);
...@@ -186,4 +196,109 @@ int ib_nl_handle_set_timeout(struct sk_buff *skb, ...@@ -186,4 +196,109 @@ int ib_nl_handle_set_timeout(struct sk_buff *skb,
int ib_nl_handle_ip_res_resp(struct sk_buff *skb, int ib_nl_handle_ip_res_resp(struct sk_buff *skb,
struct netlink_callback *cb); struct netlink_callback *cb);
int ib_get_cached_subnet_prefix(struct ib_device *device,
u8 port_num,
u64 *sn_pfx);
#ifdef CONFIG_SECURITY_INFINIBAND
int ib_security_pkey_access(struct ib_device *dev,
u8 port_num,
u16 pkey_index,
void *sec);
void ib_security_destroy_port_pkey_list(struct ib_device *device);
void ib_security_cache_change(struct ib_device *device,
u8 port_num,
u64 subnet_prefix);
int ib_security_modify_qp(struct ib_qp *qp,
struct ib_qp_attr *qp_attr,
int qp_attr_mask,
struct ib_udata *udata);
int ib_create_qp_security(struct ib_qp *qp, struct ib_device *dev);
void ib_destroy_qp_security_begin(struct ib_qp_security *sec);
void ib_destroy_qp_security_abort(struct ib_qp_security *sec);
void ib_destroy_qp_security_end(struct ib_qp_security *sec);
int ib_open_shared_qp_security(struct ib_qp *qp, struct ib_device *dev);
void ib_close_shared_qp_security(struct ib_qp_security *sec);
int ib_mad_agent_security_setup(struct ib_mad_agent *agent,
enum ib_qp_type qp_type);
void ib_mad_agent_security_cleanup(struct ib_mad_agent *agent);
int ib_mad_enforce_security(struct ib_mad_agent_private *map, u16 pkey_index);
#else
static inline int ib_security_pkey_access(struct ib_device *dev,
u8 port_num,
u16 pkey_index,
void *sec)
{
return 0;
}
static inline void ib_security_destroy_port_pkey_list(struct ib_device *device)
{
}
static inline void ib_security_cache_change(struct ib_device *device,
u8 port_num,
u64 subnet_prefix)
{
}
static inline int ib_security_modify_qp(struct ib_qp *qp,
struct ib_qp_attr *qp_attr,
int qp_attr_mask,
struct ib_udata *udata)
{
return qp->device->modify_qp(qp->real_qp,
qp_attr,
qp_attr_mask,
udata);
}
static inline int ib_create_qp_security(struct ib_qp *qp,
struct ib_device *dev)
{
return 0;
}
static inline void ib_destroy_qp_security_begin(struct ib_qp_security *sec)
{
}
static inline void ib_destroy_qp_security_abort(struct ib_qp_security *sec)
{
}
static inline void ib_destroy_qp_security_end(struct ib_qp_security *sec)
{
}
static inline int ib_open_shared_qp_security(struct ib_qp *qp,
struct ib_device *dev)
{
return 0;
}
static inline void ib_close_shared_qp_security(struct ib_qp_security *sec)
{
}
static inline int ib_mad_agent_security_setup(struct ib_mad_agent *agent,
enum ib_qp_type qp_type)
{
return 0;
}
static inline void ib_mad_agent_security_cleanup(struct ib_mad_agent *agent)
{
}
static inline int ib_mad_enforce_security(struct ib_mad_agent_private *map,
u16 pkey_index)
{
return 0;
}
#endif
#endif /* _CORE_PRIV_H */ #endif /* _CORE_PRIV_H */
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/security.h>
#include <linux/notifier.h>
#include <rdma/rdma_netlink.h> #include <rdma/rdma_netlink.h>
#include <rdma/ib_addr.h> #include <rdma/ib_addr.h>
#include <rdma/ib_cache.h> #include <rdma/ib_cache.h>
...@@ -82,6 +84,14 @@ static LIST_HEAD(client_list); ...@@ -82,6 +84,14 @@ static LIST_HEAD(client_list);
static DEFINE_MUTEX(device_mutex); static DEFINE_MUTEX(device_mutex);
static DECLARE_RWSEM(lists_rwsem); static DECLARE_RWSEM(lists_rwsem);
static int ib_security_change(struct notifier_block *nb, unsigned long event,
void *lsm_data);
static void ib_policy_change_task(struct work_struct *work);
static DECLARE_WORK(ib_policy_change_work, ib_policy_change_task);
static struct notifier_block ibdev_lsm_nb = {
.notifier_call = ib_security_change,
};
static int ib_device_check_mandatory(struct ib_device *device) static int ib_device_check_mandatory(struct ib_device *device)
{ {
...@@ -325,6 +335,64 @@ void ib_get_device_fw_str(struct ib_device *dev, char *str, size_t str_len) ...@@ -325,6 +335,64 @@ void ib_get_device_fw_str(struct ib_device *dev, char *str, size_t str_len)
} }
EXPORT_SYMBOL(ib_get_device_fw_str); EXPORT_SYMBOL(ib_get_device_fw_str);
static int setup_port_pkey_list(struct ib_device *device)
{
int i;
/**
* device->port_pkey_list is indexed directly by the port number,
* Therefore it is declared as a 1 based array with potential empty
* slots at the beginning.
*/
device->port_pkey_list = kcalloc(rdma_end_port(device) + 1,
sizeof(*device->port_pkey_list),
GFP_KERNEL);
if (!device->port_pkey_list)
return -ENOMEM;
for (i = 0; i < (rdma_end_port(device) + 1); i++) {
spin_lock_init(&device->port_pkey_list[i].list_lock);
INIT_LIST_HEAD(&device->port_pkey_list[i].pkey_list);
}
return 0;
}
static void ib_policy_change_task(struct work_struct *work)
{
struct ib_device *dev;
down_read(&lists_rwsem);
list_for_each_entry(dev, &device_list, core_list) {
int i;
for (i = rdma_start_port(dev); i <= rdma_end_port(dev); i++) {
u64 sp;
int ret = ib_get_cached_subnet_prefix(dev,
i,
&sp);
WARN_ONCE(ret,
"ib_get_cached_subnet_prefix err: %d, this should never happen here\n",
ret);
ib_security_cache_change(dev, i, sp);
}
}
up_read(&lists_rwsem);
}
static int ib_security_change(struct notifier_block *nb, unsigned long event,
void *lsm_data)
{
if (event != LSM_POLICY_CHANGE)
return NOTIFY_DONE;
schedule_work(&ib_policy_change_work);
return NOTIFY_OK;
}
/** /**
* ib_register_device - Register an IB device with IB core * ib_register_device - Register an IB device with IB core
* @device:Device to register * @device:Device to register
...@@ -385,6 +453,12 @@ int ib_register_device(struct ib_device *device, ...@@ -385,6 +453,12 @@ int ib_register_device(struct ib_device *device,
goto out; goto out;
} }
ret = setup_port_pkey_list(device);
if (ret) {
pr_warn("Couldn't create per port_pkey_list\n");
goto out;
}
ret = ib_cache_setup_one(device); ret = ib_cache_setup_one(device);
if (ret) { if (ret) {
pr_warn("Couldn't set up InfiniBand P_Key/GID cache\n"); pr_warn("Couldn't set up InfiniBand P_Key/GID cache\n");
...@@ -468,6 +542,9 @@ void ib_unregister_device(struct ib_device *device) ...@@ -468,6 +542,9 @@ void ib_unregister_device(struct ib_device *device)
ib_device_unregister_sysfs(device); ib_device_unregister_sysfs(device);
ib_cache_cleanup_one(device); ib_cache_cleanup_one(device);
ib_security_destroy_port_pkey_list(device);
kfree(device->port_pkey_list);
down_write(&lists_rwsem); down_write(&lists_rwsem);
spin_lock_irqsave(&device->client_data_lock, flags); spin_lock_irqsave(&device->client_data_lock, flags);
list_for_each_entry_safe(context, tmp, &device->client_data_list, list) list_for_each_entry_safe(context, tmp, &device->client_data_list, list)
...@@ -1082,10 +1159,18 @@ static int __init ib_core_init(void) ...@@ -1082,10 +1159,18 @@ static int __init ib_core_init(void)
goto err_sa; goto err_sa;
} }
ret = register_lsm_notifier(&ibdev_lsm_nb);
if (ret) {
pr_warn("Couldn't register LSM notifier. ret %d\n", ret);
goto err_ibnl_clients;
}
ib_cache_setup(); ib_cache_setup();
return 0; return 0;
err_ibnl_clients:
ib_remove_ibnl_clients();
err_sa: err_sa:
ib_sa_cleanup(); ib_sa_cleanup();
err_mad: err_mad:
...@@ -1105,6 +1190,7 @@ static int __init ib_core_init(void) ...@@ -1105,6 +1190,7 @@ static int __init ib_core_init(void)
static void __exit ib_core_cleanup(void) static void __exit ib_core_cleanup(void)
{ {
unregister_lsm_notifier(&ibdev_lsm_nb);
ib_cache_cleanup(); ib_cache_cleanup();
ib_remove_ibnl_clients(); ib_remove_ibnl_clients();
ib_sa_cleanup(); ib_sa_cleanup();
......
...@@ -40,9 +40,11 @@ ...@@ -40,9 +40,11 @@
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/security.h>
#include <rdma/ib_cache.h> #include <rdma/ib_cache.h>
#include "mad_priv.h" #include "mad_priv.h"
#include "core_priv.h"
#include "mad_rmpp.h" #include "mad_rmpp.h"
#include "smi.h" #include "smi.h"
#include "opa_smi.h" #include "opa_smi.h"
...@@ -369,6 +371,12 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device, ...@@ -369,6 +371,12 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
atomic_set(&mad_agent_priv->refcount, 1); atomic_set(&mad_agent_priv->refcount, 1);
init_completion(&mad_agent_priv->comp); init_completion(&mad_agent_priv->comp);
ret2 = ib_mad_agent_security_setup(&mad_agent_priv->agent, qp_type);
if (ret2) {
ret = ERR_PTR(ret2);
goto error4;
}
spin_lock_irqsave(&port_priv->reg_lock, flags); spin_lock_irqsave(&port_priv->reg_lock, flags);
mad_agent_priv->agent.hi_tid = ++ib_mad_client_id; mad_agent_priv->agent.hi_tid = ++ib_mad_client_id;
...@@ -386,7 +394,7 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device, ...@@ -386,7 +394,7 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
if (method) { if (method) {
if (method_in_use(&method, if (method_in_use(&method,
mad_reg_req)) mad_reg_req))
goto error4; goto error5;
} }
} }
ret2 = add_nonoui_reg_req(mad_reg_req, mad_agent_priv, ret2 = add_nonoui_reg_req(mad_reg_req, mad_agent_priv,
...@@ -402,14 +410,14 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device, ...@@ -402,14 +410,14 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
if (is_vendor_method_in_use( if (is_vendor_method_in_use(
vendor_class, vendor_class,
mad_reg_req)) mad_reg_req))
goto error4; goto error5;
} }
} }
ret2 = add_oui_reg_req(mad_reg_req, mad_agent_priv); ret2 = add_oui_reg_req(mad_reg_req, mad_agent_priv);
} }
if (ret2) { if (ret2) {
ret = ERR_PTR(ret2); ret = ERR_PTR(ret2);
goto error4; goto error5;
} }
} }
...@@ -418,9 +426,10 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device, ...@@ -418,9 +426,10 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
spin_unlock_irqrestore(&port_priv->reg_lock, flags); spin_unlock_irqrestore(&port_priv->reg_lock, flags);
return &mad_agent_priv->agent; return &mad_agent_priv->agent;
error5:
error4:
spin_unlock_irqrestore(&port_priv->reg_lock, flags); spin_unlock_irqrestore(&port_priv->reg_lock, flags);
ib_mad_agent_security_cleanup(&mad_agent_priv->agent);
error4:
kfree(reg_req); kfree(reg_req);
error3: error3:
kfree(mad_agent_priv); kfree(mad_agent_priv);
...@@ -491,6 +500,7 @@ struct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device, ...@@ -491,6 +500,7 @@ struct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device,
struct ib_mad_agent *ret; struct ib_mad_agent *ret;
struct ib_mad_snoop_private *mad_snoop_priv; struct ib_mad_snoop_private *mad_snoop_priv;
int qpn; int qpn;
int err;
/* Validate parameters */ /* Validate parameters */
if ((is_snooping_sends(mad_snoop_flags) && !snoop_handler) || if ((is_snooping_sends(mad_snoop_flags) && !snoop_handler) ||
...@@ -525,17 +535,25 @@ struct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device, ...@@ -525,17 +535,25 @@ struct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device,
mad_snoop_priv->agent.port_num = port_num; mad_snoop_priv->agent.port_num = port_num;
mad_snoop_priv->mad_snoop_flags = mad_snoop_flags; mad_snoop_priv->mad_snoop_flags = mad_snoop_flags;
init_completion(&mad_snoop_priv->comp); init_completion(&mad_snoop_priv->comp);
err = ib_mad_agent_security_setup(&mad_snoop_priv->agent, qp_type);
if (err) {
ret = ERR_PTR(err);
goto error2;
}
mad_snoop_priv->snoop_index = register_snoop_agent( mad_snoop_priv->snoop_index = register_snoop_agent(
&port_priv->qp_info[qpn], &port_priv->qp_info[qpn],
mad_snoop_priv); mad_snoop_priv);
if (mad_snoop_priv->snoop_index < 0) { if (mad_snoop_priv->snoop_index < 0) {
ret = ERR_PTR(mad_snoop_priv->snoop_index); ret = ERR_PTR(mad_snoop_priv->snoop_index);
goto error2; goto error3;
} }
atomic_set(&mad_snoop_priv->refcount, 1); atomic_set(&mad_snoop_priv->refcount, 1);
return &mad_snoop_priv->agent; return &mad_snoop_priv->agent;
error3:
ib_mad_agent_security_cleanup(&mad_snoop_priv->agent);
error2: error2:
kfree(mad_snoop_priv); kfree(mad_snoop_priv);
error1: error1:
...@@ -581,6 +599,8 @@ static void unregister_mad_agent(struct ib_mad_agent_private *mad_agent_priv) ...@@ -581,6 +599,8 @@ static void unregister_mad_agent(struct ib_mad_agent_private *mad_agent_priv)
deref_mad_agent(mad_agent_priv); deref_mad_agent(mad_agent_priv);
wait_for_completion(&mad_agent_priv->comp); wait_for_completion(&mad_agent_priv->comp);
ib_mad_agent_security_cleanup(&mad_agent_priv->agent);
kfree(mad_agent_priv->reg_req); kfree(mad_agent_priv->reg_req);
kfree(mad_agent_priv); kfree(mad_agent_priv);
} }
...@@ -599,6 +619,8 @@ static void unregister_mad_snoop(struct ib_mad_snoop_private *mad_snoop_priv) ...@@ -599,6 +619,8 @@ static void unregister_mad_snoop(struct ib_mad_snoop_private *mad_snoop_priv)
deref_snoop_agent(mad_snoop_priv); deref_snoop_agent(mad_snoop_priv);
wait_for_completion(&mad_snoop_priv->comp); wait_for_completion(&mad_snoop_priv->comp);
ib_mad_agent_security_cleanup(&mad_snoop_priv->agent);
kfree(mad_snoop_priv); kfree(mad_snoop_priv);
} }
...@@ -1215,12 +1237,16 @@ int ib_post_send_mad(struct ib_mad_send_buf *send_buf, ...@@ -1215,12 +1237,16 @@ int ib_post_send_mad(struct ib_mad_send_buf *send_buf,
/* Walk list of send WRs and post each on send list */ /* Walk list of send WRs and post each on send list */
for (; send_buf; send_buf = next_send_buf) { for (; send_buf; send_buf = next_send_buf) {
mad_send_wr = container_of(send_buf, mad_send_wr = container_of(send_buf,
struct ib_mad_send_wr_private, struct ib_mad_send_wr_private,
send_buf); send_buf);
mad_agent_priv = mad_send_wr->mad_agent_priv; mad_agent_priv = mad_send_wr->mad_agent_priv;
ret = ib_mad_enforce_security(mad_agent_priv,
mad_send_wr->send_wr.pkey_index);
if (ret)
goto error;
if (!send_buf->mad_agent->send_handler || if (!send_buf->mad_agent->send_handler ||
(send_buf->timeout_ms && (send_buf->timeout_ms &&
!send_buf->mad_agent->recv_handler)) { !send_buf->mad_agent->recv_handler)) {
...@@ -1946,6 +1972,14 @@ static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv, ...@@ -1946,6 +1972,14 @@ static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv,
struct ib_mad_send_wr_private *mad_send_wr; struct ib_mad_send_wr_private *mad_send_wr;
struct ib_mad_send_wc mad_send_wc; struct ib_mad_send_wc mad_send_wc;
unsigned long flags; unsigned long flags;
int ret;
ret = ib_mad_enforce_security(mad_agent_priv,
mad_recv_wc->wc->pkey_index);
if (ret) {
ib_free_recv_mad(mad_recv_wc);
deref_mad_agent(mad_agent_priv);
}
INIT_LIST_HEAD(&mad_recv_wc->rmpp_list); INIT_LIST_HEAD(&mad_recv_wc->rmpp_list);
list_add(&mad_recv_wc->recv_buf.list, &mad_recv_wc->rmpp_list); list_add(&mad_recv_wc->recv_buf.list, &mad_recv_wc->rmpp_list);
...@@ -2003,6 +2037,8 @@ static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv, ...@@ -2003,6 +2037,8 @@ static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv,
mad_recv_wc); mad_recv_wc);
deref_mad_agent(mad_agent_priv); deref_mad_agent(mad_agent_priv);
} }
return;
} }
static enum smi_action handle_ib_smi(const struct ib_mad_port_private *port_priv, static enum smi_action handle_ib_smi(const struct ib_mad_port_private *port_priv,
......
This diff is collapsed.
...@@ -1508,6 +1508,10 @@ static int create_qp(struct ib_uverbs_file *file, ...@@ -1508,6 +1508,10 @@ static int create_qp(struct ib_uverbs_file *file,
} }
if (cmd->qp_type != IB_QPT_XRC_TGT) { if (cmd->qp_type != IB_QPT_XRC_TGT) {
ret = ib_create_qp_security(qp, device);
if (ret)
goto err_cb;
qp->real_qp = qp; qp->real_qp = qp;
qp->device = device; qp->device = device;
qp->pd = pd; qp->pd = pd;
...@@ -2002,14 +2006,17 @@ static int modify_qp(struct ib_uverbs_file *file, ...@@ -2002,14 +2006,17 @@ static int modify_qp(struct ib_uverbs_file *file,
if (ret) if (ret)
goto release_qp; goto release_qp;
} }
ret = qp->device->modify_qp(qp, attr, ret = ib_security_modify_qp(qp,
attr,
modify_qp_mask(qp->qp_type, modify_qp_mask(qp->qp_type,
cmd->base.attr_mask), cmd->base.attr_mask),
udata); udata);
} else { } else {
ret = ib_modify_qp(qp, attr, ret = ib_security_modify_qp(qp,
modify_qp_mask(qp->qp_type, attr,
cmd->base.attr_mask)); modify_qp_mask(qp->qp_type,
cmd->base.attr_mask),
NULL);
} }
release_qp: release_qp:
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include <linux/in.h> #include <linux/in.h>
#include <linux/in6.h> #include <linux/in6.h>
#include <net/addrconf.h> #include <net/addrconf.h>
#include <linux/security.h>
#include <rdma/ib_verbs.h> #include <rdma/ib_verbs.h>
#include <rdma/ib_cache.h> #include <rdma/ib_cache.h>
...@@ -713,11 +714,19 @@ static struct ib_qp *__ib_open_qp(struct ib_qp *real_qp, ...@@ -713,11 +714,19 @@ static struct ib_qp *__ib_open_qp(struct ib_qp *real_qp,
{ {
struct ib_qp *qp; struct ib_qp *qp;
unsigned long flags; unsigned long flags;
int err;
qp = kzalloc(sizeof *qp, GFP_KERNEL); qp = kzalloc(sizeof *qp, GFP_KERNEL);
if (!qp) if (!qp)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
qp->real_qp = real_qp;
err = ib_open_shared_qp_security(qp, real_qp->device);
if (err) {
kfree(qp);
return ERR_PTR(err);
}
qp->real_qp = real_qp; qp->real_qp = real_qp;
atomic_inc(&real_qp->usecnt); atomic_inc(&real_qp->usecnt);
qp->device = real_qp->device; qp->device = real_qp->device;
...@@ -804,6 +813,12 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd, ...@@ -804,6 +813,12 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
if (IS_ERR(qp)) if (IS_ERR(qp))
return qp; return qp;
ret = ib_create_qp_security(qp, device);
if (ret) {
ib_destroy_qp(qp);
return ERR_PTR(ret);
}
qp->device = device; qp->device = device;
qp->real_qp = qp; qp->real_qp = qp;
qp->uobject = NULL; qp->uobject = NULL;
...@@ -1266,7 +1281,7 @@ int ib_modify_qp(struct ib_qp *qp, ...@@ -1266,7 +1281,7 @@ int ib_modify_qp(struct ib_qp *qp,
return ret; return ret;
} }
return qp->device->modify_qp(qp->real_qp, qp_attr, qp_attr_mask, NULL); return ib_security_modify_qp(qp->real_qp, qp_attr, qp_attr_mask, NULL);
} }
EXPORT_SYMBOL(ib_modify_qp); EXPORT_SYMBOL(ib_modify_qp);
...@@ -1295,6 +1310,7 @@ int ib_close_qp(struct ib_qp *qp) ...@@ -1295,6 +1310,7 @@ int ib_close_qp(struct ib_qp *qp)
spin_unlock_irqrestore(&real_qp->device->event_handler_lock, flags); spin_unlock_irqrestore(&real_qp->device->event_handler_lock, flags);
atomic_dec(&real_qp->usecnt); atomic_dec(&real_qp->usecnt);
ib_close_shared_qp_security(qp->qp_sec);
kfree(qp); kfree(qp);
return 0; return 0;
...@@ -1335,6 +1351,7 @@ int ib_destroy_qp(struct ib_qp *qp) ...@@ -1335,6 +1351,7 @@ int ib_destroy_qp(struct ib_qp *qp)
struct ib_cq *scq, *rcq; struct ib_cq *scq, *rcq;
struct ib_srq *srq; struct ib_srq *srq;
struct ib_rwq_ind_table *ind_tbl; struct ib_rwq_ind_table *ind_tbl;
struct ib_qp_security *sec;
int ret; int ret;
WARN_ON_ONCE(qp->mrs_used > 0); WARN_ON_ONCE(qp->mrs_used > 0);
...@@ -1350,6 +1367,9 @@ int ib_destroy_qp(struct ib_qp *qp) ...@@ -1350,6 +1367,9 @@ int ib_destroy_qp(struct ib_qp *qp)
rcq = qp->recv_cq; rcq = qp->recv_cq;
srq = qp->srq; srq = qp->srq;
ind_tbl = qp->rwq_ind_tbl; ind_tbl = qp->rwq_ind_tbl;
sec = qp->qp_sec;
if (sec)
ib_destroy_qp_security_begin(sec);
if (!qp->uobject) if (!qp->uobject)
rdma_rw_cleanup_mrs(qp); rdma_rw_cleanup_mrs(qp);
...@@ -1366,6 +1386,11 @@ int ib_destroy_qp(struct ib_qp *qp) ...@@ -1366,6 +1386,11 @@ int ib_destroy_qp(struct ib_qp *qp)
atomic_dec(&srq->usecnt); atomic_dec(&srq->usecnt);
if (ind_tbl) if (ind_tbl)
atomic_dec(&ind_tbl->usecnt); atomic_dec(&ind_tbl->usecnt);
if (sec)
ib_destroy_qp_security_end(sec);
} else {
if (sec)
ib_destroy_qp_security_abort(sec);
} }
return ret; return ret;
......
...@@ -2545,10 +2545,25 @@ EXPORT_SYMBOL_GPL(nfs_set_sb_security); ...@@ -2545,10 +2545,25 @@ EXPORT_SYMBOL_GPL(nfs_set_sb_security);
int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot, int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
struct nfs_mount_info *mount_info) struct nfs_mount_info *mount_info)
{ {
int error;
unsigned long kflags = 0, kflags_out = 0;
/* clone any lsm security options from the parent to the new sb */ /* clone any lsm security options from the parent to the new sb */
if (d_inode(mntroot)->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) if (d_inode(mntroot)->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
return -ESTALE; return -ESTALE;
return security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
if (NFS_SB(s)->caps & NFS_CAP_SECURITY_LABEL)
kflags |= SECURITY_LSM_NATIVE_LABELS;
error = security_sb_clone_mnt_opts(mount_info->cloned->sb, s, kflags,
&kflags_out);
if (error)
return error;
if (NFS_SB(s)->caps & NFS_CAP_SECURITY_LABEL &&
!(kflags_out & SECURITY_LSM_NATIVE_LABELS))
NFS_SB(s)->caps &= ~NFS_CAP_SECURITY_LABEL;
return 0;
} }
EXPORT_SYMBOL_GPL(nfs_clone_sb_security); EXPORT_SYMBOL_GPL(nfs_clone_sb_security);
......
...@@ -75,11 +75,17 @@ static inline void ima_add_kexec_buffer(struct kimage *image) ...@@ -75,11 +75,17 @@ static inline void ima_add_kexec_buffer(struct kimage *image)
#endif #endif
#ifdef CONFIG_IMA_APPRAISE #ifdef CONFIG_IMA_APPRAISE
extern bool is_ima_appraise_enabled(void);
extern void ima_inode_post_setattr(struct dentry *dentry); extern void ima_inode_post_setattr(struct dentry *dentry);
extern int ima_inode_setxattr(struct dentry *dentry, const char *xattr_name, extern int ima_inode_setxattr(struct dentry *dentry, const char *xattr_name,
const void *xattr_value, size_t xattr_value_len); const void *xattr_value, size_t xattr_value_len);
extern int ima_inode_removexattr(struct dentry *dentry, const char *xattr_name); extern int ima_inode_removexattr(struct dentry *dentry, const char *xattr_name);
#else #else
static inline bool is_ima_appraise_enabled(void)
{
return 0;
}
static inline void ima_inode_post_setattr(struct dentry *dentry) static inline void ima_inode_post_setattr(struct dentry *dentry)
{ {
return; return;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/path.h> #include <linux/path.h>
#include <linux/key.h> #include <linux/key.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <rdma/ib_verbs.h>
struct lsm_network_audit { struct lsm_network_audit {
int netif; int netif;
...@@ -45,6 +46,16 @@ struct lsm_ioctlop_audit { ...@@ -45,6 +46,16 @@ struct lsm_ioctlop_audit {
u16 cmd; u16 cmd;
}; };
struct lsm_ibpkey_audit {
u64 subnet_prefix;
u16 pkey;
};
struct lsm_ibendport_audit {
char dev_name[IB_DEVICE_NAME_MAX];
u8 port;
};
/* Auxiliary data to use in generating the audit record. */ /* Auxiliary data to use in generating the audit record. */
struct common_audit_data { struct common_audit_data {
char type; char type;
...@@ -60,6 +71,8 @@ struct common_audit_data { ...@@ -60,6 +71,8 @@ struct common_audit_data {
#define LSM_AUDIT_DATA_DENTRY 10 #define LSM_AUDIT_DATA_DENTRY 10
#define LSM_AUDIT_DATA_IOCTL_OP 11 #define LSM_AUDIT_DATA_IOCTL_OP 11
#define LSM_AUDIT_DATA_FILE 12 #define LSM_AUDIT_DATA_FILE 12
#define LSM_AUDIT_DATA_IBPKEY 13
#define LSM_AUDIT_DATA_IBENDPORT 14
union { union {
struct path path; struct path path;
struct dentry *dentry; struct dentry *dentry;
...@@ -77,6 +90,8 @@ struct common_audit_data { ...@@ -77,6 +90,8 @@ struct common_audit_data {
char *kmod_name; char *kmod_name;
struct lsm_ioctlop_audit *op; struct lsm_ioctlop_audit *op;
struct file *file; struct file *file;
struct lsm_ibpkey_audit *ibpkey;
struct lsm_ibendport_audit *ibendport;
} u; } u;
/* this union contains LSM specific data */ /* this union contains LSM specific data */
union { union {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
* Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group) * Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group)
* Copyright (C) 2015 Intel Corporation. * Copyright (C) 2015 Intel Corporation.
* Copyright (C) 2015 Casey Schaufler <casey@schaufler-ca.com> * Copyright (C) 2015 Casey Schaufler <casey@schaufler-ca.com>
* Copyright (C) 2016 Mellanox Techonologies
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -912,6 +913,26 @@ ...@@ -912,6 +913,26 @@
* associated with the TUN device's security structure. * associated with the TUN device's security structure.
* @security pointer to the TUN devices's security structure. * @security pointer to the TUN devices's security structure.
* *
* Security hooks for Infiniband
*
* @ib_pkey_access:
* Check permission to access a pkey when modifing a QP.
* @subnet_prefix the subnet prefix of the port being used.
* @pkey the pkey to be accessed.
* @sec pointer to a security structure.
* @ib_endport_manage_subnet:
* Check permissions to send and receive SMPs on a end port.
* @dev_name the IB device name (i.e. mlx4_0).
* @port_num the port number.
* @sec pointer to a security structure.
* @ib_alloc_security:
* Allocate a security structure for Infiniband objects.
* @sec pointer to a security structure pointer.
* Returns 0 on success, non-zero on failure
* @ib_free_security:
* Deallocate an Infiniband security structure.
* @sec contains the security structure to be freed.
*
* Security hooks for XFRM operations. * Security hooks for XFRM operations.
* *
* @xfrm_policy_alloc_security: * @xfrm_policy_alloc_security:
...@@ -1387,7 +1408,9 @@ union security_list_options { ...@@ -1387,7 +1408,9 @@ union security_list_options {
unsigned long kern_flags, unsigned long kern_flags,
unsigned long *set_kern_flags); unsigned long *set_kern_flags);
int (*sb_clone_mnt_opts)(const struct super_block *oldsb, int (*sb_clone_mnt_opts)(const struct super_block *oldsb,
struct super_block *newsb); struct super_block *newsb,
unsigned long kern_flags,
unsigned long *set_kern_flags);
int (*sb_parse_opts_str)(char *options, struct security_mnt_opts *opts); int (*sb_parse_opts_str)(char *options, struct security_mnt_opts *opts);
int (*dentry_init_security)(struct dentry *dentry, int mode, int (*dentry_init_security)(struct dentry *dentry, int mode,
const struct qstr *name, void **ctx, const struct qstr *name, void **ctx,
...@@ -1619,6 +1642,14 @@ union security_list_options { ...@@ -1619,6 +1642,14 @@ union security_list_options {
int (*tun_dev_open)(void *security); int (*tun_dev_open)(void *security);
#endif /* CONFIG_SECURITY_NETWORK */ #endif /* CONFIG_SECURITY_NETWORK */
#ifdef CONFIG_SECURITY_INFINIBAND
int (*ib_pkey_access)(void *sec, u64 subnet_prefix, u16 pkey);
int (*ib_endport_manage_subnet)(void *sec, const char *dev_name,
u8 port_num);
int (*ib_alloc_security)(void **sec);
void (*ib_free_security)(void *sec);
#endif /* CONFIG_SECURITY_INFINIBAND */
#ifdef CONFIG_SECURITY_NETWORK_XFRM #ifdef CONFIG_SECURITY_NETWORK_XFRM
int (*xfrm_policy_alloc_security)(struct xfrm_sec_ctx **ctxp, int (*xfrm_policy_alloc_security)(struct xfrm_sec_ctx **ctxp,
struct xfrm_user_sec_ctx *sec_ctx, struct xfrm_user_sec_ctx *sec_ctx,
...@@ -1850,6 +1881,12 @@ struct security_hook_heads { ...@@ -1850,6 +1881,12 @@ struct security_hook_heads {
struct list_head tun_dev_attach; struct list_head tun_dev_attach;
struct list_head tun_dev_open; struct list_head tun_dev_open;
#endif /* CONFIG_SECURITY_NETWORK */ #endif /* CONFIG_SECURITY_NETWORK */
#ifdef CONFIG_SECURITY_INFINIBAND
struct list_head ib_pkey_access;
struct list_head ib_endport_manage_subnet;
struct list_head ib_alloc_security;
struct list_head ib_free_security;
#endif /* CONFIG_SECURITY_INFINIBAND */
#ifdef CONFIG_SECURITY_NETWORK_XFRM #ifdef CONFIG_SECURITY_NETWORK_XFRM
struct list_head xfrm_policy_alloc_security; struct list_head xfrm_policy_alloc_security;
struct list_head xfrm_policy_clone_security; struct list_head xfrm_policy_clone_security;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com> * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
* Copyright (C) 2001 James Morris <jmorris@intercode.com.au> * Copyright (C) 2001 James Morris <jmorris@intercode.com.au>
* Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group) * Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group)
* Copyright (C) 2016 Mellanox Techonologies
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -68,6 +69,10 @@ struct audit_krule; ...@@ -68,6 +69,10 @@ struct audit_krule;
struct user_namespace; struct user_namespace;
struct timezone; struct timezone;
enum lsm_event {
LSM_POLICY_CHANGE,
};
/* These functions are in security/commoncap.c */ /* These functions are in security/commoncap.c */
extern int cap_capable(const struct cred *cred, struct user_namespace *ns, extern int cap_capable(const struct cred *cred, struct user_namespace *ns,
int cap, int audit); int cap, int audit);
...@@ -163,6 +168,10 @@ struct security_mnt_opts { ...@@ -163,6 +168,10 @@ struct security_mnt_opts {
int num_mnt_opts; int num_mnt_opts;
}; };
int call_lsm_notifier(enum lsm_event event, void *data);
int register_lsm_notifier(struct notifier_block *nb);
int unregister_lsm_notifier(struct notifier_block *nb);
static inline void security_init_mnt_opts(struct security_mnt_opts *opts) static inline void security_init_mnt_opts(struct security_mnt_opts *opts)
{ {
opts->mnt_opts = NULL; opts->mnt_opts = NULL;
...@@ -240,7 +249,9 @@ int security_sb_set_mnt_opts(struct super_block *sb, ...@@ -240,7 +249,9 @@ int security_sb_set_mnt_opts(struct super_block *sb,
unsigned long kern_flags, unsigned long kern_flags,
unsigned long *set_kern_flags); unsigned long *set_kern_flags);
int security_sb_clone_mnt_opts(const struct super_block *oldsb, int security_sb_clone_mnt_opts(const struct super_block *oldsb,
struct super_block *newsb); struct super_block *newsb,
unsigned long kern_flags,
unsigned long *set_kern_flags);
int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts); int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts);
int security_dentry_init_security(struct dentry *dentry, int mode, int security_dentry_init_security(struct dentry *dentry, int mode,
const struct qstr *name, void **ctx, const struct qstr *name, void **ctx,
...@@ -381,6 +392,21 @@ int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen); ...@@ -381,6 +392,21 @@ int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen);
struct security_mnt_opts { struct security_mnt_opts {
}; };
static inline int call_lsm_notifier(enum lsm_event event, void *data)
{
return 0;
}
static inline int register_lsm_notifier(struct notifier_block *nb)
{
return 0;
}
static inline int unregister_lsm_notifier(struct notifier_block *nb)
{
return 0;
}
static inline void security_init_mnt_opts(struct security_mnt_opts *opts) static inline void security_init_mnt_opts(struct security_mnt_opts *opts)
{ {
} }
...@@ -581,7 +607,9 @@ static inline int security_sb_set_mnt_opts(struct super_block *sb, ...@@ -581,7 +607,9 @@ static inline int security_sb_set_mnt_opts(struct super_block *sb,
} }
static inline int security_sb_clone_mnt_opts(const struct super_block *oldsb, static inline int security_sb_clone_mnt_opts(const struct super_block *oldsb,
struct super_block *newsb) struct super_block *newsb,
unsigned long kern_flags,
unsigned long *set_kern_flags)
{ {
return 0; return 0;
} }
...@@ -1406,6 +1434,32 @@ static inline int security_tun_dev_open(void *security) ...@@ -1406,6 +1434,32 @@ static inline int security_tun_dev_open(void *security)
} }
#endif /* CONFIG_SECURITY_NETWORK */ #endif /* CONFIG_SECURITY_NETWORK */
#ifdef CONFIG_SECURITY_INFINIBAND
int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey);
int security_ib_endport_manage_subnet(void *sec, const char *name, u8 port_num);
int security_ib_alloc_security(void **sec);
void security_ib_free_security(void *sec);
#else /* CONFIG_SECURITY_INFINIBAND */
static inline int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey)
{
return 0;
}
static inline int security_ib_endport_manage_subnet(void *sec, const char *dev_name, u8 port_num)
{
return 0;
}
static inline int security_ib_alloc_security(void **sec)
{
return 0;
}
static inline void security_ib_free_security(void *sec)
{
}
#endif /* CONFIG_SECURITY_INFINIBAND */
#ifdef CONFIG_SECURITY_NETWORK_XFRM #ifdef CONFIG_SECURITY_NETWORK_XFRM
int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
...@@ -1651,6 +1705,10 @@ extern struct dentry *securityfs_create_file(const char *name, umode_t mode, ...@@ -1651,6 +1705,10 @@ extern struct dentry *securityfs_create_file(const char *name, umode_t mode,
struct dentry *parent, void *data, struct dentry *parent, void *data,
const struct file_operations *fops); const struct file_operations *fops);
extern struct dentry *securityfs_create_dir(const char *name, struct dentry *parent); extern struct dentry *securityfs_create_dir(const char *name, struct dentry *parent);
struct dentry *securityfs_create_symlink(const char *name,
struct dentry *parent,
const char *target,
const struct inode_operations *iops);
extern void securityfs_remove(struct dentry *dentry); extern void securityfs_remove(struct dentry *dentry);
#else /* CONFIG_SECURITYFS */ #else /* CONFIG_SECURITYFS */
...@@ -1670,6 +1728,14 @@ static inline struct dentry *securityfs_create_file(const char *name, ...@@ -1670,6 +1728,14 @@ static inline struct dentry *securityfs_create_file(const char *name,
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
} }
static inline struct dentry *securityfs_create_symlink(const char *name,
struct dentry *parent,
const char *target,
const struct inode_operations *iops)
{
return ERR_PTR(-ENODEV);
}
static inline void securityfs_remove(struct dentry *dentry) static inline void securityfs_remove(struct dentry *dentry)
{} {}
......
...@@ -575,6 +575,10 @@ struct ib_mad_agent { ...@@ -575,6 +575,10 @@ struct ib_mad_agent {
u32 flags; u32 flags;
u8 port_num; u8 port_num;
u8 rmpp_version; u8 rmpp_version;
void *security;
bool smp_allowed;
bool lsm_nb_reg;
struct notifier_block lsm_nb;
}; };
/** /**
......
...@@ -1614,6 +1614,45 @@ struct ib_rwq_ind_table_init_attr { ...@@ -1614,6 +1614,45 @@ struct ib_rwq_ind_table_init_attr {
struct ib_wq **ind_tbl; struct ib_wq **ind_tbl;
}; };
enum port_pkey_state {
IB_PORT_PKEY_NOT_VALID = 0,
IB_PORT_PKEY_VALID = 1,
IB_PORT_PKEY_LISTED = 2,
};
struct ib_qp_security;
struct ib_port_pkey {
enum port_pkey_state state;
u16 pkey_index;
u8 port_num;
struct list_head qp_list;
struct list_head to_error_list;
struct ib_qp_security *sec;
};
struct ib_ports_pkeys {
struct ib_port_pkey main;
struct ib_port_pkey alt;
};
struct ib_qp_security {
struct ib_qp *qp;
struct ib_device *dev;
/* Hold this mutex when changing port and pkey settings. */
struct mutex mutex;
struct ib_ports_pkeys *ports_pkeys;
/* A list of all open shared QP handles. Required to enforce security
* properly for all users of a shared QP.
*/
struct list_head shared_qp_list;
void *security;
bool destroying;
atomic_t error_list_count;
struct completion error_complete;
int error_comps_pending;
};
/* /*
* @max_write_sge: Maximum SGE elements per RDMA WRITE request. * @max_write_sge: Maximum SGE elements per RDMA WRITE request.
* @max_read_sge: Maximum SGE elements per RDMA READ request. * @max_read_sge: Maximum SGE elements per RDMA READ request.
...@@ -1643,6 +1682,7 @@ struct ib_qp { ...@@ -1643,6 +1682,7 @@ struct ib_qp {
u32 max_read_sge; u32 max_read_sge;
enum ib_qp_type qp_type; enum ib_qp_type qp_type;
struct ib_rwq_ind_table *rwq_ind_tbl; struct ib_rwq_ind_table *rwq_ind_tbl;
struct ib_qp_security *qp_sec;
}; };
struct ib_mr { struct ib_mr {
...@@ -1891,6 +1931,7 @@ enum ib_mad_result { ...@@ -1891,6 +1931,7 @@ enum ib_mad_result {
}; };
struct ib_port_cache { struct ib_port_cache {
u64 subnet_prefix;
struct ib_pkey_cache *pkey; struct ib_pkey_cache *pkey;
struct ib_gid_table *gid; struct ib_gid_table *gid;
u8 lmc; u8 lmc;
...@@ -1940,6 +1981,12 @@ struct rdma_netdev { ...@@ -1940,6 +1981,12 @@ struct rdma_netdev {
union ib_gid *gid, u16 mlid); union ib_gid *gid, u16 mlid);
}; };
struct ib_port_pkey_list {
/* Lock to hold while modifying the list. */
spinlock_t list_lock;
struct list_head pkey_list;
};
struct ib_device { struct ib_device {
/* Do not access @dma_device directly from ULP nor from HW drivers. */ /* Do not access @dma_device directly from ULP nor from HW drivers. */
struct device *dma_device; struct device *dma_device;
...@@ -1963,6 +2010,8 @@ struct ib_device { ...@@ -1963,6 +2010,8 @@ struct ib_device {
int num_comp_vectors; int num_comp_vectors;
struct ib_port_pkey_list *port_pkey_list;
struct iw_cm_verbs *iwcm; struct iw_cm_verbs *iwcm;
/** /**
......
...@@ -80,6 +80,8 @@ ...@@ -80,6 +80,8 @@
#define BTRFS_TEST_MAGIC 0x73727279 #define BTRFS_TEST_MAGIC 0x73727279
#define NSFS_MAGIC 0x6e736673 #define NSFS_MAGIC 0x6e736673
#define BPF_FS_MAGIC 0xcafe4a11 #define BPF_FS_MAGIC 0xcafe4a11
#define AAFS_MAGIC 0x5a3c69f0
/* Since UDF 2.01 is ISO 13346 based... */ /* Since UDF 2.01 is ISO 13346 based... */
#define UDF_SUPER_MAGIC 0x15013346 #define UDF_SUPER_MAGIC 0x15013346
#define BALLOON_KVM_MAGIC 0x13661366 #define BALLOON_KVM_MAGIC 0x13661366
......
...@@ -46,4 +46,8 @@ struct vtpm_proxy_new_dev { ...@@ -46,4 +46,8 @@ struct vtpm_proxy_new_dev {
#define VTPM_PROXY_IOC_NEW_DEV _IOWR(0xa1, 0x00, struct vtpm_proxy_new_dev) #define VTPM_PROXY_IOC_NEW_DEV _IOWR(0xa1, 0x00, struct vtpm_proxy_new_dev)
/* vendor specific commands to set locality */
#define TPM2_CC_SET_LOCALITY 0x20001000
#define TPM_ORD_SET_LOCALITY 0x20001000
#endif /* _UAPI_LINUX_VTPM_PROXY_H */ #endif /* _UAPI_LINUX_VTPM_PROXY_H */
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* of Berkeley Packet Filters/Linux Socket Filters. * of Berkeley Packet Filters/Linux Socket Filters.
*/ */
#include <linux/atomic.h> #include <linux/refcount.h>
#include <linux/audit.h> #include <linux/audit.h>
#include <linux/compat.h> #include <linux/compat.h>
#include <linux/coredump.h> #include <linux/coredump.h>
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
* to a task_struct (other than @usage). * to a task_struct (other than @usage).
*/ */
struct seccomp_filter { struct seccomp_filter {
atomic_t usage; refcount_t usage;
struct seccomp_filter *prev; struct seccomp_filter *prev;
struct bpf_prog *prog; struct bpf_prog *prog;
}; };
...@@ -378,7 +378,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog) ...@@ -378,7 +378,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
return ERR_PTR(ret); return ERR_PTR(ret);
} }
atomic_set(&sfilter->usage, 1); refcount_set(&sfilter->usage, 1);
return sfilter; return sfilter;
} }
...@@ -465,7 +465,7 @@ void get_seccomp_filter(struct task_struct *tsk) ...@@ -465,7 +465,7 @@ void get_seccomp_filter(struct task_struct *tsk)
if (!orig) if (!orig)
return; return;
/* Reference count is bounded by the number of total processes. */ /* Reference count is bounded by the number of total processes. */
atomic_inc(&orig->usage); refcount_inc(&orig->usage);
} }
static inline void seccomp_filter_free(struct seccomp_filter *filter) static inline void seccomp_filter_free(struct seccomp_filter *filter)
...@@ -481,7 +481,7 @@ void put_seccomp_filter(struct task_struct *tsk) ...@@ -481,7 +481,7 @@ void put_seccomp_filter(struct task_struct *tsk)
{ {
struct seccomp_filter *orig = tsk->seccomp.filter; struct seccomp_filter *orig = tsk->seccomp.filter;
/* Clean up single-reference branches iteratively. */ /* Clean up single-reference branches iteratively. */
while (orig && atomic_dec_and_test(&orig->usage)) { while (orig && refcount_dec_and_test(&orig->usage)) {
struct seccomp_filter *freeme = orig; struct seccomp_filter *freeme = orig;
orig = orig->prev; orig = orig->prev;
seccomp_filter_free(freeme); seccomp_filter_free(freeme);
...@@ -641,11 +641,12 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd, ...@@ -641,11 +641,12 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
return 0; return 0;
case SECCOMP_RET_KILL: case SECCOMP_RET_KILL:
default: { default:
siginfo_t info;
audit_seccomp(this_syscall, SIGSYS, action); audit_seccomp(this_syscall, SIGSYS, action);
/* Dump core only if this is the last remaining thread. */ /* Dump core only if this is the last remaining thread. */
if (get_nr_threads(current) == 1) { if (get_nr_threads(current) == 1) {
siginfo_t info;
/* Show the original registers in the dump. */ /* Show the original registers in the dump. */
syscall_rollback(current, task_pt_regs(current)); syscall_rollback(current, task_pt_regs(current));
/* Trigger a manual coredump since do_exit skips it. */ /* Trigger a manual coredump since do_exit skips it. */
...@@ -654,7 +655,6 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd, ...@@ -654,7 +655,6 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
} }
do_exit(SIGSYS); do_exit(SIGSYS);
} }
}
unreachable(); unreachable();
......
...@@ -54,6 +54,15 @@ config SECURITY_NETWORK ...@@ -54,6 +54,15 @@ config SECURITY_NETWORK
implement socket and networking access controls. implement socket and networking access controls.
If you are unsure how to answer this question, answer N. If you are unsure how to answer this question, answer N.
config SECURITY_INFINIBAND
bool "Infiniband Security Hooks"
depends on SECURITY && INFINIBAND
help
This enables the Infiniband security hooks.
If enabled, a security module can use these hooks to
implement Infiniband access controls.
If you are unsure how to answer this question, answer N.
config SECURITY_NETWORK_XFRM config SECURITY_NETWORK_XFRM
bool "XFRM (IPSec) Networking Security Hooks" bool "XFRM (IPSec) Networking Security Hooks"
depends on XFRM && SECURITY_NETWORK depends on XFRM && SECURITY_NETWORK
...@@ -139,7 +148,7 @@ config HARDENED_USERCOPY ...@@ -139,7 +148,7 @@ config HARDENED_USERCOPY
copying memory to/from the kernel (via copy_to_user() and copying memory to/from the kernel (via copy_to_user() and
copy_from_user() functions) by rejecting memory ranges that copy_from_user() functions) by rejecting memory ranges that
are larger than the specified heap object, span multiple are larger than the specified heap object, span multiple
separately allocates pages, are not on the process stack, separately allocated pages, are not on the process stack,
or are part of the kernel text. This kills entire classes or are part of the kernel text. This kills entire classes
of heap overflow exploits and similar kernel memory exposures. of heap overflow exploits and similar kernel memory exposures.
......
...@@ -4,7 +4,7 @@ obj-$(CONFIG_SECURITY_APPARMOR) += apparmor.o ...@@ -4,7 +4,7 @@ obj-$(CONFIG_SECURITY_APPARMOR) += apparmor.o
apparmor-y := apparmorfs.o audit.o capability.o context.o ipc.o lib.o match.o \ apparmor-y := apparmorfs.o audit.o capability.o context.o ipc.o lib.o match.o \
path.o domain.o policy.o policy_unpack.o procattr.o lsm.o \ path.o domain.o policy.o policy_unpack.o procattr.o lsm.o \
resource.o secid.o file.o policy_ns.o resource.o secid.o file.o policy_ns.o label.o
apparmor-$(CONFIG_SECURITY_APPARMOR_HASH) += crypto.o apparmor-$(CONFIG_SECURITY_APPARMOR_HASH) += crypto.o
clean-files := capability_names.h rlim_names.h clean-files := capability_names.h rlim_names.h
...@@ -20,7 +20,7 @@ cmd_make-caps = echo "static const char *const capability_names[] = {" > $@ ;\ ...@@ -20,7 +20,7 @@ cmd_make-caps = echo "static const char *const capability_names[] = {" > $@ ;\
sed $< >>$@ -r -n -e '/CAP_FS_MASK/d' \ sed $< >>$@ -r -n -e '/CAP_FS_MASK/d' \
-e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/[\2] = "\L\1",/p';\ -e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/[\2] = "\L\1",/p';\
echo "};" >> $@ ;\ echo "};" >> $@ ;\
echo -n '\#define AA_FS_CAPS_MASK "' >> $@ ;\ printf '%s' '\#define AA_SFS_CAPS_MASK "' >> $@ ;\
sed $< -r -n -e '/CAP_FS_MASK/d' \ sed $< -r -n -e '/CAP_FS_MASK/d' \
-e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/\L\1/p' | \ -e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/\L\1/p' | \
tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@ tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
...@@ -46,7 +46,7 @@ cmd_make-caps = echo "static const char *const capability_names[] = {" > $@ ;\ ...@@ -46,7 +46,7 @@ cmd_make-caps = echo "static const char *const capability_names[] = {" > $@ ;\
# #define RLIMIT_FSIZE 1 /* Maximum filesize */ # #define RLIMIT_FSIZE 1 /* Maximum filesize */
# #define RLIMIT_STACK 3 /* max stack size */ # #define RLIMIT_STACK 3 /* max stack size */
# to # to
# #define AA_FS_RLIMIT_MASK "fsize stack" # #define AA_SFS_RLIMIT_MASK "fsize stack"
quiet_cmd_make-rlim = GEN $@ quiet_cmd_make-rlim = GEN $@
cmd_make-rlim = echo "static const char *const rlim_names[RLIM_NLIMITS] = {" \ cmd_make-rlim = echo "static const char *const rlim_names[RLIM_NLIMITS] = {" \
> $@ ;\ > $@ ;\
...@@ -56,7 +56,7 @@ cmd_make-rlim = echo "static const char *const rlim_names[RLIM_NLIMITS] = {" \ ...@@ -56,7 +56,7 @@ cmd_make-rlim = echo "static const char *const rlim_names[RLIM_NLIMITS] = {" \
echo "static const int rlim_map[RLIM_NLIMITS] = {" >> $@ ;\ echo "static const int rlim_map[RLIM_NLIMITS] = {" >> $@ ;\
sed -r -n "s/^\# ?define[ \t]+(RLIMIT_[A-Z0-9_]+).*/\1,/p" $< >> $@ ;\ sed -r -n "s/^\# ?define[ \t]+(RLIMIT_[A-Z0-9_]+).*/\1,/p" $< >> $@ ;\
echo "};" >> $@ ; \ echo "};" >> $@ ; \
echo -n '\#define AA_FS_RLIMIT_MASK "' >> $@ ;\ printf '%s' '\#define AA_SFS_RLIMIT_MASK "' >> $@ ;\
sed -r -n 's/^\# ?define[ \t]+RLIMIT_([A-Z0-9_]+).*/\L\1/p' $< | \ sed -r -n 's/^\# ?define[ \t]+RLIMIT_([A-Z0-9_]+).*/\L\1/p' $< | \
tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@ tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
......
This diff is collapsed.
...@@ -77,14 +77,24 @@ static void audit_pre(struct audit_buffer *ab, void *ca) ...@@ -77,14 +77,24 @@ static void audit_pre(struct audit_buffer *ab, void *ca)
audit_log_format(ab, " error=%d", aad(sa)->error); audit_log_format(ab, " error=%d", aad(sa)->error);
} }
if (aad(sa)->profile) { if (aad(sa)->label) {
struct aa_profile *profile = aad(sa)->profile; struct aa_label *label = aad(sa)->label;
if (profile->ns != root_ns) {
audit_log_format(ab, " namespace="); if (label_isprofile(label)) {
audit_log_untrustedstring(ab, profile->ns->base.hname); struct aa_profile *profile = labels_profile(label);
if (profile->ns != root_ns) {
audit_log_format(ab, " namespace=");
audit_log_untrustedstring(ab,
profile->ns->base.hname);
}
audit_log_format(ab, " profile=");
audit_log_untrustedstring(ab, profile->base.hname);
} else {
audit_log_format(ab, " label=");
aa_label_xaudit(ab, root_ns, label, FLAG_VIEW_SUBNS,
GFP_ATOMIC);
} }
audit_log_format(ab, " profile=");
audit_log_untrustedstring(ab, profile->base.hname);
} }
if (aad(sa)->name) { if (aad(sa)->name) {
...@@ -139,8 +149,7 @@ int aa_audit(int type, struct aa_profile *profile, struct common_audit_data *sa, ...@@ -139,8 +149,7 @@ int aa_audit(int type, struct aa_profile *profile, struct common_audit_data *sa,
if (KILL_MODE(profile) && type == AUDIT_APPARMOR_DENIED) if (KILL_MODE(profile) && type == AUDIT_APPARMOR_DENIED)
type = AUDIT_APPARMOR_KILL; type = AUDIT_APPARMOR_KILL;
if (!unconfined(profile)) aad(sa)->label = &profile->label;
aad(sa)->profile = profile;
aa_audit_msg(type, sa, cb); aa_audit_msg(type, sa, cb);
......
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
*/ */
#include "capability_names.h" #include "capability_names.h"
struct aa_fs_entry aa_fs_entry_caps[] = { struct aa_sfs_entry aa_sfs_entry_caps[] = {
AA_FS_FILE_STRING("mask", AA_FS_CAPS_MASK), AA_SFS_FILE_STRING("mask", AA_SFS_CAPS_MASK),
{ } { }
}; };
...@@ -48,15 +48,16 @@ static DEFINE_PER_CPU(struct audit_cache, audit_cache); ...@@ -48,15 +48,16 @@ static DEFINE_PER_CPU(struct audit_cache, audit_cache);
static void audit_cb(struct audit_buffer *ab, void *va) static void audit_cb(struct audit_buffer *ab, void *va)
{ {
struct common_audit_data *sa = va; struct common_audit_data *sa = va;
audit_log_format(ab, " capname="); audit_log_format(ab, " capname=");
audit_log_untrustedstring(ab, capability_names[sa->u.cap]); audit_log_untrustedstring(ab, capability_names[sa->u.cap]);
} }
/** /**
* audit_caps - audit a capability * audit_caps - audit a capability
* @sa: audit data
* @profile: profile being tested for confinement (NOT NULL) * @profile: profile being tested for confinement (NOT NULL)
* @cap: capability tested * @cap: capability tested
@audit: whether an audit record should be generated
* @error: error code returned by test * @error: error code returned by test
* *
* Do auditing of capability and handle, audit/complain/kill modes switching * Do auditing of capability and handle, audit/complain/kill modes switching
...@@ -64,16 +65,13 @@ static void audit_cb(struct audit_buffer *ab, void *va) ...@@ -64,16 +65,13 @@ static void audit_cb(struct audit_buffer *ab, void *va)
* *
* Returns: 0 or sa->error on success, error code on failure * Returns: 0 or sa->error on success, error code on failure
*/ */
static int audit_caps(struct aa_profile *profile, int cap, int audit, static int audit_caps(struct common_audit_data *sa, struct aa_profile *profile,
int error) int cap, int error)
{ {
struct audit_cache *ent; struct audit_cache *ent;
int type = AUDIT_APPARMOR_AUTO; int type = AUDIT_APPARMOR_AUTO;
DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_CAP, OP_CAPABLE);
sa.u.cap = cap; aad(sa)->error = error;
aad(&sa)->error = error;
if (audit == SECURITY_CAP_NOAUDIT)
aad(&sa)->info = "optional: no audit";
if (likely(!error)) { if (likely(!error)) {
/* test if auditing is being forced */ /* test if auditing is being forced */
...@@ -105,24 +103,44 @@ static int audit_caps(struct aa_profile *profile, int cap, int audit, ...@@ -105,24 +103,44 @@ static int audit_caps(struct aa_profile *profile, int cap, int audit,
} }
put_cpu_var(audit_cache); put_cpu_var(audit_cache);
return aa_audit(type, profile, &sa, audit_cb); return aa_audit(type, profile, sa, audit_cb);
} }
/** /**
* profile_capable - test if profile allows use of capability @cap * profile_capable - test if profile allows use of capability @cap
* @profile: profile being enforced (NOT NULL, NOT unconfined) * @profile: profile being enforced (NOT NULL, NOT unconfined)
* @cap: capability to test if allowed * @cap: capability to test if allowed
* @audit: whether an audit record should be generated
* @sa: audit data (MAY BE NULL indicating no auditing)
* *
* Returns: 0 if allowed else -EPERM * Returns: 0 if allowed else -EPERM
*/ */
static int profile_capable(struct aa_profile *profile, int cap) static int profile_capable(struct aa_profile *profile, int cap, int audit,
struct common_audit_data *sa)
{ {
return cap_raised(profile->caps.allow, cap) ? 0 : -EPERM; int error;
if (cap_raised(profile->caps.allow, cap) &&
!cap_raised(profile->caps.denied, cap))
error = 0;
else
error = -EPERM;
if (audit == SECURITY_CAP_NOAUDIT) {
if (!COMPLAIN_MODE(profile))
return error;
/* audit the cap request in complain mode but note that it
* should be optional.
*/
aad(sa)->info = "optional: no audit";
}
return audit_caps(sa, profile, cap, error);
} }
/** /**
* aa_capable - test permission to use capability * aa_capable - test permission to use capability
* @profile: profile being tested against (NOT NULL) * @label: label being tested for capability (NOT NULL)
* @cap: capability to be tested * @cap: capability to be tested
* @audit: whether an audit record should be generated * @audit: whether an audit record should be generated
* *
...@@ -130,14 +148,15 @@ static int profile_capable(struct aa_profile *profile, int cap) ...@@ -130,14 +148,15 @@ static int profile_capable(struct aa_profile *profile, int cap)
* *
* Returns: 0 on success, or else an error code. * Returns: 0 on success, or else an error code.
*/ */
int aa_capable(struct aa_profile *profile, int cap, int audit) int aa_capable(struct aa_label *label, int cap, int audit)
{ {
int error = profile_capable(profile, cap); struct aa_profile *profile;
int error = 0;
DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_CAP, OP_CAPABLE);
if (audit == SECURITY_CAP_NOAUDIT) { sa.u.cap = cap;
if (!COMPLAIN_MODE(profile)) error = fn_for_each_confined(label, profile,
return error; profile_capable(profile, cap, audit, &sa));
}
return audit_caps(profile, cap, audit, error); return error;
} }
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
* *
* *
* AppArmor sets confinement on every task, via the the aa_task_ctx and * AppArmor sets confinement on every task, via the the aa_task_ctx and
* the aa_task_ctx.profile, both of which are required and are not allowed * the aa_task_ctx.label, both of which are required and are not allowed
* to be NULL. The aa_task_ctx is not reference counted and is unique * to be NULL. The aa_task_ctx is not reference counted and is unique
* to each cred (which is reference count). The profile pointed to by * to each cred (which is reference count). The label pointed to by
* the task_ctx is reference counted. * the task_ctx is reference counted.
* *
* TODO * TODO
...@@ -47,9 +47,9 @@ struct aa_task_ctx *aa_alloc_task_context(gfp_t flags) ...@@ -47,9 +47,9 @@ struct aa_task_ctx *aa_alloc_task_context(gfp_t flags)
void aa_free_task_context(struct aa_task_ctx *ctx) void aa_free_task_context(struct aa_task_ctx *ctx)
{ {
if (ctx) { if (ctx) {
aa_put_profile(ctx->profile); aa_put_label(ctx->label);
aa_put_profile(ctx->previous); aa_put_label(ctx->previous);
aa_put_profile(ctx->onexec); aa_put_label(ctx->onexec);
kzfree(ctx); kzfree(ctx);
} }
...@@ -63,41 +63,41 @@ void aa_free_task_context(struct aa_task_ctx *ctx) ...@@ -63,41 +63,41 @@ void aa_free_task_context(struct aa_task_ctx *ctx)
void aa_dup_task_context(struct aa_task_ctx *new, const struct aa_task_ctx *old) void aa_dup_task_context(struct aa_task_ctx *new, const struct aa_task_ctx *old)
{ {
*new = *old; *new = *old;
aa_get_profile(new->profile); aa_get_label(new->label);
aa_get_profile(new->previous); aa_get_label(new->previous);
aa_get_profile(new->onexec); aa_get_label(new->onexec);
} }
/** /**
* aa_get_task_profile - Get another task's profile * aa_get_task_label - Get another task's label
* @task: task to query (NOT NULL) * @task: task to query (NOT NULL)
* *
* Returns: counted reference to @task's profile * Returns: counted reference to @task's label
*/ */
struct aa_profile *aa_get_task_profile(struct task_struct *task) struct aa_label *aa_get_task_label(struct task_struct *task)
{ {
struct aa_profile *p; struct aa_label *p;
rcu_read_lock(); rcu_read_lock();
p = aa_get_profile(__aa_task_profile(task)); p = aa_get_newest_label(__aa_task_raw_label(task));
rcu_read_unlock(); rcu_read_unlock();
return p; return p;
} }
/** /**
* aa_replace_current_profile - replace the current tasks profiles * aa_replace_current_label - replace the current tasks label
* @profile: new profile (NOT NULL) * @label: new label (NOT NULL)
* *
* Returns: 0 or error on failure * Returns: 0 or error on failure
*/ */
int aa_replace_current_profile(struct aa_profile *profile) int aa_replace_current_label(struct aa_label *label)
{ {
struct aa_task_ctx *ctx = current_ctx(); struct aa_task_ctx *ctx = current_ctx();
struct cred *new; struct cred *new;
AA_BUG(!profile); AA_BUG(!label);
if (ctx->profile == profile) if (ctx->label == label)
return 0; return 0;
if (current_cred() != current_real_cred()) if (current_cred() != current_real_cred())
...@@ -108,8 +108,8 @@ int aa_replace_current_profile(struct aa_profile *profile) ...@@ -108,8 +108,8 @@ int aa_replace_current_profile(struct aa_profile *profile)
return -ENOMEM; return -ENOMEM;
ctx = cred_ctx(new); ctx = cred_ctx(new);
if (unconfined(profile) || (ctx->profile->ns != profile->ns)) if (unconfined(label) || (labels_ns(ctx->label) != labels_ns(label)))
/* if switching to unconfined or a different profile namespace /* if switching to unconfined or a different label namespace
* clear out context state * clear out context state
*/ */
aa_clear_task_ctx_trans(ctx); aa_clear_task_ctx_trans(ctx);
...@@ -120,9 +120,9 @@ int aa_replace_current_profile(struct aa_profile *profile) ...@@ -120,9 +120,9 @@ int aa_replace_current_profile(struct aa_profile *profile)
* keeping @profile valid, so make sure to get its reference before * keeping @profile valid, so make sure to get its reference before
* dropping the reference on ctx->profile * dropping the reference on ctx->profile
*/ */
aa_get_profile(profile); aa_get_label(label);
aa_put_profile(ctx->profile); aa_put_label(ctx->label);
ctx->profile = profile; ctx->label = label;
commit_creds(new); commit_creds(new);
return 0; return 0;
...@@ -130,11 +130,11 @@ int aa_replace_current_profile(struct aa_profile *profile) ...@@ -130,11 +130,11 @@ int aa_replace_current_profile(struct aa_profile *profile)
/** /**
* aa_set_current_onexec - set the tasks change_profile to happen onexec * aa_set_current_onexec - set the tasks change_profile to happen onexec
* @profile: system profile to set at exec (MAYBE NULL to clear value) * @label: system label to set at exec (MAYBE NULL to clear value)
* * @stack: whether stacking should be done
* Returns: 0 or error on failure * Returns: 0 or error on failure
*/ */
int aa_set_current_onexec(struct aa_profile *profile) int aa_set_current_onexec(struct aa_label *label, bool stack)
{ {
struct aa_task_ctx *ctx; struct aa_task_ctx *ctx;
struct cred *new = prepare_creds(); struct cred *new = prepare_creds();
...@@ -142,9 +142,10 @@ int aa_set_current_onexec(struct aa_profile *profile) ...@@ -142,9 +142,10 @@ int aa_set_current_onexec(struct aa_profile *profile)
return -ENOMEM; return -ENOMEM;
ctx = cred_ctx(new); ctx = cred_ctx(new);
aa_get_profile(profile); aa_get_label(label);
aa_put_profile(ctx->onexec); aa_clear_task_ctx_trans(ctx);
ctx->onexec = profile; ctx->onexec = label;
ctx->token = stack;
commit_creds(new); commit_creds(new);
return 0; return 0;
...@@ -152,7 +153,7 @@ int aa_set_current_onexec(struct aa_profile *profile) ...@@ -152,7 +153,7 @@ int aa_set_current_onexec(struct aa_profile *profile)
/** /**
* aa_set_current_hat - set the current tasks hat * aa_set_current_hat - set the current tasks hat
* @profile: profile to set as the current hat (NOT NULL) * @label: label to set as the current hat (NOT NULL)
* @token: token value that must be specified to change from the hat * @token: token value that must be specified to change from the hat
* *
* Do switch of tasks hat. If the task is currently in a hat * Do switch of tasks hat. If the task is currently in a hat
...@@ -160,29 +161,29 @@ int aa_set_current_onexec(struct aa_profile *profile) ...@@ -160,29 +161,29 @@ int aa_set_current_onexec(struct aa_profile *profile)
* *
* Returns: 0 or error on failure * Returns: 0 or error on failure
*/ */
int aa_set_current_hat(struct aa_profile *profile, u64 token) int aa_set_current_hat(struct aa_label *label, u64 token)
{ {
struct aa_task_ctx *ctx; struct aa_task_ctx *ctx;
struct cred *new = prepare_creds(); struct cred *new = prepare_creds();
if (!new) if (!new)
return -ENOMEM; return -ENOMEM;
AA_BUG(!profile); AA_BUG(!label);
ctx = cred_ctx(new); ctx = cred_ctx(new);
if (!ctx->previous) { if (!ctx->previous) {
/* transfer refcount */ /* transfer refcount */
ctx->previous = ctx->profile; ctx->previous = ctx->label;
ctx->token = token; ctx->token = token;
} else if (ctx->token == token) { } else if (ctx->token == token) {
aa_put_profile(ctx->profile); aa_put_label(ctx->label);
} else { } else {
/* previous_profile && ctx->token != token */ /* previous_profile && ctx->token != token */
abort_creds(new); abort_creds(new);
return -EACCES; return -EACCES;
} }
ctx->profile = aa_get_newest_profile(profile); ctx->label = aa_get_newest_label(label);
/* clear exec on switching context */ /* clear exec on switching context */
aa_put_profile(ctx->onexec); aa_put_label(ctx->onexec);
ctx->onexec = NULL; ctx->onexec = NULL;
commit_creds(new); commit_creds(new);
...@@ -190,15 +191,15 @@ int aa_set_current_hat(struct aa_profile *profile, u64 token) ...@@ -190,15 +191,15 @@ int aa_set_current_hat(struct aa_profile *profile, u64 token)
} }
/** /**
* aa_restore_previous_profile - exit from hat context restoring the profile * aa_restore_previous_label - exit from hat context restoring previous label
* @token: the token that must be matched to exit hat context * @token: the token that must be matched to exit hat context
* *
* Attempt to return out of a hat to the previous profile. The token * Attempt to return out of a hat to the previous label. The token
* must match the stored token value. * must match the stored token value.
* *
* Returns: 0 or error of failure * Returns: 0 or error of failure
*/ */
int aa_restore_previous_profile(u64 token) int aa_restore_previous_label(u64 token)
{ {
struct aa_task_ctx *ctx; struct aa_task_ctx *ctx;
struct cred *new = prepare_creds(); struct cred *new = prepare_creds();
...@@ -210,15 +211,15 @@ int aa_restore_previous_profile(u64 token) ...@@ -210,15 +211,15 @@ int aa_restore_previous_profile(u64 token)
abort_creds(new); abort_creds(new);
return -EACCES; return -EACCES;
} }
/* ignore restores when there is no saved profile */ /* ignore restores when there is no saved label */
if (!ctx->previous) { if (!ctx->previous) {
abort_creds(new); abort_creds(new);
return 0; return 0;
} }
aa_put_profile(ctx->profile); aa_put_label(ctx->label);
ctx->profile = aa_get_newest_profile(ctx->previous); ctx->label = aa_get_newest_label(ctx->previous);
AA_BUG(!ctx->profile); AA_BUG(!ctx->label);
/* clear exec && prev information when restoring to previous context */ /* clear exec && prev information when restoring to previous context */
aa_clear_task_ctx_trans(ctx); aa_clear_task_ctx_trans(ctx);
......
This diff is collapsed.
This diff is collapsed.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* This file contains AppArmor basic global * This file contains AppArmor basic global
* *
* Copyright (C) 1998-2008 Novell/SUSE * Copyright (C) 1998-2008 Novell/SUSE
* Copyright 2009-2010 Canonical Ltd. * Copyright 2009-2017 Canonical Ltd.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
...@@ -27,8 +27,10 @@ ...@@ -27,8 +27,10 @@
#define AA_CLASS_NET 4 #define AA_CLASS_NET 4
#define AA_CLASS_RLIMITS 5 #define AA_CLASS_RLIMITS 5
#define AA_CLASS_DOMAIN 6 #define AA_CLASS_DOMAIN 6
#define AA_CLASS_PTRACE 9
#define AA_CLASS_LABEL 16
#define AA_CLASS_LAST AA_CLASS_DOMAIN #define AA_CLASS_LAST AA_CLASS_LABEL
/* Control parameters settable through module/boot flags */ /* Control parameters settable through module/boot flags */
extern enum audit_mode aa_g_audit; extern enum audit_mode aa_g_audit;
......
...@@ -17,49 +17,49 @@ ...@@ -17,49 +17,49 @@
extern struct path aa_null; extern struct path aa_null;
enum aa_fs_type { enum aa_sfs_type {
AA_FS_TYPE_BOOLEAN, AA_SFS_TYPE_BOOLEAN,
AA_FS_TYPE_STRING, AA_SFS_TYPE_STRING,
AA_FS_TYPE_U64, AA_SFS_TYPE_U64,
AA_FS_TYPE_FOPS, AA_SFS_TYPE_FOPS,
AA_FS_TYPE_DIR, AA_SFS_TYPE_DIR,
}; };
struct aa_fs_entry; struct aa_sfs_entry;
struct aa_fs_entry { struct aa_sfs_entry {
const char *name; const char *name;
struct dentry *dentry; struct dentry *dentry;
umode_t mode; umode_t mode;
enum aa_fs_type v_type; enum aa_sfs_type v_type;
union { union {
bool boolean; bool boolean;
char *string; char *string;
unsigned long u64; unsigned long u64;
struct aa_fs_entry *files; struct aa_sfs_entry *files;
} v; } v;
const struct file_operations *file_ops; const struct file_operations *file_ops;
}; };
extern const struct file_operations aa_fs_seq_file_ops; extern const struct file_operations aa_sfs_seq_file_ops;
#define AA_FS_FILE_BOOLEAN(_name, _value) \ #define AA_SFS_FILE_BOOLEAN(_name, _value) \
{ .name = (_name), .mode = 0444, \ { .name = (_name), .mode = 0444, \
.v_type = AA_FS_TYPE_BOOLEAN, .v.boolean = (_value), \ .v_type = AA_SFS_TYPE_BOOLEAN, .v.boolean = (_value), \
.file_ops = &aa_fs_seq_file_ops } .file_ops = &aa_sfs_seq_file_ops }
#define AA_FS_FILE_STRING(_name, _value) \ #define AA_SFS_FILE_STRING(_name, _value) \
{ .name = (_name), .mode = 0444, \ { .name = (_name), .mode = 0444, \
.v_type = AA_FS_TYPE_STRING, .v.string = (_value), \ .v_type = AA_SFS_TYPE_STRING, .v.string = (_value), \
.file_ops = &aa_fs_seq_file_ops } .file_ops = &aa_sfs_seq_file_ops }
#define AA_FS_FILE_U64(_name, _value) \ #define AA_SFS_FILE_U64(_name, _value) \
{ .name = (_name), .mode = 0444, \ { .name = (_name), .mode = 0444, \
.v_type = AA_FS_TYPE_U64, .v.u64 = (_value), \ .v_type = AA_SFS_TYPE_U64, .v.u64 = (_value), \
.file_ops = &aa_fs_seq_file_ops } .file_ops = &aa_sfs_seq_file_ops }
#define AA_FS_FILE_FOPS(_name, _mode, _fops) \ #define AA_SFS_FILE_FOPS(_name, _mode, _fops) \
{ .name = (_name), .v_type = AA_FS_TYPE_FOPS, \ { .name = (_name), .v_type = AA_SFS_TYPE_FOPS, \
.mode = (_mode), .file_ops = (_fops) } .mode = (_mode), .file_ops = (_fops) }
#define AA_FS_DIR(_name, _value) \ #define AA_SFS_DIR(_name, _value) \
{ .name = (_name), .v_type = AA_FS_TYPE_DIR, .v.files = (_value) } { .name = (_name), .v_type = AA_SFS_TYPE_DIR, .v.files = (_value) }
extern void __init aa_destroy_aafs(void); extern void __init aa_destroy_aafs(void);
...@@ -74,6 +74,7 @@ enum aafs_ns_type { ...@@ -74,6 +74,7 @@ enum aafs_ns_type {
AAFS_NS_LOAD, AAFS_NS_LOAD,
AAFS_NS_REPLACE, AAFS_NS_REPLACE,
AAFS_NS_REMOVE, AAFS_NS_REMOVE,
AAFS_NS_REVISION,
AAFS_NS_COUNT, AAFS_NS_COUNT,
AAFS_NS_MAX_COUNT, AAFS_NS_MAX_COUNT,
AAFS_NS_SIZE, AAFS_NS_SIZE,
...@@ -102,16 +103,22 @@ enum aafs_prof_type { ...@@ -102,16 +103,22 @@ enum aafs_prof_type {
#define ns_subload(X) ((X)->dents[AAFS_NS_LOAD]) #define ns_subload(X) ((X)->dents[AAFS_NS_LOAD])
#define ns_subreplace(X) ((X)->dents[AAFS_NS_REPLACE]) #define ns_subreplace(X) ((X)->dents[AAFS_NS_REPLACE])
#define ns_subremove(X) ((X)->dents[AAFS_NS_REMOVE]) #define ns_subremove(X) ((X)->dents[AAFS_NS_REMOVE])
#define ns_subrevision(X) ((X)->dents[AAFS_NS_REVISION])
#define prof_dir(X) ((X)->dents[AAFS_PROF_DIR]) #define prof_dir(X) ((X)->dents[AAFS_PROF_DIR])
#define prof_child_dir(X) ((X)->dents[AAFS_PROF_PROFS]) #define prof_child_dir(X) ((X)->dents[AAFS_PROF_PROFS])
void __aa_fs_profile_rmdir(struct aa_profile *profile); void __aa_bump_ns_revision(struct aa_ns *ns);
void __aa_fs_profile_migrate_dents(struct aa_profile *old, void __aafs_profile_rmdir(struct aa_profile *profile);
void __aafs_profile_migrate_dents(struct aa_profile *old,
struct aa_profile *new); struct aa_profile *new);
int __aa_fs_profile_mkdir(struct aa_profile *profile, struct dentry *parent); int __aafs_profile_mkdir(struct aa_profile *profile, struct dentry *parent);
void __aa_fs_ns_rmdir(struct aa_ns *ns); void __aafs_ns_rmdir(struct aa_ns *ns);
int __aa_fs_ns_mkdir(struct aa_ns *ns, struct dentry *parent, int __aafs_ns_mkdir(struct aa_ns *ns, struct dentry *parent, const char *name,
const char *name); struct dentry *dent);
struct aa_loaddata;
void __aa_fs_remove_rawdata(struct aa_loaddata *rawdata);
int __aa_fs_create_rawdata(struct aa_ns *ns, struct aa_loaddata *rawdata);
#endif /* __AA_APPARMORFS_H */ #endif /* __AA_APPARMORFS_H */
...@@ -22,8 +22,7 @@ ...@@ -22,8 +22,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include "file.h" #include "file.h"
#include "label.h"
struct aa_profile;
extern const char *const audit_mode_names[]; extern const char *const audit_mode_names[];
#define AUDIT_MAX_INDEX 5 #define AUDIT_MAX_INDEX 5
...@@ -65,10 +64,12 @@ enum audit_type { ...@@ -65,10 +64,12 @@ enum audit_type {
#define OP_GETATTR "getattr" #define OP_GETATTR "getattr"
#define OP_OPEN "open" #define OP_OPEN "open"
#define OP_FRECEIVE "file_receive"
#define OP_FPERM "file_perm" #define OP_FPERM "file_perm"
#define OP_FLOCK "file_lock" #define OP_FLOCK "file_lock"
#define OP_FMMAP "file_mmap" #define OP_FMMAP "file_mmap"
#define OP_FMPROT "file_mprotect" #define OP_FMPROT "file_mprotect"
#define OP_INHERIT "file_inherit"
#define OP_CREATE "create" #define OP_CREATE "create"
#define OP_POST_CREATE "post_create" #define OP_POST_CREATE "post_create"
...@@ -91,6 +92,8 @@ enum audit_type { ...@@ -91,6 +92,8 @@ enum audit_type {
#define OP_CHANGE_HAT "change_hat" #define OP_CHANGE_HAT "change_hat"
#define OP_CHANGE_PROFILE "change_profile" #define OP_CHANGE_PROFILE "change_profile"
#define OP_CHANGE_ONEXEC "change_onexec" #define OP_CHANGE_ONEXEC "change_onexec"
#define OP_STACK "stack"
#define OP_STACK_ONEXEC "stack_onexec"
#define OP_SETPROCATTR "setprocattr" #define OP_SETPROCATTR "setprocattr"
#define OP_SETRLIMIT "setrlimit" #define OP_SETRLIMIT "setrlimit"
...@@ -102,19 +105,19 @@ enum audit_type { ...@@ -102,19 +105,19 @@ enum audit_type {
struct apparmor_audit_data { struct apparmor_audit_data {
int error; int error;
const char *op;
int type; int type;
void *profile; const char *op;
struct aa_label *label;
const char *name; const char *name;
const char *info; const char *info;
u32 request;
u32 denied;
union { union {
/* these entries require a custom callback fn */ /* these entries require a custom callback fn */
struct { struct {
struct aa_profile *peer; struct aa_label *peer;
struct { struct {
const char *target; const char *target;
u32 request;
u32 denied;
kuid_t ouid; kuid_t ouid;
} fs; } fs;
}; };
......
...@@ -19,11 +19,12 @@ ...@@ -19,11 +19,12 @@
#include "apparmorfs.h" #include "apparmorfs.h"
struct aa_profile; struct aa_label;
/* aa_caps - confinement data for capabilities /* aa_caps - confinement data for capabilities
* @allowed: capabilities mask * @allowed: capabilities mask
* @audit: caps that are to be audited * @audit: caps that are to be audited
* @denied: caps that are explicitly denied
* @quiet: caps that should not be audited * @quiet: caps that should not be audited
* @kill: caps that when requested will result in the task being killed * @kill: caps that when requested will result in the task being killed
* @extended: caps that are subject finer grained mediation * @extended: caps that are subject finer grained mediation
...@@ -31,14 +32,15 @@ struct aa_profile; ...@@ -31,14 +32,15 @@ struct aa_profile;
struct aa_caps { struct aa_caps {
kernel_cap_t allow; kernel_cap_t allow;
kernel_cap_t audit; kernel_cap_t audit;
kernel_cap_t denied;
kernel_cap_t quiet; kernel_cap_t quiet;
kernel_cap_t kill; kernel_cap_t kill;
kernel_cap_t extended; kernel_cap_t extended;
}; };
extern struct aa_fs_entry aa_fs_entry_caps[]; extern struct aa_sfs_entry aa_sfs_entry_caps[];
int aa_capable(struct aa_profile *profile, int cap, int audit); int aa_capable(struct aa_label *label, int cap, int audit);
static inline void aa_free_cap_rules(struct aa_caps *caps) static inline void aa_free_cap_rules(struct aa_caps *caps)
{ {
......
This diff is collapsed.
...@@ -23,14 +23,17 @@ struct aa_domain { ...@@ -23,14 +23,17 @@ struct aa_domain {
char **table; char **table;
}; };
#define AA_CHANGE_NOFLAGS 0
#define AA_CHANGE_TEST 1
#define AA_CHANGE_CHILD 2
#define AA_CHANGE_ONEXEC 4
#define AA_CHANGE_STACK 8
int apparmor_bprm_set_creds(struct linux_binprm *bprm); int apparmor_bprm_set_creds(struct linux_binprm *bprm);
int apparmor_bprm_secureexec(struct linux_binprm *bprm); int apparmor_bprm_secureexec(struct linux_binprm *bprm);
void apparmor_bprm_committing_creds(struct linux_binprm *bprm);
void apparmor_bprm_committed_creds(struct linux_binprm *bprm);
void aa_free_domain_entries(struct aa_domain *domain); void aa_free_domain_entries(struct aa_domain *domain);
int aa_change_hat(const char *hats[], int count, u64 token, bool permtest); int aa_change_hat(const char *hats[], int count, u64 token, int flags);
int aa_change_profile(const char *fqname, bool onexec, bool permtest, int aa_change_profile(const char *fqname, int flags);
bool stack);
#endif /* __AA_DOMAIN_H */ #endif /* __AA_DOMAIN_H */
This diff is collapsed.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* This file contains AppArmor ipc mediation function definitions. * This file contains AppArmor ipc mediation function definitions.
* *
* Copyright (C) 1998-2008 Novell/SUSE * Copyright (C) 1998-2008 Novell/SUSE
* Copyright 2009-2010 Canonical Ltd. * Copyright 2009-2017 Canonical Ltd.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
...@@ -19,10 +19,16 @@ ...@@ -19,10 +19,16 @@
struct aa_profile; struct aa_profile;
int aa_may_ptrace(struct aa_profile *tracer, struct aa_profile *tracee, #define AA_PTRACE_TRACE MAY_WRITE
unsigned int mode); #define AA_PTRACE_READ MAY_READ
#define AA_MAY_BE_TRACED AA_MAY_APPEND
#define AA_MAY_BE_READ AA_MAY_CREATE
#define PTRACE_PERM_SHIFT 2
int aa_ptrace(struct task_struct *tracer, struct task_struct *tracee, #define AA_PTRACE_PERM_MASK (AA_PTRACE_READ | AA_PTRACE_TRACE | \
unsigned int mode); AA_MAY_BE_READ | AA_MAY_BE_TRACED)
int aa_may_ptrace(struct aa_label *tracer, struct aa_label *tracee,
u32 request);
#endif /* __AA_IPC_H */ #endif /* __AA_IPC_H */
This diff is collapsed.
This diff is collapsed.
...@@ -23,11 +23,12 @@ enum path_flags { ...@@ -23,11 +23,12 @@ enum path_flags {
PATH_CHROOT_NSCONNECT = 0x10, /* connect paths that are at ns root */ PATH_CHROOT_NSCONNECT = 0x10, /* connect paths that are at ns root */
PATH_DELEGATE_DELETED = 0x08000, /* delegate deleted files */ PATH_DELEGATE_DELETED = 0x08000, /* delegate deleted files */
PATH_MEDIATE_DELETED = 0x10000, /* mediate deleted paths */ PATH_MEDIATE_DELETED = 0x10000, /* mediate deleted paths */
}; };
int aa_path_name(const struct path *path, int flags, char **buffer, int aa_path_name(const struct path *path, int flags, char *buffer,
const char **name, const char **info); const char **name, const char **info,
const char *disconnected);
#define MAX_PATH_BUFFERS 2 #define MAX_PATH_BUFFERS 2
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -182,7 +182,7 @@ security_initcall(integrity_iintcache_init); ...@@ -182,7 +182,7 @@ security_initcall(integrity_iintcache_init);
* *
*/ */
int integrity_kernel_read(struct file *file, loff_t offset, int integrity_kernel_read(struct file *file, loff_t offset,
char *addr, unsigned long count) void *addr, unsigned long count)
{ {
mm_segment_t old_fs; mm_segment_t old_fs;
char __user *buf = (char __user *)addr; char __user *buf = (char __user *)addr;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment