Skip to content

Commit

Permalink
module: Do not expose section addresses to non-CAP_SYSLOG
Browse files Browse the repository at this point in the history
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: Dominik Czarnota <[email protected]>
Fixes: be71eda ("module: Fix display of wrong module .text address")
Cc: [email protected]
Tested-by: Jessica Yu <[email protected]>
Acked-by: Jessica Yu <[email protected]>
Signed-off-by: Kees Cook <[email protected]>
  • Loading branch information
kees committed Jul 8, 2020
1 parent ed66f99 commit b25a7c5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1530,8 +1530,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)
Expand Down Expand Up @@ -4380,7 +4380,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;
Expand Down

0 comments on commit b25a7c5

Please sign in to comment.