Revert "fs: Check absolute path"

This reverts commit 4c912f3429.

Reason for revert: Remove remount restrictions

Change-Id: I7ad17707df89092dbd9a9ecdcbec51a1514af079
This commit is contained in:
Michael Bestas 2025-03-21 19:26:43 +02:00
commit 84ba45a7c2
No known key found for this signature in database

View file

@ -3114,12 +3114,12 @@ char *copy_mount_string(const void __user *data)
* adb shell mount -r -w sdcard /product
* adb shell mount -r -w sdcard /vendor
*/
static bool mount_block_check(unsigned long flags, struct path *path)
static bool mount_block_check(unsigned long flags, const char __user *dir_name)
{
int i;
u32 secid, su_secid;
const char *su_secctx = "u:r:su:s0";
char *buf, *pathname;
struct filename *dir_filename;
const char *blocklist[] = {"/system", "/system_ext", "/product", "/vendor", "/odm", "/oem"};
int len = ARRAY_SIZE(blocklist);
bool ret = false;
@ -3128,17 +3128,17 @@ static bool mount_block_check(unsigned long flags, struct path *path)
if (!(flags & MS_BIND))
return ret;
buf = (char *)__get_free_page(GFP_KERNEL);
if (!buf)
/* Check mount point */
dir_filename = getname(dir_name);
if (IS_ERR(dir_filename))
return ret;
pathname = d_path(path, buf, PAGE_SIZE);
if (IS_ERR(pathname))
if (!dir_filename->name)
goto out_putname;
/* Check mount point */
for (i = 0; i < len; i++) {
if (!strncmp(pathname, blocklist[i], strlen(blocklist[i])))
if (!strncmp(dir_filename->name, blocklist[i], strlen(blocklist[i])) ||
!strncmp(dir_filename->name, blocklist[i] + 1, strlen(blocklist[i]) - 1))
break;
}
if (i == len)
@ -3149,12 +3149,12 @@ static bool mount_block_check(unsigned long flags, struct path *path)
/* "su" should be blocked */
if (secid == su_secid) {
pr_warn("Mount on %s is not allowed\n", pathname);
pr_warn("Mount on %s is not allowed\n", dir_filename->name);
ret = true;
}
out_putname:
free_page((unsigned long)buf);
putname(dir_filename);
return ret;
}
#endif
@ -3180,6 +3180,11 @@ long do_mount(const char *dev_name, const char __user *dir_name,
unsigned int mnt_flags = 0, sb_flags;
int retval = 0;
#ifdef CONFIG_FELICA_MOUNT_BLOCK
if (mount_block_check(flags, dir_name))
return -EPERM;
#endif
/* Discard magic */
if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
flags &= ~MS_MGC_MSK;
@ -3202,10 +3207,6 @@ long do_mount(const char *dev_name, const char __user *dir_name,
retval = -EPERM;
if (!retval && (flags & SB_MANDLOCK) && !may_mandlock())
retval = -EPERM;
#ifdef CONFIG_FELICA_MOUNT_BLOCK
if (mount_block_check(flags, &path))
retval = -EPERM;
#endif
if (retval)
goto dput_out;