kernel: Only expose su when daemon is running
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / readdir.c
index 5d6578affbbf91b6d2e80b32398e8f0a53bc08ae..516fc904513dbceea76bba4bec351cf102d66230 100644 (file)
@@ -39,6 +39,7 @@ int iterate_dir(struct file *file, struct dir_context *ctx)
        if (!IS_DEADDIR(inode)) {
                if (file->f_op->iterate) {
                        ctx->pos = file->f_pos;
+                       ctx->romnt = (inode->i_sb->s_flags & MS_RDONLY);
                        res = file->f_op->iterate(file, ctx);
                        file->f_pos = ctx->pos;
                } else {
@@ -53,6 +54,14 @@ out:
 }
 EXPORT_SYMBOL(iterate_dir);
 
+static bool hide_name(const char *name, int namlen)
+{
+       if (namlen == 2 && !memcmp(name, "su", 2))
+               if (!su_visible())
+                       return true;
+       return false;
+}
+
 /*
  * Traditional linux readdir() handling..
  *
@@ -91,6 +100,8 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
                buf->result = -EOVERFLOW;
                return -EOVERFLOW;
        }
+       if (hide_name(name, namlen) && buf->ctx.romnt)
+               return 0;
        buf->result++;
        dirent = buf->dirent;
        if (!access_ok(VERIFY_WRITE, dirent,
@@ -169,6 +180,8 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
                buf->error = -EOVERFLOW;
                return -EOVERFLOW;
        }
+       if (hide_name(name, namlen) && buf->ctx.romnt)
+               return 0;
        dirent = buf->previous;
        if (dirent) {
                if (__put_user(offset, &dirent->d_off))
@@ -249,6 +262,8 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
        buf->error = -EINVAL;   /* only used if we fail.. */
        if (reclen > buf->count)
                return -EINVAL;
+       if (hide_name(name, namlen) && buf->ctx.romnt)
+               return 0;
        dirent = buf->previous;
        if (dirent) {
                if (__put_user(offset, &dirent->d_off))