Merge 0a9b9d17f3 ("Merge tag 'pm-6.12-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm") into android-mainline
Steps on the way to 6.12-final Change-Id: I91b51b7db5887e4fba193c8db3322cd672fdd6c0 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
@@ -1084,7 +1084,8 @@ static void evm_file_release(struct file *file)
|
||||
if (!S_ISREG(inode->i_mode) || !(mode & FMODE_WRITE))
|
||||
return;
|
||||
|
||||
if (iint && atomic_read(&inode->i_writecount) == 1)
|
||||
if (iint && iint->flags & EVM_NEW_FILE &&
|
||||
atomic_read(&inode->i_writecount) == 1)
|
||||
iint->flags &= ~EVM_NEW_FILE;
|
||||
}
|
||||
|
||||
|
||||
@@ -318,15 +318,21 @@ static int ima_eventdigest_init_common(const u8 *digest, u32 digestsize,
|
||||
hash_algo_name[hash_algo]);
|
||||
}
|
||||
|
||||
if (digest)
|
||||
if (digest) {
|
||||
memcpy(buffer + offset, digest, digestsize);
|
||||
else
|
||||
} else {
|
||||
/*
|
||||
* If digest is NULL, the event being recorded is a violation.
|
||||
* Make room for the digest by increasing the offset by the
|
||||
* hash algorithm digest size.
|
||||
* hash algorithm digest size. If the hash algorithm is not
|
||||
* specified increase the offset by IMA_DIGEST_SIZE which
|
||||
* fits SHA1 or MD5
|
||||
*/
|
||||
offset += hash_digest_size[hash_algo];
|
||||
if (hash_algo < HASH_ALGO__LAST)
|
||||
offset += hash_digest_size[hash_algo];
|
||||
else
|
||||
offset += IMA_DIGEST_SIZE;
|
||||
}
|
||||
|
||||
return ima_write_template_field_data(buffer, offset + digestsize,
|
||||
fmt, field_data);
|
||||
|
||||
@@ -37,6 +37,8 @@ struct evm_ima_xattr_data {
|
||||
);
|
||||
u8 data[];
|
||||
} __packed;
|
||||
static_assert(offsetof(struct evm_ima_xattr_data, data) == sizeof(struct evm_ima_xattr_data_hdr),
|
||||
"struct member likely outside of __struct_group()");
|
||||
|
||||
/* Only used in the EVM HMAC code. */
|
||||
struct evm_xattr {
|
||||
@@ -65,6 +67,8 @@ struct ima_digest_data {
|
||||
);
|
||||
u8 digest[];
|
||||
} __packed;
|
||||
static_assert(offsetof(struct ima_digest_data, digest) == sizeof(struct ima_digest_data_hdr),
|
||||
"struct member likely outside of __struct_group()");
|
||||
|
||||
/*
|
||||
* Instead of wrapping the ima_digest_data struct inside a local structure
|
||||
|
||||
+8
-23
@@ -388,38 +388,22 @@ static bool is_nouser_or_private(const struct dentry *dentry)
|
||||
unlikely(IS_PRIVATE(d_backing_inode(dentry))));
|
||||
}
|
||||
|
||||
static access_mask_t
|
||||
get_raw_handled_fs_accesses(const struct landlock_ruleset *const domain)
|
||||
{
|
||||
access_mask_t access_dom = 0;
|
||||
size_t layer_level;
|
||||
|
||||
for (layer_level = 0; layer_level < domain->num_layers; layer_level++)
|
||||
access_dom |=
|
||||
landlock_get_raw_fs_access_mask(domain, layer_level);
|
||||
return access_dom;
|
||||
}
|
||||
|
||||
static access_mask_t
|
||||
get_handled_fs_accesses(const struct landlock_ruleset *const domain)
|
||||
{
|
||||
/* Handles all initially denied by default access rights. */
|
||||
return get_raw_handled_fs_accesses(domain) |
|
||||
return landlock_union_access_masks(domain).fs |
|
||||
LANDLOCK_ACCESS_FS_INITIALLY_DENIED;
|
||||
}
|
||||
|
||||
static const struct landlock_ruleset *
|
||||
get_fs_domain(const struct landlock_ruleset *const domain)
|
||||
{
|
||||
if (!domain || !get_raw_handled_fs_accesses(domain))
|
||||
return NULL;
|
||||
|
||||
return domain;
|
||||
}
|
||||
static const struct access_masks any_fs = {
|
||||
.fs = ~0,
|
||||
};
|
||||
|
||||
static const struct landlock_ruleset *get_current_fs_domain(void)
|
||||
{
|
||||
return get_fs_domain(landlock_get_current_domain());
|
||||
return landlock_get_applicable_domain(landlock_get_current_domain(),
|
||||
any_fs);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1517,7 +1501,8 @@ static int hook_file_open(struct file *const file)
|
||||
access_mask_t open_access_request, full_access_request, allowed_access,
|
||||
optional_access;
|
||||
const struct landlock_ruleset *const dom =
|
||||
get_fs_domain(landlock_cred(file->f_cred)->domain);
|
||||
landlock_get_applicable_domain(
|
||||
landlock_cred(file->f_cred)->domain, any_fs);
|
||||
|
||||
if (!dom)
|
||||
return 0;
|
||||
|
||||
+6
-22
@@ -39,27 +39,9 @@ int landlock_append_net_rule(struct landlock_ruleset *const ruleset,
|
||||
return err;
|
||||
}
|
||||
|
||||
static access_mask_t
|
||||
get_raw_handled_net_accesses(const struct landlock_ruleset *const domain)
|
||||
{
|
||||
access_mask_t access_dom = 0;
|
||||
size_t layer_level;
|
||||
|
||||
for (layer_level = 0; layer_level < domain->num_layers; layer_level++)
|
||||
access_dom |= landlock_get_net_access_mask(domain, layer_level);
|
||||
return access_dom;
|
||||
}
|
||||
|
||||
static const struct landlock_ruleset *get_current_net_domain(void)
|
||||
{
|
||||
const struct landlock_ruleset *const dom =
|
||||
landlock_get_current_domain();
|
||||
|
||||
if (!dom || !get_raw_handled_net_accesses(dom))
|
||||
return NULL;
|
||||
|
||||
return dom;
|
||||
}
|
||||
static const struct access_masks any_net = {
|
||||
.net = ~0,
|
||||
};
|
||||
|
||||
static int current_check_access_socket(struct socket *const sock,
|
||||
struct sockaddr *const address,
|
||||
@@ -72,7 +54,9 @@ static int current_check_access_socket(struct socket *const sock,
|
||||
struct landlock_id id = {
|
||||
.type = LANDLOCK_KEY_NET_PORT,
|
||||
};
|
||||
const struct landlock_ruleset *const dom = get_current_net_domain();
|
||||
const struct landlock_ruleset *const dom =
|
||||
landlock_get_applicable_domain(landlock_get_current_domain(),
|
||||
any_net);
|
||||
|
||||
if (!dom)
|
||||
return 0;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/build_bug.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/rbtree.h>
|
||||
#include <linux/refcount.h>
|
||||
@@ -47,6 +48,15 @@ struct access_masks {
|
||||
access_mask_t scope : LANDLOCK_NUM_SCOPE;
|
||||
};
|
||||
|
||||
union access_masks_all {
|
||||
struct access_masks masks;
|
||||
u32 all;
|
||||
};
|
||||
|
||||
/* Makes sure all fields are covered. */
|
||||
static_assert(sizeof(typeof_member(union access_masks_all, masks)) ==
|
||||
sizeof(typeof_member(union access_masks_all, all)));
|
||||
|
||||
typedef u16 layer_mask_t;
|
||||
/* Makes sure all layers can be checked. */
|
||||
static_assert(BITS_PER_TYPE(layer_mask_t) >= LANDLOCK_MAX_NUM_LAYERS);
|
||||
@@ -260,6 +270,61 @@ static inline void landlock_get_ruleset(struct landlock_ruleset *const ruleset)
|
||||
refcount_inc(&ruleset->usage);
|
||||
}
|
||||
|
||||
/**
|
||||
* landlock_union_access_masks - Return all access rights handled in the
|
||||
* domain
|
||||
*
|
||||
* @domain: Landlock ruleset (used as a domain)
|
||||
*
|
||||
* Returns: an access_masks result of the OR of all the domain's access masks.
|
||||
*/
|
||||
static inline struct access_masks
|
||||
landlock_union_access_masks(const struct landlock_ruleset *const domain)
|
||||
{
|
||||
union access_masks_all matches = {};
|
||||
size_t layer_level;
|
||||
|
||||
for (layer_level = 0; layer_level < domain->num_layers; layer_level++) {
|
||||
union access_masks_all layer = {
|
||||
.masks = domain->access_masks[layer_level],
|
||||
};
|
||||
|
||||
matches.all |= layer.all;
|
||||
}
|
||||
|
||||
return matches.masks;
|
||||
}
|
||||
|
||||
/**
|
||||
* landlock_get_applicable_domain - Return @domain if it applies to (handles)
|
||||
* at least one of the access rights specified
|
||||
* in @masks
|
||||
*
|
||||
* @domain: Landlock ruleset (used as a domain)
|
||||
* @masks: access masks
|
||||
*
|
||||
* Returns: @domain if any access rights specified in @masks is handled, or
|
||||
* NULL otherwise.
|
||||
*/
|
||||
static inline const struct landlock_ruleset *
|
||||
landlock_get_applicable_domain(const struct landlock_ruleset *const domain,
|
||||
const struct access_masks masks)
|
||||
{
|
||||
const union access_masks_all masks_all = {
|
||||
.masks = masks,
|
||||
};
|
||||
union access_masks_all merge = {};
|
||||
|
||||
if (!domain)
|
||||
return NULL;
|
||||
|
||||
merge.masks = landlock_union_access_masks(domain);
|
||||
if (merge.all & masks_all.all)
|
||||
return domain;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline void
|
||||
landlock_add_fs_access_mask(struct landlock_ruleset *const ruleset,
|
||||
const access_mask_t fs_access_mask,
|
||||
@@ -295,19 +360,12 @@ landlock_add_scope_mask(struct landlock_ruleset *const ruleset,
|
||||
ruleset->access_masks[layer_level].scope |= mask;
|
||||
}
|
||||
|
||||
static inline access_mask_t
|
||||
landlock_get_raw_fs_access_mask(const struct landlock_ruleset *const ruleset,
|
||||
const u16 layer_level)
|
||||
{
|
||||
return ruleset->access_masks[layer_level].fs;
|
||||
}
|
||||
|
||||
static inline access_mask_t
|
||||
landlock_get_fs_access_mask(const struct landlock_ruleset *const ruleset,
|
||||
const u16 layer_level)
|
||||
{
|
||||
/* Handles all initially denied by default access rights. */
|
||||
return landlock_get_raw_fs_access_mask(ruleset, layer_level) |
|
||||
return ruleset->access_masks[layer_level].fs |
|
||||
LANDLOCK_ACCESS_FS_INITIALLY_DENIED;
|
||||
}
|
||||
|
||||
|
||||
@@ -329,7 +329,7 @@ static int add_rule_path_beneath(struct landlock_ruleset *const ruleset,
|
||||
return -ENOMSG;
|
||||
|
||||
/* Checks that allowed_access matches the @ruleset constraints. */
|
||||
mask = landlock_get_raw_fs_access_mask(ruleset, 0);
|
||||
mask = ruleset->access_masks[0].fs;
|
||||
if ((path_beneath_attr.allowed_access | mask) != mask)
|
||||
return -EINVAL;
|
||||
|
||||
|
||||
@@ -204,12 +204,17 @@ static bool is_abstract_socket(struct sock *const sock)
|
||||
return false;
|
||||
}
|
||||
|
||||
static const struct access_masks unix_scope = {
|
||||
.scope = LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET,
|
||||
};
|
||||
|
||||
static int hook_unix_stream_connect(struct sock *const sock,
|
||||
struct sock *const other,
|
||||
struct sock *const newsk)
|
||||
{
|
||||
const struct landlock_ruleset *const dom =
|
||||
landlock_get_current_domain();
|
||||
landlock_get_applicable_domain(landlock_get_current_domain(),
|
||||
unix_scope);
|
||||
|
||||
/* Quick return for non-landlocked tasks. */
|
||||
if (!dom)
|
||||
@@ -225,7 +230,8 @@ static int hook_unix_may_send(struct socket *const sock,
|
||||
struct socket *const other)
|
||||
{
|
||||
const struct landlock_ruleset *const dom =
|
||||
landlock_get_current_domain();
|
||||
landlock_get_applicable_domain(landlock_get_current_domain(),
|
||||
unix_scope);
|
||||
|
||||
if (!dom)
|
||||
return 0;
|
||||
@@ -243,6 +249,10 @@ static int hook_unix_may_send(struct socket *const sock,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct access_masks signal_scope = {
|
||||
.scope = LANDLOCK_SCOPE_SIGNAL,
|
||||
};
|
||||
|
||||
static int hook_task_kill(struct task_struct *const p,
|
||||
struct kernel_siginfo *const info, const int sig,
|
||||
const struct cred *const cred)
|
||||
@@ -256,6 +266,7 @@ static int hook_task_kill(struct task_struct *const p,
|
||||
} else {
|
||||
dom = landlock_get_current_domain();
|
||||
}
|
||||
dom = landlock_get_applicable_domain(dom, signal_scope);
|
||||
|
||||
/* Quick return for non-landlocked tasks. */
|
||||
if (!dom)
|
||||
@@ -279,7 +290,8 @@ static int hook_file_send_sigiotask(struct task_struct *tsk,
|
||||
|
||||
/* Lock already held by send_sigio() and send_sigurg(). */
|
||||
lockdep_assert_held(&fown->lock);
|
||||
dom = landlock_file(fown->file)->fown_domain;
|
||||
dom = landlock_get_applicable_domain(
|
||||
landlock_file(fown->file)->fown_domain, signal_scope);
|
||||
|
||||
/* Quick return for unowned socket. */
|
||||
if (!dom)
|
||||
|
||||
Reference in New Issue
Block a user