Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 314ac273 authored by Kees Cook's avatar Kees Cook Committed by Greg Kroah-Hartman
Browse files

module: Do not expose section addresses to non-CAP_SYSLOG



commit b25a7c5af9051850d4f3d93ca500056ab6ec724b upstream.

The printing of section addresses in /sys/module/*/sections/* was not
using the correct credentials to evaluate visibility.

Before:

 # cat /sys/module/*/sections/.*text
 0xffffffffc0458000
 ...
 # capsh --drop=CAP_SYSLOG -- -c "cat /sys/module/*/sections/.*text"
 0xffffffffc0458000
 ...

After:

 # cat /sys/module/*/sections/*.text
 0xffffffffc0458000
 ...
 # capsh --drop=CAP_SYSLOG -- -c "cat /sys/module/*/sections/.*text"
 0x0000000000000000
 ...

Additionally replaces the existing (safe) /proc/modules check with
file->f_cred for consistency.

Reported-by: default avatarDominik Czarnota <dominik.czarnota@trailofbits.com>
Fixes: be71eda5 ("module: Fix display of wrong module .text address")
Cc: stable@vger.kernel.org
Tested-by: default avatarJessica Yu <jeyu@kernel.org>
Acked-by: default avatarJessica Yu <jeyu@kernel.org>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0d5d9413
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1527,8 +1527,8 @@ static ssize_t module_sect_read(struct file *file, struct kobject *kobj,
	if (pos != 0)
		return -EINVAL;

	return sprintf(buf, "0x%px\n", kptr_restrict < 2 ?
		       (void *)sattr->address : NULL);
	return sprintf(buf, "0x%px\n",
		       kallsyms_show_value(file->f_cred) ? (void *)sattr->address : NULL);
}

static void free_sect_attrs(struct module_sect_attrs *sect_attrs)
@@ -4394,7 +4394,7 @@ static int modules_open(struct inode *inode, struct file *file)

	if (!err) {
		struct seq_file *m = file->private_data;
		m->private = kallsyms_show_value(current_cred()) ? NULL : (void *)8ul;
		m->private = kallsyms_show_value(file->f_cred) ? NULL : (void *)8ul;
	}

	return err;