1 diff -urNp linux-2.6.16.2/arch/sparc/Makefile linux-2.6.16.2/arch/sparc/Makefile
2 --- linux-2.6.16.2/arch/sparc/Makefile 2006-04-07 12:56:47.000000000 -0400
3 +++ linux-2.6.16.2/arch/sparc/Makefile 2006-04-09 21:23:54.000000000 -0400
4 @@ -34,7 +34,7 @@ libs-y += arch/sparc/prom/ arch/sparc/li
5 # Renaming is done to avoid confusing pattern matching rules in 2.5.45 (multy-)
6 INIT_Y := $(patsubst %/, %/built-in.o, $(init-y))
8 -CORE_Y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
9 +CORE_Y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
10 CORE_Y := $(patsubst %/, %/built-in.o, $(CORE_Y))
11 DRIVERS_Y := $(patsubst %/, %/built-in.o, $(drivers-y))
12 NET_Y := $(patsubst %/, %/built-in.o, $(net-y))
13 diff -urN linux-2.6.16.2/Makefile linux-2.6.16.2-grsec/Makefile
14 --- linux-2.6.16.2/Makefile 2006-04-07 18:56:47.000000000 +0200
15 +++ linux-2.6.16.2-grsec/Makefile 2006-04-11 17:44:40.069707000 +0200
19 ifeq ($(KBUILD_EXTMOD),)
20 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
21 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
23 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
24 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
25 diff -urN linux-2.6.16.2/drivers/char/keyboard.c linux-2.6.16.2-grsec/drivers/char/keyboard.c
26 --- linux-2.6.16.2/drivers/char/keyboard.c 2006-04-07 18:56:47.000000000 +0200
27 +++ linux-2.6.16.2-grsec/drivers/char/keyboard.c 2006-04-11 17:44:40.073707250 +0200
29 kbd->kbdmode == VC_MEDIUMRAW) &&
31 return; /* SAK is allowed even in raw mode */
33 +#if defined(CONFIG_GRKERNSEC_PROC)
35 + void *func = fn_handler[value];
36 + if (func == fn_show_state || func == fn_show_ptregs ||
37 + func == fn_show_mem)
42 fn_handler[value](vc);
45 diff -urNp linux-2.6.16.2/drivers/pci/proc.c linux-2.6.16.2-grsec/drivers/pci/proc.c
46 --- linux-2.6.16.2/drivers/pci/proc.c 2006-04-07 18:56:47.000000000 +0200
47 +++ linux-2.6.16.2-grsec/drivers/pci/proc.c 2006-04-11 17:44:40.073707250 +0200
48 @@ -467,7 +467,15 @@ static int __init pci_proc_init(void)
50 struct proc_dir_entry *entry;
51 struct pci_dev *dev = NULL;
52 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
53 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54 + proc_bus_pci_dir = proc_mkdir_mode("pci", S_IRUSR | S_IXUSR, proc_bus);
55 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56 + proc_bus_pci_dir = proc_mkdir_mode("pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, proc_bus);
59 proc_bus_pci_dir = proc_mkdir("pci", proc_bus);
61 entry = create_proc_entry("devices", 0, proc_bus_pci_dir);
63 entry->proc_fops = &proc_bus_pci_dev_operations;
64 diff -urNp linux-2.6.16.2/fs/Kconfig linux-2.6.16.2-grsec/fs/Kconfig
65 --- linux-2.6.16.2/fs/Kconfig 2006-04-07 18:56:47.000000000 +0200
66 +++ linux-2.6.16.2-grsec/fs/Kconfig 2006-04-11 17:44:40.073707250 +0200
67 @@ -817,7 +817,7 @@ config PROC_FS
70 bool "/proc/kcore support" if !ARM
71 - depends on PROC_FS && MMU
72 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
75 bool "/proc/vmcore support (EXPERIMENTAL)"
76 diff -urN linux-2.6.16.2/fs/namei.c linux-2.6.16.2-grsec/fs/namei.c
77 --- linux-2.6.16.2/fs/namei.c 2006-04-07 18:56:47.000000000 +0200
78 +++ linux-2.6.16.2-grsec/fs/namei.c 2006-04-11 18:10:35.961452750 +0200
80 #include <linux/vs_cowbl.h>
81 #include <linux/vs_device.h>
82 #include <linux/vs_context.h>
83 +#include <linux/grsecurity.h>
84 #include <asm/namei.h>
85 #include <asm/uaccess.h>
88 err = security_inode_follow_link(path->dentry, nd);
92 + if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
93 + path->dentry->d_inode, path->dentry, nd->mnt)) {
98 current->link_count++;
99 current->total_link_count++;
101 @@ -1647,6 +1655,13 @@
106 + if (gr_handle_fifo(path.dentry, nd->mnt, dir, flag, acc_mode)) {
107 + mutex_unlock(&dir->d_inode->i_mutex);
112 mutex_unlock(&dir->d_inode->i_mutex);
113 audit_inode_update(path.dentry->d_inode);
115 @@ -1700,6 +1715,13 @@
116 error = security_inode_follow_link(path.dentry, nd);
120 + if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
121 + path.dentry, nd->mnt)) {
126 error = __do_follow_link(&path, nd);
128 /* Does someone understand code flow here? Or it is only
129 @@ -2326,7 +2454,16 @@ asmlinkage long sys_linkat(int olddfd, c
130 error = PTR_ERR(new_dentry);
131 if (IS_ERR(new_dentry))
134 + if (gr_handle_hardlink(old_nd.dentry, old_nd.mnt,
135 + old_nd.dentry->d_inode,
136 + old_nd.dentry->d_inode->i_mode, to)) {
138 + goto out_unlock_dput;
141 error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry, &nd);
145 mutex_unlock(&nd.dentry->d_inode->i_mutex);
146 diff -urN linux-2.6.16.2/fs/proc/array.c linux-2.6.16.2-grsec/fs/proc/array.c
147 --- linux-2.6.16.2/fs/proc/array.c 2006-04-07 18:56:47.000000000 +0200
148 +++ linux-2.6.16.2-grsec/fs/proc/array.c 2006-04-11 17:44:40.077707500 +0200
150 return sprintf(buffer,"%d %d %d %d %d %d %d\n",
151 size, resident, shared, text, lib, data, 0);
154 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
155 +int proc_pid_ipaddr(struct task_struct *task, char * buffer)
159 + len = sprintf(buffer, "%u.%u.%u.%u\n", NIPQUAD(task->signal->curr_ip));
164 diff -urNp linux-2.6.16.2/fs/proc/inode.c linux-2.6.16.2-grsec/fs/proc/inode.c
165 --- linux-2.6.16.2/fs/proc/inode.c 2006-04-07 18:56:47.000000000 +0200
166 +++ linux-2.6.16.2-grsec/fs/proc/inode.c 2006-04-11 17:44:40.077707500 +0200
167 @@ -166,7 +166,11 @@ struct inode *proc_get_inode(struct supe
169 inode->i_mode = de->mode;
170 inode->i_uid = de->uid;
171 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
172 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
174 inode->i_gid = de->gid;
178 PROC_I(inode)->vx_flags = de->vx_flags;
179 diff -urNp linux-2.6.16.2/fs/proc/internal.h linux-2.6.16.2-grsec/fs/proc/internal.h
180 --- linux-2.6.16.2/fs/proc/internal.h 2006-04-07 18:56:47.000000000 +0200
181 +++ linux-2.6.16.2-grsec/fs/proc/internal.h 2006-04-11 17:44:40.077707500 +0200
182 @@ -36,6 +36,9 @@ extern int proc_tid_stat(struct task_str
183 extern int proc_tgid_stat(struct task_struct *, char *);
184 extern int proc_pid_status(struct task_struct *, char *);
185 extern int proc_pid_statm(struct task_struct *, char *);
186 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
187 +extern int proc_pid_ipaddr(struct task_struct*,char*);
190 extern struct file_operations proc_maps_operations;
191 extern struct file_operations proc_numa_maps_operations;
192 diff -urN linux-2.6.16.2/fs/proc/proc_misc.c linux-2.6.16.2-grsec/fs/proc/proc_misc.c
193 --- linux-2.6.16.2/fs/proc/proc_misc.c 2006-04-07 18:56:47.000000000 +0200
194 +++ linux-2.6.16.2-grsec/fs/proc/proc_misc.c 2006-04-11 17:44:40.109709500 +0200
195 @@ -667,6 +667,8 @@ void create_seq_entry(char *name, mode_t
197 void __init proc_misc_init(void)
203 int (*read_proc)(char*,char**,off_t,int,int*,void*);
204 @@ -685,7 +687,9 @@ void __init proc_misc_init(void)
205 {"stram", stram_read_proc},
207 {"filesystems", filesystems_read_proc},
208 +#ifndef CONFIG_GRKERNSEC_PROC_ADD
209 {"cmdline", cmdline_read_proc},
211 {"locks", locks_read_proc},
212 {"execdomains", execdomains_read_proc},
214 @@ -735,6 +735,15 @@ void __init proc_misc_init(void)
215 for (p = simple_ones; p->name; p++)
216 create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
218 +#ifdef CONFIG_GRKERNSEC_PROC_USER
220 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
221 + gr_mode = S_IRUSR | S_IRGRP;
223 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
224 + create_proc_read_entry("cmdline", gr_mode, NULL, &cmdline_read_proc, NULL);
227 proc_symlink("mounts", NULL, "self/mounts");
229 /* And now for trickier ones */
232 entry->proc_fops = &proc_kmsg_operations;
234 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
235 + create_seq_entry("devices", gr_mode, &proc_devinfo_operations);
237 create_seq_entry("devices", 0, &proc_devinfo_operations);
239 create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations);
241 create_seq_entry("partitions", 0, &proc_partitions_operations);
242 @@ -707,7 +724,11 @@ void __init proc_misc_init(void)
243 create_seq_entry("stat", 0, &proc_stat_operations);
244 create_seq_entry("interrupts", 0, &proc_interrupts_operations);
246 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
247 + create_seq_entry("slabinfo",S_IWUSR|gr_mode,&proc_slabinfo_operations);
249 create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations);
251 #ifdef CONFIG_DEBUG_SLAB_LEAK
252 create_seq_entry("slab_allocators", 0 ,&proc_slabstats_operations);
254 @@ -724,7 +745,7 @@ void __init proc_misc_init(void)
255 #ifdef CONFIG_SCHEDSTATS
256 create_seq_entry("schedstat", 0, &proc_schedstat_operations);
258 -#ifdef CONFIG_PROC_KCORE
259 +#if defined(CONFIG_PROC_KCORE) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
260 proc_root_kcore = create_proc_entry("kcore", S_IRUSR, NULL);
261 if (proc_root_kcore) {
262 proc_root_kcore->proc_fops = &proc_kcore_operations;
263 diff -urN linux-2.6.16.2/fs/proc/root.c linux-2.6.16.2-grsec/fs/proc/root.c
264 --- linux-2.6.16.2/fs/proc/root.c 2006-04-07 18:56:47.000000000 +0200
265 +++ linux-2.6.16.2-grsec/fs/proc/root.c 2006-04-11 17:44:40.113709750 +0200
270 +#ifdef CONFIG_GRKERNSEC_PROC_USER
271 + proc_net = proc_mkdir_mode("net", S_IRUSR | S_IXUSR, NULL);
272 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
273 + proc_net = proc_mkdir_mode("net", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
275 proc_net = proc_mkdir("net", NULL);
277 proc_net_stat = proc_mkdir("net/stat", NULL);
279 #ifdef CONFIG_SYSVIPC
281 #ifdef CONFIG_PROC_DEVICETREE
282 proc_device_tree_init();
284 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
285 +#ifdef CONFIG_GRKERNSEC_PROC_USER
286 + proc_bus = proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
287 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
288 + proc_bus = proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
291 proc_bus = proc_mkdir("bus", NULL);
296 diff -urN linux-2.6.16.2/grsecurity/Kconfig linux-2.6.16.2-grsec/grsecurity/Kconfig
297 --- linux-2.6.16.2/grsecurity/Kconfig 1970-01-01 01:00:00.000000000 +0100
298 +++ linux-2.6.16.2-grsec/grsecurity/Kconfig 2006-04-11 19:03:04.020561250 +0200
301 +# grecurity configuration
309 + select CRYPTO_SHA256
311 + If you say Y here, you will be able to configure many features
312 + that will enhance the security of your system. It is highly
313 + recommended that you say Y here and read through the help
314 + for each option so that you fully understand the features and
315 + can evaluate their usefulness for your machine.
317 +menu "Filesystem Protections"
318 +depends on GRKERNSEC
320 +config GRKERNSEC_PROC
321 + bool "Proc restrictions"
323 + If you say Y here, the permissions of the /proc filesystem
324 + will be altered to enhance system security and privacy. You MUST
325 + choose either a user only restriction or a user and group restriction.
326 + Depending upon the option you choose, you can either restrict users to
327 + see only the processes they themselves run, or choose a group that can
328 + view all processes and files normally restricted to root if you choose
329 + the "restrict to user only" option. NOTE: If you're running identd as
330 + a non-root user, you will have to run it as the group you specify here.
332 +config GRKERNSEC_PROC_USER
333 + bool "Restrict /proc to user only"
334 + depends on GRKERNSEC_PROC
336 + If you say Y here, non-root users will only be able to view their own
337 + processes, and restricts them from viewing network-related information,
338 + and viewing kernel symbol and module information.
340 +config GRKERNSEC_PROC_USERGROUP
341 + bool "Allow special group"
342 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
344 + If you say Y here, you will be able to select a group that will be
345 + able to view all processes, network-related information, and
346 + kernel and symbol information. This option is useful if you want
347 + to run identd as a non-root user.
349 +config GRKERNSEC_PROC_GID
350 + int "GID for special group"
351 + depends on GRKERNSEC_PROC_USERGROUP
354 +config GRKERNSEC_PROC_ADD
355 + bool "Additional restrictions"
356 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
358 + If you say Y here, additional restrictions will be placed on
359 + /proc that keep normal users from viewing device information and
360 + slabinfo information that could be useful for exploits.
362 +config GRKERNSEC_LINK
363 + bool "Linking restrictions"
365 + If you say Y here, /tmp race exploits will be prevented, since users
366 + will no longer be able to follow symlinks owned by other users in
367 + world-writable +t directories (i.e. /tmp), unless the owner of the
368 + symlink is the owner of the directory. users will also not be
369 + able to hardlink to files they do not own. If the sysctl option is
370 + enabled, a sysctl option with name "linking_restrictions" is created.
372 +config GRKERNSEC_FIFO
373 + bool "FIFO restrictions"
375 + If you say Y here, users will not be able to write to FIFOs they don't
376 + own in world-writable +t directories (i.e. /tmp), unless the owner of
377 + the FIFO is the same owner of the directory it's held in. If the sysctl
378 + option is enabled, a sysctl option with name "fifo_restrictions" is
383 +config GRKERNSEC_PROC_IPADDR
384 + depends on GRKERNSEC
385 + bool "/proc/<pid>/ipaddr support"
387 + If you say Y here, a new entry will be added to each /proc/<pid>
388 + directory that contains the IP address of the person using the task.
389 + The IP is carried across local TCP and AF_UNIX stream sockets.
390 + This information can be useful for IDS/IPSes to perform remote response
391 + to a local attack. The entry is readable by only the owner of the
392 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
393 + the RBAC system), and thus does not create privacy concerns.
395 +config GRKERNSEC_SHM
396 + depends on GRKERNSEC
397 + bool "Destroy unused shared memory"
400 + If you say Y here, shared memory will be destroyed when no one is
401 + attached to it. Otherwise, resources involved with the shared
402 + memory can be used up and not be associated with any process (as the
403 + shared memory still exists, and the creating process has exited). If
404 + the sysctl option is enabled, a sysctl option with name
405 + "destroy_unused_shm" is created.
407 +config GRKERNSEC_SYSCTL
408 + depends on GRKERNSEC && SYSCTL
409 + bool "Sysctl support"
411 + If you say Y here, you will be able to change the options that
412 + grsecurity runs with at bootup, without having to recompile your
413 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
414 + to enable (1) or disable (0) various features. All the sysctl entries
415 + are mutable until the "grsec_lock" entry is set to a non-zero value.
416 + All features enabled in the kernel configuration are disabled at boot
417 + if you do not say Y to the "Turn on features by default" option.
418 + All options should be set at startup, and the grsec_lock entry should
419 + be set to a non-zero value after all the options are set.
420 + *THIS IS EXTREMELY IMPORTANT*
422 +config GRKERNSEC_SYSCTL_ON
423 + bool "Turn on features by default"
424 + depends on GRKERNSEC_SYSCTL
426 + If you say Y here, instead of having all features enabled in the
427 + kernel configuration disabled at boot time, the features will be
428 + enabled at boot time. It is recommended you say Y here unless
429 + there is some reason you would want all sysctl-tunable features to
430 + be disabled by default. As mentioned elsewhere, it is important
431 + to enable the grsec_lock entry once you have finished modifying
432 + the sysctl entries.
435 diff -urN linux-2.6.16.2/grsecurity/Makefile linux-2.6.16.2-grsec/grsecurity/Makefile
436 --- linux-2.6.16.2/grsecurity/Makefile 1970-01-01 01:00:00.000000000 +0100
437 +++ linux-2.6.16.2-grsec/grsecurity/Makefile 2006-04-11 19:03:17.509404250 +0200
439 +# All code in this directory and various hooks inserted throughout the kernel
440 +# are copyright Brad Spengler, and released under the GPL v2 or higher
442 +obj-y = grsec_fifo.o grsec_sock.o grsec_sysctl.o grsec_link.o
444 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o
446 +ifndef CONFIG_GRKERNSEC
447 +obj-y += grsec_disabled.o
450 diff -urN linux-2.6.16.2/grsecurity/grsec_disabled.c linux-2.6.16.2-grsec/grsecurity/grsec_disabled.c
451 --- linux-2.6.16.2/grsecurity/grsec_disabled.c 1970-01-01 01:00:00.000000000 +0100
452 +++ linux-2.6.16.2-grsec/grsecurity/grsec_disabled.c 2006-04-11 17:44:40.113709750 +0200
455 +grsecurity_init(void)
459 diff -urN linux-2.6.16.2/grsecurity/grsec_fifo.c linux-2.6.16.2-grsec/grsecurity/grsec_fifo.c
460 --- linux-2.6.16.2/grsecurity/grsec_fifo.c 1970-01-01 01:00:00.000000000 +0100
461 +++ linux-2.6.16.2-grsec/grsecurity/grsec_fifo.c 2006-04-11 19:04:02.872239250 +0200
463 +#include <linux/kernel.h>
464 +#include <linux/sched.h>
465 +#include <linux/fs.h>
466 +#include <linux/file.h>
467 +#include <linux/grinternal.h>
470 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
471 + const struct dentry *dir, const int flag, const int acc_mode)
473 +#ifdef CONFIG_GRKERNSEC_FIFO
474 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
475 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
476 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
477 + (current->fsuid != dentry->d_inode->i_uid)) {
483 diff -urN linux-2.6.16.2/grsecurity/grsec_init.c linux-2.6.16.2-grsec/grsecurity/grsec_init.c
484 --- linux-2.6.16.2/grsecurity/grsec_init.c 1970-01-01 01:00:00.000000000 +0100
485 +++ linux-2.6.16.2-grsec/grsecurity/grsec_init.c 2006-04-11 19:04:24.693603000 +0200
487 +#include <linux/kernel.h>
488 +#include <linux/sched.h>
489 +#include <linux/mm.h>
490 +#include <linux/smp_lock.h>
491 +#include <linux/slab.h>
492 +#include <linux/vmalloc.h>
493 +#include <linux/percpu.h>
495 +int grsec_enable_shm;
496 +int grsec_enable_link;
497 +int grsec_enable_fifo;
501 +grsecurity_init(void)
503 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
504 +#ifndef CONFIG_GRKERNSEC_SYSCTL
507 +#ifdef CONFIG_GRKERNSEC_SHM
508 + grsec_enable_shm = 1;
510 +#ifdef CONFIG_GRKERNSEC_LINK
511 + grsec_enable_link = 1;
513 +#ifdef CONFIG_GRKERNSEC_FIFO
514 + grsec_enable_fifo = 1;
520 diff -urN linux-2.6.16.2/grsecurity/grsec_link.c linux-2.6.16.2-grsec/grsecurity/grsec_link.c
521 --- linux-2.6.16.2/grsecurity/grsec_link.c 1970-01-01 01:00:00.000000000 +0100
522 +++ linux-2.6.16.2-grsec/grsecurity/grsec_link.c 2006-04-11 19:04:40.258575750 +0200
524 +#include <linux/kernel.h>
525 +#include <linux/sched.h>
526 +#include <linux/fs.h>
527 +#include <linux/file.h>
528 +#include <linux/grinternal.h>
531 +gr_handle_follow_link(const struct inode *parent,
532 + const struct inode *inode,
533 + const struct dentry *dentry, const struct vfsmount *mnt)
535 +#ifdef CONFIG_GRKERNSEC_LINK
536 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
537 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
538 + (parent->i_mode & S_IWOTH) && (current->fsuid != inode->i_uid)) {
546 +gr_handle_hardlink(const struct dentry *dentry,
547 + const struct vfsmount *mnt,
548 + struct inode *inode, const int mode, const char *to)
550 +#ifdef CONFIG_GRKERNSEC_LINK
551 + if (grsec_enable_link && current->fsuid != inode->i_uid &&
552 + (!S_ISREG(mode) || (mode & S_ISUID) ||
553 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
554 + (generic_permission(inode, MAY_READ | MAY_WRITE, NULL))) &&
555 + !capable(CAP_FOWNER) && current->uid) {
561 diff -urN linux-2.6.16.2/grsecurity/grsec_sock.c linux-2.6.16.2-grsec/grsecurity/grsec_sock.c
562 --- linux-2.6.16.2/grsecurity/grsec_sock.c 1970-01-01 01:00:00.000000000 +0100
563 +++ linux-2.6.16.2-grsec/grsecurity/grsec_sock.c 2006-04-11 19:20:18.301199750 +0200
565 +#include <linux/kernel.h>
566 +#include <linux/module.h>
567 +#include <linux/sched.h>
568 +#include <linux/file.h>
569 +#include <linux/net.h>
570 +#include <linux/in.h>
571 +#include <linux/ip.h>
572 +#include <net/sock.h>
573 +#include <net/inet_sock.h>
574 +#include <linux/grsecurity.h>
575 +#include <linux/grinternal.h>
577 +#ifdef CONFIG_GRKERNSEC
578 +#define gr_conn_table_size 32749
579 +struct conn_table_entry {
580 + struct conn_table_entry *next;
581 + struct signal_struct *sig;
584 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
585 +spinlock_t gr_conn_table_lock = SPIN_LOCK_UNLOCKED;
587 +static __inline__ int
588 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
590 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
593 +static __inline__ int
594 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
595 + __u16 sport, __u16 dport)
597 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
598 + sig->gr_sport == sport && sig->gr_dport == dport))
604 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
606 + struct conn_table_entry **match;
607 + unsigned int index;
609 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
610 + sig->gr_sport, sig->gr_dport,
611 + gr_conn_table_size);
615 + match = &gr_conn_table[index];
616 + newent->next = *match;
622 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
624 + struct conn_table_entry *match, *last = NULL;
625 + unsigned int index;
627 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
628 + sig->gr_sport, sig->gr_dport,
629 + gr_conn_table_size);
631 + match = gr_conn_table[index];
632 + while (match && !conn_match(match->sig,
633 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
636 + match = match->next;
641 + last->next = match->next;
643 + gr_conn_table[index] = NULL;
650 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
651 + __u16 sport, __u16 dport)
653 + struct conn_table_entry *match;
654 + unsigned int index;
656 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
658 + match = gr_conn_table[index];
659 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
660 + match = match->next;
670 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
672 +#ifdef CONFIG_GRKERNSEC
673 + struct signal_struct *sig = task->signal;
674 + struct conn_table_entry *newent;
676 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
677 + if (newent == NULL)
680 + spin_lock(&gr_conn_table_lock);
681 + gr_del_task_from_ip_table_nolock(sig);
682 + sig->gr_saddr = inet->rcv_saddr;
683 + sig->gr_daddr = inet->daddr;
684 + sig->gr_sport = inet->sport;
685 + sig->gr_dport = inet->dport;
686 + gr_add_to_task_ip_table_nolock(sig, newent);
687 + spin_unlock(&gr_conn_table_lock);
692 +void gr_del_task_from_ip_table(struct task_struct *task)
694 +#ifdef CONFIG_GRKERNSEC
695 + spin_lock(&gr_conn_table_lock);
696 + gr_del_task_from_ip_table_nolock(task->signal);
697 + spin_unlock(&gr_conn_table_lock);
703 +gr_attach_curr_ip(const struct sock *sk)
705 +#ifdef CONFIG_GRKERNSEC
706 + struct signal_struct *p, *set;
707 + const struct inet_sock *inet = inet_sk(sk);
709 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
712 + set = current->signal;
714 + spin_lock(&gr_conn_table_lock);
715 + p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
716 + inet->dport, inet->sport);
717 + if (unlikely(p != NULL)) {
718 + set->curr_ip = p->curr_ip;
719 + gr_del_task_from_ip_table_nolock(p);
720 + spin_unlock(&gr_conn_table_lock);
723 + spin_unlock(&gr_conn_table_lock);
725 + set->curr_ip = inet->daddr;
729 diff -urN linux-2.6.16.2/grsecurity/grsec_sysctl.c linux-2.6.16.2-grsec/grsecurity/grsec_sysctl.c
730 --- linux-2.6.16.2/grsecurity/grsec_sysctl.c 1970-01-01 01:00:00.000000000 +0100
731 +++ linux-2.6.16.2-grsec/grsecurity/grsec_sysctl.c 2006-04-11 19:04:50.363207250 +0200
733 +#include <linux/kernel.h>
734 +#include <linux/sched.h>
735 +#include <linux/sysctl.h>
736 +#include <linux/grsecurity.h>
737 +#include <linux/grinternal.h>
740 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
742 +#ifdef CONFIG_GRKERNSEC_SYSCTL
743 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & 002)) {
750 +#if defined(CONFIG_GRKERNSEC_SYSCTL)
751 +enum {GS_LINK=1, GS_FIFO, GS_SHM, GS_LOCK};
754 +ctl_table grsecurity_table[] = {
755 +#ifdef CONFIG_GRKERNSEC_SYSCTL
756 +#ifdef CONFIG_GRKERNSEC_LINK
758 + .ctl_name = GS_LINK,
759 + .procname = "linking_restrictions",
760 + .data = &grsec_enable_link,
761 + .maxlen = sizeof(int),
763 + .proc_handler = &proc_dointvec,
766 +#ifdef CONFIG_GRKERNSEC_FIFO
768 + .ctl_name = GS_FIFO,
769 + .procname = "fifo_restrictions",
770 + .data = &grsec_enable_fifo,
771 + .maxlen = sizeof(int),
773 + .proc_handler = &proc_dointvec,
776 +#ifdef CONFIG_GRKERNSEC_SHM
778 + .ctl_name = GS_SHM,
779 + .procname = "destroy_unused_shm",
780 + .data = &grsec_enable_shm,
781 + .maxlen = sizeof(int),
783 + .proc_handler = &proc_dointvec,
787 + .ctl_name = GS_LOCK,
788 + .procname = "grsec_lock",
789 + .data = &grsec_lock,
790 + .maxlen = sizeof(int),
792 + .proc_handler = &proc_dointvec,
798 diff -urN linux-2.6.16.2/include/linux/grinternal.h linux-2.6.16.2-grsec/include/linux/grinternal.h
799 --- linux-2.6.16.2/include/linux/grinternal.h 1970-01-01 01:00:00.000000000 +0100
800 +++ linux-2.6.16.2-grsec/include/linux/grinternal.h 2006-04-11 19:03:34.734480750 +0200
802 +#ifndef __GRINTERNAL_H
803 +#define __GRINTERNAL_H
805 +#ifdef CONFIG_GRKERNSEC
807 +#include <linux/fs.h>
809 +extern int grsec_enable_link;
810 +extern int grsec_enable_fifo;
811 +extern int grsec_enable_shm;
812 +extern int grsec_lock;
817 diff -urN linux-2.6.16.2/include/linux/grsecurity.h linux-2.6.16.2-grsec/include/linux/grsecurity.h
818 --- linux-2.6.16.2/include/linux/grsecurity.h 1970-01-01 01:00:00.000000000 +0100
819 +++ linux-2.6.16.2-grsec/include/linux/grsecurity.h 2006-04-11 18:06:03.000000000 +0200
821 +#ifndef GR_SECURITY_H
822 +#define GR_SECURITY_H
823 +#include <linux/fs.h>
824 +#include <linux/binfmts.h>
826 +extern void gr_del_task_from_ip_table(struct task_struct *p);
828 +extern int gr_handle_follow_link(const struct inode *parent,
829 + const struct inode *inode,
830 + const struct dentry *dentry,
831 + const struct vfsmount *mnt);
832 +extern int gr_handle_fifo(const struct dentry *dentry,
833 + const struct vfsmount *mnt,
834 + const struct dentry *dir, const int flag,
835 + const int acc_mode);
836 +extern int gr_handle_hardlink(const struct dentry *dentry,
837 + const struct vfsmount *mnt,
838 + struct inode *inode,
839 + const int mode, const char *to);
841 +#ifdef CONFIG_SYSVIPC
842 +extern void gr_shm_exit(struct task_struct *task);
844 +static inline void gr_shm_exit(struct task_struct *task)
850 +#ifdef CONFIG_GRKERNSEC
851 +extern int grsec_enable_shm;
855 diff -urNp linux-2.6.16.2/include/linux/sched.h linux-2.6.16.2-grsec/include/linux/sched.h
856 --- linux-2.6.16.2/include/linux/sched.h 2006-04-07 18:56:47.000000000 +0200
857 +++ linux-2.6.16.2-grsec/include/linux/sched.h 2006-04-11 19:14:15.574530750 +0200
858 @@ -474,6 +474,13 @@ struct signal_struct {
859 spinlock_t stats_lock;
860 struct taskstats *stats;
862 +#ifdef CONFIG_GRKERNSEC
871 /* Context switch must be unlocked if interrupts are to be enabled */
872 diff -urN linux-2.6.16.2/include/linux/shm.h linux-2.6.16.2-grsec/include/linux/shm.h
873 --- linux-2.6.16.2/include/linux/shm.h 2006-04-07 18:56:47.000000000 +0200
874 +++ linux-2.6.16.2-grsec/include/linux/shm.h 2006-04-11 17:44:40.121710250 +0200
878 struct user_struct *mlock_user;
879 +#ifdef CONFIG_GRKERNSEC
880 + time_t shm_createtime;
885 /* shm_mode upper byte flags */
886 diff -urN linux-2.6.16.2/include/linux/sysctl.h linux-2.6.16.2-grsec/include/linux/sysctl.h
887 --- linux-2.6.16.2/include/linux/sysctl.h 2006-04-07 18:56:47.000000000 +0200
888 +++ linux-2.6.16.2-grsec/include/linux/sysctl.h 2006-04-11 18:09:09.244033250 +0200
893 +#ifdef CONFIG_GRKERNSEC
894 + KERN_GRSECURITY=98, /* grsecurity */
896 VM_UNUSED1=1, /* was: struct: Set vm swapping control */
897 VM_UNUSED2=2, /* was; int: Linear or sqrt() swapout for hogs */
898 VM_UNUSED3=3, /* was: struct: Set free page thresholds */
899 diff -urNp linux-2.6.16.2/ipc/shm.c linux-2.6.16.2-grsec/ipc/shm.c
900 --- linux-2.6.16.2/ipc/shm.c 2006-04-07 18:56:47.000000000 +0200
901 +++ linux-2.6.16.2-grsec/ipc/shm.c 2006-04-11 17:44:40.121710250 +0200
903 #include <linux/mutex.h>
904 #include <linux/vs_context.h>
905 #include <linux/vs_limit.h>
906 +#include <linux/grsecurity.h>
908 #include <asm/uaccess.h>
910 @@ -156,6 +157,17 @@ static void shm_close (struct vm_area_st
911 shp->shm_lprid = current->tgid;
912 shp->shm_dtim = get_seconds();
914 +#ifdef CONFIG_GRKERNSEC_SHM
915 + if (grsec_enable_shm) {
916 + if (shp->shm_nattch == 0) {
917 + shp->shm_perm.mode |= SHM_DEST;
918 + shm_destroy(ns, shp);
921 + mutex_unlock(&shm_ids(ns).mutex);
925 if(shp->shm_nattch == 0 &&
926 shp->shm_perm.mode & SHM_DEST)
928 @@ -258,6 +270,9 @@ static int newseg (key_t key, int shmflg
930 shp->shm_atim = shp->shm_dtim = 0;
931 shp->shm_ctim = get_seconds();
932 +#ifdef CONFIG_GRKERNSEC
933 + shp->shm_createtime = get_seconds();
935 shp->shm_segsz = size;
937 shp->id = shm_buildid(id,shp->shm_perm.seq);
938 @@ -774,6 +789,9 @@ long do_shmat(int shmid, char __user *sh
939 path.dentry = dget(shp->shm_file->f_path.dentry);
940 path.mnt = mntget(shp->shm_file->f_path.mnt);
942 +#ifdef CONFIG_GRKERNSEC
943 + shp->shm_lapid = current->pid;
945 size = i_size_read(path.dentry->d_inode);
948 @@ -1014,3 +1059,27 @@ static int sysvipc_shm_proc_show(struct
953 +void gr_shm_exit(struct task_struct *task)
955 +#ifdef CONFIG_GRKERNSEC_SHM
957 + struct shmid_kernel *shp;
958 + struct ipc_namespace *ns;
960 + ns = current->nsproxy->ipc_ns;
962 + if (!grsec_enable_shm)
965 + for (i = 0; i <= shm_ids(ns).max_id; i++) {
966 + shp = shm_get(ns, i);
967 + if (shp && (shp->shm_cprid == task->pid) &&
968 + (shp->shm_nattch <= 0)) {
969 + shp->shm_perm.mode |= SHM_DEST;
970 + shm_destroy(ns, shp);
976 diff -urNp linux-2.6.18/kernel/configs.c linux-2.6.18/kernel/configs.c
977 --- linux-2.6.18/kernel/configs.c 2006-09-19 23:42:06.000000000 -0400
978 +++ linux-2.6.18/kernel/configs.c 2006-09-22 20:04:35.000000000 -0400
979 @@ -88,8 +88,16 @@ static int __init ikconfig_init(void)
980 struct proc_dir_entry *entry;
982 /* create the current config file */
983 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
984 +#ifdef CONFIG_GRKERNSEC_PROC_USER
985 + entry = create_proc_entry("config.gz", S_IFREG | S_IRUSR, &proc_root);
986 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
987 + entry = create_proc_entry("config.gz", S_IFREG | S_IRUSR | S_IRGRP, &proc_root);
990 entry = create_proc_entry("config.gz", S_IFREG | S_IRUGO,
996 diff -urN linux-2.6.16.2/kernel/exit.c linux-2.6.16.2-grsec/kernel/exit.c
997 --- linux-2.6.16.2/kernel/exit.c 2006-04-07 18:56:47.000000000 +0200
998 +++ linux-2.6.16.2-grsec/kernel/exit.c 2006-04-11 17:44:40.125710500 +0200
1000 #include <linux/resource.h>
1001 #include <linux/blkdev.h>
1002 #include <linux/task_io_accounting_ops.h>
1003 +#include <linux/grsecurity.h>
1004 #include <linux/vs_limit.h>
1005 #include <linux/vs_context.h>
1006 #include <linux/vs_network.h>
1007 @@ -118,6 +123,7 @@ static void __exit_signal(struct task_st
1009 __unhash_process(tsk);
1011 + gr_del_task_from_ip_table(tsk);
1013 tsk->sighand = NULL;
1014 spin_unlock(&sighand->siglock);
1015 @@ -914,6 +942,7 @@ fastcall NORET_TYPE void do_exit(long co
1023 diff -urNp linux-2.6.18/kernel/kallsyms.c linux-2.6.18/kernel/kallsyms.c
1024 --- linux-2.6.18/kernel/kallsyms.c 2006-09-19 23:42:06.000000000 -0400
1025 +++ linux-2.6.18/kernel/kallsyms.c 2006-09-22 20:45:04.000000000 -0400
1026 @@ -411,7 +410,15 @@ static int __init kallsyms_init(void)
1028 struct proc_dir_entry *entry;
1030 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
1031 +#ifdef CONFIG_GRKERNSEC_PROC_USER
1032 + entry = create_proc_entry("kallsyms", S_IFREG | S_IRUSR, NULL);
1033 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
1034 + entry = create_proc_entry("kallsyms", S_IFREG | S_IRUSR | S_IRGRP, NULL);
1037 entry = create_proc_entry("kallsyms", 0444, NULL);
1040 entry->proc_fops = &kallsyms_operations;
1042 diff -urNp linux-2.6.18/kernel/resource.c linux-2.6.18/kernel/resource.c
1043 --- linux-2.6.18/kernel/resource.c 2006-09-19 23:42:06.000000000 -0400
1044 +++ linux-2.6.18/kernel/resource.c 2006-09-22 20:04:35.000000000 -0400
1045 @@ -133,10 +133,27 @@ static int __init ioresources_init(void)
1047 struct proc_dir_entry *entry;
1049 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
1050 +#ifdef CONFIG_GRKERNSEC_PROC_USER
1051 + entry = create_proc_entry("ioports", S_IRUSR, NULL);
1052 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
1053 + entry = create_proc_entry("ioports", S_IRUSR | S_IRGRP, NULL);
1056 entry = create_proc_entry("ioports", 0, NULL);
1059 entry->proc_fops = &proc_ioports_operations;
1061 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
1062 +#ifdef CONFIG_GRKERNSEC_PROC_USER
1063 + entry = create_proc_entry("iomem", S_IRUSR, NULL);
1064 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
1065 + entry = create_proc_entry("iomem", S_IRUSR | S_IRGRP, NULL);
1068 entry = create_proc_entry("iomem", 0, NULL);
1071 entry->proc_fops = &proc_iomem_operations;
1073 diff -urN linux-2.6.16.2/kernel/sysctl.c linux-2.6.16.2-grsec/kernel/sysctl.c
1074 --- linux-2.6.16.2/kernel/sysctl.c 2006-04-07 18:56:47.000000000 +0200
1075 +++ linux-2.6.16.2-grsec/kernel/sysctl.c 2006-04-11 17:44:40.125710500 +0200
1076 @@ -58,6 +58,11 @@ extern int proc_nr_files(ctl_table *tabl
1079 #if defined(CONFIG_SYSCTL)
1080 +#include <linux/grsecurity.h>
1081 +#include <linux/grinternal.h>
1083 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
1086 /* External variables not in a header file. */
1088 @@ -163,6 +168,7 @@ extern ctl_table inotify_table[];
1089 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1090 int sysctl_legacy_va_layout;
1092 +extern ctl_table grsecurity_table[];
1094 /* /proc declarations: */
1096 @@ -972,6 +978,16 @@ static ctl_table vm_table[] = {
1101 +#if defined(CONFIG_GRKERNSEC_SYSCTL)
1103 + .ctl_name = KERN_GRSECURITY,
1104 + .procname = "grsecurity",
1106 + .child = grsecurity_table,
1113 @@ -1233,6 +1249,10 @@ static int test_perm(int mode, int op)
1114 static inline int ctl_perm(ctl_table *table, int op)
1117 + if (table->parent != NULL && table->parent->procname != NULL &&
1118 + table->procname != NULL &&
1119 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
1121 error = security_sysctl(table, op);
1124 diff -urNp linux-2.6.16.2/net/ipv4/inet_hashtables.c linux-2.6.16.2-grsec/net/ipv4/inet_hashtables.c
1125 --- linux-2.6.16.2/net/ipv4/inet_hashtables.c 2006-04-07 18:56:47.000000000 +0200
1126 +++ linux-2.6.16.2-grsec/net/ipv4/inet_hashtables.c 2006-04-11 17:44:40.125710500 +0200
1128 #include <linux/sched.h>
1129 #include <linux/slab.h>
1130 #include <linux/wait.h>
1131 +#include <linux/grsecurity.h>
1133 #include <net/inet_connection_sock.h>
1134 #include <net/inet_hashtables.h>
1137 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
1140 * Allocate and initialize a new local port bind bucket.
1141 * The bindhash mutex for snum's hash chain must be held here.
1142 @@ -308,6 +311,8 @@ ok:
1144 spin_unlock(&head->lock);
1146 + gr_update_task_in_ip_table(current, inet_sk(sk));
1149 inet_twsk_deschedule(tw, death_row);
1151 diff -urNp linux-2.6.16.2/net/socket.c linux-2.6.16.2-grsec/net/socket.c
1152 --- linux-2.6.16.2/net/socket.c 2006-04-07 18:56:47.000000000 +0200
1153 +++ linux-2.6.16.2-grsec/net/socket.c 2006-04-11 17:44:40.125710500 +0200
1155 #include <linux/compat.h>
1156 #include <linux/kmod.h>
1157 #include <linux/audit.h>
1158 +#include <linux/in.h>
1159 #include <linux/wireless.h>
1161 #include <asm/uaccess.h>
1163 #include <linux/netfilter.h>
1164 #include <linux/vs_socket.h>
1166 +extern void gr_attach_curr_ip(const struct sock *sk);
1167 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
1168 static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf,
1169 size_t size, loff_t pos);
1170 @@ -1482,6 +1484,7 @@ asmlinkage long sys_accept(int fd, struc
1173 security_socket_post_accept(sock, newsock);
1174 + gr_attach_curr_ip(newsock->sk);
1177 fput_light(sock->file, fput_needed);
1178 diff -urN linux-2.6.16.2/security/Kconfig linux-2.6.16.2-grsec/security/Kconfig
1179 --- linux-2.6.16.2/security/Kconfig 2006-04-07 18:56:47.000000000 +0200
1180 +++ linux-2.6.16.2-grsec/security/Kconfig 2006-04-11 17:44:40.129710750 +0200
1183 menu "Security options"
1185 +source grsecurity/Kconfig
1188 bool "Enable access key retention support"
1190 diff -urN linux-2.6.18/fs/proc/base.c linux-2.6.18-grsec/fs/proc/base.c
1191 --- linux-2.6.18/fs/proc/base.c.orig 2006-11-03 18:27:40.112510768 +0100
1192 +++ linux-2.6.18/fs/proc/base.c 2006-11-03 18:42:56.408212648 +0100
1193 @@ -969,7 +969,11 @@ static struct inode *proc_pid_make_inode
1194 if (task_dumpable(task)) {
1195 inode->i_uid = task->euid;
1196 inode->i_gid = task->egid;
1197 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
1198 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
1202 /* procfs is xid tagged */
1203 inode->i_tag = (tag_t)vx_task_xid(task);
1204 security_task_to_inode(task, inode);
1205 @@ -985,17 +992,38 @@ static int pid_getattr(struct vfsmount *
1207 struct inode *inode = dentry->d_inode;
1208 struct task_struct *task;
1209 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
1210 + struct task_struct *tmp = current;
1213 generic_fillattr(inode, stat);
1218 task = pid_task(proc_pid(inode), PIDTYPE_PID);
1221 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
1222 + && (!tmp->uid || (tmp->uid == task->uid)
1223 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
1224 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
1229 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
1230 +#ifdef CONFIG_GRKERNSEC_PROC_USER
1231 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
1232 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
1233 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
1235 task_dumpable(task)) {
1236 stat->uid = task->euid;
1237 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
1238 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
1240 stat->gid = task->egid;
1245 @@ -1025,9 +1053,18 @@ static int pid_revalidate(struct dentry
1246 struct task_struct *task = get_proc_task(inode);
1248 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
1249 +#ifdef CONFIG_GRKERNSEC_PROC_USER
1250 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
1251 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
1252 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
1254 task_dumpable(task)) {
1255 inode->i_uid = task->euid;
1256 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
1257 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
1259 inode->i_gid = task->egid;
1264 @@ -1791,6 +1833,9 @@ static struct pid_entry tgid_base_stuff[
1265 #ifdef CONFIG_AUDITSYSCALL
1266 REG("loginuid", S_IWUSR|S_IRUGO, loginuid),
1268 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
1269 + INF("ipaddr", S_IRUSR, pid_ipaddr),
1273 static int proc_tgid_base_readdir(struct file * filp,
1274 @@ -1893,7 +1938,14 @@ struct dentry *proc_pid_instantiate(stru
1278 +#ifdef CONFIG_GRKERNSEC_PROC_USER
1279 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
1280 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
1281 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
1282 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
1284 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
1286 inode->i_op = &proc_tgid_base_inode_operations;
1287 inode->i_fop = &proc_tgid_base_operations;
1288 inode->i_flags|=S_IMMUTABLE;
1289 @@ -1992,6 +2048,9 @@ int proc_pid_readdir(struct file * filp,
1291 unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
1292 struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
1293 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
1294 + struct task_struct *tmp = current;
1296 struct task_struct *task;
1299 @@ -2009,6 +2068,16 @@ int proc_pid_readdir(struct file * filp,
1301 put_task_struct(task), task = next_tgid(tgid + 1)) {
1304 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
1305 + if (tmp->uid && (task->uid != tmp->uid)
1306 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
1307 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
1313 filp->f_pos = tgid + TGID_OFFSET;
1314 if (proc_pid_fill_cache(filp, dirent, filldir, task, tgid) < 0) {
1315 put_task_struct(task);