Skip to content

Commit 6e14154

Browse files
dhowellsxjamesmorris
authored andcommitted
NOMMU: Optimise away the {dac_,}mmap_min_addr tests
In NOMMU mode clamp dac_mmap_min_addr to zero to cause the tests on it to be skipped by the compiler. We do this as the minimum mmap address doesn't make any sense in NOMMU mode. mmap_min_addr and round_hint_to_min() can be discarded entirely in NOMMU mode. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: Eric Paris <eparis@redhat.com> Signed-off-by: James Morris <jmorris@namei.org>
1 parent dd880fb commit 6e14154

4 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎include/linux/security.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,13 @@ struct seq_file;
9595
extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
9696
extern int cap_netlink_recv(struct sk_buff *skb, int cap);
9797

98+
#ifdef CONFIG_MMU
9899
extern unsigned long mmap_min_addr;
99100
extern unsigned long dac_mmap_min_addr;
101+
#else
102+
#define dac_mmap_min_addr 0UL
103+
#endif
104+
100105
/*
101106
* Values used in the task_security_ops calls
102107
*/
@@ -121,6 +126,7 @@ struct request_sock;
121126
#define LSM_UNSAFE_PTRACE 2
122127
#define LSM_UNSAFE_PTRACE_CAP 4
123128

129+
#ifdef CONFIG_MMU
124130
/*
125131
* If a hint addr is less than mmap_min_addr change hint to be as
126132
* low as possible but still greater than mmap_min_addr
@@ -135,6 +141,7 @@ static inline unsigned long round_hint_to_min(unsigned long hint)
135141
}
136142
extern int mmap_min_addr_handler(struct ctl_table *table, int write,
137143
void __user *buffer, size_t *lenp, loff_t *ppos);
144+
#endif
138145

139146
#ifdef CONFIG_SECURITY
140147

‎kernel/sysctl.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,13 +1214,15 @@ static struct ctl_table vm_table[] = {
12141214
.proc_handler = proc_dointvec_jiffies,
12151215
},
12161216
#endif
1217+
#ifdef CONFIG_MMU
12171218
{
12181219
.procname = "mmap_min_addr",
12191220
.data = &dac_mmap_min_addr,
12201221
.maxlen = sizeof(unsigned long),
12211222
.mode = 0644,
12221223
.proc_handler = mmap_min_addr_handler,
12231224
},
1225+
#endif
12241226
#ifdef CONFIG_NUMA
12251227
{
12261228
.procname = "numa_zonelist_order",

‎mm/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ config KSM
221221

222222
config DEFAULT_MMAP_MIN_ADDR
223223
int "Low address space to protect from user allocation"
224+
depends on MMU
224225
default 4096
225226
help
226227
This is the portion of low virtual memory which should be protected

‎security/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ subdir-$(CONFIG_SECURITY_SMACK) += smack
88
subdir-$(CONFIG_SECURITY_TOMOYO) += tomoyo
99

1010
# always enable default capabilities
11-
obj-y += commoncap.o min_addr.o
11+
obj-y += commoncap.o
12+
obj-$(CONFIG_MMU) += min_addr.o
1213

1314
# Object file lists
1415
obj-$(CONFIG_SECURITY) += security.o capability.o

0 commit comments

Comments
 (0)