Commit da062855 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'tomoyo-pr-20201214' of git://git.osdn.net/gitroot/tomoyo/tomoyo-test1

Pull tomoyo updates from Tetsuo Handa:
 "Limit recursion depth, fix clang warning, fix comment typo, and
  silence memory allocation failure warning"

* tag 'tomoyo-pr-20201214' of git://git.osdn.net/gitroot/tomoyo/tomoyo-test1:
  tomoyo: Fix typo in comments.
  tomoyo: Fix null pointer check
  tomoyo: Limit wildcard recursion depth.
  tomoyo: fix clang pointer arithmetic warning
  tomoyo: Loosen pathname/domainname validation.
parents fab0fca1 15269fb1
...@@ -311,7 +311,7 @@ static LIST_HEAD(tomoyo_log); ...@@ -311,7 +311,7 @@ static LIST_HEAD(tomoyo_log);
/* Lock for "struct list_head tomoyo_log". */ /* Lock for "struct list_head tomoyo_log". */
static DEFINE_SPINLOCK(tomoyo_log_lock); static DEFINE_SPINLOCK(tomoyo_log_lock);
/* Length of "stuct list_head tomoyo_log". */ /* Length of "struct list_head tomoyo_log". */
static unsigned int tomoyo_log_count; static unsigned int tomoyo_log_count;
/** /**
......
...@@ -498,7 +498,7 @@ static struct tomoyo_profile *tomoyo_assign_profile ...@@ -498,7 +498,7 @@ static struct tomoyo_profile *tomoyo_assign_profile
ptr = ns->profile_ptr[profile]; ptr = ns->profile_ptr[profile];
if (ptr) if (ptr)
return ptr; return ptr;
entry = kzalloc(sizeof(*entry), GFP_NOFS); entry = kzalloc(sizeof(*entry), GFP_NOFS | __GFP_NOWARN);
if (mutex_lock_interruptible(&tomoyo_policy_lock)) if (mutex_lock_interruptible(&tomoyo_policy_lock))
goto out; goto out;
ptr = ns->profile_ptr[profile]; ptr = ns->profile_ptr[profile];
...@@ -635,7 +635,7 @@ static int tomoyo_set_mode(char *name, const char *value, ...@@ -635,7 +635,7 @@ static int tomoyo_set_mode(char *name, const char *value,
if (strstr(value, tomoyo_mode[mode])) if (strstr(value, tomoyo_mode[mode]))
/* /*
* Update lower 3 bits in order to distinguish * Update lower 3 bits in order to distinguish
* 'config' from 'TOMOYO_CONFIG_USE_DEAFULT'. * 'config' from 'TOMOYO_CONFIG_USE_DEFAULT'.
*/ */
config = (config & ~7) | mode; config = (config & ~7) | mode;
if (config != TOMOYO_CONFIG_USE_DEFAULT) { if (config != TOMOYO_CONFIG_USE_DEFAULT) {
...@@ -2574,7 +2574,7 @@ static inline bool tomoyo_has_more_namespace(struct tomoyo_io_buffer *head) ...@@ -2574,7 +2574,7 @@ static inline bool tomoyo_has_more_namespace(struct tomoyo_io_buffer *head)
* tomoyo_read_control - read() for /sys/kernel/security/tomoyo/ interface. * tomoyo_read_control - read() for /sys/kernel/security/tomoyo/ interface.
* *
* @head: Pointer to "struct tomoyo_io_buffer". * @head: Pointer to "struct tomoyo_io_buffer".
* @buffer: Poiner to buffer to write to. * @buffer: Pointer to buffer to write to.
* @buffer_len: Size of @buffer. * @buffer_len: Size of @buffer.
* *
* Returns bytes read on success, negative value otherwise. * Returns bytes read on success, negative value otherwise.
...@@ -2608,7 +2608,7 @@ ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer, ...@@ -2608,7 +2608,7 @@ ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer,
/** /**
* tomoyo_parse_policy - Parse a policy line. * tomoyo_parse_policy - Parse a policy line.
* *
* @head: Poiter to "struct tomoyo_io_buffer". * @head: Pointer to "struct tomoyo_io_buffer".
* @line: Line to parse. * @line: Line to parse.
* *
* Returns 0 on success, negative value otherwise. * Returns 0 on success, negative value otherwise.
......
...@@ -98,7 +98,7 @@ static bool tomoyo_envp(const char *env_name, const char *env_value, ...@@ -98,7 +98,7 @@ static bool tomoyo_envp(const char *env_name, const char *env_value,
* @argc: Length of @argc. * @argc: Length of @argc.
* @argv: Pointer to "struct tomoyo_argv". * @argv: Pointer to "struct tomoyo_argv".
* @envc: Length of @envp. * @envc: Length of @envp.
* @envp: Poiner to "struct tomoyo_envp". * @envp: Pointer to "struct tomoyo_envp".
* *
* Returns true on success, false otherwise. * Returns true on success, false otherwise.
*/ */
......
...@@ -473,9 +473,7 @@ struct tomoyo_policy_namespace *tomoyo_assign_namespace(const char *domainname) ...@@ -473,9 +473,7 @@ struct tomoyo_policy_namespace *tomoyo_assign_namespace(const char *domainname)
return ptr; return ptr;
if (len >= TOMOYO_EXEC_TMPSIZE - 10 || !tomoyo_domain_def(domainname)) if (len >= TOMOYO_EXEC_TMPSIZE - 10 || !tomoyo_domain_def(domainname))
return NULL; return NULL;
entry = kzalloc(sizeof(*entry) + len + 1, GFP_NOFS); entry = kzalloc(sizeof(*entry) + len + 1, GFP_NOFS | __GFP_NOWARN);
if (!entry)
return NULL;
if (mutex_lock_interruptible(&tomoyo_policy_lock)) if (mutex_lock_interruptible(&tomoyo_policy_lock))
goto out; goto out;
ptr = tomoyo_find_namespace(domainname, len); ptr = tomoyo_find_namespace(domainname, len);
...@@ -891,7 +889,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm) ...@@ -891,7 +889,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
* *
* @bprm: Pointer to "struct linux_binprm". * @bprm: Pointer to "struct linux_binprm".
* @pos: Location to dump. * @pos: Location to dump.
* @dump: Poiner to "struct tomoyo_page_dump". * @dump: Pointer to "struct tomoyo_page_dump".
* *
* Returns true on success, false otherwise. * Returns true on success, false otherwise.
*/ */
......
...@@ -463,7 +463,7 @@ static void tomoyo_try_to_gc(const enum tomoyo_policy_id type, ...@@ -463,7 +463,7 @@ static void tomoyo_try_to_gc(const enum tomoyo_policy_id type,
return; return;
reinject: reinject:
/* /*
* We can safely reinject this element here bacause * We can safely reinject this element here because
* (1) Appending list elements and removing list elements are protected * (1) Appending list elements and removing list elements are protected
* by tomoyo_policy_lock mutex. * by tomoyo_policy_lock mutex.
* (2) Only this function removes list elements and this function is * (2) Only this function removes list elements and this function is
......
...@@ -73,7 +73,7 @@ bool tomoyo_memory_ok(void *ptr) ...@@ -73,7 +73,7 @@ bool tomoyo_memory_ok(void *ptr)
*/ */
void *tomoyo_commit_ok(void *data, const unsigned int size) void *tomoyo_commit_ok(void *data, const unsigned int size)
{ {
void *ptr = kzalloc(size, GFP_NOFS); void *ptr = kzalloc(size, GFP_NOFS | __GFP_NOWARN);
if (tomoyo_memory_ok(ptr)) { if (tomoyo_memory_ok(ptr)) {
memmove(ptr, data, size); memmove(ptr, data, size);
...@@ -170,7 +170,7 @@ const struct tomoyo_path_info *tomoyo_get_name(const char *name) ...@@ -170,7 +170,7 @@ const struct tomoyo_path_info *tomoyo_get_name(const char *name)
atomic_inc(&ptr->head.users); atomic_inc(&ptr->head.users);
goto out; goto out;
} }
ptr = kzalloc(sizeof(*ptr) + len, GFP_NOFS); ptr = kzalloc(sizeof(*ptr) + len, GFP_NOFS | __GFP_NOWARN);
if (tomoyo_memory_ok(ptr)) { if (tomoyo_memory_ok(ptr)) {
ptr->entry.name = ((char *) ptr) + sizeof(*ptr); ptr->entry.name = ((char *) ptr) + sizeof(*ptr);
memmove((char *) ptr->entry.name, name, len); memmove((char *) ptr->entry.name, name, len);
......
...@@ -131,8 +131,8 @@ static const struct file_operations tomoyo_self_operations = { ...@@ -131,8 +131,8 @@ static const struct file_operations tomoyo_self_operations = {
*/ */
static int tomoyo_open(struct inode *inode, struct file *file) static int tomoyo_open(struct inode *inode, struct file *file)
{ {
const int key = ((u8 *) file_inode(file)->i_private) const u8 key = (uintptr_t) file_inode(file)->i_private;
- ((u8 *) NULL);
return tomoyo_open_control(key, file); return tomoyo_open_control(key, file);
} }
...@@ -223,7 +223,7 @@ static const struct file_operations tomoyo_operations = { ...@@ -223,7 +223,7 @@ static const struct file_operations tomoyo_operations = {
static void __init tomoyo_create_entry(const char *name, const umode_t mode, static void __init tomoyo_create_entry(const char *name, const umode_t mode,
struct dentry *parent, const u8 key) struct dentry *parent, const u8 key)
{ {
securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key, securityfs_create_file(name, mode, parent, (void *) (uintptr_t) key,
&tomoyo_operations); &tomoyo_operations);
} }
......
...@@ -434,59 +434,64 @@ void tomoyo_normalize_line(unsigned char *buffer) ...@@ -434,59 +434,64 @@ void tomoyo_normalize_line(unsigned char *buffer)
*/ */
static bool tomoyo_correct_word2(const char *string, size_t len) static bool tomoyo_correct_word2(const char *string, size_t len)
{ {
u8 recursion = 20;
const char *const start = string; const char *const start = string;
bool in_repetition = false; bool in_repetition = false;
unsigned char c;
unsigned char d;
unsigned char e;
if (!len) if (!len)
goto out; goto out;
while (len--) { while (len--) {
c = *string++; unsigned char c = *string++;
if (c == '\\') { if (c == '\\') {
if (!len--) if (!len--)
goto out; goto out;
c = *string++; c = *string++;
if (c >= '0' && c <= '3') {
unsigned char d;
unsigned char e;
if (!len-- || !len--)
goto out;
d = *string++;
e = *string++;
if (d < '0' || d > '7' || e < '0' || e > '7')
goto out;
c = tomoyo_make_byte(c, d, e);
if (c <= ' ' || c >= 127)
continue;
goto out;
}
switch (c) { switch (c) {
case '\\': /* "\\" */ case '\\': /* "\\" */
continue;
case '$': /* "\$" */
case '+': /* "\+" */ case '+': /* "\+" */
case '?': /* "\?" */ case '?': /* "\?" */
case 'x': /* "\x" */
case 'a': /* "\a" */
case '-': /* "\-" */
continue;
}
if (!recursion--)
goto out;
switch (c) {
case '*': /* "\*" */ case '*': /* "\*" */
case '@': /* "\@" */ case '@': /* "\@" */
case 'x': /* "\x" */ case '$': /* "\$" */
case 'X': /* "\X" */ case 'X': /* "\X" */
case 'a': /* "\a" */
case 'A': /* "\A" */ case 'A': /* "\A" */
case '-': /* "\-" */
continue; continue;
case '{': /* "/\{" */ case '{': /* "/\{" */
if (string - 3 < start || *(string - 3) != '/') if (string - 3 < start || *(string - 3) != '/')
break; goto out;
in_repetition = true; in_repetition = true;
continue; continue;
case '}': /* "\}/" */ case '}': /* "\}/" */
if (*string != '/') if (*string != '/')
break; goto out;
if (!in_repetition) if (!in_repetition)
break; goto out;
in_repetition = false; in_repetition = false;
continue; continue;
case '0': /* "\ooo" */
case '1':
case '2':
case '3':
if (!len-- || !len--)
break;
d = *string++;
e = *string++;
if (d < '0' || d > '7' || e < '0' || e > '7')
break;
c = tomoyo_make_byte(c, d, e);
if (c <= ' ' || c >= 127)
continue;
} }
goto out; goto out;
} else if (in_repetition && c == '/') { } else if (in_repetition && c == '/') {
......
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