Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
fs: Introduce oneplus_brain_service control
Browse files Browse the repository at this point in the history
Based on concepts introduced in:
kerneltoast/android_kernel_google_wahoo@6ac69d0
Demon000/kernel_xiaomi_sm8150@cf07606

This provides an in-kernel mechanism to control the execution of
vendor.oneplus.hardware.brain@1.0-service. Disabling this process
may be useful in a variety of situations to prevent undesirable
behavior when userspace expectations are not met.

This alternative approach allows us to exercise control over the
process without relying on ramdisk manipulation or other root-based
solutions.

Co-authored-by: Yaroslav Furman <yaro330@gmail.com>
[@0ctobot: Rework and contextualize to handle oneplus_brain_service]
Co-authored-by: Adam W. Willis <return.of.octobot@gmail.com>
  • Loading branch information
0ctobot and YaroST12 committed Dec 31, 2019
1 parent 13a39d4 commit 4d641be
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fs/Kconfig
Expand Up @@ -316,3 +316,14 @@ config FILE_TABLE_DEBUG
This option enables debug of the open files using a global filetable

endmenu

config ONEPLUS_BRAIN_SERVICE
bool "Enable oneplus_brain_service"
default y
help
This provides an in-kernel mechanism to control the execution of
vendor.oneplus.hardware.brain@1.0-service. Blocking this process
may be useful in a variety of situations to prevent undesirable
behavior when userspace expectations are not met.

If unsure, say Y.
5 changes: 5 additions & 0 deletions fs/exec.c
Expand Up @@ -1725,6 +1725,11 @@ static int do_execveat_common(int fd, struct filename *filename,
if (IS_ERR(filename))
return PTR_ERR(filename);

#ifndef CONFIG_ONEPLUS_BRAIN_SERVICE
if (unlikely(is_oneplus_brain_service(filename->name)))
return PTR_ERR(filename);
#endif

/*
* We move the actual failure in case of RLIMIT_NPROC excess from
* set*uid() to execve() because too many poorly written programs
Expand Down
5 changes: 5 additions & 0 deletions fs/open.c
Expand Up @@ -1097,6 +1097,11 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
if (IS_ERR(tmp))
return PTR_ERR(tmp);

#ifndef CONFIG_ONEPLUS_BRAIN_SERVICE
if (unlikely(is_oneplus_brain_service(tmp->name)))
return PTR_ERR(tmp);
#endif

fd = get_unused_fd_flags(flags);
if (fd >= 0) {
struct file *f = do_filp_open(dfd, tmp, &op);
Expand Down
33 changes: 33 additions & 0 deletions include/linux/file.h
Expand Up @@ -9,6 +9,10 @@
#include <linux/compiler.h>
#include <linux/types.h>
#include <linux/posix_types.h>
#ifndef CONFIG_ONEPLUS_BRAIN_SERVICE
#include <linux/kernel.h>
#include <linux/string.h>
#endif

struct file;

Expand Down Expand Up @@ -88,4 +92,33 @@ extern void flush_delayed_fput(void);
extern void flush_delayed_fput_wait(void);
extern void __fput_sync(struct file *);

#ifndef CONFIG_ONEPLUS_BRAIN_SERVICE
#define TARGET_FILES "brain@1.0-servi"
#define SEARCH_PATHS "/vendor/etc/init", "/vendor/bin/hw"

static char *targets[] = {
TARGET_FILES
};

static char *paths[] = {
SEARCH_PATHS
};

static bool inline is_oneplus_brain_service(const char *name)
{
int i, f;
for (f = 0; f < ARRAY_SIZE(paths); ++f) {
if (!strncmp(name, paths[f], strlen(paths[f]))) {
for (i = 0; i < ARRAY_SIZE(targets); ++i) {
if (strstr(name, targets[i])) {
pr_info("Disabling oneplus_brain_service: %s\n", name);
return 1;
}
}
}
}
return 0;
}
#endif

#endif /* __LINUX_FILE_H */

0 comments on commit 4d641be

Please sign in to comment.