mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-18 09:44:18 +08:00
822cceec72
Redirecting directly to lsm, here's the patch discussed on lkml: http://lkml.org/lkml/2010/4/22/219 The mmap_min_addr value is useful information for an admin to see without being root ("is my system vulnerable to kernel NULL pointer attacks?") and its setting is trivially easy for an attacker to determine by calling mmap() in PAGE_SIZE increments starting at 0, so trying to keep it private has no value. Only require CAP_SYS_RAWIO if changing the value, not reading it. Comment from Serge : Me, I like to write my passwords with light blue pen on dark blue paper, pasted on my window - if you're going to get my password, you're gonna get a headache. Signed-off-by: Kees Cook <kees.cook@canonical.com> Acked-by: Serge Hallyn <serue@us.ibm.com> Signed-off-by: James Morris <jmorris@namei.org>
53 lines
1.3 KiB
C
53 lines
1.3 KiB
C
#include <linux/init.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/security.h>
|
|
#include <linux/sysctl.h>
|
|
|
|
/* amount of vm to protect from userspace access by both DAC and the LSM*/
|
|
unsigned long mmap_min_addr;
|
|
/* amount of vm to protect from userspace using CAP_SYS_RAWIO (DAC) */
|
|
unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
|
|
/* amount of vm to protect from userspace using the LSM = CONFIG_LSM_MMAP_MIN_ADDR */
|
|
|
|
/*
|
|
* Update mmap_min_addr = max(dac_mmap_min_addr, CONFIG_LSM_MMAP_MIN_ADDR)
|
|
*/
|
|
static void update_mmap_min_addr(void)
|
|
{
|
|
#ifdef CONFIG_LSM_MMAP_MIN_ADDR
|
|
if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
|
|
mmap_min_addr = dac_mmap_min_addr;
|
|
else
|
|
mmap_min_addr = CONFIG_LSM_MMAP_MIN_ADDR;
|
|
#else
|
|
mmap_min_addr = dac_mmap_min_addr;
|
|
#endif
|
|
}
|
|
|
|
/*
|
|
* sysctl handler which just sets dac_mmap_min_addr = the new value and then
|
|
* calls update_mmap_min_addr() so non MAP_FIXED hints get rounded properly
|
|
*/
|
|
int mmap_min_addr_handler(struct ctl_table *table, int write,
|
|
void __user *buffer, size_t *lenp, loff_t *ppos)
|
|
{
|
|
int ret;
|
|
|
|
if (write && !capable(CAP_SYS_RAWIO))
|
|
return -EPERM;
|
|
|
|
ret = proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
|
|
|
|
update_mmap_min_addr();
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int __init init_mmap_min_addr(void)
|
|
{
|
|
update_mmap_min_addr();
|
|
|
|
return 0;
|
|
}
|
|
pure_initcall(init_mmap_min_addr);
|