Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 35819 | Differences between
and this patch

Collapse All | Expand All

(-)linux-2.4.22-ppc-dev.orig/Documentation/Configure.help (+879 lines)
Lines 2725-2730 Link Here
2725
  If you want to compile it as a module, say M here and read
2725
  If you want to compile it as a module, say M here and read
2726
  Documentation/modules.txt.  If unsure, say `N'.
2726
  Documentation/modules.txt.  If unsure, say `N'.
2727
2727
2728
stealth networking support
2729
CONFIG_IP_NF_MATCH_STEALTH
2730
  Enabling this option will drop all syn packets coming to unserved tcp
2731
  ports as well as all packets coming to unserved udp ports.  If you
2732
  are using your system to route any type of packets (ie. via NAT)
2733
  you should put this module at the end of your ruleset, since it will 
2734
  drop packets that aren't going to ports that are listening on your 
2735
  machine itself, it doesn't take into account that the packet might be 
2736
  destined for someone on your internal network if you're using NAT for 
2737
  instance.
2738
2739
  If you want to compile it as a module, say M here and read
2740
  Documentation/modules.txt.  If unsure, say `N'.
2741
2728
MAC address match support
2742
MAC address match support
2729
CONFIG_IP_NF_MATCH_MAC
2743
CONFIG_IP_NF_MATCH_MAC
2730
  MAC matching allows you to match packets based on the source
2744
  MAC matching allows you to match packets based on the source
Lines 22283-22288 Link Here
22283
22297
22284
  "Area6" will work for most boards. For ADX, select "Area5".
22298
  "Area6" will work for most boards. For ADX, select "Area5".
22285
22299
22300
Grsecurity
22301
CONFIG_GRKERNSEC
22302
  If you say Y here, you will be able to configure many features that
22303
  will enhance the security of your system.  It is highly recommended
22304
  that you say Y here and read through the help for each option so
22305
  you fully understand the features and can evaluate their usefulness
22306
  for your machine.
22307
22308
Additional security levels
22309
CONFIG_GRKERNSEC_LOW
22310
22311
  Low additional security
22312
  -----------------------------------------------------------------------
22313
  If you choose this option, several of the grsecurity options will
22314
  be enabled that will give you greater protection against a number
22315
  of attacks, while assuring that none of your software will have any 
22316
  conflicts with the additional security measures.  If you run a lot of 
22317
  unusual software, or you are having problems with the higher security 
22318
  levels, you should say Y here.  With this option, the following features
22319
  are enabled:
22320
  
22321
  linking restrictions
22322
  fifo restrictions
22323
  random pids
22324
  enforcing nproc on execve()
22325
  restricted dmesg
22326
  random ip ids
22327
  enforced chdir("/") on chroot
22328
22329
  Medium additional security
22330
  -----------------------------------------------------------------------
22331
  If you say Y here, several features in addition to those included in the 
22332
  low additional security level will be enabled.  These features provide
22333
  even more security to your system, though in rare cases they may
22334
  be incompatible with very old or poorly written software.  If you 
22335
  enable this option, make sure that your auth service (identd) is 
22336
  running as gid 10 (usually group wheel). With this option the following 
22337
  features (in addition to those provided in the low additional security 
22338
  level) will be enabled:
22339
22340
  random tcp source ports
22341
  altered ping ids
22342
  failed fork logging
22343
  time change logging
22344
  signal logging
22345
  deny mounts in chroot
22346
  deny double chrooting
22347
  deny sysctl writes in chroot
22348
  deny mknod in chroot
22349
  deny access to abstract AF_UNIX sockets out of chroot
22350
  deny pivot_root in chroot
22351
  denied writes of /dev/kmem, /dev/mem, and /dev/port
22352
  /proc restrictions with special gid set to 10 (usually wheel)
22353
  address space layout randomization
22354
22355
  High additional security
22356
  ----------------------------------------------------------------------
22357
  If you say Y here, many of the features of grsecurity will be enabled,
22358
  that will protect you against many kinds of attacks against
22359
  your system.  The heightened security comes at a cost of an 
22360
  increased chance of incompatibilities with rare software on your 
22361
  machine.  It is highly recommended that you view 
22362
  <http://grsecurity.net/features.htm> and read about each option.  Since 
22363
  this security level enabled PaX, you should also view 
22364
  <http://pageexec.virtualave.net> and read about the PaX project.  While 
22365
  you are there, download chpax.c and run chpax -p on binaries that cause 
22366
  problems with PaX.  Also remember that since the /proc restrictions are 
22367
  enabled, you must run your identd as group wheel (gid 10).  
22368
  This security level enables the following features in addition to those
22369
  listed in the low and medium security levels:
22370
22371
  additional /proc restrictions
22372
  chmod restrictions in chroot
22373
  no signals, ptrace, or viewing processes outside of chroot
22374
  capability restrictions in chroot
22375
  deny fchdir out of chroot
22376
  priority restrictions in chroot
22377
  segmentation-based implementation of PaX
22378
  mprotect restrictions
22379
  removal of /proc/<pid>/[maps|mem]
22380
  kernel stack randomization
22381
  mount/unmount/remount logging
22382
  kernel symbol hiding
22383
22384
Customized additional security
22385
CONFIG_GRKERNSEC_CUSTOM
22386
  If you say Y here, you will be able to configure every grsecurity 
22387
  option, which allows you to enable many more features that aren't 
22388
  covered in the basic security levels.  These additional features include 
22389
  TPE, socket restrictions, and the sysctl system for grsecurity.  It is 
22390
  advised that you read through the help for each option to determine its 
22391
  usefulness in your situation.
22392
22393
Enforce non-executable pages
22394
CONFIG_GRKERNSEC_PAX_NOEXEC
22395
  By design some architectures do not allow for protecting memory
22396
  pages against execution or even if they do, Linux does not make
22397
  use of this feature.  In practice this means that if a page is
22398
  readable (such as the stack or heap) it is also executable.
22399
22400
  There is a well known exploit technique that makes use of this
22401
  fact and a common programming mistake where an attacker can
22402
  introduce code of his choice somewhere in the attacked program's
22403
  memory (typically the stack or the heap) and then execute it.
22404
22405
  If the attacked program was running with different (typically
22406
  higher) privileges than that of the attacker, then he can elevate
22407
  his own privilege level (e.g. get a root shell, write to files for
22408
  which he does not have write access to, etc).
22409
22410
  Enabling this option will let you choose from various features
22411
  that prevent the injection and execution of 'foreign' code in
22412
  a program.
22413
22414
  This will also break programs that rely on the old behaviour and
22415
  expect that dynamically allocated memory via the malloc() family
22416
  of functions is executable (which it is not).  Notable examples
22417
  are the XFree86 4.x server, the java runtime and wine.
22418
22419
  NOTE: you can use the 'chpax' utility to enable/disable this
22420
  feature on a per file basis.  chpax is available at
22421
  <http://pageexec.virtualave.net>
22422
22423
Paging based non-executable pages
22424
CONFIG_GRKERNSEC_PAX_PAGEEXEC
22425
  This implementation is based on the paging feature of the CPU.
22426
  On i386 it has a variable performance impact on applications
22427
  depending on their memory usage pattern.  You should carefully
22428
  test your applications before using this feature in production.
22429
  On alpha, parisc, sparc and sparc64 there is no performance
22430
  impact.  On ppc there is a slight performance impact.
22431
22432
Segmentation based non-executable pages
22433
CONFIG_GRKERNSEC_PAX_SEGMEXEC
22434
  This implementation is based on the segmentation feature of the
22435
  CPU and has little performance impact, however applications will
22436
  be limited to a 1.5 GB address space instead of the normal 3 GB.
22437
22438
Emulate trampolines
22439
CONFIG_GRKERNSEC_PAX_EMUTRAMP
22440
  There are some programs and libraries that for one reason or
22441
  another attempt to execute special small code snippets from
22442
  non-executable memory pages.  Most notable examples are the
22443
  signal handler return code generated by the kernel itself and
22444
  the GCC trampolines.
22445
22446
  If you enabled CONFIG_GRKERNSEC_PAX_PAGEEXEC or 
22447
  CONFIG_GRKERNSEC_PAX_SEGMEXEC then such programs will no longer
22448
  work under your kernel.
22449
22450
  As a remedy you can say Y here and use the 'chpax' utility to
22451
  enable trampoline emulation for the affected programs yet still
22452
  have the protection provided by the non-executable pages.
22453
22454
  On parisc and ppc you MUST enable this option and EMUSIGRT as
22455
  well, otherwise your system will not even boot.
22456
22457
  Alternatively you can say N here and use the 'chpax' utility
22458
  to disable CONFIG_GRKERNSEC_PAX_PAGEEXEC and 
22459
  CONFIG_GRKERNSEC_PAX_SEGMEXEC for the affected files.
22460
22461
  NOTE: enabling this feature *may* open up a loophole in the
22462
  protection provided by non-executable pages that an attacker
22463
  could abuse.  Therefore the best solution is to not have any
22464
  files on your system that would require this option.  This can
22465
  be achieved by not using libc5 (which relies on the kernel
22466
  signal handler return code) and not using or rewriting programs
22467
  that make use of the nested function implementation of GCC.
22468
  Skilled users can just fix GCC itself so that it implements
22469
  nested function calls in a way that does not interfere with PaX.
22470
22471
Automatically emulate sigreturn trampolines
22472
CONFIG_GRKERNSEC_PAX_EMUSIGRT
22473
  Enabling this option will have the kernel automatically detect
22474
  and emulate signal return trampolines executing on the stack
22475
  that would otherwise lead to task termination.
22476
22477
  This solution is intended as a temporary one for users with
22478
  legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
22479
  Modula-3 runtime, etc) or executables linked to such, basically
22480
  everything that does not specify its own SA_RESTORER function in
22481
  normal executable memory like glibc 2.1+ does.
22482
22483
  On parisc and ppc you MUST enable this option, otherwise your
22484
  system will not even boot.
22485
22486
  NOTE: this feature cannot be disabled on a per executable basis
22487
  and since it *does* open up a loophole in the protection provided
22488
  by non-executable pages, the best solution is to not have any
22489
  files on your system that would require this option.
22490
22491
Restrict mprotect()
22492
CONFIG_GRKERNSEC_PAX_MPROTECT
22493
  Enabling this option will prevent programs from
22494
   - changing the executable status of memory pages that were
22495
     not originally created as executable,
22496
   - making read-only executable pages writable again,
22497
   - creating executable pages from anonymous memory.
22498
22499
  You should say Y here to complete the protection provided by
22500
  the enforcement of non-executable pages.
22501
22502
  NOTE: you can use the 'chpax' utility to control this
22503
  feature on a per file basis. chpax is available at
22504
  <http://pageexec.virtualave.net>
22505
22506
Disallow ELF text relocations
22507
CONFIG_GRKERNSEC_PAX_NOELFRELOCS
22508
  Non-executable pages and mprotect() restrictions are effective
22509
  in preventing the introduction of new executable code into an
22510
  attacked task's address space.  There remain only two venues
22511
  for this kind of attack: if the attacker can execute already
22512
  existing code in the attacked task then he can either have it
22513
  create and mmap() a file containing his code or have it mmap()
22514
  an already existing ELF library that does not have position
22515
  independent code in it and use mprotect() on it to make it
22516
  writable and copy his code there.  While protecting against
22517
  the former approach is beyond PaX, the latter can be prevented
22518
  by having only PIC ELF libraries on one's system (which do not
22519
  need to relocate their code).  If you are sure this is your case,
22520
  then enable this option otherwise be careful as you may not even
22521
  be able to boot or log on your system (for example, some PAM
22522
  modules are erroneously compiled as non-PIC by default).
22523
22524
  NOTE: if you are using dynamic ELF executables (as suggested
22525
  when using ASLR) then you must have made sure that you linked
22526
  your files using the PIC version of crt1 (the et_dyn.zip package
22527
  referenced there has already been updated to support this).
22528
22529
Enforce non-executable kernel pages
22530
CONFIG_GRKERNSEC_PAX_KERNEXEC
22531
  This is the kernel land equivalent of PAGEEXEC and MPROTECT,
22532
  that is, enabling this option will make it harder to inject
22533
  and execute 'foreign' code in kernel memory itself.
22534
22535
Address Space Layout Randomization
22536
CONFIG_GRKERNSEC_PAX_ASLR
22537
  Many if not most exploit techniques rely on the knowledge of
22538
  certain addresses in the attacked program.  The following options
22539
  will allow the kernel to apply a certain amount of randomization
22540
  to specific parts of the program thereby forcing an attacker to
22541
  guess them in most cases.  Any failed guess will most likely crash
22542
  the attacked program which allows the kernel to detect such attempts
22543
  and react on them.  PaX itself provides no reaction mechanisms,
22544
  instead it is strongly encouraged that you make use of grsecurity's
22545
  built-in crash detection features or develop one yourself.
22546
22547
  By saying Y here you can choose to randomize the following areas:
22548
   - top of the task's kernel stack
22549
   - top of the task's userland stack
22550
   - base address for mmap() requests that do not specify one
22551
     (this includes all libraries)
22552
   - base address of the main executable
22553
22554
  It is strongly recommended to say Y here as address space layout
22555
  randomization has negligible impact on performance yet it provides
22556
  a very effective protection.
22557
22558
  NOTE: you can use the 'chpax' utility to control most of these features
22559
  on a per file basis.
22560
22561
Randomize kernel stack base
22562
CONFIG_GRKERNSEC_PAX_RANDKSTACK
22563
  By saying Y here the kernel will randomize every task's kernel
22564
  stack on every system call.  This will not only force an attacker
22565
  to guess it but also prevent him from making use of possible
22566
  leaked information about it.
22567
22568
  Since the kernel stack is a rather scarce resource, randomization
22569
  may cause unexpected stack overflows, therefore you should very
22570
  carefully test your system.  Note that once enabled in the kernel
22571
  configuration, this feature cannot be disabled on a per file basis.
22572
22573
Randomize user stack base
22574
CONFIG_GRKERNSEC_PAX_RANDUSTACK
22575
  By saying Y here the kernel will randomize every task's userland
22576
  stack.  The randomization is done in two steps where the second
22577
  one may apply a big amount of shift to the top of the stack and
22578
  cause problems for programs that want to use lots of memory (more
22579
  than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
22580
  For this reason the second step can be controlled by 'chpax' on
22581
  a per file basis.
22582
22583
Randomize ET_EXEC base
22584
CONFIG_GRKERNSEC_PAX_RANDEXEC     
22585
  By saying Y here the kernel will randomize the base address of normal
22586
  ET_EXEC ELF executables as well.  This is accomplished by mapping the
22587
  executable in memory in a special way which also allows for detecting
22588
  attackers who attempt to execute its code for their purposes.  Since
22589
  this special mapping causes performance degradation and the attack
22590
  detection may create false alarms as well, you should carefully test
22591
  your executables when this feature is enabled.
22592
22593
  This solution is intended only as a temporary one until you relink
22594
  your programs as a dynamic ELF file.
22595
22596
  NOTE: you can use the 'chpax' utility to control this feature
22597
  on a per file basis.
22598
22599
Allow ELF ET_EXEC text relocations
22600
CONFIG_GRKERNSEC_PAX_ETEXECRELOCS
22601
  On some architectures like the alpha there are incorrectly
22602
  created applications that require text relocations and would
22603
  not work without enabling this option.  If you are an alpha
22604
  user, you should enable this option and disable it once you
22605
  have made sure that none of your applications need it.
22606
22607
Automatically emulate ELF PLT
22608
CONFIG_GRKERNSEC_PAX_EMUPLT
22609
  Enabling this option will have the kernel automatically detect
22610
  and emulate the Procedure Linkage Table entries in ELF files.
22611
  On some architectures such entries are in writable memory, and
22612
  become non-executable leading to task termination.  Therefore
22613
  it is mandatory that you enable this option on alpha, parisc, ppc,
22614
  sparc and sparc64, otherwise your system would not even boot.
22615
22616
  NOTE: this feature *does* open up a loophole in the protection
22617
  provided by the non-executable pages, therefore the proper
22618
  solution is to modify the toolchain to produce a PLT that does
22619
  not need to be writable.
22620
22621
22622
Randomize mmap() base
22623
CONFIG_GRKERNSEC_PAX_RANDMMAP
22624
  By saying Y here the kernel will use a randomized base address for
22625
  mmap() requests that do not specify one themselves.  As a result
22626
  all dynamically loaded libraries will appear at random addresses
22627
  and therefore be harder to exploit by a technique where an attacker
22628
  attempts to execute library code for his purposes (e.g. spawn a
22629
  shell from an exploited program that is running at an elevated
22630
  privilege level).
22631
22632
  Furthermore, if a program is relinked as a dynamic ELF file, its
22633
  base address will be randomized as well, completing the full
22634
  randomization of the address space layout.  Attacking such programs
22635
  becomes a guess game.  You can find an example of doing this at
22636
  <http://pageexec.virtualave.net/et_dyn.zip> and practical samples at
22637
  <http://www.grsecurity.net/grsec-gcc-specs.tar.gz> .
22638
22639
  NOTE: you can use the 'chpax' utility to control this feature
22640
  on a per file basis.
22641
22642
Deny writing to /dev/kmem, /dev/mem, and /dev/port
22643
CONFIG_GRKERNSEC_KMEM
22644
  If you say Y here, /dev/kmem and /dev/mem won't be allowed to
22645
  be written to via mmap or otherwise to modify the running kernel.
22646
  /dev/port will also not be allowed to be opened. If you have module
22647
  support disabled, enabling this will close up four ways that are
22648
  currently used  to insert malicious code into the running kernel.
22649
  Even with all these features enabled, we still highly recommend that
22650
  you use the ACL system, as it is still possible for an attacker to 
22651
  modify the running kernel through privileged I/O granted by ioperm/iopl.
22652
  If you are not using XFree86, you may be able to stop this additional
22653
  case by enabling the 'Disable privileged I/O' option. Though nothing
22654
  legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
22655
  but only to video memory, which is the only writing we allow in this
22656
  case.  If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
22657
  not be allowed to mprotect it with PROT_WRITE later.
22658
  Enabling this feature could make certain apps like VMWare stop working,
22659
  as they need to write to other locations in /dev/mem.
22660
  It is highly recommended that you say Y here if you meet all the 
22661
  conditions above.
22662
22663
Disable privileged I/O
22664
CONFIG_GRKERNSEC_IO
22665
  If you say Y here, all ioperm and iopl calls will return an error.
22666
  Ioperm and iopl can be used to modify the running kernel.
22667
  Unfortunately, some programs need this access to operate properly,
22668
  the most notable of which are XFree86 and hwclock.  hwclock can be
22669
  remedied by having RTC support in the kernel, so CONFIG_RTC is
22670
  enabled if this option is enabled, to ensure that hwclock operates
22671
  correctly.  XFree86 still will not operate correctly with this option
22672
  enabled, so DO NOT CHOOSE Y IF YOU USE XFree86.  If you use XFree86
22673
  and you still want to protect your kernel against modification,
22674
  use the ACL system.
22675
22676
Hide kernel symbols
22677
CONFIG_GRKERNSEC_HIDESYM
22678
  If you say Y here, getting information on loaded modules, and 
22679
  displaying all kernel symbols through a syscall will be restricted
22680
  to users with CAP_SYS_MODULE.  This option is only effective 
22681
  provided the following conditions are met:
22682
  1) The kernel using grsecurity is not precompiled by some distribution
22683
  2) You are using the ACL system and hiding other files such as your
22684
     kernel image and System.map
22685
  3) You have the additional /proc restrictions enabled, which removes
22686
     /proc/kcore
22687
  If the above conditions are met, this option will aid to provide a
22688
  useful protection against local and remote kernel exploitation of
22689
  overflows and arbitrary read/write vulnerabilities.
22690
22691
/proc/<pid>/ipaddr support
22692
CONFIG_GRKERNSEC_PROC_IPADDR
22693
  If you say Y here, a new entry will be added to each /proc/<pid>
22694
  directory that contains the IP address of the person using the task.
22695
  The IP is carried across local TCP and AF_UNIX stream sockets.
22696
  This information can be useful for IDS/IPSes to perform remote response
22697
  to a local attack.  The entry is readable by only the owner of the 
22698
  process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
22699
  the RBAC system), and thus does not create privacy concerns.
22700
22701
Proc Restrictions
22702
CONFIG_GRKERNSEC_PROC
22703
  If you say Y here, the permissions of the /proc filesystem
22704
  will be altered to enhance system security and privacy.  Depending
22705
  upon the options you choose, you can either restrict users to see
22706
  only the processes they themselves run, or choose a group that can
22707
  view all processes and files normally restricted to root if you choose
22708
  the "restrict to user only" option.  NOTE: If you're running identd as 
22709
  a non-root user, you will have to run it as the group you specify here.
22710
22711
Restrict /proc to user only
22712
CONFIG_GRKERNSEC_PROC_USER
22713
  If you say Y here, non-root users will only be able to view their own 
22714
  processes, and restricts them from viewing network-related information,  
22715
  and viewing kernel symbol and module information.
22716
22717
Restrict /proc to user and group
22718
CONFIG_GRKERNSEC_PROC_USERGROUP
22719
  If you say Y here, you will be able to select a group that will be
22720
  able to view all processes, network-related information, and
22721
  kernel and symbol information.  This option is useful if you want
22722
  to run identd as a non-root user.
22723
22724
Remove addresses from /proc/pid/[maps|stat]
22725
CONFIG_GRKERNSEC_PROC_MEMMAP
22726
  If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
22727
  give no information about the addresses of its mappings if
22728
  PaX features that rely on random addresses are enabled on the task.
22729
  If you use PaX it is greatly recommended that you say Y here as it 
22730
  closes up a hole that makes the full ASLR useless for suid 
22731
  binaries.
22732
22733
Additional proc restrictions
22734
CONFIG_GRKERNSEC_PROC_ADD
22735
  If you say Y here, additional restrictions will be placed on
22736
  /proc that keep normal users from viewing cpu and device information.
22737
22738
Dmesg(8) Restriction
22739
CONFIG_GRKERNSEC_DMESG
22740
  If you say Y here, non-root users will not be able to use dmesg(8)
22741
  to view up to the last 4kb of messages in the kernel's log buffer.
22742
  If the sysctl option is enabled, a sysctl option with name "dmesg" is 
22743
  created.
22744
22745
Linking restrictions
22746
CONFIG_GRKERNSEC_LINK
22747
  If you say Y here, /tmp race exploits will be prevented, since users
22748
  will no longer be able to follow symlinks owned by other users in 
22749
  world-writable +t directories (i.e. /tmp), unless the owner of the 
22750
  symlink is the owner of the directory. users will also not be
22751
  able to hardlink to files they do not own.  If the sysctl option is
22752
  enabled, a sysctl option with name "linking_restrictions" is created.
22753
22754
FIFO restrictions
22755
CONFIG_GRKERNSEC_FIFO
22756
  If you say Y here, users will not be able to write to FIFOs they don't
22757
  own in world-writable +t directories (i.e. /tmp), unless the owner of
22758
  the FIFO is the same owner of the directory it's held in.  If the sysctl
22759
  option is enabled, a sysctl option with name "fifo_restrictions" is 
22760
  created.
22761
22762
Enforce RLIMIT_NPROC on execs
22763
CONFIG_GRKERNSEC_EXECVE
22764
  If you say Y here, users with a resource limit on processes will
22765
  have the value checked during execve() calls.  The current system
22766
  only checks the system limit during fork() calls.  If the sysctl option
22767
  is enabled, a sysctl option with name "execve_limiting" is created.
22768
22769
Single group for auditing
22770
CONFIG_GRKERNSEC_AUDIT_GROUP
22771
  If you say Y here, the exec, chdir, (un)mount, and ipc logging features
22772
  will only operate on a group you specify.  This option is recommended
22773
  if you only want to watch certain users instead of having a large
22774
  amount of logs from the entire system.  If the sysctl option is enabled,
22775
  a sysctl option with name "audit_group" is created.
22776
22777
GID for auditing
22778
CONFIG_GRKERNSEC_AUDIT_GID
22779
  Here you can choose the GID that will be the target of kernel auditing.
22780
  Remember to add the users you want to log to the GID specified here.
22781
  If the sysctl option is enabled, whatever you choose here won't matter. 
22782
  You'll have to specify the GID in your bootup script by echoing the GID 
22783
  to the proper /proc entry.  View the help on the sysctl option for more 
22784
  information.  If the sysctl option is enabled, a sysctl option with name 
22785
  "audit_gid" is created.
22786
22787
Chdir logging
22788
CONFIG_GRKERNSEC_AUDIT_CHDIR
22789
  If you say Y here, all chdir() calls will be logged.  If the sysctl 
22790
  option is enabled, a sysctl option with name "audit_chdir" is created.
22791
22792
(Un)Mount logging
22793
CONFIG_GRKERNSEC_AUDIT_MOUNT
22794
  If you say Y here, all mounts and unmounts will be logged.  If the 
22795
  sysctl option is enabled, a sysctl option with name "audit_mount" is 
22796
  created.
22797
22798
IPC logging
22799
CONFIG_GRKERNSEC_AUDIT_IPC
22800
  If you say Y here, creation and removal of message queues, semaphores,
22801
  and shared memory will be logged.  If the sysctl option is enabled, a
22802
  sysctl option with name "audit_ipc" is created.
22803
22804
Exec logging
22805
CONFIG_GRKERNSEC_EXECLOG
22806
  If you say Y here, all execve() calls will be logged (since the
22807
  other exec*() calls are frontends to execve(), all execution
22808
  will be logged).  Useful for shell-servers that like to keep track
22809
  of their users.  If the sysctl option is enabled, a sysctl option with
22810
  name "exec_logging" is created.
22811
  WARNING: This option when enabled will produce a LOT of logs, especially
22812
  on an active system.
22813
22814
Resource logging
22815
CONFIG_GRKERNSEC_RESLOG
22816
  If you say Y here, all attempts to overstep resource limits will
22817
  be logged with the resource name, the requested size, and the current
22818
  limit.  It is highly recommended that you say Y here.
22819
22820
Signal logging
22821
CONFIG_GRKERNSEC_SIGNAL
22822
  If you say Y here, certain important signals will be logged, such as
22823
  SIGSEGV, which will as a result inform you of when a error in a program
22824
  occurred, which in some cases could mean a possible exploit attempt.
22825
  If the sysctl option is enabled, a sysctl option with name 
22826
  "signal_logging" is created.
22827
22828
Fork failure logging
22829
CONFIG_GRKERNSEC_FORKFAIL
22830
  If you say Y here, all failed fork() attempts will be logged.
22831
  This could suggest a fork bomb, or someone attempting to overstep
22832
  their process limit.  If the sysctl option is enabled, a sysctl option
22833
  with name "forkfail_logging" is created.
22834
22835
Time change logging
22836
CONFIG_GRKERNSEC_TIME
22837
  If you say Y here, any changes of the system clock will be logged.
22838
  If the sysctl option is enabled, a sysctl option with name 
22839
  "timechange_logging" is created.
22840
22841
Chroot jail restrictions
22842
CONFIG_GRKERNSEC_CHROOT
22843
  If you say Y here, you will be able to choose several options that will
22844
  make breaking out of a chrooted jail much more difficult.  If you
22845
  encounter no software incompatibilities with the following options, it
22846
  is recommended that you enable each one.
22847
22848
Deny access to abstract AF_UNIX sockets out of chroot
22849
CONFIG_GRKERNSEC_CHROOT_UNIX
22850
  If you say Y here, processes inside a chroot will not be able to
22851
  connect to abstract (meaning not belonging to a filesystem) Unix
22852
  domain sockets that were bound outside of a chroot.  It is recommended
22853
  that you say Y here.  If the sysctl option is enabled, a sysctl option
22854
  with name "chroot_deny_unix" is created.
22855
22856
Deny shmat() out of chroot
22857
CONFIG_GRKERNSEC_CHROOT_SHMAT
22858
  If you say Y here, processes inside a chroot will not be able to attach
22859
  to shared memory segments that were created outside of the chroot jail.
22860
  It is recommended that you say Y here.  If the sysctl option is enabled,
22861
  a sysctl option with name "chroot_deny_shmat" is created.
22862
22863
Protect outside processes
22864
CONFIG_GRKERNSEC_CHROOT_FINDTASK
22865
  If you say Y here, processes inside a chroot will not be able to
22866
  kill, send signals with fcntl, ptrace, capget, setpgid, getpgid, 
22867
  getsid, or view any process outside of the chroot.  If the sysctl 
22868
  option is enabled, a sysctl option with name "chroot_findtask" is 
22869
  created.
22870
22871
Deny mounts in chroot
22872
CONFIG_GRKERNSEC_CHROOT_MOUNT
22873
  If you say Y here, processes inside a chroot will not be able to
22874
  mount or remount filesystems.  If the sysctl option is enabled, a 
22875
  sysctl option with name "chroot_deny_mount" is created.
22876
22877
Deny pivot_root in chroot
22878
CONFIG_GRKERNSEC_CHROOT_PIVOT
22879
  If you say Y here, processes inside a chroot will not be able to use
22880
  a function called pivot_root() that was introduced in Linux 2.3.41.  It 
22881
  works similar to chroot in that it changes the root filesystem.  This 
22882
  function could be misused in a chrooted process to attempt to break out 
22883
  of the chroot, and therefore should not be allowed.  If the sysctl 
22884
  option is enabled, a sysctl option with name "chroot_deny_pivot" is 
22885
  created.
22886
22887
Deny double-chroots
22888
CONFIG_GRKERNSEC_CHROOT_DOUBLE
22889
  If you say Y here, processes inside a chroot will not be able to chroot
22890
  again.  This is a widely used method of breaking out of a chroot jail
22891
  and should not be allowed.  If the sysctl option is enabled, a sysctl
22892
  option with name "chroot_deny_chroot" is created.
22893
22894
Deny fchdir outside of chroot
22895
CONFIG_GRKERNSEC_CHROOT_FCHDIR
22896
  If you say Y here, a well-known method of breaking chroots by fchdir'ing
22897
  to a file descriptor of the chrooting process that points to a directory
22898
  outside the filesystem will be stopped.  If the sysctl option
22899
  is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
22900
22901
Enforce chdir("/") on all chroots
22902
CONFIG_GRKERNSEC_CHROOT_CHDIR
22903
  If you say Y here, the current working directory of all newly-chrooted
22904
  applications will be set to the the root directory of the chroot.
22905
  The man page on chroot(2) states:
22906
  Note that this call does not change  the  current  working
22907
  directory,  so  that `.' can be outside the tree rooted at
22908
  `/'.  In particular, the  super-user  can  escape  from  a
22909
  `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.  
22910
22911
  It is recommended that you say Y here, since it's not known to break
22912
  any software.  If the sysctl option is enabled, a sysctl option with
22913
  name "chroot_enforce_chdir" is created.
22914
22915
Deny (f)chmod +s in chroot
22916
CONFIG_GRKERNSEC_CHROOT_CHMOD
22917
  If you say Y here, processes inside a chroot will not be able to chmod
22918
  or fchmod files to make them have suid or sgid bits.  This protects 
22919
  against another published method of breaking a chroot.  If the sysctl 
22920
  option is enabled, a sysctl option with name "chroot_deny_chmod" is
22921
  created.
22922
22923
Deny mknod in chroot
22924
CONFIG_GRKERNSEC_CHROOT_MKNOD
22925
  If you say Y here, processes inside a chroot will not be allowed to
22926
  mknod.  The problem with using mknod inside a chroot is that it
22927
  would allow an attacker to create a device entry that is the same
22928
  as one on the physical root of your system, which could range from
22929
  anything from the console device to a device for your harddrive (which
22930
  they could then use to wipe the drive or steal data).  It is recommended
22931
  that you say Y here, unless you run into software incompatibilities.
22932
  If the sysctl option is enabled, a sysctl option with name
22933
  "chroot_deny_mknod" is created.
22934
22935
Restrict priority changes in chroot
22936
CONFIG_GRKERNSEC_CHROOT_NICE
22937
  If you say Y here, processes inside a chroot will not be able to raise
22938
  the priority of processes in the chroot, or alter the priority of 
22939
  processes outside the chroot.  This provides more security than simply
22940
  removing CAP_SYS_NICE from the process' capability set.  If the
22941
  sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
22942
  is created.
22943
22944
Log all execs within chroot
22945
CONFIG_GRKERNSEC_CHROOT_EXECLOG
22946
  If you say Y here, all executions inside a chroot jail will be logged 
22947
  to syslog.  This can cause a large amount of logs if certain
22948
  applications (eg. djb's daemontools) are installed on the system, and
22949
  is therefore left as an option.  If the sysctl option is enabled, a 
22950
  sysctl option with name "chroot_execlog" is created.
22951
22952
Deny sysctl writes in chroot
22953
CONFIG_GRKERNSEC_CHROOT_SYSCTL
22954
  If you say Y here, an attacker in a chroot will not be able to
22955
  write to sysctl entries, either by sysctl(2) or through a /proc
22956
  interface.  It is strongly recommended that you say Y here. If the
22957
  sysctl option is enabled, a sysctl option with name 
22958
  "chroot_deny_sysctl" is created.
22959
22960
Chroot jail capability restrictions
22961
CONFIG_GRKERNSEC_CHROOT_CAPS
22962
  If you say Y here, the capabilities on all root processes within a
22963
  chroot jail will be lowered to stop module insertion, raw i/o,
22964
  system and net admin tasks, rebooting the system, modifying immutable 
22965
  files, modifying IPC owned by another, and changing the system time.
22966
  This is left an option because it can break some apps.  Disable this
22967
  if your chrooted apps are having problems performing those kinds of
22968
  tasks.  If the sysctl option is enabled, a sysctl option with
22969
  name "chroot_caps" is created.
22970
22971
Trusted path execution
22972
CONFIG_GRKERNSEC_TPE
22973
  If you say Y here, you will be able to choose a gid to add to the
22974
  supplementary groups of users you want to mark as "untrusted."
22975
  These users will not be able to execute any files that are not in
22976
  root-owned directories writable only by root.  If the sysctl option
22977
  is enabled, a sysctl option with name "tpe" is created.
22978
22979
Group for trusted path execution
22980
CONFIG_GRKERNSEC_TPE_GID
22981
  Here you can choose the GID to enable trusted path protection for.
22982
  Remember to add the users you want protection enabled for to the GID 
22983
  specified here.  If the sysctl option is enabled, whatever you choose
22984
  here won't matter. You'll have to specify the GID in your bootup 
22985
  script by echoing the GID to the proper /proc entry.  View the help
22986
  on the sysctl option for more information.  If the sysctl option is
22987
  enabled, a sysctl option with name "tpe_gid" is created.
22988
22989
Partially restrict non-root users
22990
CONFIG_GRKERNSEC_TPE_ALL
22991
  If you say Y here, All non-root users other than the ones in the 
22992
  group specified in the main TPE option will only be allowed to
22993
  execute files in directories they own that are not group or
22994
  world-writable, or in directories owned by root and writable only by
22995
  root.  If the sysctl option is enabled, a sysctl option with name 
22996
  "tpe_restrict_all" is created.
22997
22998
Randomized PIDs
22999
CONFIG_GRKERNSEC_RANDPID
23000
  If you say Y here, all PIDs created on the system will be
23001
  pseudo-randomly generated.  This is extremely effective along
23002
  with the /proc restrictions to disallow an attacker from guessing
23003
  pids of daemons, etc.  PIDs are also used in some cases as part
23004
  of a naming system for temporary files, so this option would keep
23005
  those filenames from being predicted as well.  We also use code
23006
  to make sure that PID numbers aren't reused too soon.  If the sysctl
23007
  option is enabled, a sysctl option with name "rand_pids" is created.
23008
23009
Larger entropy pools
23010
CONFIG_GRKERNSEC_RANDNET
23011
  If you say Y here, the entropy pools used for many features of Linux
23012
  and grsecurity will be doubled in size.  Since several grsecurity 
23013
  features use additional randomness, it is recommended that you say Y 
23014
  here.  Saying Y here has a similar effect as modifying
23015
  /proc/sys/kernel/random/poolsize.
23016
23017
Truly random TCP ISN selection
23018
CONFIG_GRKERNSEC_RANDISN
23019
  If you say Y here, Linux's default selection of TCP Initial Sequence
23020
  Numbers (ISNs) will be replaced with that of OpenBSD.  Linux uses
23021
  an MD4 hash based on the connection plus a time value to create the
23022
  ISN, while OpenBSD's selection is random.  If the sysctl option is 
23023
  enabled, a sysctl option with name "rand_isns" is created.
23024
23025
Randomized IP IDs
23026
CONFIG_GRKERNSEC_RANDID
23027
  If you say Y here, all the id field on all outgoing packets
23028
  will be randomized.  This hinders os fingerprinters and
23029
  keeps your machine from being used as a bounce for an untraceable
23030
  portscan.  Ids are used for fragmented packets, fragments belonging
23031
  to the same packet have the same id.  By default linux only
23032
  increments the id value on each packet sent to an individual host.
23033
  We use a port of the OpenBSD random ip id code to achieve the
23034
  randomness, while keeping the possibility of id duplicates to
23035
  near none.  If the sysctl option is enabled, a sysctl option with name
23036
  "rand_ip_ids" is created.
23037
23038
Randomized TCP source ports
23039
CONFIG_GRKERNSEC_RANDSRC
23040
  If you say Y here, situations where a source port is generated on the
23041
  fly for the TCP protocol (ie. with connect() ) will be altered so that
23042
  the source port is generated at random, instead of a simple incrementing
23043
  algorithm.  If the sysctl option is enabled, a sysctl option with name
23044
  "rand_tcp_src_ports" is created.
23045
23046
Randomized RPC XIDs
23047
CONFIG_GRKERNSEC_RANDRPC
23048
  If you say Y here, the method of determining XIDs for RPC requests will
23049
  be randomized, instead of using linux's default behavior of simply
23050
  incrementing the XID.  If you want your RPC connections to be more
23051
  secure, say Y here.  If the sysctl option is enabled, a sysctl option 
23052
  with name "rand_rpc" is created.
23053
23054
Socket restrictions
23055
CONFIG_GRKERNSEC_SOCKET
23056
  If you say Y here, you will be able to choose from several options.
23057
  If you assign a GID on your system and add it to the supplementary
23058
  groups of users you want to restrict socket access to, this patch
23059
  will perform up to three things, based on the option(s) you choose.
23060
23061
Deny all socket access
23062
CONFIG_GRKERNSEC_SOCKET_ALL
23063
  If you say Y here, you will be able to choose a GID of whose users will
23064
  be unable to connect to other hosts from your machine or run server
23065
  applications from your machine.  If the sysctl option is enabled, a
23066
  sysctl option with name "socket_all" is created.
23067
23068
Group for disabled socket access
23069
CONFIG_GRKERNSEC_SOCKET_ALL_GID
23070
  Here you can choose the GID to disable socket access for. Remember to 
23071
  add the users you want socket access disabled for to the GID 
23072
  specified here.  If the sysctl option is enabled, whatever you choose
23073
  here won't matter. You'll have to specify the GID in your bootup 
23074
  script by echoing the GID to the proper /proc entry.  View the help
23075
  on the sysctl option for more information.  If the sysctl option is
23076
  enabled, a sysctl option with name "socket_all_gid" is created.
23077
23078
Deny all client socket access
23079
CONFIG_GRKERNSEC_SOCKET_CLIENT
23080
  If you say Y here, you will be able to choose a GID of whose users will
23081
  be unable to connect to other hosts from your machine, but will be
23082
  able to run servers.  If this option is enabled, all users in the group
23083
  you specify will have to use passive mode when initiating ftp transfers
23084
  from the shell on your machine.  If the sysctl option is enabled, a
23085
  sysctl option with name "socket_client" is created.
23086
23087
Group for disabled client socket access
23088
CONFIG_GRKERNSEC_SOCKET_CLIENT_GID
23089
  Here you can choose the GID to disable client socket access for. 
23090
  Remember to add the users you want client socket access disabled for to 
23091
  the GID specified here.  If the sysctl option is enabled, whatever you 
23092
  choose here won't matter. You'll have to specify the GID in your bootup 
23093
  script by echoing the GID to the proper /proc entry.  View the help
23094
  on the sysctl option for more information.  If the sysctl option is
23095
  enabled, a sysctl option with name "socket_client_gid" is created.
23096
23097
Deny all server socket access
23098
CONFIG_GRKERNSEC_SOCKET_SERVER
23099
  If you say Y here, you will be able to choose a GID of whose users will
23100
  be unable to run server applications from your machine.  If the sysctl 
23101
  option is enabled, a sysctl option with name "socket_server" is created.
23102
23103
Group for disabled server socket access
23104
CONFIG_GRKERNSEC_SOCKET_SERVER_GID
23105
  Here you can choose the GID to disable server socket access for. 
23106
  Remember to add the users you want server socket access disabled for to 
23107
  the GID specified here.  If the sysctl option is enabled, whatever you 
23108
  choose here won't matter. You'll have to specify the GID in your bootup 
23109
  script by echoing the GID to the proper /proc entry.  View the help
23110
  on the sysctl option for more information.  If the sysctl option is
23111
  enabled, a sysctl option with name "socket_server_gid" is created.
23112
23113
Sysctl support
23114
CONFIG_GRKERNSEC_SYSCTL
23115
  If you say Y here, you will be able to change the options that
23116
  grsecurity runs with at bootup, without having to recompile your
23117
  kernel.  You can echo values to files in /proc/sys/kernel/grsecurity
23118
  to enable (1) or disable (0) various features.  All the sysctl entries
23119
  are mutable until the "grsec_lock" entry is set to a non-zero value.
23120
  All features are disabled by default. Please note that this option could 
23121
  reduce the effectiveness of the added security of this patch if an ACL 
23122
  system is not put in place.  Your init scripts should be read-only, and 
23123
  root should not have access to adding modules or performing raw i/o 
23124
  operations.  All options should be set at startup, and the grsec_lock 
23125
  entry should be set to a non-zero value after all the options are set.  
23126
  *THIS IS EXTREMELY IMPORTANT*
23127
23128
Number of burst messages
23129
CONFIG_GRKERNSEC_FLOODBURST
23130
  This option allows you to choose the maximum number of messages allowed
23131
  within the flood time interval you chose in a separate option.  The 
23132
  default should be suitable for most people, however if you find that 
23133
  many of your logs are being interpreted as flooding, you may want to 
23134
  raise this value.
23135
23136
Seconds in between log messages
23137
CONFIG_GRKERNSEC_FLOODTIME
23138
  This option allows you to enforce the number of seconds between
23139
  grsecurity log messages.  The default should be suitable for most 
23140
  people, however, if you choose to change it, choose a value small enough
23141
  to allow informative logs to be produced, but large enough to
23142
  prevent flooding.
23143
23144
Hide kernel processes
23145
CONFIG_GRKERNSEC_ACL_HIDEKERN
23146
  If you say Y here, when the ACL system is enabled via gradm -E,
23147
  an additional ACL will be passed to the kernel that hides all kernel
23148
  processes.  These processes will only be viewable by the authenticated
23149
  admin, or processes that have viewing access set.
23150
23151
Maximum tries before password lockout
23152
CONFIG_GRKERNSEC_ACL_MAXTRIES
23153
  This option enforces the maximum number of times a user can attempt
23154
  to authorize themselves with the grsecurity ACL system before being
23155
  denied the ability to attempt authorization again for a specified time.  
23156
  The lower the number, the harder it will be to brute-force a password.
23157
23158
Time to wait after max password tries, in seconds
23159
CONFIG_GRKERNSEC_ACL_TIMEOUT
23160
  This option specifies the time the user must wait after attempting to 
23161
  authorize to the ACL system with the maximum number of invalid 
23162
  passwords.  The higher the number, the harder it will be to brute-force 
23163
  a password.
23164
22286
Disable data cache
23165
Disable data cache
22287
CONFIG_DCACHE_DISABLE
23166
CONFIG_DCACHE_DISABLE
22288
  This option allows you to run the kernel with data cache disabled.
23167
  This option allows you to run the kernel with data cache disabled.
(-)linux-2.4.22-ppc-dev.orig/Makefile (-2 / +4 lines)
Lines 126-134 Link Here
126
126
127
CORE_FILES	=kernel/kernel.o mm/mm.o fs/fs.o ipc/ipc.o
127
CORE_FILES	=kernel/kernel.o mm/mm.o fs/fs.o ipc/ipc.o
128
NETWORKS	=net/network.o
128
NETWORKS	=net/network.o
129
GRSECURITY	=grsecurity/grsec.o
129
130
130
LIBS		=$(TOPDIR)/lib/lib.a
131
LIBS		=$(TOPDIR)/lib/lib.a
131
SUBDIRS		=kernel drivers mm fs net ipc lib crypto
132
SUBDIRS		=kernel drivers mm fs net ipc lib crypto grsecurity
132
133
133
DRIVERS-n :=
134
DRIVERS-n :=
134
DRIVERS-y :=
135
DRIVERS-y :=
Lines 270-276 Link Here
270
271
271
export	CPPFLAGS CFLAGS CFLAGS_KERNEL AFLAGS AFLAGS_KERNEL
272
export	CPPFLAGS CFLAGS CFLAGS_KERNEL AFLAGS AFLAGS_KERNEL
272
273
273
export	NETWORKS DRIVERS LIBS HEAD LDFLAGS LINKFLAGS MAKEBOOT ASFLAGS
274
export	NETWORKS DRIVERS LIBS HEAD LDFLAGS LINKFLAGS MAKEBOOT ASFLAGS GRSECURITY
274
275
275
.S.s:
276
.S.s:
276
	$(CPP) $(AFLAGS) $(AFLAGS_KERNEL) -traditional -o $*.s $<
277
	$(CPP) $(AFLAGS) $(AFLAGS_KERNEL) -traditional -o $*.s $<
Lines 289-294 Link Here
289
		$(CORE_FILES) \
290
		$(CORE_FILES) \
290
		$(DRIVERS) \
291
		$(DRIVERS) \
291
		$(NETWORKS) \
292
		$(NETWORKS) \
293
		$(GRSECURITY) \
292
		$(LIBS) \
294
		$(LIBS) \
293
		--end-group \
295
		--end-group \
294
		-o vmlinux
296
		-o vmlinux
(-)linux-2.4.22-ppc-dev.orig/arch/alpha/config.in (+9 lines)
Lines 457-459 Link Here
457
457
458
source crypto/Config.in
458
source crypto/Config.in
459
source lib/Config.in
459
source lib/Config.in
460
461
mainmenu_option next_comment
462
comment 'Grsecurity'
463
bool 'Grsecurity' CONFIG_GRKERNSEC
464
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
465
	source grsecurity/Config.in
466
fi
467
endmenu
468
(-)linux-2.4.22-ppc-dev.orig/arch/alpha/kernel/osf_sys.c (-2 / +26 lines)
Lines 33-38 Link Here
33
#include <linux/file.h>
33
#include <linux/file.h>
34
#include <linux/types.h>
34
#include <linux/types.h>
35
#include <linux/ipc.h>
35
#include <linux/ipc.h>
36
#include <linux/grsecurity.h>
36
37
37
#include <asm/fpu.h>
38
#include <asm/fpu.h>
38
#include <asm/io.h>
39
#include <asm/io.h>
Lines 230-235 Link Here
230
	struct file *file = NULL;
231
	struct file *file = NULL;
231
	unsigned long ret = -EBADF;
232
	unsigned long ret = -EBADF;
232
233
234
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
235
	if (flags & MAP_MIRROR)
236
		return -EINVAL;
237
#endif
238
233
#if 0
239
#if 0
234
	if (flags & (_MAP_HASSEMAPHORE | _MAP_INHERIT | _MAP_UNALIGNED))
240
	if (flags & (_MAP_HASSEMAPHORE | _MAP_INHERIT | _MAP_UNALIGNED))
235
		printk("%s: unimplemented OSF mmap flags %04lx\n", 
241
		printk("%s: unimplemented OSF mmap flags %04lx\n", 
Lines 240-245 Link Here
240
		if (!file)
246
		if (!file)
241
			goto out;
247
			goto out;
242
	}
248
	}
249
250
	if(gr_handle_mmap(file, prot)) {
251
		fput(file);
252
		ret = -EACCES;
253
		goto out;
254
	}
255
243
	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
256
	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
244
	down_write(&current->mm->mmap_sem);
257
	down_write(&current->mm->mmap_sem);
245
	ret = do_mmap(file, addr, len, prot, flags, off);
258
	ret = do_mmap(file, addr, len, prot, flags, off);
Lines 1357-1362 Link Here
1357
	   merely specific addresses, but regions of memory -- perhaps
1370
	   merely specific addresses, but regions of memory -- perhaps
1358
	   this feature should be incorporated into all ports?  */
1371
	   this feature should be incorporated into all ports?  */
1359
1372
1373
#ifdef CONFIG_GRKERNSEC_PAX_RANDMMAP
1374
	if (!(current->flags & PF_PAX_RANDMMAP) || !filp)
1375
#endif
1376
1360
	if (addr) {
1377
	if (addr) {
1361
		addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
1378
		addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
1362
		if (addr != -ENOMEM)
1379
		if (addr != -ENOMEM)
Lines 1364-1371 Link Here
1364
	}
1381
	}
1365
1382
1366
	/* Next, try allocating at TASK_UNMAPPED_BASE.  */
1383
	/* Next, try allocating at TASK_UNMAPPED_BASE.  */
1367
	addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
1384
1368
					 len, limit);
1385
	addr = TASK_UNMAPPED_BASE;
1386
1387
#ifdef CONFIG_GRKERNSEC_PAX_RANDMMAP
1388
	if (current->flags & PF_PAX_RANDMMAP)
1389
		addr += current->mm->delta_mmap;
1390
#endif
1391
1392
	addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
1369
	if (addr != -ENOMEM)
1393
	if (addr != -ENOMEM)
1370
		return addr;
1394
		return addr;
1371
1395
(-)linux-2.4.22-ppc-dev.orig/arch/alpha/kernel/ptrace.c (+5 lines)
Lines 13-18 Link Here
13
#include <linux/ptrace.h>
13
#include <linux/ptrace.h>
14
#include <linux/user.h>
14
#include <linux/user.h>
15
#include <linux/slab.h>
15
#include <linux/slab.h>
16
#include <linux/grsecurity.h>
16
17
17
#include <asm/uaccess.h>
18
#include <asm/uaccess.h>
18
#include <asm/pgtable.h>
19
#include <asm/pgtable.h>
Lines 275-280 Link Here
275
	read_unlock(&tasklist_lock);
276
	read_unlock(&tasklist_lock);
276
	if (!child)
277
	if (!child)
277
		goto out_notsk;
278
		goto out_notsk;
279
280
	if(gr_handle_ptrace(child, request))
281
		goto out;
282
278
	if (request == PTRACE_ATTACH) {
283
	if (request == PTRACE_ATTACH) {
279
		ret = ptrace_attach(child);
284
		ret = ptrace_attach(child);
280
		goto out;
285
		goto out;
(-)linux-2.4.22-ppc-dev.orig/arch/alpha/mm/fault.c (-1 / +158 lines)
Lines 53-58 Link Here
53
	__reload_thread(&current->thread);
53
	__reload_thread(&current->thread);
54
}
54
}
55
55
56
/*
57
 * PaX: decide what to do with offenders (regs->pc = fault address)
58
 *
59
 * returns 1 when task should be killed
60
 *         2 when patched PLT trampoline was detected
61
 *         3 when unpatched PLT trampoline was detected
62
 *	   4 when legitimate ET_EXEC was detected
63
 */
64
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
65
static int pax_handle_fetch_fault(struct pt_regs *regs)
66
{
67
	int err;
68
69
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
70
	if (current->flags & PF_PAX_RANDEXEC) {
71
		if (regs->pc >= current->mm->start_code &&
72
		    regs->pc < current->mm->end_code)
73
		{
74
			if (regs->r26 == regs->pc)
75
				return 1;
76
			regs->pc += current->mm->delta_exec;
77
			return 4;
78
		}
79
	}
80
#endif
81
82
#ifdef CONFIG_GRKERNSEC_PAX_EMUPLT
83
	do { /* PaX: patched PLT emulation #1 */
84
		unsigned int ldah, ldq, jmp;
85
86
		err = get_user(ldah, (unsigned int *)regs->pc);
87
		err |= get_user(ldq, (unsigned int *)(regs->pc+4));
88
		err |= get_user(jmp, (unsigned int *)(regs->pc+8));
89
90
		if (err)
91
			break;
92
93
		if ((ldah & 0xFFFF0000U)== 0x277B0000U &&
94
		    (ldq & 0xFFFF0000U) == 0xA77B0000U &&
95
		    jmp == 0x6BFB0000U)
96
		{
97
			unsigned long r27, addr;
98
			unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
99
			unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
100
101
			addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
102
			err = get_user(r27, (unsigned long*)addr);
103
			if (err)
104
				break;
105
106
			regs->r27 = r27;
107
			regs->pc = r27;
108
			return 2;
109
		}
110
	} while (0);
111
112
	do { /* PaX: patched PLT emulation #2 */
113
		unsigned int ldah, lda, br;
114
115
		err = get_user(ldah, (unsigned int *)regs->pc);
116
		err |= get_user(lda, (unsigned int *)(regs->pc+4));
117
		err |= get_user(br, (unsigned int *)(regs->pc+8));
118
119
		if (err)
120
			break;
121
122
		if ((ldah & 0xFFFF0000U)== 0x277B0000U &&
123
		    (lda & 0xFFFF0000U) == 0xA77B0000U &&
124
		    (br & 0xFFE00000U) == 0xC3E00000U)
125
		{
126
			unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
127
			unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
128
			unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
129
130
			regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
131
			regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
132
			return 2;
133
		}
134
	} while (0);
135
136
	do { /* PaX: unpatched PLT emulation */
137
		unsigned int br;
138
139
		err = get_user(br, (unsigned int *)regs->pc);
140
141
		if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
142
			unsigned int br2, ldq, nop, jmp;
143
			unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
144
145
			addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
146
			err = get_user(br2, (unsigned int *)addr);  
147
			err |= get_user(ldq, (unsigned int *)(addr+4));
148
			err |= get_user(nop, (unsigned int *)(addr+8));
149
			err |= get_user(jmp, (unsigned int *)(addr+12));
150
			err |= get_user(resolver, (unsigned long *)(addr+16));
151
152
			if (err)
153
				break;
154
155
			if (br2 == 0xC3600000U &&
156
			    ldq == 0xA77B000CU &&
157
			    nop == 0x47FF041FU &&
158
			    jmp == 0x6B7B0000U)
159
			{
160
				regs->r28 = regs->pc+4;
161
				regs->r27 = addr+16;
162
				regs->pc = resolver;
163
				return 3;
164
			}
165
		}
166
	} while (0);
167
#endif
168
169
	return 1;
170
}
171
172
void pax_report_insns(void *pc)
173
{
174
	unsigned long i;
175
176
	printk(KERN_ERR "PAX: bytes at PC: ");
177
	for (i = 0; i < 5; i++) {
178
		unsigned int c;
179
		if (get_user(c, (unsigned int*)pc+i)) {
180
			printk("<invalid address>.");
181
			break;
182
		}
183
		printk("%08x ", c);
184
	}
185
	printk("\n");
186
}
187
#endif
188
56
189
57
/*
190
/*
58
 * This routine handles page faults.  It determines the address,
191
 * This routine handles page faults.  It determines the address,
Lines 133-140 Link Here
133
good_area:
266
good_area:
134
	info.si_code = SEGV_ACCERR;
267
	info.si_code = SEGV_ACCERR;
135
	if (cause < 0) {
268
	if (cause < 0) {
136
		if (!(vma->vm_flags & VM_EXEC))
269
		if (!(vma->vm_flags & VM_EXEC)) {
270
271
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
272
			if (!(current->flags & PF_PAX_PAGEEXEC) || address != regs->pc)
273
				goto bad_area;
274
275
			up_read(&mm->mmap_sem);
276
			switch(pax_handle_fetch_fault(regs)) {
277
278
#ifdef CONFIG_GRKERNSEC_PAX_EMUPLT
279
			case 2:
280
			case 3:
281
				return;
282
#endif
283
284
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
285
			case 4:
286
				return;
287
#endif
288
			}
289
			pax_report_fault(regs, (void*)regs->pc, (void*)rdusp());
290
			do_exit(SIGKILL);
291
#else
137
			goto bad_area;
292
			goto bad_area;
293
#endif
294
		}
138
	} else if (!cause) {
295
	} else if (!cause) {
139
		/* Allow reads even for write-only mappings */
296
		/* Allow reads even for write-only mappings */
140
		if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
297
		if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
(-)linux-2.4.22-ppc-dev.orig/arch/arm/config.in (+8 lines)
Lines 734-736 Link Here
734
734
735
source crypto/Config.in
735
source crypto/Config.in
736
source lib/Config.in
736
source lib/Config.in
737
738
mainmenu_option next_comment
739
comment 'Grsecurity'
740
bool 'Grsecurity' CONFIG_GRKERNSEC
741
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
742
	source grsecurity/Config.in
743
fi
744
endmenu
(-)linux-2.4.22-ppc-dev.orig/arch/cris/config.in (+9 lines)
Lines 275-277 Link Here
275
source crypto/Config.in
275
source crypto/Config.in
276
source lib/Config.in
276
source lib/Config.in
277
endmenu
277
endmenu
278
279
mainmenu_option next_comment
280
comment 'Grsecurity'
281
bool 'Grsecurity' CONFIG_GRKERNSEC
282
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
283
    source grsecurity/Config.in
284
fi
285
endmenu
286
(-)linux-2.4.22-ppc-dev.orig/arch/i386/Makefile (+4 lines)
Lines 114-119 Link Here
114
114
115
MAKEBOOT = $(MAKE) -C arch/$(ARCH)/boot
115
MAKEBOOT = $(MAKE) -C arch/$(ARCH)/boot
116
116
117
arch/i386/vmlinux.lds: arch/i386/vmlinux.lds.S FORCE
118
	$(CPP) -C -P -I$(HPATH) -imacros $(HPATH)/linux/config.h -imacros $(HPATH)/asm-i386/segment.h -imacros $(HPATH)/asm-i386/page_offset.h -Ui386 arch/i386/vmlinux.lds.S >arch/i386/vmlinux.lds
119
117
vmlinux: arch/i386/vmlinux.lds
120
vmlinux: arch/i386/vmlinux.lds
118
121
119
FORCE: ;
122
FORCE: ;
Lines 150-155 Link Here
150
	@$(MAKEBOOT) clean
153
	@$(MAKEBOOT) clean
151
154
152
archmrproper:
155
archmrproper:
156
	rm -f arch/i386/vmlinux.lds
153
157
154
archdep:
158
archdep:
155
	@$(MAKEBOOT) dep
159
	@$(MAKEBOOT) dep
(-)linux-2.4.22-ppc-dev.orig/arch/i386/config.in (+8 lines)
Lines 480-482 Link Here
480
480
481
source crypto/Config.in
481
source crypto/Config.in
482
source lib/Config.in
482
source lib/Config.in
483
484
mainmenu_option next_comment
485
comment 'Grsecurity'
486
bool 'Grsecurity' CONFIG_GRKERNSEC
487
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
488
	source grsecurity/Config.in
489
fi
490
endmenu
(-)linux-2.4.22-ppc-dev.orig/arch/i386/kernel/apm.c (-2 / +35 lines)
Lines 614-620 Link Here
614
	__asm__ __volatile__(APM_DO_ZERO_SEGS
614
	__asm__ __volatile__(APM_DO_ZERO_SEGS
615
		"pushl %%edi\n\t"
615
		"pushl %%edi\n\t"
616
		"pushl %%ebp\n\t"
616
		"pushl %%ebp\n\t"
617
		"lcall %%cs:" SYMBOL_NAME_STR(apm_bios_entry) "\n\t"
617
		"lcall *%%ss:" SYMBOL_NAME_STR(apm_bios_entry) "\n\t"
618
		"setc %%al\n\t"
618
		"setc %%al\n\t"
619
		"popl %%ebp\n\t"
619
		"popl %%ebp\n\t"
620
		"popl %%edi\n\t"
620
		"popl %%edi\n\t"
Lines 666-672 Link Here
666
		__asm__ __volatile__(APM_DO_ZERO_SEGS
666
		__asm__ __volatile__(APM_DO_ZERO_SEGS
667
			"pushl %%edi\n\t"
667
			"pushl %%edi\n\t"
668
			"pushl %%ebp\n\t"
668
			"pushl %%ebp\n\t"
669
			"lcall %%cs:" SYMBOL_NAME_STR(apm_bios_entry) "\n\t"
669
			"lcall *%%ss:" SYMBOL_NAME_STR(apm_bios_entry) "\n\t"
670
			"setc %%bl\n\t"
670
			"setc %%bl\n\t"
671
			"popl %%ebp\n\t"
671
			"popl %%ebp\n\t"
672
			"popl %%edi\n\t"
672
			"popl %%edi\n\t"
Lines 1985-1990 Link Here
1985
		 __va((unsigned long)0x40 << 4));
1985
		 __va((unsigned long)0x40 << 4));
1986
	_set_limit((char *)&gdt[APM_40 >> 3], 4095 - (0x40 << 4));
1986
	_set_limit((char *)&gdt[APM_40 >> 3], 4095 - (0x40 << 4));
1987
1987
1988
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
1989
	set_base(gdt2[APM_40 >> 3],
1990
		__va((unsigned long)0x40 << 4));
1991
	_set_limit((char *)&gdt2[APM_40 >> 3], 4095 - (0x40 << 4));
1992
#endif
1993
1988
	apm_bios_entry.offset = apm_info.bios.offset;
1994
	apm_bios_entry.offset = apm_info.bios.offset;
1989
	apm_bios_entry.segment = APM_CS;
1995
	apm_bios_entry.segment = APM_CS;
1990
	set_base(gdt[APM_CS >> 3],
1996
	set_base(gdt[APM_CS >> 3],
Lines 1993-1998 Link Here
1993
		 __va((unsigned long)apm_info.bios.cseg_16 << 4));
1999
		 __va((unsigned long)apm_info.bios.cseg_16 << 4));
1994
	set_base(gdt[APM_DS >> 3],
2000
	set_base(gdt[APM_DS >> 3],
1995
		 __va((unsigned long)apm_info.bios.dseg << 4));
2001
		 __va((unsigned long)apm_info.bios.dseg << 4));
2002
2003
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
2004
	set_base(gdt2[APM_CS >> 3],
2005
		__va((unsigned long)apm_info.bios.cseg << 4));
2006
	set_base(gdt2[APM_CS_16 >> 3],
2007
		__va((unsigned long)apm_info.bios.cseg_16 << 4));
2008
	set_base(gdt2[APM_DS >> 3],
2009
		__va((unsigned long)apm_info.bios.dseg << 4));
2010
#endif
2011
1996
#ifndef APM_RELAX_SEGMENTS
2012
#ifndef APM_RELAX_SEGMENTS
1997
	if (apm_info.bios.version == 0x100) {
2013
	if (apm_info.bios.version == 0x100) {
1998
#endif
2014
#endif
Lines 2002-2007 Link Here
2002
		_set_limit((char *)&gdt[APM_CS_16 >> 3], 64 * 1024 - 1);
2018
		_set_limit((char *)&gdt[APM_CS_16 >> 3], 64 * 1024 - 1);
2003
		/* For the DEC Hinote Ultra CT475 (and others?) */
2019
		/* For the DEC Hinote Ultra CT475 (and others?) */
2004
		_set_limit((char *)&gdt[APM_DS >> 3], 64 * 1024 - 1);
2020
		_set_limit((char *)&gdt[APM_DS >> 3], 64 * 1024 - 1);
2021
2022
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
2023
		_set_limit((char *)&gdt2[APM_CS >> 3], 64 * 1024 - 1);
2024
		_set_limit((char *)&gdt2[APM_CS_16 >> 3], 64 * 1024 - 1);
2025
		_set_limit((char *)&gdt2[APM_DS >> 3], 64 * 1024 - 1);
2026
#endif
2027
2005
#ifndef APM_RELAX_SEGMENTS
2028
#ifndef APM_RELAX_SEGMENTS
2006
	} else {
2029
	} else {
2007
		_set_limit((char *)&gdt[APM_CS >> 3],
2030
		_set_limit((char *)&gdt[APM_CS >> 3],
Lines 2010-2015 Link Here
2010
			(apm_info.bios.cseg_16_len - 1) & 0xffff);
2033
			(apm_info.bios.cseg_16_len - 1) & 0xffff);
2011
		_set_limit((char *)&gdt[APM_DS >> 3],
2034
		_set_limit((char *)&gdt[APM_DS >> 3],
2012
			(apm_info.bios.dseg_len - 1) & 0xffff);
2035
			(apm_info.bios.dseg_len - 1) & 0xffff);
2036
2037
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
2038
		_set_limit((char *)&gdt2[APM_CS >> 3],
2039
			(apm_info.bios.cseg_len - 1) & 0xffff);
2040
		_set_limit((char *)&gdt2[APM_CS_16 >> 3],
2041
			(apm_info.bios.cseg_16_len - 1) & 0xffff);
2042
		_set_limit((char *)&gdt2[APM_DS >> 3],
2043
			(apm_info.bios.dseg_len - 1) & 0xffff);
2044
#endif
2045
2013
	}
2046
	}
2014
#endif
2047
#endif
2015
2048
(-)linux-2.4.22-ppc-dev.orig/arch/i386/kernel/entry.S (-1 / +60 lines)
Lines 209-214 Link Here
209
	jae badsys
209
	jae badsys
210
	call *SYMBOL_NAME(sys_call_table)(,%eax,4)
210
	call *SYMBOL_NAME(sys_call_table)(,%eax,4)
211
	movl %eax,EAX(%esp)		# save the return value
211
	movl %eax,EAX(%esp)		# save the return value
212
213
#ifdef CONFIG_GRKERNSEC_PAX_RANDKSTACK
214
	cli                             # need_resched and signals atomic test
215
	cmpl $0,need_resched(%ebx)
216
	jne reschedule
217
	cmpl $0,sigpending(%ebx)
218
	jne signal_return
219
	call SYMBOL_NAME(pax_randomize_kstack)
220
	jmp restore_all
221
#endif
222
212
ENTRY(ret_from_sys_call)
223
ENTRY(ret_from_sys_call)
213
	cli				# need_resched and signals atomic test
224
	cli				# need_resched and signals atomic test
214
	cmpl $0,need_resched(%ebx)
225
	cmpl $0,need_resched(%ebx)
Lines 389-396 Link Here
389
	jmp error_code
400
	jmp error_code
390
401
391
ENTRY(page_fault)
402
ENTRY(page_fault)
403
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
404
	ALIGN
405
	pushl $ SYMBOL_NAME(pax_do_page_fault)
406
#else
392
	pushl $ SYMBOL_NAME(do_page_fault)
407
	pushl $ SYMBOL_NAME(do_page_fault)
408
#endif
409
410
#ifndef CONFIG_GRKERNSEC_PAX_EMUTRAMP
393
	jmp error_code
411
	jmp error_code
412
#else
413
	pushl %ds
414
	pushl %eax
415
	xorl %eax,%eax
416
	pushl %ebp
417
	pushl %edi
418
	pushl %esi
419
	pushl %edx
420
	decl %eax			# eax = -1
421
	pushl %ecx
422
	pushl %ebx
423
	cld
424
	movl %es,%ecx
425
	movl ORIG_EAX(%esp), %esi	# get the error code
426
	movl ES(%esp), %edi		# get the function address
427
	movl %eax, ORIG_EAX(%esp)
428
	movl %ecx, ES(%esp)
429
	movl %esp,%edx
430
	pushl %esi			# push the error code
431
	pushl %edx			# push the pt_regs pointer
432
	movl $(__KERNEL_DS),%edx
433
	movl %edx,%ds
434
	movl %edx,%es
435
	GET_CURRENT(%ebx)
436
	call *%edi
437
	addl $8,%esp
438
	decl %eax
439
	jnz ret_from_exception
440
441
	popl %ebx
442
	popl %ecx
443
	popl %edx
444
	popl %esi
445
	popl %edi
446
	popl %ebp
447
	popl %eax
448
	popl %ds
449
	popl %es
450
	addl $4,%esp
451
	jmp system_call
452
#endif
394
453
395
ENTRY(machine_check)
454
ENTRY(machine_check)
396
	pushl $0
455
	pushl $0
Lines 402-408 Link Here
402
	pushl $ SYMBOL_NAME(do_spurious_interrupt_bug)
461
	pushl $ SYMBOL_NAME(do_spurious_interrupt_bug)
403
	jmp error_code
462
	jmp error_code
404
463
405
.data
464
.section .rodata, "a"
406
ENTRY(sys_call_table)
465
ENTRY(sys_call_table)
407
	.long SYMBOL_NAME(sys_ni_syscall)	/* 0  -  old "setup()" system call*/
466
	.long SYMBOL_NAME(sys_ni_syscall)	/* 0  -  old "setup()" system call*/
408
	.long SYMBOL_NAME(sys_exit)
467
	.long SYMBOL_NAME(sys_exit)
(-)linux-2.4.22-ppc-dev.orig/arch/i386/kernel/head.S (-33 / +100 lines)
Lines 41-46 Link Here
41
 *
41
 *
42
 * On entry, %esi points to the real-mode code as a 32-bit pointer.
42
 * On entry, %esi points to the real-mode code as a 32-bit pointer.
43
 */
43
 */
44
.global startup_32
44
startup_32:
45
startup_32:
45
/*
46
/*
46
 * Set segments to known values
47
 * Set segments to known values
Lines 86-92 Link Here
86
				   PRESENT+RW+USER */
87
				   PRESENT+RW+USER */
87
2:	stosl
88
2:	stosl
88
	add $0x1000,%eax
89
	add $0x1000,%eax
89
	cmp $empty_zero_page-__PAGE_OFFSET,%edi
90
	cmp $0x00c00007,%eax
90
	jne 2b
91
	jne 2b
91
92
92
/*
93
/*
Lines 100-108 Link Here
100
	movl %eax,%cr0		/* ..and set paging (PG) bit */
101
	movl %eax,%cr0		/* ..and set paging (PG) bit */
101
	jmp 1f			/* flush the prefetch-queue */
102
	jmp 1f			/* flush the prefetch-queue */
102
1:
103
1:
104
105
#if !defined(CONFIG_GRKERNSEC_PAX_KERNEXEC) || defined(CONFIG_SMP)
106
107
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
108
	orw  %bx,%bx
109
	jz  1f
110
#endif
111
103
	movl $1f,%eax
112
	movl $1f,%eax
104
	jmp *%eax		/* make sure eip is relocated */
113
	jmp *%eax		/* make sure eip is relocated */
105
1:
114
1:
115
#endif
116
106
	/* Set up the stack pointer */
117
	/* Set up the stack pointer */
107
	lss stack_start,%esp
118
	lss stack_start,%esp
108
119
Lines 121-127 Link Here
121
 */
132
 */
122
	xorl %eax,%eax
133
	xorl %eax,%eax
123
	movl $ SYMBOL_NAME(__bss_start),%edi
134
	movl $ SYMBOL_NAME(__bss_start),%edi
124
	movl $ SYMBOL_NAME(_end),%ecx
135
	movl $ SYMBOL_NAME(__bss_end),%ecx
125
	subl %edi,%ecx
136
	subl %edi,%ecx
126
	rep
137
	rep
127
	stosb
138
	stosb
Lines 272-279 Link Here
272
	jmp L6			# main should never return here, but
283
	jmp L6			# main should never return here, but
273
				# just in case, we know what happens.
284
				# just in case, we know what happens.
274
285
275
ready:	.byte 0
276
277
/*
286
/*
278
 * We depend on ET to be correct. This checks for 287/387.
287
 * We depend on ET to be correct. This checks for 287/387.
279
 */
288
 */
Lines 319-331 Link Here
319
	jne rp_sidt
328
	jne rp_sidt
320
	ret
329
	ret
321
330
322
ENTRY(stack_start)
323
	.long SYMBOL_NAME(init_task_union)+8192
324
	.long __KERNEL_DS
325
326
/* This is the default interrupt "handler" :-) */
327
int_msg:
328
	.asciz "Unknown interrupt\n"
329
	ALIGN
331
	ALIGN
330
ignore_int:
332
ignore_int:
331
	cld
333
	cld
Lines 347-352 Link Here
347
	popl %eax
349
	popl %eax
348
	iret
350
	iret
349
351
352
.data
353
ready:	.byte 0
354
355
ENTRY(stack_start)
356
	.long SYMBOL_NAME(init_task_union)+8192
357
	.long __KERNEL_DS
358
359
.section .rodata,"a"
360
/* This is the default interrupt "handler" :-) */
361
int_msg:
362
	.asciz "Unknown interrupt\n"
363
350
/*
364
/*
351
 * The interrupt descriptor table has room for 256 idt's,
365
 * The interrupt descriptor table has room for 256 idt's,
352
 * the global descriptor table is dependent on the number
366
 * the global descriptor table is dependent on the number
Lines 372-412 Link Here
372
SYMBOL_NAME(gdt):
386
SYMBOL_NAME(gdt):
373
	.long SYMBOL_NAME(gdt_table)
387
	.long SYMBOL_NAME(gdt_table)
374
388
389
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
390
.globl SYMBOL_NAME(gdt2)
391
	.word 0
392
gdt_descr2:
393
	.word GDT_ENTRIES*8-1
394
SYMBOL_NAME(gdt2):
395
	.long SYMBOL_NAME(gdt_table2)
396
#endif
397
375
/*
398
/*
376
 * This is initialized to create an identity-mapping at 0-8M (for bootup
399
 * This is initialized to create an identity-mapping at 0-8M (for bootup
377
 * purposes) and another mapping of the 0-8M area at virtual address
400
 * purposes) and another mapping of the 0-8M area at virtual address
378
 * PAGE_OFFSET.
401
 * PAGE_OFFSET.
379
 */
402
 */
380
.org 0x1000
403
.section .data.swapper_pg_dir,"a"
381
ENTRY(swapper_pg_dir)
404
ENTRY(swapper_pg_dir)
382
	.long 0x00102007
405
	.long pg0-__PAGE_OFFSET+7
383
	.long 0x00103007
406
	.long pg1-__PAGE_OFFSET+7
384
	.fill BOOT_USER_PGD_PTRS-2,4,0
407
	.long pg2-__PAGE_OFFSET+7
408
	.fill BOOT_USER_PGD_PTRS-3,4,0
385
	/* default: 766 entries */
409
	/* default: 766 entries */
386
	.long 0x00102007
410
	.long pg0-__PAGE_OFFSET+7
387
	.long 0x00103007
411
	.long pg1-__PAGE_OFFSET+7
412
	.long pg2-__PAGE_OFFSET+7
388
	/* default: 254 entries */
413
	/* default: 254 entries */
389
	.fill BOOT_KERNEL_PGD_PTRS-2,4,0
414
	.fill BOOT_KERNEL_PGD_PTRS-3,4,0
390
415
391
/*
416
/*
392
 * The page tables are initialized to only 8MB here - the final page
417
 * The page tables are initialized to only 8MB here - the final page
393
 * tables are set up later depending on memory size.
418
 * tables are set up later depending on memory size.
394
 */
419
 */
395
.org 0x2000
420
.section .data.pg0,"a"
396
ENTRY(pg0)
421
ENTRY(pg0)
422
	.fill 1024,4,0
397
423
398
.org 0x3000
424
.section .data.pg1,"a"
399
ENTRY(pg1)
425
ENTRY(pg1)
426
	.fill 1024,4,0
427
428
.section .data.pg2,"a"
429
ENTRY(pg2)
430
	.fill 1024,4,0
400
431
401
/*
432
/*
402
 * empty_zero_page must immediately follow the page tables ! (The
433
 * empty_zero_page must immediately follow the page tables ! (The
403
 * initialization loop counts until empty_zero_page)
434
 * initialization loop counts until empty_zero_page)
404
 */
435
 */
405
436
.section .data.empty_zero_page,"a"
406
.org 0x4000
407
ENTRY(empty_zero_page)
437
ENTRY(empty_zero_page)
438
	.fill 1024,4,0
408
439
409
.org 0x5000
440
.text
410
441
411
/*
442
/*
412
 * Real beginning of normal "text" segment
443
 * Real beginning of normal "text" segment
Lines 419-425 Link Here
419
 * in the text section because it has alignment requirements
450
 * in the text section because it has alignment requirements
420
 * that we cannot fulfill any other way.
451
 * that we cannot fulfill any other way.
421
 */
452
 */
422
.data
453
.section .rodata,"a"
423
454
424
ALIGN
455
ALIGN
425
/*
456
/*
Lines 430-448 Link Here
430
 */
461
 */
431
ENTRY(gdt_table)
462
ENTRY(gdt_table)
432
	.quad 0x0000000000000000	/* NULL descriptor */
463
	.quad 0x0000000000000000	/* NULL descriptor */
433
	.quad 0x0000000000000000	/* not used */
464
434
	.quad 0x00cf9a000000ffff	/* 0x10 kernel 4GB code at 0x00000000 */
465
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
435
	.quad 0x00cf92000000ffff	/* 0x18 kernel 4GB data at 0x00000000 */
466
	.quad 0x00cf9b000000ffff        /* 0x08 kernel 4GB code at 0x00000000 */
436
	.quad 0x00cffa000000ffff	/* 0x23 user   4GB code at 0x00000000 */
467
	.quad 0xc0cf9b400000ffff        /* 0x10 kernel 4GB code at 0xc0400000 */
437
	.quad 0x00cff2000000ffff	/* 0x2b user   4GB data at 0x00000000 */
468
#else
469
	.quad 0x0000000000000000        /* not used */
470
	.quad 0x00cf9b000000ffff        /* 0x10 kernel 4GB code at 0x00000000 */
471
#endif
472
473
	.quad 0x00cf93000000ffff	/* 0x18 kernel 4GB data at 0x00000000 */
474
	.quad 0x00cffb000000ffff	/* 0x23 user   4GB code at 0x00000000 */
475
	.quad 0x00cff3000000ffff	/* 0x2b user   4GB data at 0x00000000 */
476
	.quad 0x0000000000000000        /* not used */
477
	.quad 0x0000000000000000        /* not used */
478
	/*
479
	 * The APM segments have byte granularity and their bases
480
	 * and limits are set at run time.
481
	 */
482
	.quad 0x0040930000000000        /* 0x40 APM set up for bad BIOS's */
483
	.quad 0x00409b0000000000        /* 0x48 APM CS    code */
484
	.quad 0x00009b0000000000        /* 0x50 APM CS 16 code (16 bit) */
485
	.quad 0x0040930000000000        /* 0x58 APM DS    data */
486
	.fill NR_CPUS*4,8,0             /* space for TSS's and LDT's */
487
488
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
489
ENTRY(gdt_table2)
490
	.quad 0x0000000000000000        /* NULL descriptor */
491
492
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
493
	.quad 0x00cf9b000000ffff        /* 0x08 kernel 4GB code at 0x00000000 */
494
	.quad 0xc0cf9b400000ffff        /* 0x10 kernel 4GB code at 0xc0400000 */
495
#else
496
	.quad 0x0000000000000000        /* not used */
497
	.quad 0x00cf9b000000ffff        /* 0x10 kernel 4GB code at 0x00000000 */
498
#endif
499
500
	.quad 0x00cf93000000ffff        /* 0x18 kernel 4GB data at 0x00000000 */
501
	.quad 0x60c5fb000000ffff        /* 0x23 user 1.5GB code at 0x60000000 */
502
	.quad 0x00c5f3000000ffff        /* 0x2b user 1.5GB data at 0x00000000 */
503
438
	.quad 0x0000000000000000	/* not used */
504
	.quad 0x0000000000000000	/* not used */
439
	.quad 0x0000000000000000	/* not used */
505
	.quad 0x0000000000000000	/* not used */
440
	/*
506
	/*
441
	 * The APM segments have byte granularity and their bases
507
	 * The APM segments have byte granularity and their bases
442
	 * and limits are set at run time.
508
	 * and limits are set at run time.
443
	 */
509
	 */
444
	.quad 0x0040920000000000	/* 0x40 APM set up for bad BIOS's */
510
	.quad 0x0040930000000000	/* 0x40 APM set up for bad BIOS's */
445
	.quad 0x00409a0000000000	/* 0x48 APM CS    code */
511
	.quad 0x00409b0000000000	/* 0x48 APM CS    code */
446
	.quad 0x00009a0000000000	/* 0x50 APM CS 16 code (16 bit) */
512
	.quad 0x00009b0000000000	/* 0x50 APM CS 16 code (16 bit) */
447
	.quad 0x0040920000000000	/* 0x58 APM DS    data */
513
	.quad 0x0040930000000000	/* 0x58 APM DS    data */
448
	.fill NR_CPUS*4,8,0		/* space for TSS's and LDT's */
514
	.fill NR_CPUS*4,8,0		/* space for TSS's and LDT's */
515
#endif
(-)linux-2.4.22-ppc-dev.orig/arch/i386/kernel/i386_ksyms.c (+3 lines)
Lines 73-78 Link Here
73
EXPORT_SYMBOL(get_cmos_time);
73
EXPORT_SYMBOL(get_cmos_time);
74
EXPORT_SYMBOL(apm_info);
74
EXPORT_SYMBOL(apm_info);
75
EXPORT_SYMBOL(gdt);
75
EXPORT_SYMBOL(gdt);
76
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
77
EXPORT_SYMBOL(gdt2);
78
#endif
76
EXPORT_SYMBOL(empty_zero_page);
79
EXPORT_SYMBOL(empty_zero_page);
77
80
78
#ifdef CONFIG_DEBUG_IOVIRT
81
#ifdef CONFIG_DEBUG_IOVIRT
(-)linux-2.4.22-ppc-dev.orig/arch/i386/kernel/ioport.c (+14 lines)
Lines 14-19 Link Here
14
#include <linux/smp.h>
14
#include <linux/smp.h>
15
#include <linux/smp_lock.h>
15
#include <linux/smp_lock.h>
16
#include <linux/stddef.h>
16
#include <linux/stddef.h>
17
#include <linux/grsecurity.h>
17
18
18
/* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */
19
/* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */
19
static void set_bitmap(unsigned long *bitmap, short base, short extent, int new_value)
20
static void set_bitmap(unsigned long *bitmap, short base, short extent, int new_value)
Lines 59-66 Link Here
59
60
60
	if ((from + num <= from) || (from + num > IO_BITMAP_SIZE*32))
61
	if ((from + num <= from) || (from + num > IO_BITMAP_SIZE*32))
61
		return -EINVAL;
62
		return -EINVAL;
63
#ifdef CONFIG_GRKERNSEC_IO
64
	if (turn_on) {
65
		gr_handle_ioperm();
66
#else
62
	if (turn_on && !capable(CAP_SYS_RAWIO))
67
	if (turn_on && !capable(CAP_SYS_RAWIO))
68
#endif
63
		return -EPERM;
69
		return -EPERM;
70
#ifdef CONFIG_GRKERNSEC_IO
71
	}
72
#endif
64
	/*
73
	/*
65
	 * If it's the first ioperm() call in this thread's lifetime, set the
74
	 * If it's the first ioperm() call in this thread's lifetime, set the
66
	 * IO bitmap up. ioperm() is much less timing critical than clone(),
75
	 * IO bitmap up. ioperm() is much less timing critical than clone(),
Lines 109-116 Link Here
109
		return -EINVAL;
118
		return -EINVAL;
110
	/* Trying to gain more privileges? */
119
	/* Trying to gain more privileges? */
111
	if (level > old) {
120
	if (level > old) {
121
#ifdef CONFIG_GRKERNSEC_IO
122
		gr_handle_iopl();
123
		return -EPERM;
124
#else
112
		if (!capable(CAP_SYS_RAWIO))
125
		if (!capable(CAP_SYS_RAWIO))
113
			return -EPERM;
126
			return -EPERM;
127
#endif
114
	}
128
	}
115
	regs->eflags = (regs->eflags & 0xffffcfff) | (level << 12);
129
	regs->eflags = (regs->eflags & 0xffffcfff) | (level << 12);
116
	return 0;
130
	return 0;
(-)linux-2.4.22-ppc-dev.orig/arch/i386/kernel/ldt.c (+7 lines)
Lines 122-127 Link Here
122
		}
122
		}
123
	}
123
	}
124
124
125
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
126
	if ((current->flags & PF_PAX_SEGMEXEC) && (ldt_info.contents & 2)) {
127
		error = -EINVAL;
128
		goto out_unlock;
129
	}
130
#endif
131
125
	entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) |
132
	entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) |
126
		  (ldt_info.limit & 0x0ffff);
133
		  (ldt_info.limit & 0x0ffff);
127
	entry_2 = (ldt_info.base_addr & 0xff000000) |
134
	entry_2 = (ldt_info.base_addr & 0xff000000) |
(-)linux-2.4.22-ppc-dev.orig/arch/i386/kernel/pci-pc.c (-2 / +12 lines)
Lines 17-22 Link Here
17
#include <asm/io.h>
17
#include <asm/io.h>
18
#include <asm/smp.h>
18
#include <asm/smp.h>
19
#include <asm/smpboot.h>
19
#include <asm/smpboot.h>
20
#include <asm/desc.h>
20
21
21
#include "pci-i386.h"
22
#include "pci-i386.h"
22
23
Lines 575-584 Link Here
575
 * the array there.
576
 * the array there.
576
 */
577
 */
577
578
579
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
580
#define __FLAT_KERNEL_CS 0x08
581
#else
582
#define __FLAT_KERNEL_CS __KERNEL_CS
583
#endif
584
578
static struct {
585
static struct {
579
	unsigned long address;
586
	unsigned long address;
580
	unsigned short segment;
587
	unsigned short segment;
581
} bios32_indirect = { 0, __KERNEL_CS };
588
} bios32_indirect = { 0, __FLAT_KERNEL_CS };
582
589
583
/*
590
/*
584
 * Returns the entry point for the given service, NULL on error
591
 * Returns the entry point for the given service, NULL on error
Lines 619-625 Link Here
619
static struct {
626
static struct {
620
	unsigned long address;
627
	unsigned long address;
621
	unsigned short segment;
628
	unsigned short segment;
622
} pci_indirect = { 0, __KERNEL_CS };
629
} pci_indirect = { 0, __FLAT_KERNEL_CS };
630
631
#undef __FLAT_KERNEL_CS
623
632
624
static int pci_bios_present;
633
static int pci_bios_present;
625
634
Lines 1456-1461 Link Here
1456
	if ((pci_probe & PCI_BIOS_SORT) && !(pci_probe & PCI_NO_SORT))
1465
	if ((pci_probe & PCI_BIOS_SORT) && !(pci_probe & PCI_NO_SORT))
1457
		pcibios_sort();
1466
		pcibios_sort();
1458
#endif
1467
#endif
1468
1459
}
1469
}
1460
1470
1461
char * __devinit  pcibios_setup(char *str)
1471
char * __devinit  pcibios_setup(char *str)
(-)linux-2.4.22-ppc-dev.orig/arch/i386/kernel/process.c (+40 lines)
Lines 585-591 Link Here
585
{
585
{
586
	struct pt_regs * childregs;
586
	struct pt_regs * childregs;
587
587
588
#ifdef CONFIG_GRKERNSEC_PAX_RANDKSTACK
589
	childregs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long) p - sizeof(unsigned long))) - 1;
590
#else
588
	childregs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long) p)) - 1;
591
	childregs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long) p)) - 1;
592
#endif
589
	struct_cpy(childregs, regs);
593
	struct_cpy(childregs, regs);
590
	childregs->eax = 0;
594
	childregs->eax = 0;
591
	childregs->esp = esp;
595
	childregs->esp = esp;
Lines 646-651 Link Here
646
	dump->u_fpvalid = dump_fpu (regs, &dump->i387);
650
	dump->u_fpvalid = dump_fpu (regs, &dump->i387);
647
}
651
}
648
652
653
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
654
void pax_switch_segments(struct task_struct * tsk)
655
{
656
	if (tsk->flags & PF_PAX_SEGMEXEC)
657
		__asm__ __volatile__("lgdt %0": "=m" (gdt_descr2));
658
	else
659
		__asm__ __volatile__("lgdt %0": "=m" (gdt_descr));
660
}
661
#endif
662
649
/*
663
/*
650
 * This special macro can be used to load a debugging register
664
 * This special macro can be used to load a debugging register
651
 */
665
 */
Lines 685-690 Link Here
685
699
686
	unlazy_fpu(prev_p);
700
	unlazy_fpu(prev_p);
687
701
702
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
703
	pax_switch_segments(next_p);
704
#endif
705
688
	/*
706
	/*
689
	 * Reload esp0, LDT and the page table pointer:
707
	 * Reload esp0, LDT and the page table pointer:
690
	 */
708
	 */
Lines 825-827 Link Here
825
}
843
}
826
#undef last_sched
844
#undef last_sched
827
#undef first_sched
845
#undef first_sched
846
847
#ifdef CONFIG_GRKERNSEC_PAX_RANDKSTACK
848
asmlinkage void pax_randomize_kstack(void)
849
{
850
	struct tss_struct *tss = init_tss + smp_processor_id();
851
	unsigned long time;
852
853
	rdtscl(time);
854
855
	/* P4 seems to return a 0 LSB, ignore it */
856
#ifdef CONFIG_MPENTIUM4
857
	time &= 0x3EUL;
858
	time <<= 1;
859
#else
860
	time &= 0x1FUL;
861
	time <<= 2;
862
#endif
863
864
	current->thread.esp0 ^= time;
865
	tss->esp0 = current->thread.esp0;
866
}
867
#endif
(-)linux-2.4.22-ppc-dev.orig/arch/i386/kernel/ptrace.c (+15 lines)
Lines 13-18 Link Here
13
#include <linux/errno.h>
13
#include <linux/errno.h>
14
#include <linux/ptrace.h>
14
#include <linux/ptrace.h>
15
#include <linux/user.h>
15
#include <linux/user.h>
16
#include <linux/grsecurity.h>
16
17
17
#include <asm/uaccess.h>
18
#include <asm/uaccess.h>
18
#include <asm/pgtable.h>
19
#include <asm/pgtable.h>
Lines 177-182 Link Here
177
	if (pid == 1)		/* you may not mess with init */
178
	if (pid == 1)		/* you may not mess with init */
178
		goto out_tsk;
179
		goto out_tsk;
179
180
181
	if(gr_handle_ptrace(child, request))
182
		goto out_tsk;
183
180
	if (request == PTRACE_ATTACH) {
184
	if (request == PTRACE_ATTACH) {
181
		ret = ptrace_attach(child);
185
		ret = ptrace_attach(child);
182
		goto out_tsk;
186
		goto out_tsk;
Lines 256-261 Link Here
256
			  if(addr < (long) &dummy->u_debugreg[4] &&
260
			  if(addr < (long) &dummy->u_debugreg[4] &&
257
			     ((unsigned long) data) >= TASK_SIZE-3) break;
261
			     ((unsigned long) data) >= TASK_SIZE-3) break;
258
			  
262
			  
263
#ifdef CONFIG_GRKERNSEC
264
			  if(addr >= (long) &dummy->u_debugreg[0] &&
265
			     addr <= (long) &dummy->u_debugreg[3]){
266
				  long reg   = (addr - (long) &dummy->u_debugreg[0]) >> 2;
267
				  long type  = (child->thread.debugreg[7] >> (DR_CONTROL_SHIFT + 4*reg)) & 3;
268
				  long align = (child->thread.debugreg[7] >> (DR_CONTROL_SHIFT + 2 + 4*reg)) & 3;
269
				  if((type & 1) && (data & align))
270
					break;
271
			  }
272
#endif
273
259
			  if(addr == (long) &dummy->u_debugreg[7]) {
274
			  if(addr == (long) &dummy->u_debugreg[7]) {
260
				  data &= ~DR_CONTROL_RESERVED;
275
				  data &= ~DR_CONTROL_RESERVED;
261
				  for(i=0; i<4; i++)
276
				  for(i=0; i<4; i++)
(-)linux-2.4.22-ppc-dev.orig/arch/i386/kernel/setup.c (-1 / +1 lines)
Lines 3126-3132 Link Here
3126
	set_tss_desc(nr,t);
3126
	set_tss_desc(nr,t);
3127
	gdt_table[__TSS(nr)].b &= 0xfffffdff;
3127
	gdt_table[__TSS(nr)].b &= 0xfffffdff;
3128
	load_TR(nr);
3128
	load_TR(nr);
3129
	load_LDT(&init_mm);
3129
	_load_LDT(&init_mm);
3130
3130
3131
	/*
3131
	/*
3132
	 * Clear all 6 debug registers:
3132
	 * Clear all 6 debug registers:
(-)linux-2.4.22-ppc-dev.orig/arch/i386/kernel/sys_i386.c (-1 / +13 lines)
Lines 18-23 Link Here
18
#include <linux/mman.h>
18
#include <linux/mman.h>
19
#include <linux/file.h>
19
#include <linux/file.h>
20
#include <linux/utsname.h>
20
#include <linux/utsname.h>
21
#include <linux/grsecurity.h>
21
22
22
#include <asm/uaccess.h>
23
#include <asm/uaccess.h>
23
#include <asm/ipc.h>
24
#include <asm/ipc.h>
Lines 48-53 Link Here
48
	int error = -EBADF;
49
	int error = -EBADF;
49
	struct file * file = NULL;
50
	struct file * file = NULL;
50
51
52
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
53
	if (flags & MAP_MIRROR)
54
		return -EINVAL;
55
#endif
56
51
	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
57
	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
52
	if (!(flags & MAP_ANONYMOUS)) {
58
	if (!(flags & MAP_ANONYMOUS)) {
53
		file = fget(fd);
59
		file = fget(fd);
Lines 55-62 Link Here
55
			goto out;
61
			goto out;
56
	}
62
	}
57
63
64
	if(gr_handle_mmap(file, prot)) {
65
		fput(file);
66
		error = -EACCES;
67
		goto out;
68
	}
69
58
	down_write(&current->mm->mmap_sem);
70
	down_write(&current->mm->mmap_sem);
59
	error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
71
	error = do_mmap(file, addr, len, prot, flags, pgoff << PAGE_SHIFT);
60
	up_write(&current->mm->mmap_sem);
72
	up_write(&current->mm->mmap_sem);
61
73
62
	if (file)
74
	if (file)
(-)linux-2.4.22-ppc-dev.orig/arch/i386/kernel/trampoline.S (-1 / +1 lines)
Lines 54-60 Link Here
54
	lmsw	%ax		# into protected mode
54
	lmsw	%ax		# into protected mode
55
	jmp	flush_instr
55
	jmp	flush_instr
56
flush_instr:
56
flush_instr:
57
	ljmpl	$__KERNEL_CS, $0x00100000
57
	ljmpl	$__KERNEL_CS, $SYMBOL_NAME(startup_32)-__PAGE_OFFSET
58
			# jump to startup_32 in arch/i386/kernel/head.S
58
			# jump to startup_32 in arch/i386/kernel/head.S
59
59
60
idt_48:
60
idt_48:
(-)linux-2.4.22-ppc-dev.orig/arch/i386/kernel/traps.c (-2 / +77 lines)
Lines 228-241 Link Here
228
		show_stack((unsigned long*)esp);
228
		show_stack((unsigned long*)esp);
229
229
230
		printk("\nCode: ");
230
		printk("\nCode: ");
231
232
#ifndef CONFIG_GRKERNSEC_PAX_KERNEXEC
231
		if(regs->eip < PAGE_OFFSET)
233
		if(regs->eip < PAGE_OFFSET)
232
			goto bad;
234
			goto bad;
235
#endif
233
236
234
		for(i=0;i<20;i++)
237
		for(i=0;i<20;i++)
235
		{
238
		{
236
			unsigned char c;
239
			unsigned char c;
240
241
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
242
			if(__get_user(c, &((unsigned char*)regs->eip)[i+__KERNEL_TEXT_OFFSET])) {
243
#else
237
			if(__get_user(c, &((unsigned char*)regs->eip)[i])) {
244
			if(__get_user(c, &((unsigned char*)regs->eip)[i])) {
238
bad:
245
bad:
246
#endif
247
239
				printk(" Bad EIP value.");
248
				printk(" Bad EIP value.");
240
				break;
249
				break;
241
			}
250
			}
Lines 258-265 Link Here
258
267
259
	eip = regs->eip;
268
	eip = regs->eip;
260
269
270
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
271
	eip += __KERNEL_TEXT_OFFSET;
272
#else
261
	if (eip < PAGE_OFFSET)
273
	if (eip < PAGE_OFFSET)
262
		goto no_bug;
274
		goto no_bug;
275
#endif
276
263
	if (__get_user(ud2, (unsigned short *)eip))
277
	if (__get_user(ud2, (unsigned short *)eip))
264
		goto no_bug;
278
		goto no_bug;
265
	if (ud2 != 0x0b0f)
279
	if (ud2 != 0x0b0f)
Lines 267-273 Link Here
267
	if (__get_user(line, (unsigned short *)(eip + 2)))
281
	if (__get_user(line, (unsigned short *)(eip + 2)))
268
		goto bug;
282
		goto bug;
269
	if (__get_user(file, (char **)(eip + 4)) ||
283
	if (__get_user(file, (char **)(eip + 4)) ||
284
285
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
286
		__get_user(c, file + __KERNEL_TEXT_OFFSET))
287
#else
270
		(unsigned long)file < PAGE_OFFSET || __get_user(c, file))
288
		(unsigned long)file < PAGE_OFFSET || __get_user(c, file))
289
#endif
290
271
		file = "<bad filename>";
291
		file = "<bad filename>";
272
292
273
	printk("kernel BUG at %s:%d!\n", file, line);
293
	printk("kernel BUG at %s:%d!\n", file, line);
Lines 417-422 Link Here
417
gp_in_kernel:
437
gp_in_kernel:
418
	{
438
	{
419
		unsigned long fixup;
439
		unsigned long fixup;
440
441
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
442
		if ((regs->xcs & 0xFFFF) == __KERNEL_CS) {
443
			if (current->curr_ip)
444
				printk(KERN_ERR "PAX: From %u.%u.%u.%u: task %s:%d, uid/euid: %u/%u, may have attempted to execute invalid code at %08lx\n",
445
						NIPQUAD(current->curr_ip), current->comm, current->pid, current->uid, current->euid, regs->eip);
446
			else
447
				printk(KERN_ERR "PAX: task %s:%d, uid/euid: %u/%u, may have attempted to execute invalid code at %08lx\n",
448
						current->comm, current->pid, current->uid, current->euid, regs->eip);
449
		}
450
#endif
451
420
		fixup = search_exception_table(regs->eip);
452
		fixup = search_exception_table(regs->eip);
421
		if (fixup) {
453
		if (fixup) {
422
			regs->eip = fixup;
454
			regs->eip = fixup;
Lines 527-539 Link Here
527
{
559
{
528
	unsigned int condition;
560
	unsigned int condition;
529
	struct task_struct *tsk = current;
561
	struct task_struct *tsk = current;
530
	unsigned long eip = regs->eip;
531
	siginfo_t info;
562
	siginfo_t info;
532
563
533
	__asm__ __volatile__("movl %%db6,%0" : "=r" (condition));
564
	__asm__ __volatile__("movl %%db6,%0" : "=r" (condition));
534
565
535
	/* If the user set TF, it's simplest to clear it right away. */
566
	/* If the user set TF, it's simplest to clear it right away. */
536
	if ((eip >=PAGE_OFFSET) && (regs->eflags & TF_MASK))
567
	if (!(regs->xcs & 3) && (regs->eflags & TF_MASK) && !(regs->eflags & VM_MASK))
537
		goto clear_TF;
568
		goto clear_TF;
538
569
539
	/* Mask out spurious debug traps due to lazy DR7 setting */
570
	/* Mask out spurious debug traps due to lazy DR7 setting */
Lines 855-865 Link Here
855
void set_tss_desc(unsigned int n, void *addr)
886
void set_tss_desc(unsigned int n, void *addr)
856
{
887
{
857
	_set_tssldt_desc(gdt_table+__TSS(n), (int)addr, 235, 0x89);
888
	_set_tssldt_desc(gdt_table+__TSS(n), (int)addr, 235, 0x89);
889
890
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
891
	_set_tssldt_desc(gdt_table2+__TSS(n), (int)addr, 235, 0x89);
892
#endif
893
894
}
895
896
void __set_ldt_desc(unsigned int n, void *addr, unsigned int size)
897
{
898
	_set_tssldt_desc(gdt_table+__LDT(n), (int)addr, ((size << 3)-1), 0x82);
899
900
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
901
	_set_tssldt_desc(gdt_table2+__LDT(n), (int)addr, ((size << 3)-1), 0x82);
902
#endif
903
858
}
904
}
859
905
860
void set_ldt_desc(unsigned int n, void *addr, unsigned int size)
906
void set_ldt_desc(unsigned int n, void *addr, unsigned int size)
861
{
907
{
908
909
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
910
	unsigned long temp, cr3;
911
	pgd_t* pgd;
912
	pmd_t* pmd;
913
914
	asm("movl %%cr3,%0":"=r" (cr3));
915
	for (temp = __KERNEL_TEXT_OFFSET; temp < __KERNEL_TEXT_OFFSET + 0x00400000UL; temp += (1UL << PMD_SHIFT)) {
916
		pgd = (pgd_t *)__va(cr3) + __pgd_offset(temp);
917
		pmd = pmd_offset(pgd, temp);
918
		set_pmd(pmd, __pmd(pmd_val(*pmd) | _PAGE_RW));
919
	}
920
	__flush_tlb_all();
921
#endif
922
862
	_set_tssldt_desc(gdt_table+__LDT(n), (int)addr, ((size << 3)-1), 0x82);
923
	_set_tssldt_desc(gdt_table+__LDT(n), (int)addr, ((size << 3)-1), 0x82);
924
925
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
926
	_set_tssldt_desc(gdt_table2+__LDT(n), (int)addr, ((size << 3)-1), 0x82);
927
#endif
928
929
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
930
	for (temp = __KERNEL_TEXT_OFFSET; temp < __KERNEL_TEXT_OFFSET + 0x00400000UL; temp += (1UL << PMD_SHIFT)) {
931
		pgd = (pgd_t *)__va(cr3) + __pgd_offset(temp);
932
		pmd = pmd_offset(pgd, temp);
933
		set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
934
	}
935
	flush_tlb_all();
936
#endif
937
863
}
938
}
864
939
865
#ifdef CONFIG_X86_VISWS_APIC
940
#ifdef CONFIG_X86_VISWS_APIC
(-)linux-2.4.22-ppc-dev.orig/arch/i386/mm/fault.c (-7 / +398 lines)
Lines 4-9 Link Here
4
 *  Copyright (C) 1995  Linus Torvalds
4
 *  Copyright (C) 1995  Linus Torvalds
5
 */
5
 */
6
6
7
#include <linux/config.h>
7
#include <linux/signal.h>
8
#include <linux/signal.h>
8
#include <linux/sched.h>
9
#include <linux/sched.h>
9
#include <linux/kernel.h>
10
#include <linux/kernel.h>
Lines 19-24 Link Here
19
#include <linux/init.h>
20
#include <linux/init.h>
20
#include <linux/tty.h>
21
#include <linux/tty.h>
21
#include <linux/vt_kern.h>		/* For unblank_screen() */
22
#include <linux/vt_kern.h>		/* For unblank_screen() */
23
#include <linux/unistd.h>
24
#include <linux/compiler.h>
22
25
23
#include <asm/system.h>
26
#include <asm/system.h>
24
#include <asm/uaccess.h>
27
#include <asm/uaccess.h>
Lines 128-133 Link Here
128
asmlinkage void do_invalid_op(struct pt_regs *, unsigned long);
131
asmlinkage void do_invalid_op(struct pt_regs *, unsigned long);
129
extern unsigned long idt;
132
extern unsigned long idt;
130
133
134
#if defined(CONFIG_GRKERNSEC_PAX_PAGEEXEC) || defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC)
135
static int pax_handle_fetch_fault(struct pt_regs *regs);
136
#endif
137
131
/*
138
/*
132
 * This routine handles page faults.  It determines the address,
139
 * This routine handles page faults.  It determines the address,
133
 * and the problem, and then passes it off to one of the appropriate
140
 * and the problem, and then passes it off to one of the appropriate
Lines 138-160 Link Here
138
 *	bit 1 == 0 means read, 1 means write
145
 *	bit 1 == 0 means read, 1 means write
139
 *	bit 2 == 0 means kernel, 1 means user-mode
146
 *	bit 2 == 0 means kernel, 1 means user-mode
140
 */
147
 */
141
asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code)
148
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
149
static int do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
150
#else
151
asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long error_code)
152
#endif
142
{
153
{
143
	struct task_struct *tsk;
154
	struct task_struct *tsk;
144
	struct mm_struct *mm;
155
	struct mm_struct *mm;
145
	struct vm_area_struct * vma, * prev_vma;
156
	struct vm_area_struct * vma, * prev_vma;
157
#ifndef CONFIG_GRKERNSEC_PAX_PAGEEXEC
146
	unsigned long address;
158
	unsigned long address;
159
#endif
147
	unsigned long page;
160
	unsigned long page;
148
	unsigned long fixup;
161
	unsigned long fixup;
149
	int write;
162
	int write;
150
	siginfo_t info;
163
	siginfo_t info;
151
164
165
#ifndef CONFIG_GRKERNSEC_PAX_PAGEEXEC
152
	/* get the address */
166
	/* get the address */
153
	__asm__("movl %%cr2,%0":"=r" (address));
167
	__asm__("movl %%cr2,%0":"=r" (address));
154
168
155
	/* It's safe to allow irq's after cr2 has been saved */
169
	/* It's safe to allow irq's after cr2 has been saved */
156
	if (regs->eflags & X86_EFLAGS_IF)
170
	if (regs->eflags & X86_EFLAGS_IF)
157
		local_irq_enable();
171
		local_irq_enable();
172
#endif
158
173
159
	tsk = current;
174
	tsk = current;
160
175
Lines 260-266 Link Here
260
			tsk->thread.screen_bitmap |= 1 << bit;
275
			tsk->thread.screen_bitmap |= 1 << bit;
261
	}
276
	}
262
	up_read(&mm->mmap_sem);
277
	up_read(&mm->mmap_sem);
263
	return;
278
	return 0;
264
279
265
/*
280
/*
266
 * Something tried to access memory that isn't in our memory map..
281
 * Something tried to access memory that isn't in our memory map..
Lines 271-276 Link Here
271
286
272
	/* User mode accesses just cause a SIGSEGV */
287
	/* User mode accesses just cause a SIGSEGV */
273
	if (error_code & 4) {
288
	if (error_code & 4) {
289
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
290
		if (current->flags & PF_PAX_SEGMEXEC) {
291
292
#if defined(CONFIG_GRKERNSEC_PAX_EMUTRAMP) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
293
		if ((error_code == 4) && (regs->eip + SEGMEXEC_TASK_SIZE == address)) {
294
			switch (pax_handle_fetch_fault(regs)) {
295
296
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
297
			case 5:
298
				return 0;
299
#endif
300
301
#ifdef CONFIG_GRKERNSEC_PAX_EMUTRAMP
302
			case 4:
303
				return 0;
304
			case 3:
305
			case 2:
306
				return 1;
307
#endif
308
309
			case 1:
310
			default:
311
			}
312
		}
313
#endif
314
315
			if (address >= SEGMEXEC_TASK_SIZE) {
316
				pax_report_fault(regs, (void*)regs->eip, (void*)regs->esp);
317
				do_exit(SIGKILL);
318
			}
319
		}
320
#endif
321
274
		tsk->thread.cr2 = address;
322
		tsk->thread.cr2 = address;
275
		tsk->thread.error_code = error_code;
323
		tsk->thread.error_code = error_code;
276
		tsk->thread.trap_no = 14;
324
		tsk->thread.trap_no = 14;
Lines 279-285 Link Here
279
		/* info.si_code has been set above */
327
		/* info.si_code has been set above */
280
		info.si_addr = (void *)address;
328
		info.si_addr = (void *)address;
281
		force_sig_info(SIGSEGV, &info, tsk);
329
		force_sig_info(SIGSEGV, &info, tsk);
282
		return;
330
		return 0;
283
	}
331
	}
284
332
285
	/*
333
	/*
Lines 292-298 Link Here
292
340
293
		if (nr == 6) {
341
		if (nr == 6) {
294
			do_invalid_op(regs, 0);
342
			do_invalid_op(regs, 0);
295
			return;
343
			return 0;
296
		}
344
		}
297
	}
345
	}
298
346
Lines 300-306 Link Here
300
	/* Are we prepared to handle this kernel fault?  */
348
	/* Are we prepared to handle this kernel fault?  */
301
	if ((fixup = search_exception_table(regs->eip)) != 0) {
349
	if ((fixup = search_exception_table(regs->eip)) != 0) {
302
		regs->eip = fixup;
350
		regs->eip = fixup;
303
		return;
351
		return 0;
304
	}
352
	}
305
353
306
/*
354
/*
Lines 312-317 Link Here
312
360
313
	if (address < PAGE_SIZE)
361
	if (address < PAGE_SIZE)
314
		printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference");
362
		printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference");
363
364
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
365
	else if (init_mm.start_code + __KERNEL_TEXT_OFFSET <= address && address < init_mm.end_code + __KERNEL_TEXT_OFFSET) {
366
		if (tsk->curr_ip)
367
			printk(KERN_ERR "PAX: From %u.%u.%u.%u: %s:%d, uid/euid: %u/%u, attempted to modify kernel code",
368
					 NIPQUAD(tsk->curr_ip), tsk->comm, tsk->pid, tsk->uid, tsk->euid);
369
		else
370
			printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code",
371
					 tsk->comm, tsk->pid, tsk->uid, tsk->euid);
372
	}
373
#endif
374
315
	else
375
	else
316
		printk(KERN_ALERT "Unable to handle kernel paging request");
376
		printk(KERN_ALERT "Unable to handle kernel paging request");
317
	printk(" at virtual address %08lx\n",address);
377
	printk(" at virtual address %08lx\n",address);
Lines 364-370 Link Here
364
	/* Kernel mode? Handle exceptions or die */
424
	/* Kernel mode? Handle exceptions or die */
365
	if (!(error_code & 4))
425
	if (!(error_code & 4))
366
		goto no_context;
426
		goto no_context;
367
	return;
427
	return 0;
368
428
369
vmalloc_fault:
429
vmalloc_fault:
370
	{
430
	{
Lines 397-402 Link Here
397
		pte_k = pte_offset(pmd_k, address);
457
		pte_k = pte_offset(pmd_k, address);
398
		if (!pte_present(*pte_k))
458
		if (!pte_present(*pte_k))
399
			goto no_context;
459
			goto no_context;
400
		return;
460
		return 0;
461
	}
462
}
463
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
464
/* PaX: called with the page_table_lock spinlock held */
465
static inline pte_t * pax_get_pte(struct mm_struct *mm, unsigned long address)
466
{
467
	pgd_t *pgd;
468
	pmd_t *pmd;
469
470
	pgd = pgd_offset(mm, address);
471
	if (!pgd || !pgd_present(*pgd))
472
		return 0;
473
	pmd = pmd_offset(pgd, address);
474
	if (!pmd || !pmd_present(*pmd))
475
		return 0;
476
	return pte_offset(pmd, address);
477
}
478
#endif
479
480
/*
481
 * PaX: decide what to do with offenders (regs->eip = fault address)
482
 *
483
 * returns 1 when task should be killed
484
 *         2 when sigreturn trampoline was detected
485
 *         3 when rt_sigreturn trampoline was detected
486
 *         4 when gcc trampoline was detected
487
 *	   5 when legitimate ET_EXEC was detected
488
 */
489
#if defined(CONFIG_GRKERNSEC_PAX_PAGEEXEC) || defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC)
490
static int pax_handle_fetch_fault(struct pt_regs *regs)
491
{
492
#ifdef CONFIG_GRKERNSEC_PAX_EMUTRAMP
493
	static const unsigned char trans[8] = {6, 1, 2, 0, 13, 5, 3, 4};
494
#endif
495
	int err;
496
	
497
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
498
	if (current->flags & PF_PAX_RANDEXEC) {
499
		unsigned long esp_4;
500
		if (regs->eip >= current->mm->start_code &&
501
		    regs->eip < current->mm->end_code)
502
		{
503
			err = get_user(esp_4, (unsigned long*)(regs->esp-4UL));
504
			if (err || esp_4 == regs->eip)
505
				return 1;
506
			regs->eip += current->mm->delta_exec;
507
			return 5;
508
		}
509
	}
510
#endif
511
512
#ifdef CONFIG_GRKERNSEC_PAX_EMUTRAMP
513
514
#ifndef CONFIG_GRKERNSEC_PAX_EMUSIGRT
515
	if (!(current->flags & PF_PAX_EMUTRAMP))
516
		return 1;
517
#endif
518
519
	do { /* PaX: sigreturn emulation */
520
		unsigned char pop, mov;
521
		unsigned short sys;
522
		unsigned long nr;
523
524
		err = get_user(pop, (unsigned char *)(regs->eip));
525
		err |= get_user(mov, (unsigned char *)(regs->eip + 1));
526
		err |= get_user(nr, (unsigned long *)(regs->eip + 2));
527
		err |= get_user(sys, (unsigned short *)(regs->eip + 6));
528
529
		if (err)
530
			break;
531
532
		if (pop == 0x58 &&
533
		    mov == 0xb8 &&
534
		    nr == __NR_sigreturn &&
535
		    sys == 0x80cd)
536
		{
537
538
#ifdef CONFIG_GRKERNSEC_PAX_EMUSIGRT
539
			int sig;
540
			struct k_sigaction *ka;
541
			__sighandler_t handler;
542
543
			if (get_user(sig, (int *)regs->esp))
544
				return 1;
545
			if (sig < 1 || sig > _NSIG || sig == SIGKILL || sig == SIGSTOP)
546
				return 1;
547
			ka = &current->sig->action[sig-1];
548
			handler = ka->sa.sa_handler;
549
			if (handler == SIG_DFL || handler == SIG_IGN) {
550
				if (!(current->flags & PF_PAX_EMUTRAMP))
551
					return 1;
552
			} else if (!(ka->sa.sa_flags & SA_SIGINFO))
553
				return 1;
554
#endif
555
556
			regs->esp += 4;
557
			regs->eax = nr;
558
			regs->eip += 8;
559
			return 2;
560
		}
561
	} while (0);
562
563
	do { /* PaX: rt_sigreturn emulation */
564
		unsigned char mov;
565
		unsigned short sys;
566
		unsigned long nr;
567
568
		err = get_user(mov, (unsigned char *)(regs->eip));
569
		err |= get_user(nr, (unsigned long *)(regs->eip + 1));
570
		err |= get_user(sys, (unsigned short *)(regs->eip + 5));
571
572
		if (err)
573
			break;
574
575
		if (mov == 0xb8 &&
576
		    nr == __NR_rt_sigreturn &&
577
		    sys == 0x80cd)
578
		{
579
580
#ifdef CONFIG_GRKERNSEC_PAX_EMUSIGRT
581
			int sig;
582
			struct k_sigaction *ka;
583
			__sighandler_t handler;
584
585
			if (get_user(sig, (int *)regs->esp))
586
				return 1;
587
			if (sig < 1 || sig > _NSIG || sig == SIGKILL || sig == SIGSTOP)
588
				return 1;
589
			ka = &current->sig->action[sig-1];
590
			handler = ka->sa.sa_handler;
591
			if (handler == SIG_DFL || handler == SIG_IGN) {
592
				if (!(current->flags & PF_PAX_EMUTRAMP))
593
					return 1;
594
			} else if (ka->sa.sa_flags & SA_SIGINFO)
595
				return 1;
596
#endif
597
598
			regs->eax = nr;
599
			regs->eip += 7;
600
			return 3;
601
		}
602
	} while (0);
603
604
#ifdef CONFIG_GRKERNSEC_PAX_EMUSIGRT
605
	if (!(current->flags & PF_PAX_EMUTRAMP))
606
		return 1;
607
#endif
608
609
	do { /* PaX: gcc trampoline emulation #1 */
610
		unsigned char mov1, mov2;
611
		unsigned short jmp;
612
		unsigned long addr1, addr2, ret;
613
		unsigned short call;
614
615
		err = get_user(mov1, (unsigned char *)regs->eip);
616
		err |= get_user(addr1, (unsigned long *)(regs->eip + 1));
617
		err |= get_user(mov2, (unsigned char *)(regs->eip + 5));
618
		err |= get_user(addr2, (unsigned long *)(regs->eip + 6));
619
		err |= get_user(jmp, (unsigned short *)(regs->eip + 10));
620
		err |= get_user(ret, (unsigned long *)regs->esp);
621
622
		if (err)
623
			break;
624
625
		err = get_user(call, (unsigned short *)(ret-2));
626
		if (err)
627
			break;
628
629
		if ((mov1 & 0xF8) == 0xB8 &&
630
		    (mov2 & 0xF8) == 0xB8 &&
631
		    (mov1 & 0x07) != (mov2 & 0x07) &&
632
		    (jmp & 0xF8FF) == 0xE0FF &&
633
		    (mov2 & 0x07) == ((jmp>>8) & 0x07) &&
634
		    (call & 0xF8FF) == 0xD0FF &&
635
		    regs->eip == ((unsigned long*)regs)[trans[(call>>8) & 0x07]])
636
		{
637
			((unsigned long *)regs)[trans[mov1 & 0x07]] = addr1;
638
			((unsigned long *)regs)[trans[mov2 & 0x07]] = addr2;
639
			regs->eip = addr2;
640
			return 4;
641
		}
642
	} while (0);
643
644
	do { /* PaX: gcc trampoline emulation #2 */
645
		unsigned char mov, jmp;
646
		unsigned long addr1, addr2, ret;
647
		unsigned short call;
648
649
		err = get_user(mov, (unsigned char *)regs->eip);
650
		err |= get_user(addr1, (unsigned long *)(regs->eip + 1));
651
		err |= get_user(jmp, (unsigned char *)(regs->eip + 5));
652
		err |= get_user(addr2, (unsigned long *)(regs->eip + 6));
653
		err |= get_user(ret, (unsigned long *)regs->esp);
654
655
		if (err)
656
			break;
657
658
		err = get_user(call, (unsigned short *)(ret-2));
659
		if (err)
660
			break;
661
662
		if ((mov & 0xF8) == 0xB8 &&
663
		    jmp == 0xE9 &&
664
		    (call & 0xF8FF) == 0xD0FF &&
665
		    regs->eip == ((unsigned long*)regs)[trans[(call>>8) & 0x07]])
666
		{
667
			((unsigned long *)regs)[trans[mov & 0x07]] = addr1;
668
			regs->eip += addr2 + 10;
669
			return 4;
670
		}
671
	} while (0);
672
#endif
673
674
	return 1; /* PaX in action */
675
}
676
677
void pax_report_insns(void *pc)
678
{
679
	unsigned long i;
680
681
	printk(KERN_ERR "PAX: bytes at PC: ");
682
	for (i = 0; i < 20; i++) {
683
		unsigned char c;
684
		if (get_user(c, (unsigned char*)pc+i)) {
685
			printk("<invalid address>.");
686
			break;
687
		}
688
		printk("%02x ", c);
689
	}
690
	printk("\n");
691
}
692
#endif
693
694
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
695
/*
696
 * PaX: handle the extra page faults or pass it down to the original handler
697
 *
698
 * returns 0 when nothing special was detected
699
 *         1 when sigreturn trampoline (syscall) has to be emulated
700
 */
701
asmlinkage int pax_do_page_fault(struct pt_regs *regs, unsigned long error_code)
702
{
703
	struct mm_struct *mm = current->mm;
704
	unsigned long address;
705
	pte_t *pte;
706
	unsigned char pte_mask;
707
	int ret;
708
709
	__asm__("movl %%cr2,%0":"=r" (address));
710
711
	/* It's safe to allow irq's after cr2 has been saved */
712
	if (likely(regs->eflags & X86_EFLAGS_IF))
713
		local_irq_enable();
714
715
	if (unlikely((error_code & 5) != 5 ||
716
		     address >= TASK_SIZE ||
717
		     !(current->flags & PF_PAX_PAGEEXEC)))
718
		return do_page_fault(regs, error_code, address);
719
720
	/* PaX: it's our fault, let's handle it if we can */
721
722
	/* PaX: take a look at read faults before acquiring any locks */
723
	if (unlikely((error_code == 5) && (regs->eip == address))) { 
724
		/* instruction fetch attempt from a protected page in user mode */
725
		ret = pax_handle_fetch_fault(regs);
726
		switch (ret) {
727
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
728
		case 5:
729
			return 0;
730
#endif
731
732
#ifdef CONFIG_GRKERNSEC_PAX_EMUTRAMP
733
		case 4:
734
			return 0;
735
		case 3:
736
		case 2:
737
			return 1;
738
#endif
739
		case 1:
740
		default:
741
			pax_report_fault(regs, (void*)regs->eip, (void*)regs->esp);
742
			do_exit(SIGKILL);
743
		}
744
	}
745
746
	pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & 2) << (_PAGE_BIT_DIRTY-1));
747
748
	spin_lock(&mm->page_table_lock);
749
	pte = pax_get_pte(mm, address);
750
	if (unlikely(!pte || !(pte_val(*pte) & _PAGE_PRESENT) || pte_exec(*pte))) {
751
		spin_unlock(&mm->page_table_lock);
752
		do_page_fault(regs, error_code, address);
753
		return 0;
401
	}
754
	}
755
756
	if (unlikely((error_code == 7) && !pte_write(*pte))) {
757
		/* write attempt to a protected page in user mode */
758
		spin_unlock(&mm->page_table_lock);
759
		do_page_fault(regs, error_code, address);
760
		return 0;
761
	}
762
763
	/*
764
	 * PaX: fill DTLB with user rights and retry
765
	 */
766
	__asm__ __volatile__ (
767
		"orb %2,%1\n"
768
#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
769
/*   
770
 * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's   
771
 * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
772
 * page fault when examined during a TLB load attempt. this is true not only
773
 * for PTEs holding a non-present entry but also present entries that will
774
 * raise a page fault (such as those set up by PaX, or the copy-on-write
775
 * mechanism). in effect it means that we do *not* need to flush the TLBs
776
 * for our target pages since their PTEs are simply not in the TLBs at all.
777
 * the best thing in omitting it is that we gain around 15-20% speed in the
778
 * fast path of the page fault handler and can get rid of tracing since we
779
 * can no longer flush unintended entries.
780
 */
781
782
		"invlpg %0\n"
783
#endif
784
785
		"testb $0,%0\n"
786
		"xorb %3,%1\n"
787
		:
788
		: "m" (*(char*)address), "m" (*(char*)pte) , "q" (pte_mask) , "i" (_PAGE_USER)
789
		: "memory", "cc");
790
	spin_unlock(&mm->page_table_lock);
791
	return 0;
402
}
792
}
793
#endif
(-)linux-2.4.22-ppc-dev.orig/arch/i386/mm/init.c (-2 / +40 lines)
Lines 37-42 Link Here
37
#include <asm/e820.h>
37
#include <asm/e820.h>
38
#include <asm/apic.h>
38
#include <asm/apic.h>
39
#include <asm/tlb.h>
39
#include <asm/tlb.h>
40
#include <asm/page_offset.h>
41
#include <asm/desc.h>
40
42
41
mmu_gather_t mmu_gathers[NR_CPUS];
43
mmu_gather_t mmu_gathers[NR_CPUS];
42
unsigned long highstart_pfn, highend_pfn;
44
unsigned long highstart_pfn, highend_pfn;
Lines 122-128 Link Here
122
124
123
/* References to section boundaries */
125
/* References to section boundaries */
124
126
125
extern char _text, _etext, _edata, __bss_start, _end;
127
extern char _text, _etext, _data, _edata, __bss_start, _end;
126
extern char __init_begin, __init_end;
128
extern char __init_begin, __init_end;
127
129
128
static inline void set_pte_phys (unsigned long vaddr,
130
static inline void set_pte_phys (unsigned long vaddr,
Lines 521-527 Link Here
521
	reservedpages = free_pages_init();
523
	reservedpages = free_pages_init();
522
524
523
	codesize =  (unsigned long) &_etext - (unsigned long) &_text;
525
	codesize =  (unsigned long) &_etext - (unsigned long) &_text;
524
	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
526
	datasize =  (unsigned long) &_edata - (unsigned long) &_data;
525
	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
527
	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
526
528
527
	printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, %dk init, %ldk highmem)\n",
529
	printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, %dk init, %ldk highmem)\n",
Lines 589-594 Link Here
589
		totalram_pages++;
591
		totalram_pages++;
590
	}
592
	}
591
	printk (KERN_INFO "Freeing unused kernel memory: %dk freed\n", (&__init_end - &__init_begin) >> 10);
593
	printk (KERN_INFO "Freeing unused kernel memory: %dk freed\n", (&__init_end - &__init_begin) >> 10);
594
595
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
596
	/* PaX: limit KERNEL_CS to actual size */
597
	{
598
		unsigned long limit;
599
600
		limit = (unsigned long)&_etext >> PAGE_SHIFT;
601
		gdt_table[2].a = (gdt_table[2].a & 0xFFFF0000UL) | (limit & 0x0FFFFUL);
602
		gdt_table[2].b = (gdt_table[2].b & 0xFFF0FFFFUL) | (limit & 0xF0000UL);
603
604
		/* PaX: nuke __FLAT_KERNEL_CS, no longer needed */
605
		gdt_table[1].a = 0UL;
606
		gdt_table[1].b = 0UL;
607
608
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
609
		gdt_table2[2].a = (gdt_table2[2].a & 0xFFFF0000UL) | (limit & 0x0FFFFUL);
610
		gdt_table2[2].b = (gdt_table2[2].b & 0xFFF0FFFFUL) | (limit & 0xF0000UL);
611
612
		/* PaX: nuke __FLAT_KERNEL_CS, no longer needed */
613
		gdt_table2[1].a = 0UL;
614
		gdt_table2[1].b = 0UL;
615
#endif
616
617
	/* PaX: make KERNEL_CS read-only */
618
		for (addr = __KERNEL_TEXT_OFFSET; addr < __KERNEL_TEXT_OFFSET + 0x00400000UL; addr += (1UL << PMD_SHIFT)) {
619
			pgd_t *pgd;
620
			pmd_t *pmd;
621
622
			pgd = pgd_offset_k(addr);
623
			pmd = pmd_offset(pgd, addr);
624
			set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
625
		}
626
		flush_tlb_all();
627
	}
628
#endif
629
592
}
630
}
593
631
594
#ifdef CONFIG_BLK_DEV_INITRD
632
#ifdef CONFIG_BLK_DEV_INITRD
(-)linux-2.4.22-ppc-dev.orig/arch/i386/vmlinux.lds (-82 lines)
Lines 1-82 Link Here
1
/* ld script to make i386 Linux kernel
2
 * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>;
3
 */
4
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
5
OUTPUT_ARCH(i386)
6
ENTRY(_start)
7
SECTIONS
8
{
9
  . = 0xC0000000 + 0x100000;
10
  _text = .;			/* Text and read-only data */
11
  .text : {
12
	*(.text)
13
	*(.fixup)
14
	*(.gnu.warning)
15
	} = 0x9090
16
17
  _etext = .;			/* End of text section */
18
19
  .rodata : { *(.rodata) *(.rodata.*) }
20
  .kstrtab : { *(.kstrtab) }
21
22
  . = ALIGN(16);		/* Exception table */
23
  __start___ex_table = .;
24
  __ex_table : { *(__ex_table) }
25
  __stop___ex_table = .;
26
27
  __start___ksymtab = .;	/* Kernel symbol table */
28
  __ksymtab : { *(__ksymtab) }
29
  __stop___ksymtab = .;
30
31
  .data : {			/* Data */
32
	*(.data)
33
	CONSTRUCTORS
34
	}
35
36
  _edata = .;			/* End of data section */
37
38
  . = ALIGN(8192);		/* init_task */
39
  .data.init_task : { *(.data.init_task) }
40
41
  . = ALIGN(4096);		/* Init code and data */
42
  __init_begin = .;
43
  .text.init : { *(.text.init) }
44
  .data.init : { *(.data.init) }
45
  . = ALIGN(16);
46
  __setup_start = .;
47
  .setup.init : { *(.setup.init) }
48
  __setup_end = .;
49
  __initcall_start = .;
50
  .initcall.init : { *(.initcall.init) }
51
  __initcall_end = .;
52
  . = ALIGN(4096);
53
  __init_end = .;
54
55
  . = ALIGN(4096);
56
  .data.page_aligned : { *(.data.idt) }
57
58
  . = ALIGN(32);
59
  .data.cacheline_aligned : { *(.data.cacheline_aligned) }
60
61
  __bss_start = .;		/* BSS */
62
  .bss : {
63
	*(.bss)
64
	}
65
  _end = . ;
66
67
  /* Sections to be discarded */
68
  /DISCARD/ : {
69
	*(.text.exit)
70
	*(.data.exit)
71
	*(.exitcall.exit)
72
	}
73
74
  /* Stabs debugging sections.  */
75
  .stab 0 : { *(.stab) }
76
  .stabstr 0 : { *(.stabstr) }
77
  .stab.excl 0 : { *(.stab.excl) }
78
  .stab.exclstr 0 : { *(.stab.exclstr) }
79
  .stab.index 0 : { *(.stab.index) }
80
  .stab.indexstr 0 : { *(.stab.indexstr) }
81
  .comment 0 : { *(.comment) }
82
}
(-)linux-2.4.22-ppc-dev.orig/arch/i386/vmlinux.lds.S (+136 lines)
Line 0 Link Here
1
/* ld script to make i386 Linux kernel
2
 * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>;
3
 */
4
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
5
OUTPUT_ARCH(i386)
6
ENTRY(_start)
7
SECTIONS
8
{
9
  . = __PAGE_OFFSET + 0x100000;
10
  .text.startup : {
11
	BYTE(0xEA) /* jmp far */
12
13
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
14
	LONG(startup_32 + __KERNEL_TEXT_OFFSET - __PAGE_OFFSET)
15
#else
16
	LONG(startup_32 - __PAGE_OFFSET)
17
#endif
18
19
	SHORT(__KERNEL_CS)
20
	}
21
22
  . = ALIGN(32);
23
  _data = .;
24
  .data : {			/* Data */
25
	*(.data)
26
	CONSTRUCTORS
27
	}
28
29
  . = ALIGN(32);
30
  .data.cacheline_aligned : { *(.data.cacheline_aligned) }
31
32
  . = ALIGN(8192);
33
  .data.init_task : { *(.data.init_task) }
34
35
  . = ALIGN(4096);
36
  .data.page_aligned : { *(.data.swapper_pg_dir) }
37
38
  _edata = .;			/* End of data section */
39
40
  __bss_start = .;		/* BSS */
41
  .bss : {
42
	*(.bss)
43
	LONG(0)
44
	} 
45
  __bss_end = . ;
46
47
  . = ALIGN(4096);		/* Init code and data */
48
  __init_begin = .;
49
50
  .data.init : {
51
	*(.data.pg0)
52
	*(.data.pg1)
53
	*(.data.pg2)
54
	*(.data.init)
55
	}
56
  . = ALIGN(16);
57
  __setup_start = .;
58
  .setup.init : { *(.setup.init) }
59
  __setup_end = .;
60
  __initcall_start = .;
61
  .initcall.init : { *(.initcall.init) }
62
  __initcall_end = .;
63
64
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
65
  __text_init_start = .;
66
  .text.init (. - __KERNEL_TEXT_OFFSET) : AT (__text_init_start) {
67
	*(.text.init)
68
	. = ALIGN(4*1024*1024) - 1;
69
	BYTE(0)
70
	}
71
  __init_end = . + __KERNEL_TEXT_OFFSET;
72
73
/*
74
 * PaX: this must be kept in synch with the KERNEL_CS base
75
 * in the GDTs in arch/i386/kernel/head.S
76
 */
77
  _text = .;			/* Text and read-only data */
78
  .text : AT (. + __KERNEL_TEXT_OFFSET) {
79
#else
80
  .text.init : { *(.text.init) }
81
  . = ALIGN(4096);
82
  __init_end = .;
83
  _text = .;			/* Text and read-only data */
84
  .text : {
85
#endif
86
87
	*(.text)
88
	*(.fixup)
89
	*(.gnu.warning)
90
	} = 0x9090
91
92
  _etext = .;			/* End of text section */
93
  . = ALIGN(4096);
94
95
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
96
  . += __KERNEL_TEXT_OFFSET;
97
#endif
98
99
  .rodata.page_aligned : {
100
	*(.data.empty_zero_page)
101
	*(.data.idt)
102
	}
103
  .rodata : { *(.rodata) *(.rodata.*) }
104
  .kstrtab : { *(.kstrtab) }
105
106
  . = ALIGN(16);		/* Exception table */
107
  __start___ex_table = .;
108
  __ex_table : { *(__ex_table) }
109
  __stop___ex_table = .;
110
111
  __start___ksymtab = .;	/* Kernel symbol table */
112
  __ksymtab : { *(__ksymtab) }
113
  __stop___ksymtab = .;
114
115
#ifdef CONFIG_GRKERNSEC_PAX_KERNEXEC
116
  _end = ALIGN(4*1024*1024);
117
#else
118
  _end = .;
119
#endif
120
121
  /* Sections to be discarded */
122
  /DISCARD/ : {
123
	*(.text.exit)
124
	*(.data.exit)
125
	*(.exitcall.exit)
126
	}
127
128
  /* Stabs debugging sections.  */
129
  .stab 0 : { *(.stab) }
130
  .stabstr 0 : { *(.stabstr) }
131
  .stab.excl 0 : { *(.stab.excl) }
132
  .stab.exclstr 0 : { *(.stab.exclstr) }
133
  .stab.index 0 : { *(.stab.index) }
134
  .stab.indexstr 0 : { *(.stab.indexstr) }
135
  .comment 0 : { *(.comment) }
136
}
(-)linux-2.4.22-ppc-dev.orig/arch/ia64/config.in (+9 lines)
Lines 291-293 Link Here
291
fi
291
fi
292
292
293
endmenu
293
endmenu
294
295
mainmenu_option next_comment
296
comment 'Grsecurity'
297
bool 'Grsecurity' CONFIG_GRKERNSEC
298
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
299
    source grsecurity/Config.in
300
fi
301
endmenu
302
(-)linux-2.4.22-ppc-dev.orig/arch/ia64/kernel/ptrace.c (+4 lines)
Lines 16-21 Link Here
16
#include <linux/ptrace.h>
16
#include <linux/ptrace.h>
17
#include <linux/smp_lock.h>
17
#include <linux/smp_lock.h>
18
#include <linux/user.h>
18
#include <linux/user.h>
19
#include <linux/grsecurity.h>
19
20
20
#include <asm/pgtable.h>
21
#include <asm/pgtable.h>
21
#include <asm/processor.h>
22
#include <asm/processor.h>
Lines 1213-1218 Link Here
1213
	if (pid == 1)		/* no messing around with init! */
1214
	if (pid == 1)		/* no messing around with init! */
1214
		goto out_tsk;
1215
		goto out_tsk;
1215
1216
1217
	if (gr_handle_ptrace(child, request))
1218
		goto out_tsk;
1219
1216
	if (request == PTRACE_ATTACH) {
1220
	if (request == PTRACE_ATTACH) {
1217
		ret = ptrace_attach(child);
1221
		ret = ptrace_attach(child);
1218
		goto out_tsk;
1222
		goto out_tsk;
(-)linux-2.4.22-ppc-dev.orig/arch/ia64/kernel/sys_ia64.c (+6 lines)
Lines 15-20 Link Here
15
#include <linux/smp.h>
15
#include <linux/smp.h>
16
#include <linux/smp_lock.h>
16
#include <linux/smp_lock.h>
17
#include <linux/highuid.h>
17
#include <linux/highuid.h>
18
#include <linux/grsecurity.h>
18
19
19
#include <asm/shmparam.h>
20
#include <asm/shmparam.h>
20
#include <asm/uaccess.h>
21
#include <asm/uaccess.h>
Lines 206-211 Link Here
206
		goto out;
207
		goto out;
207
	}
208
	}
208
209
210
	if (gr_handle_mmap(file, prot)) {
211
		addr = -EACCES;
212
		goto out;
213
	}
214
209
	down_write(&current->mm->mmap_sem);
215
	down_write(&current->mm->mmap_sem);
210
	addr = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
216
	addr = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
211
	up_write(&current->mm->mmap_sem);
217
	up_write(&current->mm->mmap_sem);
(-)linux-2.4.22-ppc-dev.orig/arch/m68k/config.in (+8 lines)
Lines 564-566 Link Here
564
564
565
source crypto/Config.in
565
source crypto/Config.in
566
source lib/Config.in
566
source lib/Config.in
567
568
mainmenu_option next_comment
569
comment 'Grsecurity'
570
bool 'Grsecurity' CONFIG_GRKERNSEC
571
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
572
	source grsecurity/Config.in
573
fi
574
endmenu
(-)linux-2.4.22-ppc-dev.orig/arch/mips/config.in (+8 lines)
Lines 7-9 Link Here
7
define_bool CONFIG_MIPS64 n
7
define_bool CONFIG_MIPS64 n
8
8
9
source arch/mips/config-shared.in
9
source arch/mips/config-shared.in
10
11
mainmenu_option next_comment
12
comment 'Grsecurity'
13
bool 'Grsecurity' CONFIG_GRKERNSEC
14
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
15
        source grsecurity/Config.in
16
fi
17
endmenu
(-)linux-2.4.22-ppc-dev.orig/arch/mips64/config.in (+8 lines)
Lines 7-9 Link Here
7
define_bool CONFIG_MIPS64 y
7
define_bool CONFIG_MIPS64 y
8
8
9
source arch/mips/config-shared.in
9
source arch/mips/config-shared.in
10
11
mainmenu_option next_comment
12
comment 'Grsecurity'
13
bool 'Grsecurity' CONFIG_GRKERNSEC
14
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
15
        source grsecurity/Config.in
16
fi
17
endmenu
(-)linux-2.4.22-ppc-dev.orig/arch/parisc/config.in (+8 lines)
Lines 198-200 Link Here
198
198
199
source crypto/Config.in
199
source crypto/Config.in
200
source lib/Config.in
200
source lib/Config.in
201
202
mainmenu_option next_comment
203
comment 'Grsecurity'
204
bool 'Grsecurity' CONFIG_GRKERNSEC
205
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
206
	source grsecurity/Config.in
207
fi
208
endmenu
(-)linux-2.4.22-ppc-dev.orig/arch/parisc/kernel/ioctl32.c (+4 lines)
Lines 1434-1440 Link Here
1434
	 * To have permissions to do most of the vt ioctls, we either have
1434
	 * To have permissions to do most of the vt ioctls, we either have
1435
	 * to be the owner of the tty, or super-user.
1435
	 * to be the owner of the tty, or super-user.
1436
	 */
1436
	 */
1437
#ifdef CONFIG_GRKERNSEC
1438
	if (current->tty == tty || capable(CAP_SYS_TTY_CONFIG))
1439
#else
1437
	if (current->tty == tty || suser())
1440
	if (current->tty == tty || suser())
1441
#endif
1438
		return 1;
1442
		return 1;
1439
	return 0;                                                    
1443
	return 0;                                                    
1440
}
1444
}
(-)linux-2.4.22-ppc-dev.orig/arch/parisc/kernel/ptrace.c (-1 / +4 lines)
Lines 15-21 Link Here
15
#include <linux/ptrace.h>
15
#include <linux/ptrace.h>
16
#include <linux/user.h>
16
#include <linux/user.h>
17
#include <linux/personality.h>
17
#include <linux/personality.h>
18
18
#include <linux/grsecurity.h>
19
#include <asm/uaccess.h>
19
#include <asm/uaccess.h>
20
#include <asm/pgtable.h>
20
#include <asm/pgtable.h>
21
#include <asm/system.h>
21
#include <asm/system.h>
Lines 119-124 Link Here
119
	if (pid == 1)		/* no messing around with init! */
119
	if (pid == 1)		/* no messing around with init! */
120
		goto out_tsk;
120
		goto out_tsk;
121
121
122
	if (gr_handle_ptrace(child, request))
123
		goto out_tsk;
124
122
	if (request == PTRACE_ATTACH) {
125
	if (request == PTRACE_ATTACH) {
123
		ret = ptrace_attach(child);
126
		ret = ptrace_attach(child);
124
		goto out_tsk;
127
		goto out_tsk;
(-)linux-2.4.22-ppc-dev.orig/arch/parisc/kernel/sys_parisc.c (+17 lines)
Lines 12-17 Link Here
12
#include <linux/mman.h>
12
#include <linux/mman.h>
13
#include <linux/shm.h>
13
#include <linux/shm.h>
14
#include <linux/smp_lock.h>
14
#include <linux/smp_lock.h>
15
#include <linux/grsecurity.h>
15
16
16
int sys_pipe(int *fildes)
17
int sys_pipe(int *fildes)
17
{
18
{
Lines 90-95 Link Here
90
		inode = filp->f_dentry->d_inode;
91
		inode = filp->f_dentry->d_inode;
91
	}
92
	}
92
93
94
#ifdef CONFIG_GRKERNSEC_PAX_RANDMMAP
95
	if ((current->flags & PF_PAX_RANDMMAP) && (!addr || filp))
96
		addr = TASK_UNMAPPED_BASE + current->mm->delta_mmap;
97
#endif
98
93
	if (inode && (flags & MAP_SHARED) && (inode->i_mapping->i_mmap_shared)) {
99
	if (inode && (flags & MAP_SHARED) && (inode->i_mapping->i_mmap_shared)) {
94
		addr = get_shared_area(inode, addr, len, pgoff);
100
		addr = get_shared_area(inode, addr, len, pgoff);
95
	} else {
101
	} else {
Lines 104-115 Link Here
104
{
110
{
105
	struct file * file = NULL;
111
	struct file * file = NULL;
106
	unsigned long error = -EBADF;
112
	unsigned long error = -EBADF;
113
114
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
115
	if (flags & MAP_MIRROR)
116
		return -EINVAL;
117
#endif
118
107
	if (!(flags & MAP_ANONYMOUS)) {
119
	if (!(flags & MAP_ANONYMOUS)) {
108
		file = fget(fd);
120
		file = fget(fd);
109
		if (!file)
121
		if (!file)
110
			goto out;
122
			goto out;
111
	}
123
	}
112
124
125
	if (gr_handle_mmap(file, prot)) {
126
		fput(file);
127
		return -EACCES;
128
	}
129
113
	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
130
	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
114
131
115
	down_write(&current->mm->mmap_sem);
132
	down_write(&current->mm->mmap_sem);
(-)linux-2.4.22-ppc-dev.orig/arch/parisc/kernel/sys_parisc32.c (-1 / +60 lines)
Lines 50-55 Link Here
50
#include <linux/highmem.h>
50
#include <linux/highmem.h>
51
#include <linux/highuid.h>
51
#include <linux/highuid.h>
52
#include <linux/mman.h>
52
#include <linux/mman.h>
53
#include <linux/grsecurity.h>
53
54
54
#include <asm/types.h>
55
#include <asm/types.h>
55
#include <asm/uaccess.h>
56
#include <asm/uaccess.h>
Lines 177-182 Link Here
177
	struct file *file;
178
	struct file *file;
178
	int retval;
179
	int retval;
179
	int i;
180
	int i;
181
#ifdef CONFIG_GRKERNSEC
182
	struct file *old_exec_file;
183
	struct acl_subject_label *old_acl;
184
	struct rlimit old_rlim[RLIM_NLIMITS];
185
#endif
180
186
181
	file = open_exec(filename);
187
	file = open_exec(filename);
182
188
Lines 184-190 Link Here
184
	if (IS_ERR(file))
190
	if (IS_ERR(file))
185
		return retval;
191
		return retval;
186
192
193
	gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->user->processes));
194
195
	if (gr_handle_nproc()) {
196
		allow_write_access(file);
197
		fput(file);
198
		return -EAGAIN;
199
	}
200
201
	if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
202
		allow_write_access(file);
203
		fput(file);
204
		return -EACCES;
205
	}
206
187
	bprm.p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
207
	bprm.p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
208
209
#ifdef CONFIG_GRKERNSEC_PAX_RANDUSTACK
210
	bprm.p -= (get_random_long() & ~(sizeof(void *)-1)) & ~PAGE_MASK;
211
#endif
212
188
	memset(bprm.page, 0, MAX_ARG_PAGES*sizeof(bprm.page[0]));
213
	memset(bprm.page, 0, MAX_ARG_PAGES*sizeof(bprm.page[0]));
189
214
190
	DBG(("do_execve32(%s, %p, %p, %p)\n", filename, argv, envp, regs));
215
	DBG(("do_execve32(%s, %p, %p, %p)\n", filename, argv, envp, regs));
Lines 209-219 Link Here
209
	if (retval < 0)
234
	if (retval < 0)
210
		goto out;
235
		goto out;
211
	
236
	
237
	if (!gr_tpe_allow(file)) {
238
		retval = -EACCES;
239
		goto out;
240
	}
241
242
	if (gr_check_crash_exec(file)) {
243
		retval = -EACCES;
244
		goto out;
245
	}
246
212
	retval = copy_strings_kernel(1, &bprm.filename, &bprm);
247
	retval = copy_strings_kernel(1, &bprm.filename, &bprm);
213
	if (retval < 0)
248
	if (retval < 0)
214
		goto out;
249
		goto out;
215
250
216
	bprm.exec = bprm.p;
251
	bprm.exec = bprm.p;
252
253
	gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
254
217
	retval = copy_strings32(bprm.envc, envp, &bprm);
255
	retval = copy_strings32(bprm.envc, envp, &bprm);
218
	if (retval < 0)
256
	if (retval < 0)
219
		goto out;
257
		goto out;
Lines 222-232 Link Here
222
	if (retval < 0)
260
	if (retval < 0)
223
		goto out;
261
		goto out;
224
262
263
#ifdef CONFIG_GRKERNSEC
264
	old_acl = current->acl;
265
	memcpy(old_rlim, current->rlim, sizeof(old_rlim));
266
	old_exec_file = current->exec_file;
267
	get_file(file);
268
	current->exec_file = file;
269
#endif
270
271
	gr_set_proc_label(file->f_dentry, file->f_vfsmnt);
272
225
	retval = search_binary_handler(&bprm,regs);
273
	retval = search_binary_handler(&bprm,regs);
226
	if (retval >= 0)
274
	if (retval >= 0) {
275
#ifdef CONFIG_GRKERNSEC
276
		if (old_exec_file)
277
			fput(old_exec_file);
278
#endif
227
		/* execve success */
279
		/* execve success */
228
		return retval;
280
		return retval;
281
	}
229
282
283
#ifdef CONFIG_GRKERNSEC
284
	current->acl = old_acl;
285
	memcpy(current->rlim, old_rlim, sizeof(old_rlim));
286
	fput(current->exec_file);
287
	current->exec_file = old_exec_file;
288
#endif
230
out:
289
out:
231
	/* Something went wrong, return the inode and free the argument pages*/
290
	/* Something went wrong, return the inode and free the argument pages*/
232
	allow_write_access(bprm.file);
291
	allow_write_access(bprm.file);
(-)linux-2.4.22-ppc-dev.orig/arch/parisc/kernel/traps.c (-3 / +1 lines)
Lines 637-645 Link Here
637
637
638
			down_read(&current->mm->mmap_sem);
638
			down_read(&current->mm->mmap_sem);
639
			vma = find_vma(current->mm,regs->iaoq[0]);
639
			vma = find_vma(current->mm,regs->iaoq[0]);
640
			if (vma && (regs->iaoq[0] >= vma->vm_start)
640
			if (vma && (regs->iaoq[0] >= vma->vm_start)) {
641
				&& (vma->vm_flags & VM_EXEC)) {
642
643
				fault_address = regs->iaoq[0];
641
				fault_address = regs->iaoq[0];
644
				fault_space = regs->iasq[0];
642
				fault_space = regs->iasq[0];
645
643
(-)linux-2.4.22-ppc-dev.orig/arch/parisc/mm/fault.c (-2 / +163 lines)
Lines 15-20 Link Here
15
#include <linux/ptrace.h>
15
#include <linux/ptrace.h>
16
#include <linux/sched.h>
16
#include <linux/sched.h>
17
#include <linux/interrupt.h>
17
#include <linux/interrupt.h>
18
#include <linux/unistd.h>
18
19
19
#include <asm/uaccess.h>
20
#include <asm/uaccess.h>
20
#include <asm/traps.h>
21
#include <asm/traps.h>
Lines 53-59 Link Here
53
static unsigned long
54
static unsigned long
54
parisc_acctyp(unsigned long code, unsigned int inst)
55
parisc_acctyp(unsigned long code, unsigned int inst)
55
{
56
{
56
	if (code == 6 || code == 16)
57
	if (code == 6 || code == 7 || code == 16)
57
	    return VM_EXEC;
58
	    return VM_EXEC;
58
59
59
	switch (inst & 0xf0000000) {
60
	switch (inst & 0xf0000000) {
Lines 139-144 Link Here
139
			}
140
			}
140
#endif
141
#endif
141
142
143
/*
144
 * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
145
 *
146
 * returns 1 when task should be killed 
147
 *	   2 when rt_sigreturn trampoline was detected
148
 *	   3 when unpatched PLT trampoline was detected
149
 *	   4 when legitimate ET_EXEC was detected
150
 */
151
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC  
152
static int pax_handle_fetch_fault(struct pt_regs *regs)
153
{
154
	int err;
155
156
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
157
	if (current->flags & PF_PAX_RANDEXEC) {
158
		if (instruction_pointer(regs) >= current->mm->start_code &&
159
		    instruction_pointer(regs) < current->mm->end_code)
160
		{
161
#if 0
162
			/* PaX: this needs fixing */
163
			if ((regs->gr[2] & ~3UL) == instruction_pointer(regs))
164
				return 1;
165
#endif
166
			regs->iaoq[0] += current->mm->delta_exec;
167
			if ((regs->iaoq[1] & ~3UL) >= current->mm->start_code &&
168
			    (regs->iaoq[1] & ~3UL) < current->mm->end_code)
169
				regs->iaoq[1] += current->mm->delta_exec;
170
			return 4;
171
		}
172
	}
173
#endif
174
175
#ifdef CONFIG_GRKERNSEC_PAX_EMUPLT
176
	do { /* PaX: unpatched PLT emulation */
177
		unsigned int bl, depwi;
178
179
		err = get_user(bl, (unsigned int*)instruction_pointer(regs));
180
		err |= get_user(depwi, (unsigned int*)(instruction_pointer(regs)+4));
181
182
		if (err)
183
			break;
184
185
		if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
186
			unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
187
188
			err = get_user(ldw, (unsigned int*)addr);
189
			err |= get_user(bv, (unsigned int*)(addr+4));
190
			err |= get_user(ldw2, (unsigned int*)(addr+8));
191
192
			if (err)
193
				break;
194
195
			if (ldw == 0x0E801096U &&
196
			    bv == 0xEAC0C000U &&
197
			    ldw2 == 0x0E881095U)
198
			{
199
				unsigned int resolver, map;
200
201
				err = get_user(resolver, (unsigned int*)(instruction_pointer(regs)+8));
202
				err |= get_user(map, (unsigned int*)(instruction_pointer(regs)+12));
203
				if (err)
204
					break;
205
206
				regs->gr[20] = instruction_pointer(regs)+8;
207
				regs->gr[21] = map;
208
				regs->gr[22] = resolver;
209
				regs->iaoq[0] = resolver | 3UL;
210
				regs->iaoq[1] = regs->iaoq[0] + 4;
211
				return 3;
212
			}
213
		}
214
	} while (0);
215
#endif
216
 
217
#ifdef CONFIG_GRKERNSEC_PAX_EMUTRAMP
218
219
#ifndef CONFIG_GRKERNSEC_PAX_EMUSIGRT
220
	if (!(current->flags & PF_PAX_EMUTRAMP))
221
		return 1;
222
#endif
223
224
	do { /* PaX: rt_sigreturn emulation */
225
		unsigned int ldi1, ldi2, bel, nop;
226
227
		err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
228
		err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
229
		err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
230
		err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
231
232
		if (err)
233
			break;
234
235
                if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
236
		    ldi2 == 0x3414015AU &&
237
		    bel == 0xE4008200U &&
238
		    nop == 0x08000240U)
239
		{
240
			regs->gr[25] = (ldi1 & 2) >> 1;
241
			regs->gr[20] = __NR_rt_sigreturn;
242
			regs->gr[31] = regs->iaoq[1] + 16;
243
			regs->sr[0] = regs->iasq[1];
244
			regs->iaoq[0] = 0x100UL;
245
			regs->iaoq[1] = regs->iaoq[0] + 4;
246
			regs->iasq[0] = regs->sr[2];
247
			regs->iasq[1] = regs->sr[2];
248
			return 2;
249
		}
250
	} while (0);
251
#endif
252
253
	return 1;
254
}
255
256
void pax_report_insns(void *pc)
257
{
258
	unsigned long i;
259
260
	printk(KERN_ERR "PAX: bytes at PC: ");
261
	for (i = 0; i < 5; i++) {
262
		unsigned int c;
263
		if (get_user(c, (unsigned int*)pc+i)) {
264
			printk("<invalid address>.");
265
			break;
266
		}
267
		printk("%08x ", c);
268
	}
269
	printk("\n");
270
}
271
#endif
272
142
void do_page_fault(struct pt_regs *regs, unsigned long code,
273
void do_page_fault(struct pt_regs *regs, unsigned long code,
143
			      unsigned long address)
274
			      unsigned long address)
144
{
275
{
Lines 164-171 Link Here
164
295
165
	acc_type = parisc_acctyp(code,regs->iir);
296
	acc_type = parisc_acctyp(code,regs->iir);
166
297
167
	if ((vma->vm_flags & acc_type) != acc_type)
298
	if ((vma->vm_flags & acc_type) != acc_type) {
299
300
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
301
		if ((current->flags & PF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
302
		    (address & ~3UL) == instruction_pointer(regs))
303
		   {
304
			up_read(&mm->mmap_sem);
305
			switch(pax_handle_fetch_fault(regs)) {
306
307
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
308
			case 4:
309
				return;
310
#endif
311
312
#ifdef CONFIG_GRKERNSEC_PAX_EMUPLT
313
			case 3:
314
				return;
315
#endif
316
317
#ifdef CONFIG_GRKERNSEC_PAX_EMUTRAMP
318
			case 2:
319
				return;
320
#endif
321
322
			}
323
			pax_report_fault(regs, (void*)instruction_pointer(regs), (void*)regs->gr[30]);
324
			do_exit(SIGKILL);
325
		}
326
#endif
327
168
		goto bad_area;
328
		goto bad_area;
329
	}
169
330
170
	/*
331
	/*
171
	 * If for any reason at all we couldn't handle the fault, make
332
	 * If for any reason at all we couldn't handle the fault, make
(-)linux-2.4.22-ppc-dev.orig/arch/ppc/config.in (+9 lines)
Lines 499-501 Link Here
499
  bool 'Support for early boot texts over serial port' CONFIG_SERIAL_TEXT_DEBUG
499
  bool 'Support for early boot texts over serial port' CONFIG_SERIAL_TEXT_DEBUG
500
fi
500
fi
501
endmenu
501
endmenu
502
503
mainmenu_option next_comment
504
comment 'Grsecurity'
505
bool 'Grsecurity' CONFIG_GRKERNSEC
506
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
507
    source grsecurity/Config.in
508
fi
509
endmenu
510
(-)linux-2.4.22-ppc-dev.orig/arch/ppc/kernel/ptrace.c (+4 lines)
Lines 24-29 Link Here
24
#include <linux/errno.h>
24
#include <linux/errno.h>
25
#include <linux/ptrace.h>
25
#include <linux/ptrace.h>
26
#include <linux/user.h>
26
#include <linux/user.h>
27
#include <linux/grsecurity.h>
27
28
28
#include <asm/uaccess.h>
29
#include <asm/uaccess.h>
29
#include <asm/page.h>
30
#include <asm/page.h>
Lines 195-200 Link Here
195
	if (pid == 1)		/* you may not mess with init */
196
	if (pid == 1)		/* you may not mess with init */
196
		goto out_tsk;
197
		goto out_tsk;
197
198
199
	if (gr_handle_ptrace(child, request))
200
		goto out_tsk;
201
198
	if (request == PTRACE_ATTACH) {
202
	if (request == PTRACE_ATTACH) {
199
		ret = ptrace_attach(child);
203
		ret = ptrace_attach(child);
200
		goto out_tsk;
204
		goto out_tsk;
(-)linux-2.4.22-ppc-dev.orig/arch/ppc/kernel/syscalls.c (-1 / +13 lines)
Lines 35-40 Link Here
35
#include <linux/ipc.h>
35
#include <linux/ipc.h>
36
#include <linux/utsname.h>
36
#include <linux/utsname.h>
37
#include <linux/file.h>
37
#include <linux/file.h>
38
#include <linux/grsecurity.h>
38
39
39
#include <asm/uaccess.h>
40
#include <asm/uaccess.h>
40
#include <asm/ipc.h>
41
#include <asm/ipc.h>
Lines 175-188 Link Here
175
	struct file * file = NULL;
176
	struct file * file = NULL;
176
	int ret = -EBADF;
177
	int ret = -EBADF;
177
178
179
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
180
	if (flags & MAP_MIRROR)
181
		return -EINVAL;
182
#endif
183
178
	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
184
	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
179
	if (!(flags & MAP_ANONYMOUS)) {
185
	if (!(flags & MAP_ANONYMOUS)) {
180
		if (!(file = fget(fd)))
186
		if (!(file = fget(fd)))
181
			goto out;
187
			goto out;
182
	}
188
	}
183
189
190
	if (gr_handle_mmap(file, prot)) {
191
		fput(file);
192
		ret = -EACCES;
193
		goto out;
194
	}
195
184
	down_write(&current->mm->mmap_sem);
196
	down_write(&current->mm->mmap_sem);
185
	ret = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
197
	ret = do_mmap(file, addr, len, prot, flags, pgoff << PAGE_SHIFT);
186
	up_write(&current->mm->mmap_sem);
198
	up_write(&current->mm->mmap_sem);
187
	if (file)
199
	if (file)
188
		fput(file);
200
		fput(file);
(-)linux-2.4.22-ppc-dev.orig/arch/ppc/mm/fault.c (-1 / +390 lines)
Lines 26-31 Link Here
26
#include <linux/mman.h>
26
#include <linux/mman.h>
27
#include <linux/mm.h>
27
#include <linux/mm.h>
28
#include <linux/interrupt.h>
28
#include <linux/interrupt.h>
29
#include <linux/slab.h>
30
#include <linux/pagemap.h>
31
#include <linux/compiler.h>
29
32
30
#include <asm/page.h>
33
#include <asm/page.h>
31
#include <asm/pgtable.h>
34
#include <asm/pgtable.h>
Lines 52-57 Link Here
52
void bad_page_fault(struct pt_regs *, unsigned long, int sig);
55
void bad_page_fault(struct pt_regs *, unsigned long, int sig);
53
void do_page_fault(struct pt_regs *, unsigned long, unsigned long);
56
void do_page_fault(struct pt_regs *, unsigned long, unsigned long);
54
57
58
#ifdef CONFIG_GRKERNSEC_PAX_EMUSIGRT
59
void pax_syscall_close(struct vm_area_struct * vma)
60
{
61
	vma->vm_mm->call_syscall = 0UL;
62
}
63
64
static struct page* pax_syscall_nopage(struct vm_area_struct *vma, unsigned long address, int write_access)
65
{
66
	struct page* page;
67
	unsigned int *kaddr;
68
69
	page = alloc_page(GFP_HIGHUSER);
70
	if (!page)
71
		return page;
72
73
	kaddr = kmap(page);
74
	memset(kaddr, 0, PAGE_SIZE);
75
	kaddr[0] = 0x44000002U; /* sc */
76
	__flush_dcache_icache(kaddr);
77
	kunmap(page);
78
	return page;
79
}
80
81
static struct vm_operations_struct pax_vm_ops = {
82
	close:		pax_syscall_close,
83
	nopage:		pax_syscall_nopage,
84
};
85
86
static void pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
87
{
88
	vma->vm_mm = current->mm;
89
	vma->vm_start = addr;
90
	vma->vm_end = addr + PAGE_SIZE;
91
	vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
92
	vma->vm_page_prot = protection_map[vma->vm_flags & 0x0f];
93
	vma->vm_ops = &pax_vm_ops;
94
	vma->vm_pgoff = 0UL;
95
	vma->vm_file = NULL;
96
	vma->vm_private_data = NULL;
97
	insert_vm_struct(current->mm, vma);
98
	++current->mm->total_vm;
99
}
100
#endif
101
102
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
103
/*
104
 * PaX: decide what to do with offenders (regs->nip = fault address)
105
 *
106
 * returns 1 when task should be killed
107
 *         2 when patched GOT trampoline was detected
108
 *         3 when patched PLT trampoline was detected
109
 *         4 when unpatched PLT trampoline was detected
110
 *         5 when legitimate ET_EXEC was detected
111
 *         6 when sigreturn trampoline was detected
112
 *         7 when rt_sigreturn trampoline was detected
113
 */
114
static int pax_handle_fetch_fault(struct pt_regs *regs)
115
{
116
	int err;
117
118
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
119
	if (current->flags & PF_PAX_RANDEXEC) {
120
		if (regs->nip >= current->mm->start_code &&
121
		    regs->nip < current->mm->end_code)
122
		{
123
			if (regs->link == regs->nip)
124
				return 1;
125
126
			regs->nip += current->mm->delta_exec;
127
			return 5;
128
		}
129
	}
130
#endif
131
132
#ifdef CONFIG_GRKERNSEC_PAX_EMUPLT
133
	do { /* PaX: patched GOT emulation */
134
		unsigned int blrl;
135
136
		err = get_user(blrl, (unsigned int*)regs->nip);
137
138
		if (!err && blrl == 0x4E800021U) {
139
			unsigned long temp = regs->nip;
140
141
			regs->nip = regs->link & 0xFFFFFFFCUL;
142
			regs->link = temp + 4UL;
143
			return 2;
144
		}
145
	} while (0);
146
147
	do { /* PaX: patched PLT emulation #1 */
148
		unsigned int b;
149
150
		err = get_user(b, (unsigned int *)regs->nip);
151
152
		if (!err && (b & 0xFC000003U) == 0x48000000U) {
153
			regs->nip += (((b | 0xFC000000UL) ^ 0x02000000UL) + 0x02000000UL);
154
			return 3;
155
		}
156
	} while (0);
157
158
	do { /* PaX: unpatched PLT emulation #1 */
159
		unsigned int li, b;
160
161
		err = get_user(li, (unsigned int *)regs->nip);
162
		err |= get_user(b, (unsigned int *)(regs->nip+4));
163
164
		if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) {
165
			unsigned int rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr;
166
                        unsigned long addr = b | 0xFC000000UL;
167
168
                        addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL);
169
			err = get_user(rlwinm, (unsigned int*)addr);
170
			err |= get_user(add, (unsigned int*)(addr+4));
171
			err |= get_user(li2, (unsigned int*)(addr+8));
172
			err |= get_user(addis2, (unsigned int*)(addr+12));
173
			err |= get_user(mtctr, (unsigned int*)(addr+16));
174
			err |= get_user(li3, (unsigned int*)(addr+20));
175
			err |= get_user(addis3, (unsigned int*)(addr+24));
176
			err |= get_user(bctr, (unsigned int*)(addr+28));
177
178
			if (err)
179
				break;
180
181
			if (rlwinm == 0x556C083CU &&
182
			    add == 0x7D6C5A14U &&
183
			    (li2 & 0xFFFF0000U) == 0x39800000U &&
184
			    (addis2 & 0xFFFF0000U) == 0x3D8C0000U &&
185
			    mtctr == 0x7D8903A6U &&
186
			    (li3 & 0xFFFF0000U) == 0x39800000U &&
187
			    (addis3 & 0xFFFF0000U) == 0x3D8C0000U &&
188
			    bctr == 0x4E800420U)
189
			{
190
				regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
191
				regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
192
				regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16;
193
				regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
194
				regs->ctr += (addis2 & 0xFFFFU) << 16;
195
				regs->nip = regs->ctr;
196
				return 4;
197
			}
198
		}
199
	} while (0);
200
201
#if 0
202
	do { /* PaX: unpatched PLT emulation #2 */
203
		unsigned int lis, lwzu, b, bctr;
204
205
		err = get_user(lis, (unsigned int *)regs->nip);
206
		err |= get_user(lwzu, (unsigned int *)(regs->nip+4));
207
		err |= get_user(b, (unsigned int *)(regs->nip+8));
208
		err |= get_user(bctr, (unsigned int *)(regs->nip+12));
209
210
		if (err)
211
			break;
212
213
		if ((lis & 0xFFFF0000U) == 0x39600000U &&
214
		    (lwzu & 0xU) == 0xU &&
215
		    (b & 0xFC000003U) == 0x48000000U &&
216
		    bctr == 0x4E800420U)
217
		{
218
			unsigned int addis, addi, rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr;
219
                        unsigned long addr = b | 0xFC000000UL;
220
221
                        addr = regs->nip + 12 + ((addr ^ 0x02000000UL) + 0x02000000UL);
222
			err = get_user(addis, (unsigned int*)addr);
223
			err |= get_user(addi, (unsigned int*)(addr+4));
224
			err |= get_user(rlwinm, (unsigned int*)(addr+8));
225
			err |= get_user(add, (unsigned int*)(addr+12));
226
			err |= get_user(li2, (unsigned int*)(addr+16));
227
			err |= get_user(addis2, (unsigned int*)(addr+20));
228
			err |= get_user(mtctr, (unsigned int*)(addr+24));
229
			err |= get_user(li3, (unsigned int*)(addr+28));
230
			err |= get_user(addis3, (unsigned int*)(addr+32));
231
			err |= get_user(bctr, (unsigned int*)(addr+36));
232
233
			if (err)
234
				break;
235
236
			if ((addis & 0xFFFF0000U) == 0x3D6B0000U &&
237
			    (addi & 0xFFFF0000U) == 0x396B0000U &&
238
			    rlwinm == 0x556C083CU &&
239
			    add == 0x7D6C5A14U &&
240
			    (li2 & 0xFFFF0000U) == 0x39800000U &&
241
			    (addis2 & 0xFFFF0000U) == 0x3D8C0000U &&
242
			    mtctr == 0x7D8903A6U &&
243
			    (li3 & 0xFFFF0000U) == 0x39800000U &&
244
			    (addis3 & 0xFFFF0000U) == 0x3D8C0000U &&
245
			    bctr == 0x4E800420U)
246
			{
247
				regs->gpr[PT_R11] = 
248
				regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
249
				regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
250
				regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16;
251
				regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
252
				regs->ctr += (addis2 & 0xFFFFU) << 16;
253
				regs->nip = regs->ctr;
254
				return 4;
255
			}
256
		}
257
	} while (0);
258
#endif
259
260
	do { /* PaX: unpatched PLT emulation #3 */
261
		unsigned int li, b;
262
263
		err = get_user(li, (unsigned int *)regs->nip);
264
		err |= get_user(b, (unsigned int *)(regs->nip+4));
265
266
		if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) {
267
			unsigned int addis, lwz, mtctr, bctr;
268
			unsigned long addr = b | 0xFC000000UL;
269
270
			addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL);
271
			err = get_user(addis, (unsigned int*)addr);
272
			err |= get_user(lwz, (unsigned int*)(addr+4));
273
			err |= get_user(mtctr, (unsigned int*)(addr+8));
274
			err |= get_user(bctr, (unsigned int*)(addr+12));
275
276
			if (err)
277
				break;
278
279
			if ((addis & 0xFFFF0000U) == 0x3D6B0000U &&
280
			    (lwz & 0xFFFF0000U) == 0x816B0000U &&
281
			    mtctr == 0x7D6903A6U &&
282
			    bctr == 0x4E800420U)
283
			{
284
				unsigned int r11;
285
286
				addr = (addis << 16) + (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
287
				addr += (((lwz | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
288
289
				err = get_user(r11, (unsigned int*)addr);
290
				if (err)
291
					break;
292
293
				regs->gpr[PT_R11] = r11;
294
				regs->ctr = r11;
295
				regs->nip = r11;
296
				return 4;
297
			}
298
		}
299
	} while (0);
300
#endif
301
302
#ifdef CONFIG_GRKERNSEC_PAX_EMUSIGRT
303
	do { /* PaX: sigreturn emulation */
304
		unsigned int li, sc;
305
306
		err = get_user(li, (unsigned int *)regs->nip);
307
		err |= get_user(sc, (unsigned int *)(regs->nip+4));
308
309
		if (!err && li == 0x38007777U && sc == 0x44000002U) {
310
			struct vm_area_struct *vma;
311
			unsigned long call_syscall;
312
313
			down_read(&current->mm->mmap_sem);
314
			call_syscall = current->mm->call_syscall;
315
			up_read(&current->mm->mmap_sem);
316
			if (likely(call_syscall))
317
				goto emulate;
318
319
			vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
320
321
			down_write(&current->mm->mmap_sem);
322
			if (current->mm->call_syscall) {
323
				call_syscall = current->mm->call_syscall;
324
				up_write(&current->mm->mmap_sem);
325
				if (vma) kmem_cache_free(vm_area_cachep, vma);
326
				goto emulate;
327
			}
328
329
			call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
330
			if (!vma || (call_syscall & ~PAGE_MASK)) {
331
				up_write(&current->mm->mmap_sem);
332
				if (vma) kmem_cache_free(vm_area_cachep, vma);
333
				return 1;
334
			}
335
336
			pax_insert_vma(vma, call_syscall);
337
			current->mm->call_syscall = call_syscall;
338
			up_write(&current->mm->mmap_sem);
339
340
emulate:
341
			regs->gpr[PT_R0] = 0x7777UL;
342
			regs->nip = call_syscall;
343
			return 6;
344
		}
345
	} while (0);
346
347
	do { /* PaX: rt_sigreturn emulation */
348
		unsigned int li, sc;
349
350
		err = get_user(li, (unsigned int *)regs->nip);
351
		err |= get_user(sc, (unsigned int *)(regs->nip+4));
352
353
		if (!err && li == 0x38006666U && sc == 0x44000002U) {
354
			struct vm_area_struct *vma;
355
			unsigned int call_syscall;
356
357
			down_read(&current->mm->mmap_sem);
358
			call_syscall = current->mm->call_syscall;
359
			up_read(&current->mm->mmap_sem);
360
			if (likely(call_syscall))
361
				goto rt_emulate;
362
363
			vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
364
365
			down_write(&current->mm->mmap_sem);
366
			if (current->mm->call_syscall) {
367
				call_syscall = current->mm->call_syscall;
368
				up_write(&current->mm->mmap_sem);
369
				if (vma) kmem_cache_free(vm_area_cachep, vma);
370
				goto rt_emulate;
371
			}
372
373
			call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
374
			if (!vma || (call_syscall & ~PAGE_MASK)) {
375
				up_write(&current->mm->mmap_sem);
376
				if (vma) kmem_cache_free(vm_area_cachep, vma);
377
				return 1;
378
			}
379
380
			pax_insert_vma(vma, call_syscall);
381
			current->mm->call_syscall = call_syscall;
382
			up_write(&current->mm->mmap_sem);
383
384
rt_emulate:
385
			regs->gpr[PT_R0] = 0x6666UL;
386
			regs->nip = call_syscall;
387
			return 7;
388
		}
389
	} while (0);
390
#endif
391
392
        return 1;
393
}
394
395
void pax_report_insns(void *pc)
396
{
397
	unsigned long i;
398
399
	printk(KERN_ERR "PAX: bytes at PC: ");
400
	for (i = 0; i < 5; i++) {
401
		unsigned int c;
402
		if (get_user(c, (unsigned int*)pc+i)) {
403
			printk("<invalid address>.");
404
			break;
405
		}
406
		printk("%08x ", c);
407
	}
408
	printk("\n");
409
}
410
#endif
411
55
/*
412
/*
56
 * Check whether the instruction at regs->nip is a store using
413
 * Check whether the instruction at regs->nip is a store using
57
 * an update addressing form which will update r1.
414
 * an update addressing form which will update r1.
Lines 112-118 Link Here
112
	 * indicate errors in DSISR but can validly be set in SRR1.
469
	 * indicate errors in DSISR but can validly be set in SRR1.
113
	 */
470
	 */
114
	if (regs->trap == 0x400)
471
	if (regs->trap == 0x400)
115
		error_code &= 0x48200000;
472
		error_code &= 0x58200000;
116
	else
473
	else
117
		is_write = error_code & 0x02000000;
474
		is_write = error_code & 0x02000000;
118
#endif /* CONFIG_4xx */
475
#endif /* CONFIG_4xx */
Lines 246-251 Link Here
246
603
247
	/* User mode accesses cause a SIGSEGV */
604
	/* User mode accesses cause a SIGSEGV */
248
	if (user_mode(regs)) {
605
	if (user_mode(regs)) {
606
607
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
608
		if (current->flags & PF_PAX_PAGEEXEC) {
609
			if ((regs->trap == 0x400) && (regs->nip == address)) {
610
				switch (pax_handle_fetch_fault(regs)) {
611
612
#ifdef CONFIG_GRKERNSEC_PAX_EMUPLT
613
				case 2:
614
				case 3:
615
				case 4:
616
					return;
617
#endif
618
619
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
620
				case 5:
621
					return;
622
#endif
623
624
#ifdef CONFIG_GRKERNSEC_PAX_EMUSIGRT
625
				case 6:
626
				case 7:
627
					return;
628
#endif
629
630
				}
631
632
				pax_report_fault(regs, (void*)regs->nip, (void*)regs->gpr[1]);
633
				do_exit(SIGKILL);
634
			}
635
		}
636
#endif
637
249
		info.si_signo = SIGSEGV;
638
		info.si_signo = SIGSEGV;
250
		info.si_errno = 0;
639
		info.si_errno = 0;
251
		info.si_code = code;
640
		info.si_code = code;
(-)linux-2.4.22-ppc-dev.orig/arch/ppc64/kernel/ioctl32.c (+4 lines)
Lines 1800-1806 Link Here
1800
	 * To have permissions to do most of the vt ioctls, we either have
1800
	 * To have permissions to do most of the vt ioctls, we either have
1801
	 * to be the owner of the tty, or super-user.
1801
	 * to be the owner of the tty, or super-user.
1802
	 */
1802
	 */
1803
#ifdef CONFIG_GRKERNSEC
1804
	if (current->tty == tty || capable(CAP_SYS_TTY_CONFIG))
1805
#else
1803
	if (current->tty == tty || suser())
1806
	if (current->tty == tty || suser())
1807
#endif
1804
		return 1;
1808
		return 1;
1805
	return 0;                                                    
1809
	return 0;                                                    
1806
}
1810
}
(-)linux-2.4.22-ppc-dev.orig/arch/s390/config.in (+8 lines)
Lines 81-83 Link Here
81
81
82
source crypto/Config.in
82
source crypto/Config.in
83
source lib/Config.in
83
source lib/Config.in
84
85
mainmenu_option next_comment
86
comment 'Grsecurity'
87
bool 'Grsecurity' CONFIG_GRKERNSEC
88
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
89
	source grsecurity/Config.in
90
fi
91
endmenu
(-)linux-2.4.22-ppc-dev.orig/arch/s390x/config.in (+8 lines)
Lines 85-87 Link Here
85
85
86
source crypto/Config.in
86
source crypto/Config.in
87
source lib/Config.in
87
source lib/Config.in
88
89
mainmenu_option next_comment
90
comment 'Grsecurity'
91
bool 'Grsecurity' CONFIG_GRKERNSEC
92
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
93
	source grsecurity/Config.in
94
fi
95
endmenu
(-)linux-2.4.22-ppc-dev.orig/arch/sh/config.in (+8 lines)
Lines 469-471 Link Here
469
469
470
source crypto/Config.in
470
source crypto/Config.in
471
source lib/Config.in
471
source lib/Config.in
472
473
mainmenu_option next_comment
474
comment 'Grsecurity'
475
bool 'Grsecurity' CONFIG_GRKERNSEC
476
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
477
	source grsecurity/Config.in
478
fi
479
endmenu
(-)linux-2.4.22-ppc-dev.orig/arch/sparc/boot/Makefile (-1 / +1 lines)
Lines 24-30 Link Here
24
24
25
BTOBJS := $(HEAD) init/main.o init/version.o init/do_mounts.o
25
BTOBJS := $(HEAD) init/main.o init/version.o init/do_mounts.o
26
BTLIBS := $(CORE_FILES_NO_BTFIX) $(FILESYSTEMS) \
26
BTLIBS := $(CORE_FILES_NO_BTFIX) $(FILESYSTEMS) \
27
	$(DRIVERS) $(NETWORKS)
27
	$(DRIVERS) $(NETWORKS) $(GRSECURITY)
28
28
29
# I wanted to make this depend upon BTOBJS so that a parallel
29
# I wanted to make this depend upon BTOBJS so that a parallel
30
# build would work, but this fails because $(HEAD) cannot work
30
# build would work, but this fails because $(HEAD) cannot work
(-)linux-2.4.22-ppc-dev.orig/arch/sparc/config.in (+8 lines)
Lines 277-279 Link Here
277
277
278
source crypto/Config.in
278
source crypto/Config.in
279
source lib/Config.in
279
source lib/Config.in
280
281
mainmenu_option next_comment
282
comment 'Grsecurity'
283
bool 'Grsecurity' CONFIG_GRKERNSEC
284
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
285
	source grsecurity/Config.in
286
fi
287
endmenu
(-)linux-2.4.22-ppc-dev.orig/arch/sparc/kernel/ptrace.c (+4 lines)
Lines 17-22 Link Here
17
#include <linux/user.h>
17
#include <linux/user.h>
18
#include <linux/smp.h>
18
#include <linux/smp.h>
19
#include <linux/smp_lock.h>
19
#include <linux/smp_lock.h>
20
#include <linux/grsecurity.h>
20
21
21
#include <asm/pgtable.h>
22
#include <asm/pgtable.h>
22
#include <asm/system.h>
23
#include <asm/system.h>
Lines 310-315 Link Here
310
		goto out;
311
		goto out;
311
	}
312
	}
312
313
314
	if(gr_handle_ptrace(child, request))
315
		goto out_tsk;
316
313
	if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
317
	if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
314
	    || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
318
	    || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
315
		if (ptrace_attach(child)) {
319
		if (ptrace_attach(child)) {
(-)linux-2.4.22-ppc-dev.orig/arch/sparc/kernel/sys_sparc.c (+19 lines)
Lines 20-25 Link Here
20
#include <linux/utsname.h>
20
#include <linux/utsname.h>
21
#include <linux/smp.h>
21
#include <linux/smp.h>
22
#include <linux/smp_lock.h>
22
#include <linux/smp_lock.h>
23
#include <linux/grsecurity.h>
23
24
24
#include <asm/uaccess.h>
25
#include <asm/uaccess.h>
25
#include <asm/ipc.h>
26
#include <asm/ipc.h>
Lines 54-59 Link Here
54
		return -ENOMEM;
55
		return -ENOMEM;
55
	if (ARCH_SUN4C_SUN4 && len > 0x20000000)
56
	if (ARCH_SUN4C_SUN4 && len > 0x20000000)
56
		return -ENOMEM;
57
		return -ENOMEM;
58
59
#ifdef CONFIG_GRKERNSEC_PAX_RANDMMAP
60
	if ((current->flags & PF_PAX_RANDMMAP) && (!addr || filp))
61
		addr = TASK_UNMAPPED_BASE + current->mm->delta_mmap;
62
	else
63
#endif
64
57
	if (!addr)
65
	if (!addr)
58
		addr = TASK_UNMAPPED_BASE;
66
		addr = TASK_UNMAPPED_BASE;
59
67
Lines 225-230 Link Here
225
	struct file * file = NULL;
233
	struct file * file = NULL;
226
	unsigned long retval = -EBADF;
234
	unsigned long retval = -EBADF;
227
235
236
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
237
	if (flags & MAP_MIRROR)
238
		return -EINVAL;
239
#endif
240
228
	if (!(flags & MAP_ANONYMOUS)) {
241
	if (!(flags & MAP_ANONYMOUS)) {
229
		file = fget(fd);
242
		file = fget(fd);
230
		if (!file)
243
		if (!file)
Lines 243-248 Link Here
243
	if (len > TASK_SIZE - PAGE_SIZE || addr + len > TASK_SIZE - PAGE_SIZE)
256
	if (len > TASK_SIZE - PAGE_SIZE || addr + len > TASK_SIZE - PAGE_SIZE)
244
		goto out_putf;
257
		goto out_putf;
245
258
259
	if (gr_handle_mmap(file, prot)) {
260
		fput(file);
261
		retval = -EACCES;
262
		goto out;
263
	}
264
246
	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
265
	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
247
266
248
	down_write(&current->mm->mmap_sem);
267
	down_write(&current->mm->mmap_sem);
(-)linux-2.4.22-ppc-dev.orig/arch/sparc/kernel/sys_sunos.c (+5 lines)
Lines 68-73 Link Here
68
	struct file * file = NULL;
68
	struct file * file = NULL;
69
	unsigned long retval, ret_type;
69
	unsigned long retval, ret_type;
70
70
71
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
72
	if (flags & MAP_MIRROR)
73
		return -EINVAL;
74
#endif
75
71
	if(flags & MAP_NORESERVE) {
76
	if(flags & MAP_NORESERVE) {
72
		static int cnt;
77
		static int cnt;
73
		if (cnt++ < 10)
78
		if (cnt++ < 10)
(-)linux-2.4.22-ppc-dev.orig/arch/sparc/mm/fault.c (+281 lines)
Lines 19-24 Link Here
19
#include <linux/smp.h>
19
#include <linux/smp.h>
20
#include <linux/smp_lock.h>
20
#include <linux/smp_lock.h>
21
#include <linux/interrupt.h>
21
#include <linux/interrupt.h>
22
#include <linux/slab.h>
23
#include <linux/pagemap.h>
24
#include <linux/compiler.h>
22
25
23
#include <asm/system.h>
26
#include <asm/system.h>
24
#include <asm/segment.h>
27
#include <asm/segment.h>
Lines 200-205 Link Here
200
	return 0;
203
	return 0;
201
}
204
}
202
205
206
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
207
void pax_emuplt_close(struct vm_area_struct * vma)
208
{
209
	vma->vm_mm->call_dl_resolve = 0UL;
210
}
211
212
static struct page* pax_emuplt_nopage(struct vm_area_struct *vma, unsigned long address, int write_access)
213
{
214
	struct page* page;
215
	unsigned int *kaddr;
216
217
	page = alloc_page(GFP_HIGHUSER);
218
	if (!page)
219
		return page;
220
221
	kaddr = kmap(page);
222
	memset(kaddr, 0, PAGE_SIZE);
223
	kaddr[0] = 0x9DE3BFA8U; /* save */
224
	flush_dcache_page(page);
225
	kunmap(page);
226
	return page;
227
}
228
229
static struct vm_operations_struct pax_vm_ops = {
230
	close:		pax_emuplt_close,
231
	nopage:		pax_emuplt_nopage,
232
};
233
234
static void pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
235
{
236
	vma->vm_mm = current->mm;
237
	vma->vm_start = addr;
238
	vma->vm_end = addr + PAGE_SIZE;
239
	vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
240
	vma->vm_page_prot = protection_map[vma->vm_flags & 0x0f];
241
	vma->vm_ops = &pax_vm_ops;
242
	vma->vm_pgoff = 0UL;
243
	vma->vm_file = NULL;
244
	vma->vm_private_data = NULL;
245
	insert_vm_struct(current->mm, vma);
246
	++current->mm->total_vm;
247
}
248
249
/*
250
 * PaX: decide what to do with offenders (regs->pc = fault address)
251
 *
252
 * returns 1 when task should be killed
253
 *         2 when patched PLT trampoline was detected
254
 *         3 when unpatched PLT trampoline was detected
255
 *	   4 when legitimate ET_EXEC was detected
256
 */
257
static int pax_handle_fetch_fault(struct pt_regs *regs)
258
{
259
	int err;
260
261
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
262
	if (current->flags & PF_PAX_RANDEXEC) {
263
		if (regs->pc >= current->mm->start_code &&
264
		    regs->pc < current->mm->end_code)
265
		{
266
			if (regs->u_regs[UREG_RETPC] + 8UL == regs->pc)
267
				return 1;
268
269
			regs->pc += current->mm->delta_exec;
270
			if (regs->npc >= current->mm->start_code &&
271
			    regs->npc < current->mm->end_code)
272
				regs->npc += current->mm->delta_exec;
273
			return 4;
274
		}
275
		if (regs->pc >= current->mm->start_code + current->mm->delta_exec &&
276
		    regs->pc < current->mm->end_code + current->mm->delta_exec)
277
		{
278
			regs->pc -= current->mm->delta_exec;
279
			if (regs->npc >= current->mm->start_code + current->mm->delta_exec &&
280
			    regs->npc < current->mm->end_code + current->mm->delta_exec)
281
				regs->npc -= current->mm->delta_exec;
282
		}
283
	}
284
#endif
285
286
#ifdef CONFIG_GRKERNSEC_PAX_EMUPLT
287
	do { /* PaX: patched PLT emulation #1 */
288
		unsigned int sethi1, sethi2, jmpl;
289
290
		err = get_user(sethi1, (unsigned int *)regs->pc);
291
		err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
292
		err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
293
294
		if (err)
295
			break;
296
297
		if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
298
		    (sethi2 & 0xFFC00000U) == 0x03000000U &&
299
		    (jmpl & 0xFFFFE000U) == 0x81C06000U)
300
		{
301
			unsigned int addr;
302
303
			regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
304
			addr = regs->u_regs[UREG_G1];
305
			addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
306
			regs->pc = addr;
307
			regs->npc = addr+4;
308
			return 2;
309
		}
310
	} while (0);
311
312
	{ /* PaX: patched PLT emulation #2 */
313
		unsigned int ba;
314
315
		err = get_user(ba, (unsigned int *)regs->pc);
316
317
		if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
318
			unsigned int addr;
319
320
			addr = regs->pc + 4 + (((ba | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
321
			regs->pc = addr;
322
			regs->npc = addr+4;
323
			return 2;
324
		}
325
	}
326
327
	do { /* PaX: patched PLT emulation #3 */
328
		unsigned int sethi, jmpl, nop;
329
330
		err = get_user(sethi, (unsigned int*)regs->pc);
331
		err |= get_user(jmpl, (unsigned int*)(regs->pc+4));
332
		err |= get_user(nop, (unsigned int*)(regs->pc+8));
333
334
		if (err)
335
			break;
336
		if ((sethi & 0xFFC00000U) == 0x03000000U &&
337
		    (jmpl & 0xFFFFE000U) == 0x81C06000U &&
338
		    nop == 0x01000000U)
339
		{
340
			unsigned int addr;
341
342
			addr = (sethi & 0x003FFFFFU) << 10;
343
			regs->u_regs[UREG_G1] = addr;
344
			addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
345
			regs->pc = addr;
346
			regs->npc = addr+4;
347
			return 2;
348
		}
349
	} while (0);
350
351
	do { /* PaX: unpatched PLT emulation step 1 */
352
		unsigned int sethi, ba, nop;
353
354
		err = get_user(sethi, (unsigned int *)regs->pc);
355
		err |= get_user(ba, (unsigned int *)(regs->pc+4));
356
		err |= get_user(nop, (unsigned int *)(regs->pc+8));
357
358
		if (err)
359
			break;
360
		if ((sethi & 0xFFC00000U) == 0x03000000U &&
361
		    (ba & 0xFFC00000U) == 0x30800000U &&
362
		    nop == 0x01000000U)
363
		{
364
			unsigned int addr, save, call;
365
366
			addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
367
368
			err = get_user(save, (unsigned int *)addr);
369
			err |= get_user(call, (unsigned int *)(addr+4));
370
			err |= get_user(nop, (unsigned int *)(addr+8)); 
371
			if (err)
372
				break;
373
374
			if (save == 0x9DE3BFA8U &&
375
			    (call & 0xC0000000U) == 0x40000000U &&
376
			    nop == 0x01000000U)
377
			{
378
				struct vm_area_struct *vma;
379
				unsigned long call_dl_resolve;
380
381
				down_read(&current->mm->mmap_sem);
382
				call_dl_resolve = current->mm->call_dl_resolve;
383
				up_read(&current->mm->mmap_sem);
384
				if (likely(call_dl_resolve))
385
					goto emulate;
386
387
				vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
388
389
				down_write(&current->mm->mmap_sem);
390
				if (current->mm->call_dl_resolve) {
391
					call_dl_resolve = current->mm->call_dl_resolve;
392
					up_write(&current->mm->mmap_sem);
393
					if (vma) kmem_cache_free(vm_area_cachep, vma);
394
					goto emulate;
395
				}
396
397
				call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
398
				if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
399
					up_write(&current->mm->mmap_sem);
400
					if (vma) kmem_cache_free(vm_area_cachep, vma);
401
					return 1;
402
				}
403
404
				pax_insert_vma(vma, call_dl_resolve);
405
				current->mm->call_dl_resolve = call_dl_resolve;
406
				up_write(&current->mm->mmap_sem);
407
408
emulate:
409
				regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
410
				regs->pc = call_dl_resolve;
411
				regs->npc = addr+4;
412
				return 3;
413
			}
414
		}
415
	} while (0);
416
417
	do { /* PaX: unpatched PLT emulation step 2 */
418
		unsigned int save, call, nop;
419
420
		err = get_user(save, (unsigned int*)(regs->pc-4));
421
		err |= get_user(call, (unsigned int*)regs->pc);
422
		err |= get_user(nop, (unsigned int*)(regs->pc+4));
423
		if (err)
424
			break;
425
426
		if (save == 0x9DE3BFA8U &&
427
		    (call & 0xC0000000U) == 0x40000000U &&
428
		    nop == 0x01000000U)
429
		{
430
			unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
431
432
			regs->u_regs[UREG_RETPC] = regs->pc;
433
			regs->pc = dl_resolve;
434
			regs->npc = dl_resolve+4;
435
			return 3;
436
		}
437
	} while (0);
438
439
#endif
440
441
	return 1;
442
}
443
444
void pax_report_insns(void *pc)
445
{
446
	unsigned long i;
447
448
	printk(KERN_ERR "PAX: bytes at PC: ");
449
	for (i = 0; i < 5; i++) {
450
		unsigned int c;
451
		if (get_user(c, (unsigned int*)pc+i)) {
452
			printk("<invalid address>.");
453
			break;
454
		}
455
		printk("%08x ", c);
456
	}
457
	printk("\n");
458
}
459
#endif
460
203
asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
461
asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
204
			       unsigned long address)
462
			       unsigned long address)
205
{
463
{
Lines 263-268 Link Here
263
		if(!(vma->vm_flags & VM_WRITE))
521
		if(!(vma->vm_flags & VM_WRITE))
264
			goto bad_area;
522
			goto bad_area;
265
	} else {
523
	} else {
524
525
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
526
		if ((current->flags & PF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
527
			up_read(&mm->mmap_sem);
528
			switch (pax_handle_fetch_fault(regs)) {
529
530
#ifdef CONFIG_GRKERNSEC_PAX_EMUPLT
531
			case 2:
532
			case 3:
533
				return;
534
#endif
535
536
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
537
			case 4:
538
				return;
539
#endif
540
541
			}
542
			pax_report_fault(regs, (void*)regs->pc, (void*)regs->u_regs[UREG_FP]);
543
			do_exit(SIGKILL);
544
		}
545
#endif
546
266
		/* Allow reads even for write-only mappings */
547
		/* Allow reads even for write-only mappings */
267
		if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
548
		if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
268
			goto bad_area;
549
			goto bad_area;
(-)linux-2.4.22-ppc-dev.orig/arch/sparc/mm/init.c (-6 / +6 lines)
Lines 350-366 Link Here
350
350
351
	/* Initialize the protection map with non-constant, MMU dependent values. */
351
	/* Initialize the protection map with non-constant, MMU dependent values. */
352
	protection_map[0] = PAGE_NONE;
352
	protection_map[0] = PAGE_NONE;
353
	protection_map[1] = PAGE_READONLY;
353
	protection_map[1] = PAGE_READONLY_NOEXEC;
354
	protection_map[2] = PAGE_COPY;
354
	protection_map[2] = PAGE_COPY_NOEXEC;
355
	protection_map[3] = PAGE_COPY;
355
	protection_map[3] = PAGE_COPY_NOEXEC;
356
	protection_map[4] = PAGE_READONLY;
356
	protection_map[4] = PAGE_READONLY;
357
	protection_map[5] = PAGE_READONLY;
357
	protection_map[5] = PAGE_READONLY;
358
	protection_map[6] = PAGE_COPY;
358
	protection_map[6] = PAGE_COPY;
359
	protection_map[7] = PAGE_COPY;
359
	protection_map[7] = PAGE_COPY;
360
	protection_map[8] = PAGE_NONE;
360
	protection_map[8] = PAGE_NONE;
361
	protection_map[9] = PAGE_READONLY;
361
	protection_map[9] = PAGE_READONLY_NOEXEC;
362
	protection_map[10] = PAGE_SHARED;
362
	protection_map[10] = PAGE_SHARED_NOEXEC;
363
	protection_map[11] = PAGE_SHARED;
363
	protection_map[11] = PAGE_SHARED_NOEXEC;
364
	protection_map[12] = PAGE_READONLY;
364
	protection_map[12] = PAGE_READONLY;
365
	protection_map[13] = PAGE_READONLY;
365
	protection_map[13] = PAGE_READONLY;
366
	protection_map[14] = PAGE_SHARED;
366
	protection_map[14] = PAGE_SHARED;
(-)linux-2.4.22-ppc-dev.orig/arch/sparc/mm/srmmu.c (+7 lines)
Lines 2042-2047 Link Here
2042
	BTFIXUPSET_INT(page_shared, pgprot_val(SRMMU_PAGE_SHARED));
2042
	BTFIXUPSET_INT(page_shared, pgprot_val(SRMMU_PAGE_SHARED));
2043
	BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
2043
	BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
2044
	BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
2044
	BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
2045
2046
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
2047
	BTFIXUPSET_INT(page_shared_noexec, pgprot_val(SRMMU_PAGE_SHARED_NOEXEC));
2048
	BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
2049
	BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
2050
#endif
2051
2045
	BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
2052
	BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
2046
	page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
2053
	page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
2047
	pg_iobits = SRMMU_VALID | SRMMU_WRITE | SRMMU_REF;
2054
	pg_iobits = SRMMU_VALID | SRMMU_WRITE | SRMMU_REF;
(-)linux-2.4.22-ppc-dev.orig/arch/sparc64/config.in (+8 lines)
Lines 311-313 Link Here
311
311
312
source crypto/Config.in
312
source crypto/Config.in
313
source lib/Config.in
313
source lib/Config.in
314
315
mainmenu_option next_comment
316
comment 'Grsecurity'
317
bool 'Grsecurity' CONFIG_GRKERNSEC
318
if [ "$CONFIG_GRKERNSEC" = "y" ]; then
319
	source grsecurity/Config.in
320
fi
321
endmenu
(-)linux-2.4.22-ppc-dev.orig/arch/sparc64/kernel/ioctl32.c (+4 lines)
Lines 2046-2052 Link Here
2046
	 * To have permissions to do most of the vt ioctls, we either have
2046
	 * To have permissions to do most of the vt ioctls, we either have
2047
	 * to be the owner of the tty, or super-user.
2047
	 * to be the owner of the tty, or super-user.
2048
	 */
2048
	 */
2049
#ifdef CONFIG_GRKERNSEC
2050
	if (current->tty == tty || capable(CAP_SYS_TTY_CONFIG))
2051
#else
2049
	if (current->tty == tty || suser())
2052
	if (current->tty == tty || suser())
2053
#endif
2050
		return 1;
2054
		return 1;
2051
	return 0;                                                    
2055
	return 0;                                                    
2052
}
2056
}
(-)linux-2.4.22-ppc-dev.orig/arch/sparc64/kernel/itlb_base.S (-3 / +3 lines)
Lines 41-47 Link Here
41
	CREATE_VPTE_OFFSET2(%g4, %g6)			! Create VPTE offset
41
	CREATE_VPTE_OFFSET2(%g4, %g6)			! Create VPTE offset
42
	ldxa		[%g3 + %g6] ASI_P, %g5		! Load VPTE
42
	ldxa		[%g3 + %g6] ASI_P, %g5		! Load VPTE
43
1:	brgez,pn	%g5, 3f				! Not valid, branch out
43
1:	brgez,pn	%g5, 3f				! Not valid, branch out
44
	 nop						! Delay-slot
44
	and		%g5, _PAGE_EXEC, %g4
45
	brz,pn		%g4, 3f				! Not executable, branch out
46
	nop						! Delay-slot
45
2:	stxa		%g5, [%g0] ASI_ITLB_DATA_IN	! Load PTE into TLB
47
2:	stxa		%g5, [%g0] ASI_ITLB_DATA_IN	! Load PTE into TLB
46
	retry						! Trap return
48
	retry						! Trap return
47
3:	rdpr		%pstate, %g4			! Move into alternate globals
49
3:	rdpr		%pstate, %g4			! Move into alternate globals
Lines 74-81 Link Here
74
	nop
76
	nop
75
	nop
77
	nop
76
	nop
78
	nop
77
	nop
78
	nop
79
	CREATE_VPTE_NOP
79
	CREATE_VPTE_NOP
80
80
81
#undef CREATE_VPTE_OFFSET1
81
#undef CREATE_VPTE_OFFSET1
(-)linux-2.4.22-ppc-dev.orig/arch/sparc64/kernel/ptrace.c (+6 lines)
Lines 18-23 Link Here
18
#include <linux/user.h>
18
#include <linux/user.h>
19
#include <linux/smp.h>
19
#include <linux/smp.h>
20
#include <linux/smp_lock.h>
20
#include <linux/smp_lock.h>
21
#include <linux/grsecurity.h>
21
22
22
#include <asm/asi.h>
23
#include <asm/asi.h>
23
#include <asm/pgtable.h>
24
#include <asm/pgtable.h>
Lines 161-166 Link Here
161
		goto out;
162
		goto out;
162
	}
163
	}
163
164
165
	if (gr_handle_ptrace(child, (long)request)) {
166
		pt_error_return(regs, EPERM);
167
		goto out;
168
	}
169
164
	if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
170
	if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
165
	    || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
171
	    || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
166
		if (ptrace_attach(child)) {
172
		if (ptrace_attach(child)) {
(-)linux-2.4.22-ppc-dev.orig/arch/sparc64/kernel/sys_sparc.c (+19 lines)
Lines 24-29 Link Here
24
#include <linux/slab.h>
24
#include <linux/slab.h>
25
#include <linux/ipc.h>
25
#include <linux/ipc.h>
26
#include <linux/personality.h>
26
#include <linux/personality.h>
27
#include <linux/grsecurity.h>
27
28
28
#include <asm/uaccess.h>
29
#include <asm/uaccess.h>
29
#include <asm/ipc.h>
30
#include <asm/ipc.h>
Lines 63-68 Link Here
63
		task_size = 0xf0000000UL;
64
		task_size = 0xf0000000UL;
64
	if (len > task_size || len > -PAGE_OFFSET)
65
	if (len > task_size || len > -PAGE_OFFSET)
65
		return -ENOMEM;
66
		return -ENOMEM;
67
68
#ifdef CONFIG_GRKERNSEC_PAX_RANDMMAP
69
	if ((current->flags & PF_PAX_RANDMMAP) && (!addr || filp))
70
		addr = TASK_UNMAPPED_BASE + current->mm->delta_mmap;
71
	else
72
#endif
73
66
	if (!addr)
74
	if (!addr)
67
		addr = TASK_UNMAPPED_BASE;
75
		addr = TASK_UNMAPPED_BASE;
68
76
Lines 289-299 Link Here
289
	struct file * file = NULL;
297
	struct file * file = NULL;
290
	unsigned long retval = -EBADF;
298
	unsigned long retval = -EBADF;
291
299
300
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
301
	if (flags & MAP_MIRROR)
302
		return -EINVAL;
303
#endif
304
292
	if (!(flags & MAP_ANONYMOUS)) {
305
	if (!(flags & MAP_ANONYMOUS)) {
293
		file = fget(fd);
306
		file = fget(fd);
294
		if (!file)
307
		if (!file)
295
			goto out;
308
			goto out;
296
	}
309
	}
310
311
	if (gr_handle_mmap(file, prot)) {
312
		retval = -EACCES;
313
		goto out_putf;
314
	}
315
297
	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
316
	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
298
	len = PAGE_ALIGN(len);
317
	len = PAGE_ALIGN(len);
299
	retval = -EINVAL;
318
	retval = -EINVAL;
(-)linux-2.4.22-ppc-dev.orig/arch/sparc64/kernel/sys_sparc32.c (-1 / +61 lines)
Lines 52-57 Link Here
52
#include <linux/sysctl.h>
52
#include <linux/sysctl.h>
53
#include <linux/dnotify.h>
53
#include <linux/dnotify.h>
54
#include <linux/netfilter_ipv4/ip_tables.h>
54
#include <linux/netfilter_ipv4/ip_tables.h>
55
#include <linux/random.h>
56
#include <linux/grsecurity.h>
55
57
56
#include <asm/types.h>
58
#include <asm/types.h>
57
#include <asm/ipc.h>
59
#include <asm/ipc.h>
Lines 3233-3240 Link Here
3233
	struct file * file;
3235
	struct file * file;
3234
	int retval;
3236
	int retval;
3235
	int i;
3237
	int i;
3238
#ifdef CONFIG_GRKERNSEC
3239
	struct file *old_exec_file;
3240
	struct acl_subject_label *old_acl;
3241
	struct rlimit old_rlim[RLIM_NLIMITS];
3242
#endif
3236
3243
3237
	bprm.p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
3244
	bprm.p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
3245
3246
#ifdef CONFIG_GRKERNSEC_PAX_RANDUSTACK
3247
	bprm.p -= (get_random_long() & ~(sizeof(void *)-1)) & ~PAGE_MASK;
3248
#endif
3249
3238
	memset(bprm.page, 0, MAX_ARG_PAGES * sizeof(bprm.page[0]));
3250
	memset(bprm.page, 0, MAX_ARG_PAGES * sizeof(bprm.page[0]));
3239
3251
3240
	file = open_exec(filename);
3252
	file = open_exec(filename);
Lines 3243-3248 Link Here
3243
	if (IS_ERR(file))
3255
	if (IS_ERR(file))
3244
		return retval;
3256
		return retval;
3245
3257
3258
	gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->user->processes));
3259
3260
	if (gr_handle_nproc()) {
3261
		allow_write_access(file);
3262
		fput(file);
3263
		return -EAGAIN;
3264
	}
3265
3266
	if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
3267
		allow_write_access(file);
3268
		fput(file);
3269
		return -EACCES;
3270
	}
3271
3246
	bprm.file = file;
3272
	bprm.file = file;
3247
	bprm.filename = filename;
3273
	bprm.filename = filename;
3248
	bprm.sh_bang = 0;
3274
	bprm.sh_bang = 0;
Lines 3263-3273 Link Here
3263
	if (retval < 0)
3289
	if (retval < 0)
3264
		goto out;
3290
		goto out;
3265
	
3291
	
3292
	if(!gr_tpe_allow(file)) {
3293
		retval = -EACCES;
3294
		goto out;
3295
	}
3296
3297
	if (gr_check_crash_exec(file)) {
3298
		retval = -EACCES;
3299
		goto out;
3300
	}
3301
3266
	retval = copy_strings_kernel(1, &bprm.filename, &bprm);
3302
	retval = copy_strings_kernel(1, &bprm.filename, &bprm);
3267
	if (retval < 0)
3303
	if (retval < 0)
3268
		goto out;
3304
		goto out;
3269
3305
3270
	bprm.exec = bprm.p;
3306
	bprm.exec = bprm.p;
3307
3308
	gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
3309
3271
	retval = copy_strings32(bprm.envc, envp, &bprm);
3310
	retval = copy_strings32(bprm.envc, envp, &bprm);
3272
	if (retval < 0)
3311
	if (retval < 0)
3273
		goto out;
3312
		goto out;
Lines 3276-3286 Link Here
3276
	if (retval < 0)
3315
	if (retval < 0)
3277
		goto out;
3316
		goto out;
3278
3317
3318
#ifdef CONFIG_GRKERNSEC
3319
	old_acl = current->acl;
3320
	memcpy(old_rlim, current->rlim, sizeof(old_rlim));
3321
	old_exec_file = current->exec_file;
3322
	get_file(file);
3323
	current->exec_file = file;
3324
#endif
3325
3326
        gr_set_proc_label(file->f_dentry, file->f_vfsmnt);
3327
3279
	retval = search_binary_handler(&bprm, regs);
3328
	retval = search_binary_handler(&bprm, regs);
3280
	if (retval >= 0)
3329
	if (retval >= 0) {
3330
#ifdef CONFIG_GRKERNSEC
3331
		if (old_exec_file)
3332
			fput(old_exec_file);
3333
#endif
3281
		/* execve success */
3334
		/* execve success */
3282
		return retval;
3335
		return retval;
3336
	}
3283
3337
3338
#ifdef CONFIG_GRKERNSEC
3339
	current->acl = old_acl;
3340
	memcpy(current->rlim, old_rlim, sizeof(old_rlim));
3341
	fput(current->exec_file);
3342
	current->exec_file = old_exec_file;
3343
#endif
3284
out:
3344
out:
3285
	/* Something went wrong, return the inode and free the argument pages*/
3345
	/* Something went wrong, return the inode and free the argument pages*/
3286
	allow_write_access(bprm.file);
3346
	allow_write_access(bprm.file);
(-)linux-2.4.22-ppc-dev.orig/arch/sparc64/kernel/sys_sunos32.c (+5 lines)
Lines 68-73 Link Here
68
	struct file *file = NULL;
68
	struct file *file = NULL;
69
	unsigned long retval, ret_type;
69
	unsigned long retval, ret_type;
70
70
71
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
72
	if (flags & MAP_MIRROR)
73
		return -EINVAL;
74
#endif
75
71
	if(flags & MAP_NORESERVE) {
76
	if(flags & MAP_NORESERVE) {
72
		static int cnt;
77
		static int cnt;
73
		if (cnt++ < 10)
78
		if (cnt++ < 10)
(-)linux-2.4.22-ppc-dev.orig/arch/sparc64/mm/fault.c (+293 lines)
Lines 16-21 Link Here
16
#include <linux/smp_lock.h>
16
#include <linux/smp_lock.h>
17
#include <linux/init.h>
17
#include <linux/init.h>
18
#include <linux/interrupt.h>
18
#include <linux/interrupt.h>
19
#include <linux/slab.h>
20
#include <linux/pagemap.h>
21
#include <linux/compiler.h>
19
22
20
#include <asm/page.h>
23
#include <asm/page.h>
21
#include <asm/pgtable.h>
24
#include <asm/pgtable.h>
Lines 299-304 Link Here
299
	unhandled_fault (address, current, regs);
302
	unhandled_fault (address, current, regs);
300
}
303
}
301
304
305
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
306
#ifdef CONFIG_GRKERNSEC_PAX_EMUPLT
307
static void pax_emuplt_close(struct vm_area_struct * vma)
308
{
309
	vma->vm_mm->call_dl_resolve = 0UL;
310
}
311
312
static struct page* pax_emuplt_nopage(struct vm_area_struct *vma, unsigned long address, int write_access)
313
{
314
	struct page* page;
315
	unsigned int *kaddr;
316
317
	page = alloc_page(GFP_HIGHUSER);
318
	if (!page)
319
		return page;
320
321
	kaddr = kmap(page);
322
	memset(kaddr, 0, PAGE_SIZE);
323
	kaddr[0] = 0x9DE3BFA8U; /* save */
324
	flush_dcache_page(page);
325
	kunmap(page);
326
	return page;
327
}
328
329
static struct vm_operations_struct pax_vm_ops = {
330
	close:		pax_emuplt_close,
331
	nopage:		pax_emuplt_nopage,
332
};
333
334
static void pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
335
{
336
	vma->vm_mm = current->mm;
337
	vma->vm_start = addr;
338
	vma->vm_end = addr + PAGE_SIZE;
339
	vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
340
	vma->vm_page_prot = protection_map[vma->vm_flags & 0x0f];
341
	vma->vm_ops = &pax_vm_ops;
342
	vma->vm_pgoff = 0UL; 
343
	vma->vm_file = NULL;
344
	vma->vm_private_data = NULL;
345
	insert_vm_struct(current->mm, vma);
346
	++current->mm->total_vm;
347
}
348
#endif
349
350
/*
351
 * PaX: decide what to do with offenders (regs->tpc = fault address)
352
 *
353
 * returns 1 when task should be killed
354
 *         2 when patched PLT trampoline was detected
355
 *         3 when unpatched PLT trampoline was detected
356
 *	   4 when legitimate ET_EXEC was detected
357
 */
358
static int pax_handle_fetch_fault(struct pt_regs *regs)
359
{
360
	int err;
361
362
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
363
	if (current->flags & PF_PAX_RANDEXEC) {
364
		if (regs->tpc >= current->mm->start_code &&
365
		    regs->tpc < current->mm->end_code)
366
		{
367
			if (regs->u_regs[UREG_RETPC] + 8UL == regs->tpc)
368
				return 1;
369
370
			regs->tpc += current->mm->delta_exec;
371
			if (regs->tnpc >= current->mm->start_code &&
372
			    regs->tnpc < current->mm->end_code)
373
				regs->tnpc += current->mm->delta_exec;
374
			return 4;
375
		}
376
		if (regs->tpc >= current->mm->start_code + current->mm->delta_exec &&
377
		    regs->tpc < current->mm->end_code + current->mm->delta_exec)
378
		{
379
			regs->tpc -= current->mm->delta_exec;
380
			if (regs->tnpc >= current->mm->start_code + current->mm->delta_exec &&
381
			    regs->tnpc < current->mm->end_code + current->mm->delta_exec)
382
				regs->tnpc -= current->mm->delta_exec;
383
		}
384
	}
385
#endif
386
387
#ifdef CONFIG_GRKERNSEC_PAX_EMUPLT
388
	do { /* PaX: patched PLT emulation #1 */
389
		unsigned int sethi1, sethi2, jmpl;
390
391
		err = get_user(sethi1, (unsigned int*)regs->tpc);
392
		err |= get_user(sethi2, (unsigned int*)(regs->tpc+4));
393
		err |= get_user(jmpl, (unsigned int*)(regs->tpc+8));
394
395
		if (err)
396
			break;
397
398
		if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
399
		    (sethi2 & 0xFFC00000U) == 0x03000000U &&
400
		    (jmpl & 0xFFFFE000U) == 0x81C06000U)
401
		{
402
			unsigned long addr;
403
404
			regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
405
			addr = regs->u_regs[UREG_G1];
406
			addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
407
			regs->tpc = addr;
408
			regs->tnpc = addr+4;
409
			return 2;
410
		}
411
	} while (0);
412
413
	{ /* PaX: patched PLT emulation #2 */
414
		unsigned int ba;
415
416
		err = get_user(ba, (unsigned int*)regs->tpc);
417
418
		if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
419
			unsigned long addr;
420
421
			addr = regs->tpc + 4 + (((ba | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
422
			regs->tpc = addr;
423
			regs->tnpc = addr+4;
424
			return 2;
425
		}
426
	}
427
428
	do { /* PaX: patched PLT emulation #3 */
429
		unsigned int sethi, jmpl, nop;
430
431
		err = get_user(sethi, (unsigned int*)regs->tpc);
432
		err |= get_user(jmpl, (unsigned int*)(regs->tpc+4));
433
		err |= get_user(nop, (unsigned int*)(regs->tpc+8));
434
435
		if (err)
436
			break;
437
438
		if ((sethi & 0xFFC00000U) == 0x03000000U &&
439
		    (jmpl & 0xFFFFE000U) == 0x81C06000U &&
440
		    nop == 0x01000000U)
441
		{
442
			unsigned long addr;
443
444
			addr = (sethi & 0x003FFFFFU) << 10;
445
			regs->u_regs[UREG_G1] = addr;
446
			addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
447
			regs->tpc = addr;
448
			regs->tnpc = addr+4;
449
			return 2;
450
		}
451
	} while (0);
452
453
	do { /* PaX: unpatched PLT emulation step 1 */
454
		unsigned int sethi, ba, nop;
455
456
		err = get_user(sethi, (unsigned int*)regs->tpc);
457
		err |= get_user(ba, (unsigned int*)(regs->tpc+4));
458
		err |= get_user(nop, (unsigned int*)(regs->tpc+8));
459
460
		if (err)
461
			break;
462
463
		if ((sethi & 0xFFC00000U) == 0x03000000U &&
464
		    (ba & 0xFFC00000U) == 0x30800000U &&
465
		    nop == 0x01000000U)
466
		{
467
			unsigned long addr;
468
			unsigned int save, call;
469
470
			addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
471
472
			err = get_user(save, (unsigned int*)addr);
473
			err |= get_user(call, (unsigned int*)(addr+4));
474
			err |= get_user(nop, (unsigned int*)(addr+8));
475
476
			if (err)
477
				break;
478
479
			if (save == 0x9DE3BFA8U &&
480
			    (call & 0xC0000000U) == 0x40000000U &&
481
			    nop == 0x01000000U)
482
			{
483
				struct vm_area_struct *vma;
484
				unsigned long call_dl_resolve;
485
486
				down_read(&current->mm->mmap_sem);
487
				call_dl_resolve = current->mm->call_dl_resolve;
488
				up_read(&current->mm->mmap_sem);
489
				if (likely(call_dl_resolve))
490
					goto emulate;
491
492
				vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
493
494
				down_write(&current->mm->mmap_sem);
495
				if (current->mm->call_dl_resolve) {
496
					call_dl_resolve = current->mm->call_dl_resolve;
497
					up_write(&current->mm->mmap_sem);
498
					if (vma) kmem_cache_free(vm_area_cachep, vma);
499
					goto emulate;
500
				}
501
502
				call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
503
				if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
504
					up_write(&current->mm->mmap_sem);
505
					if (vma) kmem_cache_free(vm_area_cachep, vma);
506
					return 1;
507
				}
508
509
				pax_insert_vma(vma, call_dl_resolve);
510
				current->mm->call_dl_resolve = call_dl_resolve;
511
				up_write(&current->mm->mmap_sem);
512
513
emulate:
514
				regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
515
				regs->tpc = call_dl_resolve;
516
				regs->tnpc = addr+4;
517
				return 3;
518
			}
519
		}
520
	} while (0);
521
522
	do { /* PaX: unpatched PLT emulation step 2 */
523
		unsigned int save, call, nop;
524
525
		err = get_user(save, (unsigned int*)(regs->tpc-4));
526
		err |= get_user(call, (unsigned int*)regs->tpc);
527
		err |= get_user(nop, (unsigned int*)(regs->tpc+4));
528
		if (err)
529
			break;
530
531
		if (save == 0x9DE3BFA8U &&
532
		    (call & 0xC0000000U) == 0x40000000U &&
533
		    nop == 0x01000000U)
534
		{
535
			unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
536
537
			regs->u_regs[UREG_RETPC] = regs->tpc;
538
			regs->tpc = dl_resolve;
539
			regs->tnpc = dl_resolve+4;
540
			return 3;
541
		}
542
	} while (0);
543
#endif
544
545
	return 1;
546
}
547
548
void pax_report_insns(void *pc)
549
{
550
	unsigned long i;
551
552
	printk(KERN_ERR "PAX: bytes at PC: ");
553
	for (i = 0; i < 5; i++) {
554
		unsigned int c;
555
		if (get_user(c, (unsigned int*)pc+i)) {
556
			printk("<invalid address>.");
557
			break;
558
		}
559
		printk("%08x ", c);
560
	}
561
	printk("\n");
562
}
563
#endif  
564
565
302
asmlinkage void do_sparc64_fault(struct pt_regs *regs)
566
asmlinkage void do_sparc64_fault(struct pt_regs *regs)
303
{
567
{
304
	struct mm_struct *mm = current->mm;
568
	struct mm_struct *mm = current->mm;
Lines 338-343 Link Here
338
602
339
	if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) {
603
	if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) {
340
		regs->tpc &= 0xffffffff;
604
		regs->tpc &= 0xffffffff;
605
		regs->tnpc &= 0xffffffff;
341
		address &= 0xffffffff;
606
		address &= 0xffffffff;
342
	}
607
	}
343
608
Lines 346-351 Link Here
346
	if (!vma)
611
	if (!vma)
347
		goto bad_area;
612
		goto bad_area;
348
613
614
	/* PaX: detect ITLB misses on non-exec pages */
615
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
616
	if ((current->flags & PF_PAX_PAGEEXEC) && vma->vm_start <= address && 
617
	    !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
618
	{
619
		if (address != regs->tpc)
620
			goto good_area;
621
622
		up_read(&mm->mmap_sem);
623
		switch (pax_handle_fetch_fault(regs)) {
624
625
#ifdef CONFIG_GRKERNSEC_PAX_EMUPLT
626
		case 2:
627
		case 3:
628
			goto fault_done;
629
#endif
630
631
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
632
		case 4:
633
			goto fault_done;
634
#endif
635
636
		}
637
		pax_report_fault(regs, (void*)regs->tpc, (void*)(regs->u_regs[UREG_FP] + STACK_BIAS));
638
		do_exit(SIGKILL);
639
	}
640
#endif
641
349
	/* Pure DTLB misses do not tell us whether the fault causing
642
	/* Pure DTLB misses do not tell us whether the fault causing
350
	 * load/store/atomic was a write or not, it only says that there
643
	 * load/store/atomic was a write or not, it only says that there
351
	 * was no match.  So in such a case we (carefully) read the
644
	 * was no match.  So in such a case we (carefully) read the
(-)linux-2.4.22-ppc-dev.orig/arch/sparc64/solaris/misc.c (+5 lines)
Lines 53-58 Link Here
53
	struct file *file = NULL;
53
	struct file *file = NULL;
54
	unsigned long retval, ret_type;
54
	unsigned long retval, ret_type;
55
55
56
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
57
	if (flags & MAP_MIRROR)
58
		return -EINVAL;
59
#endif
60
56
	/* Do we need it here? */
61
	/* Do we need it here? */
57
	set_personality(PER_SVR4);
62
	set_personality(PER_SVR4);
58
	if (flags & MAP_NORESERVE) {
63
	if (flags & MAP_NORESERVE) {
(-)linux-2.4.22-ppc-dev.orig/arch/x86_64/ia32/ia32_ioctl.c (+4 lines)
Lines 1932-1938 Link Here
1932
	 * To have permissions to do most of the vt ioctls, we either have
1932
	 * To have permissions to do most of the vt ioctls, we either have
1933
	 * to be the owner of the tty, or super-user.
1933
	 * to be the owner of the tty, or super-user.
1934
	 */
1934
	 */
1935
#ifdef CONFIG_GRKERNSEC
1936
	if (current->tty == tty || capable(CAP_SYS_TTY_CONFIG))
1937
#else
1935
	if (current->tty == tty || suser())
1938
	if (current->tty == tty || suser())
1939
#endif
1936
		return 1;
1940
		return 1;
1937
	return 0;                                                    
1941
	return 0;                                                    
1938
}
1942
}
(-)linux-2.4.22-ppc-dev.orig/drivers/char/keyboard.c (+10 lines)
Lines 533-538 Link Here
533
	if ((kbd->kbdmode == VC_RAW || kbd->kbdmode == VC_MEDIUMRAW) &&
533
	if ((kbd->kbdmode == VC_RAW || kbd->kbdmode == VC_MEDIUMRAW) &&
534
	    !(SPECIALS_ALLOWED_IN_RAW_MODE & (1 << value)))
534
	    !(SPECIALS_ALLOWED_IN_RAW_MODE & (1 << value)))
535
		return;
535
		return;
536
537
#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
538
	{
539
		void *func = spec_fn_table[value];
540
		if (func == show_state || func == show_ptregs ||
541
		    func == show_mem)
542
			return;
543
	}
544
#endif
545
536
	spec_fn_table[value]();
546
	spec_fn_table[value]();
537
}
547
}
538
548
(-)linux-2.4.22-ppc-dev.orig/drivers/char/mem.c (-3 / +45 lines)
Lines 21-26 Link Here
21
#include <linux/raw.h>
21
#include <linux/raw.h>
22
#include <linux/tty.h>
22
#include <linux/tty.h>
23
#include <linux/capability.h>
23
#include <linux/capability.h>
24
#include <linux/grsecurity.h>
24
25
25
#include <asm/uaccess.h>
26
#include <asm/uaccess.h>
26
#include <asm/io.h>
27
#include <asm/io.h>
Lines 41-46 Link Here
41
#if defined(CONFIG_S390_TAPE) && defined(CONFIG_S390_TAPE_CHAR)
42
#if defined(CONFIG_S390_TAPE) && defined(CONFIG_S390_TAPE_CHAR)
42
extern void tapechar_init(void);
43
extern void tapechar_init(void);
43
#endif
44
#endif
45
46
#ifdef CONFIG_GRKERNSEC
47
extern struct file_operations grsec_fops;
48
#endif
44
     
49
     
45
static ssize_t do_write_mem(struct file * file, void *p, unsigned long realp,
50
static ssize_t do_write_mem(struct file * file, void *p, unsigned long realp,
46
			    const char * buf, size_t count, loff_t *ppos)
51
			    const char * buf, size_t count, loff_t *ppos)
Lines 114-119 Link Here
114
	unsigned long p = *ppos;
119
	unsigned long p = *ppos;
115
	unsigned long end_mem;
120
	unsigned long end_mem;
116
121
122
#ifdef CONFIG_GRKERNSEC_KMEM
123
	gr_handle_mem_write();
124
	return -EPERM;
125
#endif
126
117
	end_mem = __pa(high_memory);
127
	end_mem = __pa(high_memory);
118
	if (p >= end_mem)
128
	if (p >= end_mem)
119
		return 0;
129
		return 0;
Lines 186-191 Link Here
186
{
196
{
187
	unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
197
	unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
188
198
199
#ifdef CONFIG_GRKERNSEC_KMEM
200
	if (gr_handle_mem_mmap(offset, vma))
201
		return -EPERM;
202
#endif
203
204
189
	/*
205
	/*
190
	 * Accessing memory above the top the kernel knows about or
206
	 * Accessing memory above the top the kernel knows about or
191
	 * through a file pointer that was marked O_SYNC will be
207
	 * through a file pointer that was marked O_SYNC will be
Lines 285-290 Link Here
285
	ssize_t virtr = 0;
301
	ssize_t virtr = 0;
286
	char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
302
	char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
287
303
304
#ifdef CONFIG_GRKERNSEC_KMEM
305
	gr_handle_kmem_write();
306
	return -EPERM;
307
#endif
308
288
	if (p < (unsigned long) high_memory) {
309
	if (p < (unsigned long) high_memory) {
289
		wrote = count;
310
		wrote = count;
290
		if (count > (unsigned long) high_memory - p)
311
		if (count > (unsigned long) high_memory - p)
Lines 401-407 Link Here
401
			count = size;
422
			count = size;
402
423
403
		zap_page_range(mm, addr, count);
424
		zap_page_range(mm, addr, count);
404
        	zeromap_page_range(addr, count, PAGE_COPY);
425
	        zeromap_page_range(addr, count, vma->vm_page_prot); 
405
426
406
		size -= count;
427
		size -= count;
407
		buf += count;
428
		buf += count;
Lines 517-522 Link Here
517
538
518
static int open_port(struct inode * inode, struct file * filp)
539
static int open_port(struct inode * inode, struct file * filp)
519
{
540
{
541
#ifdef CONFIG_GRKERNSEC_KMEM
542
	gr_handle_open_port();
543
	return -EPERM;
544
#endif
545
	return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
546
}
547
548
static int open_mem(struct inode * inode, struct file * filp)
549
{
520
	return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
550
	return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
521
}
551
}
522
552
Lines 574-579 Link Here
574
	unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
604
	unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
575
	unsigned long size = vma->vm_end - vma->vm_start;
605
	unsigned long size = vma->vm_end - vma->vm_start;
576
606
607
#ifdef CONFIG_GRKERNSEC_KMEM
608
	if (gr_handle_mem_mmap(offset, vma))
609
		return -EPERM;
610
#endif
611
577
	/*
612
	/*
578
	 * If the user is not attempting to mmap a high memory address then
613
	 * If the user is not attempting to mmap a high memory address then
579
	 * the standard mmap_mem mechanism will work.  High memory addresses
614
	 * the standard mmap_mem mechanism will work.  High memory addresses
Lines 609-615 Link Here
609
#define full_lseek      null_lseek
644
#define full_lseek      null_lseek
610
#define write_zero	write_null
645
#define write_zero	write_null
611
#define read_full       read_zero
646
#define read_full       read_zero
612
#define open_mem	open_port
613
#define open_kmem	open_mem
647
#define open_kmem	open_mem
614
648
615
static struct file_operations mem_fops = {
649
static struct file_operations mem_fops = {
Lines 685-690 Link Here
685
		case 9:
719
		case 9:
686
			filp->f_op = &urandom_fops;
720
			filp->f_op = &urandom_fops;
687
			break;
721
			break;
722
#ifdef CONFIG_GRKERNSEC
723
		case 10:
724
			filp->f_op = &grsec_fops;
725
			break;
726
#endif
688
		default:
727
		default:
689
			return -ENXIO;
728
			return -ENXIO;
690
	}
729
	}
Lines 711-717 Link Here
711
	{5, "zero",    S_IRUGO | S_IWUGO,           &zero_fops},
750
	{5, "zero",    S_IRUGO | S_IWUGO,           &zero_fops},
712
	{7, "full",    S_IRUGO | S_IWUGO,           &full_fops},
751
	{7, "full",    S_IRUGO | S_IWUGO,           &full_fops},
713
	{8, "random",  S_IRUGO | S_IWUSR,           &random_fops},
752
	{8, "random",  S_IRUGO | S_IWUSR,           &random_fops},
714
	{9, "urandom", S_IRUGO | S_IWUSR,           &urandom_fops}
753
	{9, "urandom", S_IRUGO | S_IWUSR,           &urandom_fops},
754
#ifdef CONFIG_GRKERNSEC
755
	{10,"grsec",   S_IRUSR | S_IWUGO,	    &grsec_fops}
756
#endif
715
    };
757
    };
716
    int i;
758
    int i;
717
759
(-)linux-2.4.22-ppc-dev.orig/drivers/char/random.c (+30 lines)
Lines 262-270 Link Here
262
/*
262
/*
263
 * Configuration information
263
 * Configuration information
264
 */
264
 */
265
#ifdef CONFIG_GRKERNSEC_RANDNET
266
#define DEFAULT_POOL_SIZE 1024
267
#define SECONDARY_POOL_SIZE 256
268
#define BATCH_ENTROPY_SIZE 512
269
#else
265
#define DEFAULT_POOL_SIZE 512
270
#define DEFAULT_POOL_SIZE 512
266
#define SECONDARY_POOL_SIZE 128
271
#define SECONDARY_POOL_SIZE 128
267
#define BATCH_ENTROPY_SIZE 256
272
#define BATCH_ENTROPY_SIZE 256
273
#endif
268
#define USE_SHA
274
#define USE_SHA
269
275
270
/*
276
/*
Lines 389-394 Link Here
389
/*
395
/*
390
 * Static global variables
396
 * Static global variables
391
 */
397
 */
398
392
static struct entropy_store *random_state; /* The default global store */
399
static struct entropy_store *random_state; /* The default global store */
393
static struct entropy_store *sec_random_state; /* secondary store */
400
static struct entropy_store *sec_random_state; /* secondary store */
394
static DECLARE_WAIT_QUEUE_HEAD(random_read_wait);
401
static DECLARE_WAIT_QUEUE_HEAD(random_read_wait);
Lines 2202-2207 Link Here
2202
	return halfMD4Transform(hash, keyptr->secret);
2209
	return halfMD4Transform(hash, keyptr->secret);
2203
}
2210
}
2204
2211
2212
#ifdef CONFIG_GRKERNSEC
2213
/* the following function is provided by PaX under the GPL */
2214
unsigned long get_random_long(void)
2215
{       
2216
	static time_t rekey_time;
2217
	static __u32 secret[12];
2218
	time_t t;
2219
2220
	/*
2221
	 * Pick a random secret every REKEY_INTERVAL seconds
2222
	 */
2223
	t = CURRENT_TIME;
2224
	if (!rekey_time || (t - rekey_time) > REKEY_INTERVAL) {
2225
		rekey_time = t;
2226
		get_random_bytes(secret, sizeof(secret));
2227
	}
2228
2229
	secret[1] = halfMD4Transform(secret+8, secret);
2230
	secret[0] = halfMD4Transform(secret+8, secret);
2231
	return *(unsigned long *)secret;
2232
}
2233
#endif
2234
2205
#ifdef CONFIG_SYN_COOKIES
2235
#ifdef CONFIG_SYN_COOKIES
2206
/*
2236
/*
2207
 * Secure SYN cookie computation. This is the algorithm worked out by
2237
 * Secure SYN cookie computation. This is the algorithm worked out by
(-)linux-2.4.22-ppc-dev.orig/drivers/char/tty_io.c (-1 / +17 lines)
Lines 99-105 Link Here
99
#include <linux/vt_kern.h>
99
#include <linux/vt_kern.h>
100
#include <linux/selection.h>
100
#include <linux/selection.h>
101
#include <linux/devfs_fs_kernel.h>
101
#include <linux/devfs_fs_kernel.h>
102
102
#include <linux/grsecurity.h>
103
#include <linux/kmod.h>
103
#include <linux/kmod.h>
104
104
105
#ifdef CONFIG_VT
105
#ifdef CONFIG_VT
Lines 1402-1408 Link Here
1402
		retval = -ENODEV;
1402
		retval = -ENODEV;
1403
	filp->f_flags = saved_flags;
1403
	filp->f_flags = saved_flags;
1404
1404
1405
#ifdef CONFIG_GRKERNSEC
1406
	if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_TTY_CONFIG))
1407
#else
1405
	if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) && !suser())
1408
	if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) && !suser())
1409
#endif
1406
		retval = -EBUSY;
1410
		retval = -EBUSY;
1407
1411
1408
	if (retval) {
1412
	if (retval) {
Lines 1504-1510 Link Here
1504
{
1508
{
1505
	char ch, mbz = 0;
1509
	char ch, mbz = 0;
1506
1510
1511
#ifdef CONFIG_GRKERNSEC
1512
	if ((current->tty != tty) && !capable(CAP_SYS_TTY_CONFIG))
1513
#else
1507
	if ((current->tty != tty) && !suser())
1514
	if ((current->tty != tty) && !suser())
1515
#endif
1508
		return -EPERM;
1516
		return -EPERM;
1509
	if (get_user(ch, arg))
1517
	if (get_user(ch, arg))
1510
		return -EFAULT;
1518
		return -EFAULT;
Lines 1542-1548 Link Here
1542
	if (inode->i_rdev == SYSCONS_DEV ||
1550
	if (inode->i_rdev == SYSCONS_DEV ||
1543
	    inode->i_rdev == CONSOLE_DEV) {
1551
	    inode->i_rdev == CONSOLE_DEV) {
1544
		struct file *f;
1552
		struct file *f;
1553
#ifdef CONFIG_GRKERNSEC
1554
		if (!capable(CAP_SYS_TTY_CONFIG))
1555
#else
1545
		if (!suser())
1556
		if (!suser())
1557
#endif
1546
			return -EPERM;
1558
			return -EPERM;
1547
		spin_lock(&redirect_lock);
1559
		spin_lock(&redirect_lock);
1548
		f = redirect;
1560
		f = redirect;
Lines 1594-1600 Link Here
1594
		 * This tty is already the controlling
1606
		 * This tty is already the controlling
1595
		 * tty for another session group!
1607
		 * tty for another session group!
1596
		 */
1608
		 */
1609
#ifdef CONFIG_GRKERNSEC
1610
		if ((arg == 1) && capable(CAP_SYS_ADMIN)) {
1611
#else
1597
		if ((arg == 1) && suser()) {
1612
		if ((arg == 1) && suser()) {
1613
#endif
1598
			/*
1614
			/*
1599
			 * Steal it away
1615
			 * Steal it away
1600
			 */
1616
			 */
(-)linux-2.4.22-ppc-dev.orig/drivers/char/vt.c (+13 lines)
Lines 32-37 Link Here
32
#include <linux/vt_kern.h>
32
#include <linux/vt_kern.h>
33
#include <linux/kbd_diacr.h>
33
#include <linux/kbd_diacr.h>
34
#include <linux/selection.h>
34
#include <linux/selection.h>
35
#include <linux/grsecurity.h>
35
36
36
#ifdef CONFIG_FB_COMPAT_XPMAC
37
#ifdef CONFIG_FB_COMPAT_XPMAC
37
#include <asm/vc_ioctl.h>
38
#include <asm/vc_ioctl.h>
Lines 443-449 Link Here
443
	 * to be the owner of the tty, or super-user.
444
	 * to be the owner of the tty, or super-user.
444
	 */
445
	 */
445
	perm = 0;
446
	perm = 0;
447
#ifdef CONFIG_GRKERNSEC
448
	if (current->tty == tty || capable(CAP_SYS_TTY_CONFIG))
449
#else
446
	if (current->tty == tty || suser())
450
	if (current->tty == tty || suser())
451
#endif
447
		perm = 1;
452
		perm = 1;
448
 
453
 
449
	kbd = kbd_table + console;
454
	kbd = kbd_table + console;
Lines 1038-1049 Link Here
1038
		return do_unimap_ioctl(cmd, (struct unimapdesc *)arg, perm);
1043
		return do_unimap_ioctl(cmd, (struct unimapdesc *)arg, perm);
1039
1044
1040
	case VT_LOCKSWITCH:
1045
	case VT_LOCKSWITCH:
1046
#ifdef CONFIG_GRKERNSEC
1047
		if (!capable(CAP_SYS_TTY_CONFIG))
1048
#else
1041
		if (!suser())
1049
		if (!suser())
1050
#endif
1042
		   return -EPERM;
1051
		   return -EPERM;
1043
		vt_dont_switch = 1;
1052
		vt_dont_switch = 1;
1044
		return 0;
1053
		return 0;
1045
	case VT_UNLOCKSWITCH:
1054
	case VT_UNLOCKSWITCH:
1055
#ifdef CONFIG_GRKERNSEC
1056
		if (!capable(CAP_SYS_TTY_CONFIG))
1057
#else
1046
		if (!suser())
1058
		if (!suser())
1059
#endif
1047
		   return -EPERM;
1060
		   return -EPERM;
1048
		vt_dont_switch = 0;
1061
		vt_dont_switch = 0;
1049
		return 0;
1062
		return 0;
(-)linux-2.4.22-ppc-dev.orig/drivers/pci/proc.c (+8 lines)
Lines 562-568 Link Here
562
		pci_for_each_dev(dev) {
562
		pci_for_each_dev(dev) {
563
			pci_proc_attach_device(dev);
563
			pci_proc_attach_device(dev);
564
		}
564
		}
565
#ifdef CONFIG_GRKERNSEC_PROC_ADD
566
#ifdef CONFIG_GRKERNSEC_PROC_USER
567
		entry = create_proc_entry("pci", S_IRUSR, NULL);
568
#elif CONFIG_GRKERNSEC_PROC_USERGROUP
569
		entry = create_proc_entry("pci", S_IRUSR | S_IRGRP, NULL);
570
#endif
571
#else
565
		entry = create_proc_entry("pci", 0, NULL);
572
		entry = create_proc_entry("pci", 0, NULL);
573
#endif
566
		if (entry)
574
		if (entry)
567
			entry->proc_fops = &proc_pci_operations;
575
			entry->proc_fops = &proc_pci_operations;
568
	}
576
	}
(-)linux-2.4.22-ppc-dev.orig/fs/binfmt_aout.c (-1 / +26 lines)
Lines 5-10 Link Here
5
 */
5
 */
6
6
7
#include <linux/module.h>
7
#include <linux/module.h>
8
#include <linux/config.h>
8
9
9
#include <linux/sched.h>
10
#include <linux/sched.h>
10
#include <linux/kernel.h>
11
#include <linux/kernel.h>
Lines 113-122 Link Here
113
/* If the size of the dump file exceeds the rlimit, then see what would happen
114
/* If the size of the dump file exceeds the rlimit, then see what would happen
114
   if we wrote the stack, but not the data area.  */
115
   if we wrote the stack, but not the data area.  */
115
#ifdef __sparc__
116
#ifdef __sparc__
117
	gr_learn_resource(current, RLIMIT_CORE, dump.u_dsize+dump.u_ssize);
116
	if ((dump.u_dsize+dump.u_ssize) >
118
	if ((dump.u_dsize+dump.u_ssize) >
117
	    current->rlim[RLIMIT_CORE].rlim_cur)
119
	    current->rlim[RLIMIT_CORE].rlim_cur)
118
		dump.u_dsize = 0;
120
		dump.u_dsize = 0;
119
#else
121
#else
122
	gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize+dump.u_ssize+1) * PAGE_SIZE);
120
	if ((dump.u_dsize+dump.u_ssize+1) * PAGE_SIZE >
123
	if ((dump.u_dsize+dump.u_ssize+1) * PAGE_SIZE >
121
	    current->rlim[RLIMIT_CORE].rlim_cur)
124
	    current->rlim[RLIMIT_CORE].rlim_cur)
122
		dump.u_dsize = 0;
125
		dump.u_dsize = 0;
Lines 124-133 Link Here
124
127
125
/* Make sure we have enough room to write the stack and data areas. */
128
/* Make sure we have enough room to write the stack and data areas. */
126
#ifdef __sparc__
129
#ifdef __sparc__
130
	gr_learn_resource(current, RLIMIT_CORE, dump.u_ssize);
127
	if ((dump.u_ssize) >
131
	if ((dump.u_ssize) >
128
	    current->rlim[RLIMIT_CORE].rlim_cur)
132
	    current->rlim[RLIMIT_CORE].rlim_cur)
129
		dump.u_ssize = 0;
133
		dump.u_ssize = 0;
130
#else
134
#else
135
	gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize+1) * PAGE_SIZE);
131
	if ((dump.u_ssize+1) * PAGE_SIZE >
136
	if ((dump.u_ssize+1) * PAGE_SIZE >
132
	    current->rlim[RLIMIT_CORE].rlim_cur)
137
	    current->rlim[RLIMIT_CORE].rlim_cur)
133
		dump.u_ssize = 0;
138
		dump.u_ssize = 0;
Lines 276-281 Link Here
276
	rlim = current->rlim[RLIMIT_DATA].rlim_cur;
281
	rlim = current->rlim[RLIMIT_DATA].rlim_cur;
277
	if (rlim >= RLIM_INFINITY)
282
	if (rlim >= RLIM_INFINITY)
278
		rlim = ~0;
283
		rlim = ~0;
284
285
	gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss);
279
	if (ex.a_data + ex.a_bss > rlim)
286
	if (ex.a_data + ex.a_bss > rlim)
280
		return -ENOMEM;
287
		return -ENOMEM;
281
288
Lines 307-312 Link Here
307
	current->mm->mmap = NULL;
314
	current->mm->mmap = NULL;
308
	compute_creds(bprm);
315
	compute_creds(bprm);
309
 	current->flags &= ~PF_FORKNOEXEC;
316
 	current->flags &= ~PF_FORKNOEXEC;
317
318
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
319
	if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
320
		current->flags |= PF_PAX_PAGEEXEC;
321
322
#ifdef CONFIG_GRKERNSEC_PAX_EMUTRAMP
323
		if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
324
			current->flags |= PF_PAX_EMUTRAMP;
325
#endif
326
327
#ifdef CONFIG_GRKERNSEC_PAX_MPROTECT
328
		if (!(N_FLAGS(ex) & F_PAX_MPROTECT))        
329
			current->flags |= PF_PAX_MPROTECT;
330
#endif
331
332
	}
333
#endif
334
310
#ifdef __sparc__
335
#ifdef __sparc__
311
	if (N_MAGIC(ex) == NMAGIC) {
336
	if (N_MAGIC(ex) == NMAGIC) {
312
		loff_t pos = fd_offset;
337
		loff_t pos = fd_offset;
Lines 393-399 Link Here
393
418
394
		down_write(&current->mm->mmap_sem);
419
		down_write(&current->mm->mmap_sem);
395
 		error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
420
 		error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
396
				PROT_READ | PROT_WRITE | PROT_EXEC,
421
				PROT_READ | PROT_WRITE,
397
				MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
422
				MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
398
				fd_offset + ex.a_text);
423
				fd_offset + ex.a_text);
399
		up_write(&current->mm->mmap_sem);
424
		up_write(&current->mm->mmap_sem);
(-)linux-2.4.22-ppc-dev.orig/fs/binfmt_elf.c (-11 / +172 lines)
Lines 11-16 Link Here
11
11
12
#include <linux/module.h>
12
#include <linux/module.h>
13
13
14
#include <linux/config.h>
14
#include <linux/fs.h>
15
#include <linux/fs.h>
15
#include <linux/stat.h>
16
#include <linux/stat.h>
16
#include <linux/sched.h>
17
#include <linux/sched.h>
Lines 33-42 Link Here
33
#include <linux/smp_lock.h>
34
#include <linux/smp_lock.h>
34
#include <linux/compiler.h>
35
#include <linux/compiler.h>
35
#include <linux/highmem.h>
36
#include <linux/highmem.h>
37
#include <linux/random.h>
38
#include <linux/grsecurity.h>
36
39
37
#include <asm/uaccess.h>
40
#include <asm/uaccess.h>
38
#include <asm/param.h>
41
#include <asm/param.h>
39
#include <asm/pgalloc.h>
42
#include <asm/pgalloc.h>
43
#include <asm/system.h>
40
44
41
#define DLINFO_ITEMS 13
45
#define DLINFO_ITEMS 13
42
46
Lines 86-91 Link Here
86
	if (end <= start)
90
	if (end <= start)
87
		return;
91
		return;
88
	do_brk(start, end - start);
92
	do_brk(start, end - start);
93
94
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
95
	if (current->flags & PF_PAX_RANDEXEC)
96
		do_mmap_pgoff(NULL, ELF_PAGEALIGN(start + current->mm->delta_exec), 0UL, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED | MAP_MIRROR, start);
97
#endif
98
89
}
99
}
90
100
91
101
Lines 445-450 Link Here
445
  	struct exec interp_ex;
455
  	struct exec interp_ex;
446
	char passed_fileno[6];
456
	char passed_fileno[6];
447
	struct files_struct *files;
457
	struct files_struct *files;
458
459
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
460
	unsigned long load_addr_random = 0UL;
461
	unsigned long load_bias_random = 0UL;
462
#endif
448
	
463
	
449
	/* Get the exec-header */
464
	/* Get the exec-header */
450
	elf_ex = *((struct elfhdr *) bprm->buf);
465
	elf_ex = *((struct elfhdr *) bprm->buf);
Lines 617-623 Link Here
617
	current->mm->end_data = 0;
632
	current->mm->end_data = 0;
618
	current->mm->end_code = 0;
633
	current->mm->end_code = 0;
619
	current->mm->mmap = NULL;
634
	current->mm->mmap = NULL;
635
636
#ifdef CONFIG_GRKERNSEC_PAX_ASLR
637
	current->mm->delta_mmap = 0UL;
638
	current->mm->delta_exec = 0UL;
639
	current->mm->delta_stack = 0UL;
640
#endif
641
620
	current->flags &= ~PF_FORKNOEXEC;
642
	current->flags &= ~PF_FORKNOEXEC;
643
644
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
645
	if (!(elf_ex.e_ident[EI_PAX] & EF_PAX_PAGEEXEC)) {
646
		current->flags |= PF_PAX_PAGEEXEC;
647
648
#ifdef CONFIG_GRKERNSEC_PAX_DLRESOLVE
649
		current->mm->call_dl_resolve = 0UL;
650
#endif
651
652
	}
653
#endif
654
655
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
656
	if (!(elf_ex.e_ident[EI_PAX] & EF_PAX_SEGMEXEC)) {
657
		current->flags &= ~PF_PAX_PAGEEXEC;
658
		current->flags |= PF_PAX_SEGMEXEC;
659
	}
660
#endif
661
662
#ifdef CONFIG_GRKERNSEC_PAX_EMUTRAMP
663
	if (elf_ex.e_ident[EI_PAX] & EF_PAX_EMUTRAMP)
664
		current->flags |= PF_PAX_EMUTRAMP;
665
#endif
666
667
#ifdef CONFIG_GRKERNSEC_PAX_MPROTECT
668
	if ((current->flags & (PF_PAX_PAGEEXEC | PF_PAX_SEGMEXEC)) && !(elf_ex.e_ident[EI_PAX] & EF_PAX_MPROTECT))
669
		current->flags |= PF_PAX_MPROTECT;
670
#endif
671
672
#ifdef CONFIG_GRKERNSEC_PAX_ASLR
673
	if (!(elf_ex.e_ident[EI_PAX] & EF_PAX_RANDMMAP)) {
674
		current->flags |= PF_PAX_RANDMMAP;
675
676
#define pax_delta_mask(delta, lsb, len) (((delta) & ((1UL << (len)) - 1)) << (lsb))
677
678
		current->mm->delta_mmap = pax_delta_mask(get_random_long(), PAX_DELTA_MMAP_LSB(current), PAX_DELTA_MMAP_LEN(current));
679
		current->mm->delta_exec = pax_delta_mask(get_random_long(), PAX_DELTA_EXEC_LSB(current), PAX_DELTA_EXEC_LEN(current));
680
		current->mm->delta_stack = pax_delta_mask(get_random_long(), PAX_DELTA_STACK_LSB(current), PAX_DELTA_STACK_LEN(current));
681
	}
682
#endif
683
684
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
685
	if ((elf_ex.e_ident[EI_PAX] & EF_PAX_RANDEXEC) && (elf_ex.e_type == ET_EXEC) &&
686
	    (current->flags & (PF_PAX_PAGEEXEC | PF_PAX_SEGMEXEC)))
687
		current->flags |= PF_PAX_RANDEXEC;
688
#endif
689
690
	gr_set_pax_flags(current);	
691
621
	elf_entry = (unsigned long) elf_ex.e_entry;
692
	elf_entry = (unsigned long) elf_ex.e_entry;
622
693
623
	/* Do this so that we can load the interpreter, if need be.  We will
694
	/* Do this so that we can load the interpreter, if need be.  We will
Lines 673-683 Link Here
673
			   base, as well as whatever program they might try to exec.  This
744
			   base, as well as whatever program they might try to exec.  This
674
		           is because the brk will follow the loader, and is not movable.  */
745
		           is because the brk will follow the loader, and is not movable.  */
675
			load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
746
			load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
747
748
#ifdef CONFIG_GRKERNSEC_PAX_RANDMMAP
749
			/* PaX: randomize base address at the default exe base if requested */
750
			if (current->flags & PF_PAX_RANDMMAP) {
751
				load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE(current) - vaddr + current->mm->delta_exec);
752
				elf_flags |= MAP_FIXED;
753
			}
754
#endif
755
676
		}
756
		}
677
757
678
		error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt, elf_prot, elf_flags);
758
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
679
		if (BAD_ADDR(error))
759
		if ((current->flags & PF_PAX_RANDEXEC) && (elf_ex.e_type == ET_EXEC)) {
680
			continue;
760
			unsigned long addr, len;
761
762
			error = -ENOMEM;
763
764
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
765
			if (current->flags & PF_PAX_PAGEEXEC)
766
				error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt, elf_prot & ~PROT_EXEC, elf_flags);
767
#endif
768
769
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
770
			if (current->flags & PF_PAX_SEGMEXEC) {
771
				addr = ELF_PAGESTART(load_bias + vaddr);
772
				len = elf_ppnt->p_filesz + ELF_PAGEOFFSET(elf_ppnt->p_vaddr);
773
				if (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len)
774
					continue;
775
				down_write(&current->mm->mmap_sem);
776
				error = do_mmap_pgoff(bprm->file, addr, len, elf_prot, elf_flags, (elf_ppnt->p_offset - ELF_PAGEOFFSET(elf_ppnt->p_vaddr)) >> PAGE_SHIFT);
777
				up_write(&current->mm->mmap_sem);
778
			}
779
#endif
780
781
			if (BAD_ADDR(error))
782
				continue;
783
784
			/* PaX: mirror at a randomized base */
785
			down_write(&current->mm->mmap_sem);
786
787
			if (!load_addr_set) {
788
				load_addr_random = get_unmapped_area(bprm->file, 0UL, elf_ppnt->p_filesz + ELF_PAGEOFFSET(elf_ppnt->p_vaddr), (elf_ppnt->p_offset - ELF_PAGEOFFSET(elf_ppnt->p_vaddr)) >> PAGE_SHIFT, MAP_PRIVATE);
789
				if (BAD_ADDR(load_addr_random)) {
790
					up_write(&current->mm->mmap_sem);
791
					continue;
792
				}
793
				load_bias_random = load_addr_random - vaddr;
794
			}
795
796
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
797
			if (current->flags & PF_PAX_PAGEEXEC)
798
				load_addr_random = do_mmap_pgoff(NULL, ELF_PAGESTART(load_bias_random + vaddr), 0UL, elf_prot, elf_flags | MAP_MIRROR, error);
799
#endif
800
801
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
802
			if (current->flags & PF_PAX_SEGMEXEC) {
803
				if (elf_prot & PROT_EXEC) {
804
					load_addr_random = do_mmap_pgoff(NULL, ELF_PAGESTART(load_bias_random + vaddr), elf_ppnt->p_memsz + ELF_PAGEOFFSET(elf_ppnt->p_vaddr), PROT_NONE, MAP_PRIVATE | MAP_FIXED, 0UL);
805
					if (!BAD_ADDR(load_addr_random)) {
806
						load_addr_random = do_mmap_pgoff(NULL, ELF_PAGESTART(load_bias_random + vaddr + SEGMEXEC_TASK_SIZE), 0UL, elf_prot, elf_flags | MAP_MIRROR, error);
807
						if (!BAD_ADDR(load_addr_random))
808
							load_addr_random -= SEGMEXEC_TASK_SIZE;
809
					}
810
				} else
811
					load_addr_random = do_mmap_pgoff(NULL, ELF_PAGESTART(load_bias_random + vaddr), 0UL, elf_prot, elf_flags | MAP_MIRROR, error);
812
			}
813
#endif
814
815
			up_write(&current->mm->mmap_sem);
816
			if (BAD_ADDR(load_addr_random))
817
				continue;
818
		} else
819
#endif
820
		{
821
			error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt, elf_prot, elf_flags);
822
			if (BAD_ADDR(error))
823
				continue;
824
		}
681
825
682
		if (!load_addr_set) {
826
		if (!load_addr_set) {
683
			load_addr_set = 1;
827
			load_addr_set = 1;
Lines 687-692 Link Here
687
				             ELF_PAGESTART(load_bias + vaddr);
831
				             ELF_PAGESTART(load_bias + vaddr);
688
				load_addr += load_bias;
832
				load_addr += load_bias;
689
			}
833
			}
834
835
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
836
			current->mm->delta_exec = load_addr_random - load_addr;
837
#endif
838
690
		}
839
		}
691
		k = elf_ppnt->p_vaddr;
840
		k = elf_ppnt->p_vaddr;
692
		if (k < start_code) start_code = k;
841
		if (k < start_code) start_code = k;
Lines 713-718 Link Here
713
	start_data += load_bias;
862
	start_data += load_bias;
714
	end_data += load_bias;
863
	end_data += load_bias;
715
864
865
#ifdef CONFIG_GRKERNSEC_PAX_RANDMMAP
866
	elf_brk += pax_delta_mask(get_random_long(), 4, PAGE_SHIFT);
867
#undef pax_delta_mask
868
#endif
869
870
	/* Calling set_brk effectively mmaps the pages that we need
871
	 * for the bss and break sections
872
	 */
873
	set_brk(elf_bss, elf_brk);
874
875
	padzero(elf_bss);
876
716
	if (elf_interpreter) {
877
	if (elf_interpreter) {
717
		if (interpreter_type == INTERPRETER_AOUT)
878
		if (interpreter_type == INTERPRETER_AOUT)
718
			elf_entry = load_aout_interp(&interp_ex,
879
			elf_entry = load_aout_interp(&interp_ex,
Lines 760-772 Link Here
760
	current->mm->end_data = end_data;
921
	current->mm->end_data = end_data;
761
	current->mm->start_stack = bprm->p;
922
	current->mm->start_stack = bprm->p;
762
923
763
	/* Calling set_brk effectively mmaps the pages that we need
764
	 * for the bss and break sections
765
	 */
766
	set_brk(elf_bss, elf_brk);
767
768
	padzero(elf_bss);
769
770
#if 0
924
#if 0
771
	printk("(start_brk) %lx\n" , (long) current->mm->start_brk);
925
	printk("(start_brk) %lx\n" , (long) current->mm->start_brk);
772
	printk("(end_code) %lx\n" , (long) current->mm->end_code);
926
	printk("(end_code) %lx\n" , (long) current->mm->end_code);
Lines 799-804 Link Here
799
	ELF_PLAT_INIT(regs);
953
	ELF_PLAT_INIT(regs);
800
#endif
954
#endif
801
955
956
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
957
	pax_switch_segments(current);
958
#endif
959
802
	start_thread(regs, elf_entry, bprm->p);
960
	start_thread(regs, elf_entry, bprm->p);
803
	if (current->ptrace & PT_PTRACED)
961
	if (current->ptrace & PT_PTRACED)
804
		send_sig(SIGTRAP, current, 0);
962
		send_sig(SIGTRAP, current, 0);
Lines 1026-1033 Link Here
1026
#undef DUMP_SEEK
1184
#undef DUMP_SEEK
1027
1185
1028
#define DUMP_WRITE(addr, nr)	\
1186
#define DUMP_WRITE(addr, nr)	\
1187
	do { \
1188
	gr_learn_resource(current, RLIMIT_CORE, size + (nr)); \
1029
	if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
1189
	if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
1030
		goto end_coredump;
1190
		goto end_coredump; \
1191
	} while (0);
1031
#define DUMP_SEEK(off)	\
1192
#define DUMP_SEEK(off)	\
1032
	if (!dump_seek(file, (off))) \
1193
	if (!dump_seek(file, (off))) \
1033
		goto end_coredump;
1194
		goto end_coredump;
(-)linux-2.4.22-ppc-dev.orig/fs/buffer.c (+3 lines)
Lines 1826-1831 Link Here
1826
	int err;
1826
	int err;
1827
1827
1828
	err = -EFBIG;
1828
	err = -EFBIG;
1829
1830
	gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long) size);
1831
1829
        limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
1832
        limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
1830
	if (limit != RLIM_INFINITY && size > (loff_t)limit) {
1833
	if (limit != RLIM_INFINITY && size > (loff_t)limit) {
1831
		send_sig(SIGXFSZ, current, 0);
1834
		send_sig(SIGXFSZ, current, 0);
(-)linux-2.4.22-ppc-dev.orig/fs/exec.c (-2 / +137 lines)
Lines 43-48 Link Here
43
#include <asm/uaccess.h>
43
#include <asm/uaccess.h>
44
#include <asm/pgalloc.h>
44
#include <asm/pgalloc.h>
45
#include <asm/mmu_context.h>
45
#include <asm/mmu_context.h>
46
#include <linux/major.h>
47
#include <linux/random.h>
48
#include <linux/grsecurity.h>
46
49
47
#ifdef CONFIG_KMOD
50
#ifdef CONFIG_KMOD
48
#include <linux/kmod.h>
51
#include <linux/kmod.h>
Lines 345-350 Link Here
345
		mpnt->vm_start = PAGE_MASK & (unsigned long) bprm->p;
348
		mpnt->vm_start = PAGE_MASK & (unsigned long) bprm->p;
346
		mpnt->vm_end = STACK_TOP;
349
		mpnt->vm_end = STACK_TOP;
347
		mpnt->vm_flags = VM_STACK_FLAGS;
350
		mpnt->vm_flags = VM_STACK_FLAGS;
351
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
352
		if (!(current->flags & PF_PAX_PAGEEXEC))
353
			mpnt->vm_page_prot = protection_map[(VM_STACK_FLAGS | VM_EXEC) & 0x7];
354
		else
355
#endif
348
		mpnt->vm_page_prot = protection_map[VM_STACK_FLAGS & 0x7];
356
		mpnt->vm_page_prot = protection_map[VM_STACK_FLAGS & 0x7];
349
		mpnt->vm_ops = NULL;
357
		mpnt->vm_ops = NULL;
350
		mpnt->vm_pgoff = 0;
358
		mpnt->vm_pgoff = 0;
Lines 610-615 Link Here
610
	}
618
	}
611
	current->comm[i] = '\0';
619
	current->comm[i] = '\0';
612
620
621
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
622
	current->flags &= ~PF_PAX_PAGEEXEC;
623
#endif
624
625
#ifdef CONFIG_GRKERNSEC_PAX_EMUTRAMP
626
	current->flags &= ~PF_PAX_EMUTRAMP;
627
#endif
628
629
#ifdef CONFIG_GRKERNSEC_PAX_MPROTECT
630
	current->flags &= ~PF_PAX_MPROTECT;
631
#endif
632
633
#ifdef CONFIG_GRKERNSEC_PAX_ASLR
634
	current->flags &= ~PF_PAX_RANDMMAP;
635
#endif
636
637
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
638
	current->flags &= ~PF_PAX_RANDEXEC;
639
#endif
640
641
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
642
	current->flags &= ~PF_PAX_SEGMEXEC;
643
#endif
644
613
	flush_thread();
645
	flush_thread();
614
646
615
	de_thread(current);
647
	de_thread(current);
Lines 709-714 Link Here
709
			cap_set_full(bprm->cap_effective);
741
			cap_set_full(bprm->cap_effective);
710
	}
742
	}
711
743
744
	if (gr_handle_ptrace_exec(bprm->file->f_dentry, bprm->file->f_vfsmnt))
745
		return -EACCES;
746
712
	memset(bprm->buf,0,BINPRM_BUF_SIZE);
747
	memset(bprm->buf,0,BINPRM_BUF_SIZE);
713
	return kernel_read(bprm->file,0,bprm->buf,BINPRM_BUF_SIZE);
748
	return kernel_read(bprm->file,0,bprm->buf,BINPRM_BUF_SIZE);
714
}
749
}
Lines 774-779 Link Here
774
        current->suid = current->euid = current->fsuid = bprm->e_uid;
809
        current->suid = current->euid = current->fsuid = bprm->e_uid;
775
        current->sgid = current->egid = current->fsgid = bprm->e_gid;
810
        current->sgid = current->egid = current->fsgid = bprm->e_gid;
776
811
812
	gr_handle_chroot_caps(current);
813
777
	if(do_unlock)
814
	if(do_unlock)
778
		unlock_kernel();
815
		unlock_kernel();
779
	current->keep_capabilities = 0;
816
	current->keep_capabilities = 0;
Lines 907-912 Link Here
907
	struct file *file;
944
	struct file *file;
908
	int retval;
945
	int retval;
909
	int i;
946
	int i;
947
#ifdef CONFIG_GRKERNSEC
948
	struct file *old_exec_file;
949
	struct acl_subject_label *old_acl;
950
	struct rlimit old_rlim[RLIM_NLIMITS];
951
#endif
910
952
911
	file = open_exec(filename);
953
	file = open_exec(filename);
912
954
Lines 914-920 Link Here
914
	if (IS_ERR(file))
956
	if (IS_ERR(file))
915
		return retval;
957
		return retval;
916
958
959
	gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->user->processes));
960
961
	if (gr_handle_nproc()) {
962
		allow_write_access(file);
963
		fput(file);
964
		return -EAGAIN;
965
	}
966
967
	if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
968
		allow_write_access(file);
969
		fput(file);
970
		return -EACCES;
971
	}
972
917
	bprm.p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
973
	bprm.p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
974
975
#ifdef CONFIG_GRKERNSEC_PAX_RANDUSTACK
976
	bprm.p -= (get_random_long() & ~(sizeof(void *)-1)) & ~PAGE_MASK;
977
#endif
978
918
	memset(bprm.page, 0, MAX_ARG_PAGES*sizeof(bprm.page[0])); 
979
	memset(bprm.page, 0, MAX_ARG_PAGES*sizeof(bprm.page[0])); 
919
980
920
	bprm.file = file;
981
	bprm.file = file;
Lines 938-948 Link Here
938
	if (retval < 0) 
999
	if (retval < 0) 
939
		goto out; 
1000
		goto out; 
940
1001
1002
	if (!gr_tpe_allow(file)) {
1003
		retval = -EACCES;
1004
		goto out;
1005
	}
1006
1007
	if(gr_check_crash_exec(file)) {
1008
		retval = -EACCES;
1009
		goto out;
1010
	}
1011
941
	retval = copy_strings_kernel(1, &bprm.filename, &bprm);
1012
	retval = copy_strings_kernel(1, &bprm.filename, &bprm);
942
	if (retval < 0) 
1013
	if (retval < 0) 
943
		goto out; 
1014
		goto out; 
944
1015
945
	bprm.exec = bprm.p;
1016
	bprm.exec = bprm.p;
1017
1018
	gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
1019
1020
	gr_handle_exec_args(&bprm, argv);
1021
946
	retval = copy_strings(bprm.envc, envp, &bprm);
1022
	retval = copy_strings(bprm.envc, envp, &bprm);
947
	if (retval < 0) 
1023
	if (retval < 0) 
948
		goto out; 
1024
		goto out; 
Lines 951-961 Link Here
951
	if (retval < 0) 
1027
	if (retval < 0) 
952
		goto out; 
1028
		goto out; 
953
1029
1030
#ifdef CONFIG_GRKERNSEC
1031
	old_acl = current->acl;
1032
	memcpy(old_rlim, current->rlim, sizeof(old_rlim));
1033
	old_exec_file = current->exec_file;
1034
	get_file(file);
1035
	current->exec_file = file;
1036
#endif
1037
1038
	gr_set_proc_label(file->f_dentry, file->f_vfsmnt);
1039
954
	retval = search_binary_handler(&bprm,regs);
1040
	retval = search_binary_handler(&bprm,regs);
955
	if (retval >= 0)
1041
	if (retval >= 0) {
1042
#ifdef CONFIG_GRKERNSEC
1043
		if (old_exec_file)
1044
			fput(old_exec_file);
1045
#endif
956
		/* execve success */
1046
		/* execve success */
957
		return retval;
1047
		return retval;
1048
	}
958
1049
1050
#ifdef CONFIG_GRKERNSEC
1051
	current->acl = old_acl;
1052
	memcpy(current->rlim, old_rlim, sizeof(old_rlim));
1053
	fput(current->exec_file);
1054
	current->exec_file = old_exec_file;
1055
#endif
959
out:
1056
out:
960
	/* Something went wrong, return the inode and free the argument pages*/
1057
	/* Something went wrong, return the inode and free the argument pages*/
961
	allow_write_access(bprm.file);
1058
	allow_write_access(bprm.file);
Lines 1097-1102 Link Here
1097
	*out_ptr = 0;
1194
	*out_ptr = 0;
1098
}
1195
}
1099
1196
1197
#if defined(CONFIG_GRKERNSEC_PAX_PAGEEXEC) || defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC)
1198
void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
1199
{
1200
	struct task_struct *tsk = current;
1201
	struct mm_struct *mm = current->mm;
1202
	char* buffer = (char*)__get_free_page(GFP_ATOMIC);
1203
	char* path=NULL;
1204
1205
	if (buffer) {
1206
		struct vm_area_struct* vma;
1207
1208
		down_read(&mm->mmap_sem);
1209
		vma = mm->mmap;
1210
		while (vma) {
1211
			if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file) {
1212
				break;
1213
			}
1214
			vma = vma->vm_next;
1215
		}
1216
		if (vma)
1217
			path = d_path(vma->vm_file->f_dentry, vma->vm_file->f_vfsmnt, buffer, PAGE_SIZE);
1218
		up_read(&mm->mmap_sem);
1219
	}
1220
	if (tsk->curr_ip)
1221
		printk(KERN_ERR "PAX: From %u.%u.%u.%u: terminating task: %s(%s):%d, uid/euid: %u/%u, "
1222
				"PC: %p, SP: %p\n", NIPQUAD(tsk->curr_ip), path, tsk->comm, tsk->pid,
1223
				tsk->uid, tsk->euid, pc, sp);
1224
	else
1225
		printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
1226
				"PC: %p, SP: %p\n", path, tsk->comm, tsk->pid,
1227
				tsk->uid, tsk->euid, pc, sp);
1228
	if (buffer) free_page((unsigned long)buffer);
1229
	pax_report_insns(pc);
1230
	do_coredump(SIGKILL, regs);
1231
}
1232
#endif
1233
1100
int do_coredump(long signr, struct pt_regs * regs)
1234
int do_coredump(long signr, struct pt_regs * regs)
1101
{
1235
{
1102
	struct linux_binfmt * binfmt;
1236
	struct linux_binfmt * binfmt;
Lines 1112-1117 Link Here
1112
	if (!is_dumpable(current))
1246
	if (!is_dumpable(current))
1113
		goto fail;
1247
		goto fail;
1114
	current->mm->dumpable = 0;
1248
	current->mm->dumpable = 0;
1249
	gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump);
1115
	if (current->rlim[RLIMIT_CORE].rlim_cur < binfmt->min_coredump)
1250
	if (current->rlim[RLIMIT_CORE].rlim_cur < binfmt->min_coredump)
1116
		goto fail;
1251
		goto fail;
1117
1252
Lines 1131-1137 Link Here
1131
		goto close_fail;
1266
		goto close_fail;
1132
	if (!file->f_op->write)
1267
	if (!file->f_op->write)
1133
		goto close_fail;
1268
		goto close_fail;
1134
	if (do_truncate(file->f_dentry, 0) != 0)
1269
	if (do_truncate(file->f_dentry, 0, file->f_vfsmnt) != 0)
1135
		goto close_fail;
1270
		goto close_fail;
1136
1271
1137
	retval = binfmt->core_dump(signr, regs, file);
1272
	retval = binfmt->core_dump(signr, regs, file);
(-)linux-2.4.22-ppc-dev.orig/fs/fcntl.c (+10 lines)
Lines 11-16 Link Here
11
#include <linux/smp_lock.h>
11
#include <linux/smp_lock.h>
12
#include <linux/slab.h>
12
#include <linux/slab.h>
13
#include <linux/iobuf.h>
13
#include <linux/iobuf.h>
14
#include <linux/grsecurity.h>
14
15
15
#include <asm/poll.h>
16
#include <asm/poll.h>
16
#include <asm/siginfo.h>
17
#include <asm/siginfo.h>
Lines 64-69 Link Here
64
	int error;
65
	int error;
65
	int start;
66
	int start;
66
67
68
	gr_learn_resource(current, RLIMIT_NOFILE, orig_start);
69
67
	write_lock(&files->file_lock);
70
	write_lock(&files->file_lock);
68
	
71
	
69
	error = -EINVAL;
72
	error = -EINVAL;
Lines 86-91 Link Here
86
	}
89
	}
87
	
90
	
88
	error = -EMFILE;
91
	error = -EMFILE;
92
	gr_learn_resource(current, RLIMIT_NOFILE, newfd);
89
	if (newfd >= current->rlim[RLIMIT_NOFILE].rlim_cur)
93
	if (newfd >= current->rlim[RLIMIT_NOFILE].rlim_cur)
90
		goto out;
94
		goto out;
91
95
Lines 141-146 Link Here
141
	struct file * file, *tofree;
145
	struct file * file, *tofree;
142
	struct files_struct * files = current->files;
146
	struct files_struct * files = current->files;
143
147
148
	gr_learn_resource(current, RLIMIT_NOFILE, newfd);
149
144
	write_lock(&files->file_lock);
150
	write_lock(&files->file_lock);
145
	if (!(file = fcheck(oldfd)))
151
	if (!(file = fcheck(oldfd)))
146
		goto out_unlock;
152
		goto out_unlock;
Lines 448-453 Link Here
448
			match = -p->pgrp;
454
			match = -p->pgrp;
449
		if (pid != match)
455
		if (pid != match)
450
			continue;
456
			continue;
457
		if (gr_check_protected_task(p))
458
			continue;
459
		if (gr_pid_is_chrooted(p))
460
			continue;
451
		send_sigio_to_task(p, fown, fd, band);
461
		send_sigio_to_task(p, fown, fd, band);
452
	}
462
	}
453
out:
463
out:
(-)linux-2.4.22-ppc-dev.orig/fs/locks.c (+1 lines)
Lines 138-143 Link Here
138
static struct file_lock *locks_alloc_lock(int account)
138
static struct file_lock *locks_alloc_lock(int account)
139
{
139
{
140
	struct file_lock *fl;
140
	struct file_lock *fl;
141
	if(account) gr_learn_resource(current, RLIMIT_LOCKS, current->locks);
141
	if (account && current->locks >= current->rlim[RLIMIT_LOCKS].rlim_cur)
142
	if (account && current->locks >= current->rlim[RLIMIT_LOCKS].rlim_cur)
142
		return NULL;
143
		return NULL;
143
	fl = kmem_cache_alloc(filelock_cache, SLAB_KERNEL);
144
	fl = kmem_cache_alloc(filelock_cache, SLAB_KERNEL);
(-)linux-2.4.22-ppc-dev.orig/fs/namei.c (-10 / +165 lines)
Lines 22-27 Link Here
22
#include <linux/dnotify.h>
22
#include <linux/dnotify.h>
23
#include <linux/smp_lock.h>
23
#include <linux/smp_lock.h>
24
#include <linux/personality.h>
24
#include <linux/personality.h>
25
#include <linux/grsecurity.h>
25
26
26
#include <asm/namei.h>
27
#include <asm/namei.h>
27
#include <asm/uaccess.h>
28
#include <asm/uaccess.h>
Lines 343-348 Link Here
343
		current->state = TASK_RUNNING;
344
		current->state = TASK_RUNNING;
344
		schedule();
345
		schedule();
345
	}
346
	}
347
348
	if (gr_handle_follow_link(dentry->d_parent->d_inode,
349
				  dentry->d_inode, dentry, nd->mnt)) {
350
		path_release(nd);
351
		return -EACCES;
352
	}
353
346
	current->link_count++;
354
	current->link_count++;
347
	current->total_link_count++;
355
	current->total_link_count++;
348
	UPDATE_ATIME(dentry->d_inode);
356
	UPDATE_ATIME(dentry->d_inode);
Lines 643-648 Link Here
643
			}
651
			}
644
		}
652
		}
645
return_base:
653
return_base:
654
		if (!gr_acl_handle_hidden_file(nd->dentry, nd->mnt)) {
655
			path_release(nd);
656
			return -ENOENT;
657
		}
646
		return 0;
658
		return 0;
647
out_dput:
659
out_dput:
648
		dput(dentry);
660
		dput(dentry);
Lines 1005-1011 Link Here
1005
	struct dentry *dentry;
1017
	struct dentry *dentry;
1006
	struct dentry *dir;
1018
	struct dentry *dir;
1007
	int count = 0;
1019
	int count = 0;
1008
1020
	
1009
	acc_mode = ACC_MODE(flag);
1021
	acc_mode = ACC_MODE(flag);
1010
1022
1011
	/*
1023
	/*
Lines 1015-1021 Link Here
1015
		error = path_lookup(pathname, lookup_flags(flag), nd);
1027
		error = path_lookup(pathname, lookup_flags(flag), nd);
1016
		if (error)
1028
		if (error)
1017
			return error;
1029
			return error;
1030
1031
		if (gr_handle_rawio(nd->dentry->d_inode)) {
1032
			error = -EPERM;
1033
			goto exit;
1034
		}
1035
	
1036
		if (!gr_acl_handle_open(nd->dentry, nd->mnt, flag)) {
1037
			error = -EACCES;
1038
			goto exit;
1039
		}
1040
1018
		dentry = nd->dentry;
1041
		dentry = nd->dentry;
1042
1019
		goto ok;
1043
		goto ok;
1020
	}
1044
	}
1021
1045
Lines 1048-1055 Link Here
1048
1072
1049
	/* Negative dentry, just create the file */
1073
	/* Negative dentry, just create the file */
1050
	if (!dentry->d_inode) {
1074
	if (!dentry->d_inode) {
1075
		if (!gr_acl_handle_creat(dentry, nd->dentry, nd->mnt, flag, mode)) {
1076
			error = -EACCES;
1077
			up(&dir->d_inode->i_sem);
1078
			goto exit_dput;
1079
		}
1080
1051
		error = vfs_create(dir->d_inode, dentry,
1081
		error = vfs_create(dir->d_inode, dentry,
1052
				   mode & ~current->fs->umask);
1082
				   mode & ~current->fs->umask);
1083
		if (!error)
1084
			gr_handle_create(dentry, nd->mnt);
1085
1053
		up(&dir->d_inode->i_sem);
1086
		up(&dir->d_inode->i_sem);
1054
		dput(nd->dentry);
1087
		dput(nd->dentry);
1055
		nd->dentry = dentry;
1088
		nd->dentry = dentry;
Lines 1058-1069 Link Here
1058
		/* Don't check for write permission, don't truncate */
1091
		/* Don't check for write permission, don't truncate */
1059
		acc_mode = 0;
1092
		acc_mode = 0;
1060
		flag &= ~O_TRUNC;
1093
		flag &= ~O_TRUNC;
1094
1061
		goto ok;
1095
		goto ok;
1062
	}
1096
	}
1063
1097
1064
	/*
1098
	/*
1065
	 * It already exists.
1099
	 * It already exists.
1066
	 */
1100
	 */
1101
1102
	if (gr_acl_is_enabled() && S_ISBLK(dentry->d_inode->i_mode) &&
1103
	    !capable(CAP_SYS_RAWIO)) {
1104
		error = -EPERM;
1105
		up(&dir->d_inode->i_sem);
1106
		goto exit_dput;
1107
	}
1108
1109
	if (!gr_acl_handle_open(dentry, nd->mnt, flag)) {
1110
		error = -EACCES;
1111
		up(&dir->d_inode->i_sem);
1112
		goto exit_dput;
1113
	}
1114
1115
	inode = dentry->d_inode;
1116
1117
	if (gr_handle_fifo(dentry, nd->mnt, dir, flag, acc_mode)) {
1118
		up(&dir->d_inode->i_sem);
1119
		error = -EACCES;
1120
		goto exit_dput;
1121
	}
1122
1067
	up(&dir->d_inode->i_sem);
1123
	up(&dir->d_inode->i_sem);
1068
1124
1069
	error = -EEXIST;
1125
	error = -EEXIST;
Lines 1153-1159 Link Here
1153
		if (!error) {
1209
		if (!error) {
1154
			DQUOT_INIT(inode);
1210
			DQUOT_INIT(inode);
1155
			
1211
			
1156
			error = do_truncate(dentry, 0);
1212
			error = do_truncate(dentry,0,nd->mnt);
1157
		}
1213
		}
1158
		put_write_access(inode);
1214
		put_write_access(inode);
1159
		if (error)
1215
		if (error)
Lines 1184-1189 Link Here
1184
	 * stored in nd->last.name and we will have to putname() it when we
1240
	 * stored in nd->last.name and we will have to putname() it when we
1185
	 * are done. Procfs-like symlinks just set LAST_BIND.
1241
	 * are done. Procfs-like symlinks just set LAST_BIND.
1186
	 */
1242
	 */
1243
1244
	if (gr_handle_follow_link(dentry->d_parent->d_inode, dentry->d_inode,
1245
				  dentry, nd->mnt)) {
1246
		error = -EACCES;
1247
		goto exit_dput;
1248
	}
1249
1187
	UPDATE_ATIME(dentry->d_inode);
1250
	UPDATE_ATIME(dentry->d_inode);
1188
	error = dentry->d_inode->i_op->follow_link(dentry, nd);
1251
	error = dentry->d_inode->i_op->follow_link(dentry, nd);
1189
	dput(dentry);
1252
	dput(dentry);
Lines 1282-1287 Link Here
1282
1345
1283
	mode &= ~current->fs->umask;
1346
	mode &= ~current->fs->umask;
1284
	if (!IS_ERR(dentry)) {
1347
	if (!IS_ERR(dentry)) {
1348
		if (gr_handle_chroot_mknod(dentry, nd.mnt, mode)) {
1349
			error = -EPERM;
1350
			dput(dentry);
1351
			goto out_dput;
1352
		}
1353
1354
		if (!gr_acl_handle_mknod(dentry, nd.dentry, nd.mnt, mode)) {
1355
			error = -EACCES;
1356
			dput(dentry);
1357
			goto out_dput;
1358
		}
1359
	
1285
		switch (mode & S_IFMT) {
1360
		switch (mode & S_IFMT) {
1286
		case 0: case S_IFREG:
1361
		case 0: case S_IFREG:
1287
			error = vfs_create(nd.dentry->d_inode,dentry,mode);
1362
			error = vfs_create(nd.dentry->d_inode,dentry,mode);
Lines 1295-1302 Link Here
1295
		default:
1370
		default:
1296
			error = -EINVAL;
1371
			error = -EINVAL;
1297
		}
1372
		}
1373
1374
		if(!error)
1375
			gr_handle_create(dentry, nd.mnt);
1376
1298
		dput(dentry);
1377
		dput(dentry);
1299
	}
1378
	}
1379
out_dput:
1300
	up(&nd.dentry->d_inode->i_sem);
1380
	up(&nd.dentry->d_inode->i_sem);
1301
	path_release(&nd);
1381
	path_release(&nd);
1302
out:
1382
out:
Lines 1348-1355 Link Here
1348
		dentry = lookup_create(&nd, 1);
1428
		dentry = lookup_create(&nd, 1);
1349
		error = PTR_ERR(dentry);
1429
		error = PTR_ERR(dentry);
1350
		if (!IS_ERR(dentry)) {
1430
		if (!IS_ERR(dentry)) {
1351
			error = vfs_mkdir(nd.dentry->d_inode, dentry,
1431
			error = 0;
1432
1433
			if (!gr_acl_handle_mkdir(dentry, nd.dentry, nd.mnt))
1434
				error = -EACCES;
1435
1436
			if(!error)
1437
				error = vfs_mkdir(nd.dentry->d_inode, dentry,
1352
					  mode & ~current->fs->umask);
1438
					  mode & ~current->fs->umask);
1439
			if(!error)
1440
				gr_handle_create(dentry, nd.mnt);
1441
			
1353
			dput(dentry);
1442
			dput(dentry);
1354
		}
1443
		}
1355
		up(&nd.dentry->d_inode->i_sem);
1444
		up(&nd.dentry->d_inode->i_sem);
Lines 1433-1438 Link Here
1433
	char * name;
1522
	char * name;
1434
	struct dentry *dentry;
1523
	struct dentry *dentry;
1435
	struct nameidata nd;
1524
	struct nameidata nd;
1525
	ino_t saved_ino = 0;
1526
	kdev_t saved_dev = 0;
1436
1527
1437
	name = getname(pathname);
1528
	name = getname(pathname);
1438
	if(IS_ERR(name))
1529
	if(IS_ERR(name))
Lines 1457-1463 Link Here
1457
	dentry = lookup_hash(&nd.last, nd.dentry);
1548
	dentry = lookup_hash(&nd.last, nd.dentry);
1458
	error = PTR_ERR(dentry);
1549
	error = PTR_ERR(dentry);
1459
	if (!IS_ERR(dentry)) {
1550
	if (!IS_ERR(dentry)) {
1460
		error = vfs_rmdir(nd.dentry->d_inode, dentry);
1551
		error = 0;
1552
		if (dentry->d_inode) {
1553
			if (dentry->d_inode->i_nlink <= 1) {
1554
				saved_ino = dentry->d_inode->i_ino;
1555
				saved_dev = dentry->d_inode->i_dev;
1556
			}
1557
1558
			if (!gr_acl_handle_rmdir(dentry, nd.mnt))
1559
				error = -EACCES;
1560
		}
1561
1562
		if (!error)
1563
			error = vfs_rmdir(nd.dentry->d_inode, dentry);
1564
		if (!error && (saved_dev || saved_ino))
1565
			gr_handle_delete(saved_ino,saved_dev);
1566
1461
		dput(dentry);
1567
		dput(dentry);
1462
	}
1568
	}
1463
	up(&nd.dentry->d_inode->i_sem);
1569
	up(&nd.dentry->d_inode->i_sem);
Lines 1501-1506 Link Here
1501
	char * name;
1607
	char * name;
1502
	struct dentry *dentry;
1608
	struct dentry *dentry;
1503
	struct nameidata nd;
1609
	struct nameidata nd;
1610
	ino_t saved_ino = 0;
1611
	kdev_t saved_dev = 0;
1504
1612
1505
	name = getname(pathname);
1613
	name = getname(pathname);
1506
	if(IS_ERR(name))
1614
	if(IS_ERR(name))
Lines 1519-1525 Link Here
1519
		/* Why not before? Because we want correct error value */
1627
		/* Why not before? Because we want correct error value */
1520
		if (nd.last.name[nd.last.len])
1628
		if (nd.last.name[nd.last.len])
1521
			goto slashes;
1629
			goto slashes;
1522
		error = vfs_unlink(nd.dentry->d_inode, dentry);
1630
		error = 0;
1631
		if (dentry->d_inode) {
1632
			if (dentry->d_inode->i_nlink <= 1) {
1633
				saved_ino = dentry->d_inode->i_ino;
1634
				saved_dev = dentry->d_inode->i_dev;
1635
			}
1636
1637
			if (!gr_acl_handle_unlink(dentry, nd.mnt))
1638
				error = -EACCES;
1639
		}
1640
1641
		if (!error)
1642
			error = vfs_unlink(nd.dentry->d_inode, dentry);
1643
		if (!error && (saved_ino || saved_dev))
1644
			gr_handle_delete(saved_ino,saved_dev);
1523
	exit2:
1645
	exit2:
1524
		dput(dentry);
1646
		dput(dentry);
1525
	}
1647
	}
Lines 1583-1589 Link Here
1583
		dentry = lookup_create(&nd, 0);
1705
		dentry = lookup_create(&nd, 0);
1584
		error = PTR_ERR(dentry);
1706
		error = PTR_ERR(dentry);
1585
		if (!IS_ERR(dentry)) {
1707
		if (!IS_ERR(dentry)) {
1586
			error = vfs_symlink(nd.dentry->d_inode, dentry, from);
1708
			error = 0;
1709
1710
			if (!gr_acl_handle_symlink(dentry, nd.dentry, nd.mnt, from))
1711
				error = -EACCES;
1712
1713
			if(!error)	
1714
				error = vfs_symlink(nd.dentry->d_inode, dentry, from);
1715
			if (!error)
1716
				gr_handle_create(dentry, nd.mnt);
1587
			dput(dentry);
1717
			dput(dentry);
1588
		}
1718
		}
1589
		up(&nd.dentry->d_inode->i_sem);
1719
		up(&nd.dentry->d_inode->i_sem);
Lines 1667-1673 Link Here
1667
		new_dentry = lookup_create(&nd, 0);
1797
		new_dentry = lookup_create(&nd, 0);
1668
		error = PTR_ERR(new_dentry);
1798
		error = PTR_ERR(new_dentry);
1669
		if (!IS_ERR(new_dentry)) {
1799
		if (!IS_ERR(new_dentry)) {
1670
			error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
1800
			error = 0;
1801
1802
			if (gr_handle_hardlink(old_nd.dentry, old_nd.mnt,
1803
					       old_nd.dentry->d_inode,
1804
					       old_nd.dentry->d_inode->i_mode, to)) {
1805
				error = -EPERM;
1806
				goto out_error;
1807
			}
1808
1809
			if (!gr_acl_handle_link(new_dentry, nd.dentry, nd.mnt,
1810
						 old_nd.dentry, old_nd.mnt, to)) {
1811
				error = -EACCES;
1812
				goto out_error;
1813
			}
1814
1815
			error = vfs_link(old_nd.dentry, 
1816
					nd.dentry->d_inode, new_dentry);
1817
1818
			if (!error)
1819
				gr_handle_create(new_dentry, nd.mnt);
1820
out_error:
1671
			dput(new_dentry);
1821
			dput(new_dentry);
1672
		}
1822
		}
1673
		up(&nd.dentry->d_inode->i_sem);
1823
		up(&nd.dentry->d_inode->i_sem);
Lines 1898-1907 Link Here
1898
	if (IS_ERR(new_dentry))
2048
	if (IS_ERR(new_dentry))
1899
		goto exit4;
2049
		goto exit4;
1900
2050
1901
	lock_kernel();
2051
	error = gr_acl_handle_rename(new_dentry, newnd.dentry, newnd.mnt,
1902
	error = vfs_rename(old_dir->d_inode, old_dentry,
2052
				     old_dentry, old_dir->d_inode, oldnd.mnt, newname);
2053
2054
	if (error == 1) {
2055
		lock_kernel();
2056
		error = vfs_rename(old_dir->d_inode, old_dentry,
1903
				   new_dir->d_inode, new_dentry);
2057
				   new_dir->d_inode, new_dentry);
1904
	unlock_kernel();
2058
		unlock_kernel();
2059
	}
1905
2060
1906
	dput(new_dentry);
2061
	dput(new_dentry);
1907
exit4:
2062
exit4:
(-)linux-2.4.22-ppc-dev.orig/fs/namespace.c (+19 lines)
Lines 15-20 Link Here
15
#include <linux/quotaops.h>
15
#include <linux/quotaops.h>
16
#include <linux/acct.h>
16
#include <linux/acct.h>
17
#include <linux/module.h>
17
#include <linux/module.h>
18
#include <linux/sched.h>
19
#include <linux/grsecurity.h>
18
20
19
#include <asm/uaccess.h>
21
#include <asm/uaccess.h>
20
22
Lines 325-330 Link Here
325
			lock_kernel();
327
			lock_kernel();
326
			retval = do_remount_sb(sb, MS_RDONLY, 0);
328
			retval = do_remount_sb(sb, MS_RDONLY, 0);
327
			unlock_kernel();
329
			unlock_kernel();
330
331
			gr_log_remount(mnt->mnt_devname, retval);
328
		}
332
		}
329
		up_write(&sb->s_umount);
333
		up_write(&sb->s_umount);
330
		return retval;
334
		return retval;
Lines 350-355 Link Here
350
	}
354
	}
351
	spin_unlock(&dcache_lock);
355
	spin_unlock(&dcache_lock);
352
	up_write(&current->namespace->sem);
356
	up_write(&current->namespace->sem);
357
358
	gr_log_unmount(mnt->mnt_devname, retval);
359
353
	return retval;
360
	return retval;
354
}
361
}
355
362
Lines 729-734 Link Here
729
	if (retval)
736
	if (retval)
730
		return retval;
737
		return retval;
731
738
739
	if (gr_handle_chroot_mount(nd.dentry, nd.mnt, dev_name)) {
740
		retval = -EPERM;
741
		path_release(&nd);
742
		return retval;
743
	}
744
732
	if (flags & MS_REMOUNT)
745
	if (flags & MS_REMOUNT)
733
		retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
746
		retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
734
				    data_page);
747
				    data_page);
Lines 740-745 Link Here
740
		retval = do_add_mount(&nd, type_page, flags, mnt_flags,
753
		retval = do_add_mount(&nd, type_page, flags, mnt_flags,
741
				      dev_name, data_page);
754
				      dev_name, data_page);
742
	path_release(&nd);
755
	path_release(&nd);
756
757
	gr_log_mount(dev_name, dir_name, retval);
758
743
	return retval;
759
	return retval;
744
}
760
}
745
761
Lines 909-914 Link Here
909
	if (!capable(CAP_SYS_ADMIN))
925
	if (!capable(CAP_SYS_ADMIN))
910
		return -EPERM;
926
		return -EPERM;
911
927
928
	if (gr_handle_chroot_pivot())
929
		return -EPERM;
930
912
	lock_kernel();
931
	lock_kernel();
913
932
914
	error = __user_walk(new_root, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &new_nd);
933
	error = __user_walk(new_root, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &new_nd);
(-)linux-2.4.22-ppc-dev.orig/fs/open.c (-7 / +75 lines)
Lines 15-20 Link Here
15
#include <linux/slab.h>
15
#include <linux/slab.h>
16
#include <linux/tty.h>
16
#include <linux/tty.h>
17
#include <linux/iobuf.h>
17
#include <linux/iobuf.h>
18
#include <linux/grsecurity.h>
18
19
19
#include <asm/uaccess.h>
20
#include <asm/uaccess.h>
20
21
Lines 95-101 Link Here
95
	write_unlock(&files->file_lock);
96
	write_unlock(&files->file_lock);
96
}
97
}
97
98
98
int do_truncate(struct dentry *dentry, loff_t length)
99
int do_truncate(struct dentry *dentry, loff_t length, struct vfsmount *mnt)
99
{
100
{
100
	struct inode *inode = dentry->d_inode;
101
	struct inode *inode = dentry->d_inode;
101
	int error;
102
	int error;
Lines 105-110 Link Here
105
	if (length < 0)
106
	if (length < 0)
106
		return -EINVAL;
107
		return -EINVAL;
107
108
109
	if (!gr_acl_handle_truncate(dentry, mnt))
110
		return -EACCES;
111
108
	down_write(&inode->i_alloc_sem);
112
	down_write(&inode->i_alloc_sem);
109
	down(&inode->i_sem);
113
	down(&inode->i_sem);
110
	newattrs.ia_size = length;
114
	newattrs.ia_size = length;
Lines 165-171 Link Here
165
	error = locks_verify_truncate(inode, NULL, length);
169
	error = locks_verify_truncate(inode, NULL, length);
166
	if (!error) {
170
	if (!error) {
167
		DQUOT_INIT(inode);
171
		DQUOT_INIT(inode);
168
		error = do_truncate(nd.dentry, length);
172
		error = do_truncate(nd.dentry, length, nd.mnt);
169
	}
173
	}
170
	put_write_access(inode);
174
	put_write_access(inode);
171
175
Lines 217-223 Link Here
217
221
218
	error = locks_verify_truncate(inode, file, length);
222
	error = locks_verify_truncate(inode, file, length);
219
	if (!error)
223
	if (!error)
220
		error = do_truncate(dentry, length);
224
		error = do_truncate(dentry, length, file->f_vfsmnt);
221
out_putf:
225
out_putf:
222
	fput(file);
226
	fput(file);
223
out:
227
out:
Lines 286-291 Link Here
286
		    (error = permission(inode,MAY_WRITE)) != 0)
290
		    (error = permission(inode,MAY_WRITE)) != 0)
287
			goto dput_and_out;
291
			goto dput_and_out;
288
	}
292
	}
293
294
	if (!gr_acl_handle_utime(nd.dentry, nd.mnt)) {
295
		error = -EACCES;
296
		goto dput_and_out;
297
	}
298
289
	error = notify_change(nd.dentry, &newattrs);
299
	error = notify_change(nd.dentry, &newattrs);
290
dput_and_out:
300
dput_and_out:
291
	path_release(&nd);
301
	path_release(&nd);
Lines 331-336 Link Here
331
		    (error = permission(inode,MAY_WRITE)) != 0)
341
		    (error = permission(inode,MAY_WRITE)) != 0)
332
			goto dput_and_out;
342
			goto dput_and_out;
333
	}
343
	}
344
345
	if (!gr_acl_handle_utime(nd.dentry, nd.mnt)) {
346
		error = -EACCES;
347
		goto dput_and_out;
348
	}
349
334
	error = notify_change(nd.dentry, &newattrs);
350
	error = notify_change(nd.dentry, &newattrs);
335
dput_and_out:
351
dput_and_out:
336
	path_release(&nd);
352
	path_release(&nd);
Lines 373-378 Link Here
373
		if(!res && (mode & S_IWOTH) && IS_RDONLY(nd.dentry->d_inode)
389
		if(!res && (mode & S_IWOTH) && IS_RDONLY(nd.dentry->d_inode)
374
		   && !special_file(nd.dentry->d_inode->i_mode))
390
		   && !special_file(nd.dentry->d_inode->i_mode))
375
			res = -EROFS;
391
			res = -EROFS;
392
		
393
		if (!res && !gr_acl_handle_access(nd.dentry, nd.mnt, mode))
394
			res =  -EACCES;
395
376
		path_release(&nd);
396
		path_release(&nd);
377
	}
397
	}
378
398
Lines 396-401 Link Here
396
	if (error)
416
	if (error)
397
		goto dput_and_out;
417
		goto dput_and_out;
398
418
419
	gr_log_chdir(nd.dentry, nd.mnt);
420
399
	set_fs_pwd(current->fs, nd.mnt, nd.dentry);
421
	set_fs_pwd(current->fs, nd.mnt, nd.dentry);
400
422
401
dput_and_out:
423
dput_and_out:
Lines 426-431 Link Here
426
		goto out_putf;
448
		goto out_putf;
427
449
428
	error = permission(inode, MAY_EXEC);
450
	error = permission(inode, MAY_EXEC);
451
452
	if (!error && !gr_chroot_fchdir(dentry, mnt))
453
		error = -EPERM;
454
455
	if (!error)
456
		gr_log_chdir(dentry, mnt);
457
429
	if (!error)
458
	if (!error)
430
		set_fs_pwd(current->fs, mnt, dentry);
459
		set_fs_pwd(current->fs, mnt, dentry);
431
out_putf:
460
out_putf:
Lines 452-459 Link Here
452
	if (!capable(CAP_SYS_CHROOT))
481
	if (!capable(CAP_SYS_CHROOT))
453
		goto dput_and_out;
482
		goto dput_and_out;
454
483
484
	if (gr_handle_chroot_chroot(nd.dentry, nd.mnt))
485
		goto dput_and_out;
486
455
	set_fs_root(current->fs, nd.mnt, nd.dentry);
487
	set_fs_root(current->fs, nd.mnt, nd.dentry);
456
	set_fs_altroot();
488
	set_fs_altroot();
489
490
	gr_handle_chroot_caps(current);
491
492
	gr_handle_chroot_chdir(nd.dentry, nd.mnt);
493
457
	error = 0;
494
	error = 0;
458
dput_and_out:
495
dput_and_out:
459
	path_release(&nd);
496
	path_release(&nd);
Lines 482-489 Link Here
482
	err = -EPERM;
519
	err = -EPERM;
483
	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
520
	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
484
		goto out_putf;
521
		goto out_putf;
522
523
	if (!gr_acl_handle_fchmod(dentry, file->f_vfsmnt, mode)) {
524
		err = -EACCES;
525
		goto out_putf;
526
	}
527
485
	if (mode == (mode_t) -1)
528
	if (mode == (mode_t) -1)
486
		mode = inode->i_mode;
529
		mode = inode->i_mode;
530
531
	if (gr_handle_chroot_chmod(dentry, file->f_vfsmnt, mode)) {
532
		err = -EPERM;
533
		goto out_putf;
534
	}	    
535
487
	newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
536
	newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
488
	newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
537
	newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
489
	err = notify_change(dentry, &newattrs);
538
	err = notify_change(dentry, &newattrs);
Lines 514-521 Link Here
514
	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
563
	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
515
		goto dput_and_out;
564
		goto dput_and_out;
516
565
566
	if (!gr_acl_handle_chmod(nd.dentry, nd.mnt, mode)) {
567
		error = -EACCES;
568
		goto dput_and_out;
569
	}
570
517
	if (mode == (mode_t) -1)
571
	if (mode == (mode_t) -1)
518
		mode = inode->i_mode;
572
		mode = inode->i_mode;
573
574
	if (gr_handle_chroot_chmod(nd.dentry, nd.mnt, mode)) {
575
		error = -EACCES;
576
		goto dput_and_out;
577
	}
578
519
	newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
579
	newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
520
	newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
580
	newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
521
	error = notify_change(nd.dentry, &newattrs);
581
	error = notify_change(nd.dentry, &newattrs);
Lines 526-532 Link Here
526
	return error;
586
	return error;
527
}
587
}
528
588
529
static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
589
static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
530
{
590
{
531
	struct inode * inode;
591
	struct inode * inode;
532
	int error;
592
	int error;
Lines 543-548 Link Here
543
	error = -EPERM;
603
	error = -EPERM;
544
	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
604
	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
545
		goto out;
605
		goto out;
606
607
	if (!gr_acl_handle_chown(dentry, mnt)) {
608
		error = -EACCES;
609
		goto out;
610
	}
611
546
	if (user == (uid_t) -1)
612
	if (user == (uid_t) -1)
547
		user = inode->i_uid;
613
		user = inode->i_uid;
548
	if (group == (gid_t) -1)
614
	if (group == (gid_t) -1)
Lines 593-599 Link Here
593
659
594
	error = user_path_walk(filename, &nd);
660
	error = user_path_walk(filename, &nd);
595
	if (!error) {
661
	if (!error) {
596
		error = chown_common(nd.dentry, user, group);
662
		error = chown_common(nd.dentry, user, group, nd.mnt);
597
		path_release(&nd);
663
		path_release(&nd);
598
	}
664
	}
599
	return error;
665
	return error;
Lines 606-612 Link Here
606
672
607
	error = user_path_walk_link(filename, &nd);
673
	error = user_path_walk_link(filename, &nd);
608
	if (!error) {
674
	if (!error) {
609
		error = chown_common(nd.dentry, user, group);
675
		error = chown_common(nd.dentry, user, group, nd.mnt);
610
		path_release(&nd);
676
		path_release(&nd);
611
	}
677
	}
612
	return error;
678
	return error;
Lines 620-626 Link Here
620
686
621
	file = fget(fd);
687
	file = fget(fd);
622
	if (file) {
688
	if (file) {
623
		error = chown_common(file->f_dentry, user, group);
689
		error = chown_common(file->f_dentry, user,
690
				group, file->f_vfsmnt);
624
		fput(file);
691
		fput(file);
625
	}
692
	}
626
	return error;
693
	return error;
Lines 740-745 Link Here
740
	 * N.B. For clone tasks sharing a files structure, this test
807
	 * N.B. For clone tasks sharing a files structure, this test
741
	 * will limit the total number of files that can be opened.
808
	 * will limit the total number of files that can be opened.
742
	 */
809
	 */
810
	gr_learn_resource(current, RLIMIT_NOFILE, fd);
743
	if (fd >= current->rlim[RLIMIT_NOFILE].rlim_cur)
811
	if (fd >= current->rlim[RLIMIT_NOFILE].rlim_cur)
744
		goto out;
812
		goto out;
745
813
(-)linux-2.4.22-ppc-dev.orig/fs/proc/array.c (+54 lines)
Lines 297-302 Link Here
297
	return buffer - orig;
297
	return buffer - orig;
298
}
298
}
299
299
300
#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
301
#define PAX_RAND_FLAGS (task->flags & PF_PAX_RANDMMAP || \
302
		        task->flags & PF_PAX_SEGMEXEC || \
303
			task->flags & PF_PAX_RANDEXEC)
304
#endif
305
300
int proc_pid_stat(struct task_struct *task, char * buffer)
306
int proc_pid_stat(struct task_struct *task, char * buffer)
301
{
307
{
302
	unsigned long vsize, eip, esp, wchan;
308
	unsigned long vsize, eip, esp, wchan;
Lines 334-339 Link Here
334
340
335
	wchan = get_wchan(task);
341
	wchan = get_wchan(task);
336
342
343
#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
344
	if (PAX_RAND_FLAGS) {
345
		eip = 0;
346
		esp = 0;
347
		wchan = 0;
348
	}
349
#endif
350
#ifdef CONFIG_GRKERNSEC_HIDESYM
351
	wchan = 0;
352
	eip = 0;
353
	esp = 0;
354
#endif
355
337
	collect_sigign_sigcatch(task, &sigign, &sigcatch);
356
	collect_sigign_sigcatch(task, &sigign, &sigcatch);
338
357
339
	/* scale priority and nice values from timeslices to -20..20 */
358
	/* scale priority and nice values from timeslices to -20..20 */
Lines 373-381 Link Here
373
		vsize,
392
		vsize,
374
		mm ? mm->rss : 0, /* you might want to shift this left 3 */
393
		mm ? mm->rss : 0, /* you might want to shift this left 3 */
375
		task->rlim[RLIMIT_RSS].rlim_cur,
394
		task->rlim[RLIMIT_RSS].rlim_cur,
395
#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
396
		PAX_RAND_FLAGS ? 0 : (mm ? mm->start_code : 0),
397
		PAX_RAND_FLAGS ? 0 : (mm ? mm->end_code : 0),
398
		PAX_RAND_FLAGS ? 0 : (mm ? mm->start_stack : 0),
399
#else
376
		mm ? mm->start_code : 0,
400
		mm ? mm->start_code : 0,
377
		mm ? mm->end_code : 0,
401
		mm ? mm->end_code : 0,
378
		mm ? mm->start_stack : 0,
402
		mm ? mm->start_stack : 0,
403
#endif
379
		esp,
404
		esp,
380
		eip,
405
		eip,
381
		/* The signal information here is obsolete.
406
		/* The signal information here is obsolete.
Lines 541-547 Link Here
541
#define MAPS_LINE_FORMAT	(sizeof(void*) == 4 ? MAPS_LINE_FORMAT4 : MAPS_LINE_FORMAT8)
566
#define MAPS_LINE_FORMAT	(sizeof(void*) == 4 ? MAPS_LINE_FORMAT4 : MAPS_LINE_FORMAT8)
542
#define MAPS_LINE_MAX	(sizeof(void*) == 4 ?  MAPS_LINE_MAX4 :  MAPS_LINE_MAX8)
567
#define MAPS_LINE_MAX	(sizeof(void*) == 4 ?  MAPS_LINE_MAX4 :  MAPS_LINE_MAX8)
543
568
569
#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
570
static int proc_pid_maps_get_line (char *buf, struct vm_area_struct *map,
571
				   struct task_struct *task)
572
#else
544
static int proc_pid_maps_get_line (char *buf, struct vm_area_struct *map)
573
static int proc_pid_maps_get_line (char *buf, struct vm_area_struct *map)
574
#endif
545
{
575
{
546
	/* produce the next line */
576
	/* produce the next line */
547
	char *line;
577
	char *line;
Lines 576-581 Link Here
576
	} else
606
	} else
577
		line = buf;
607
		line = buf;
578
608
609
#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
610
	if (task->flags & PF_PAX_RANDMMAP ||
611
	    task->flags & PF_PAX_SEGMEXEC ||
612
	    task->flags & PF_PAX_RANDEXEC)
613
		len = sprintf(line,
614
			      MAPS_LINE_FORMAT,
615
			      0UL, 0UL, str, 0UL,
616
			      kdevname(dev), ino);
617
	else
618
#endif
579
	len = sprintf(line,
619
	len = sprintf(line,
580
		      MAPS_LINE_FORMAT,
620
		      MAPS_LINE_FORMAT,
581
		      map->vm_start, map->vm_end, str, map->vm_pgoff << PAGE_SHIFT,
621
		      map->vm_start, map->vm_end, str, map->vm_pgoff << PAGE_SHIFT,
Lines 641-647 Link Here
641
			off -= PAGE_SIZE;
681
			off -= PAGE_SIZE;
642
			goto next;
682
			goto next;
643
		}
683
		}
684
#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
685
		len = proc_pid_maps_get_line(tmp, map, task);
686
#else
644
		len = proc_pid_maps_get_line(tmp, map);
687
		len = proc_pid_maps_get_line(tmp, map);
688
#endif
645
		if (len < 0)
689
		if (len < 0)
646
			goto out_unlock;
690
			goto out_unlock;
647
		len -= off;
691
		len -= off;
Lines 684-689 Link Here
684
	return retval;
728
	return retval;
685
}
729
}
686
730
731
#ifdef CONFIG_GRKERNSEC_PROC_IPADDR	 
732
int proc_pid_ipaddr(struct task_struct *task, char * buffer)	 
733
{	 
734
	int len;	 
735
736
	len = sprintf(buffer, "%u.%u.%u.%u\n", NIPQUAD(task->curr_ip));	 
737
	return len;	 
738
}	 
739
#endif
740
687
#ifdef CONFIG_SMP
741
#ifdef CONFIG_SMP
688
int proc_pid_cpu(struct task_struct *task, char * buffer)
742
int proc_pid_cpu(struct task_struct *task, char * buffer)
689
{
743
{
(-)linux-2.4.22-ppc-dev.orig/fs/proc/base.c (-1 / +70 lines)
Lines 25-30 Link Here
25
#include <linux/string.h>
25
#include <linux/string.h>
26
#include <linux/seq_file.h>
26
#include <linux/seq_file.h>
27
#include <linux/namespace.h>
27
#include <linux/namespace.h>
28
#include <linux/grsecurity.h>
28
29
29
/*
30
/*
30
 * For hysterical raisins we keep the same inumbers as in the old procfs.
31
 * For hysterical raisins we keep the same inumbers as in the old procfs.
Lines 41-46 Link Here
41
int proc_pid_status(struct task_struct*,char*);
42
int proc_pid_status(struct task_struct*,char*);
42
int proc_pid_statm(struct task_struct*,char*);
43
int proc_pid_statm(struct task_struct*,char*);
43
int proc_pid_cpu(struct task_struct*,char*);
44
int proc_pid_cpu(struct task_struct*,char*);
45
#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
46
int proc_pid_ipaddr(struct task_struct*,char*);
47
#endif
44
48
45
static int proc_fd_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
49
static int proc_fd_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
46
{
50
{
Lines 264-272 Link Here
264
268
265
static int proc_permission(struct inode *inode, int mask)
269
static int proc_permission(struct inode *inode, int mask)
266
{
270
{
271
	int ret;
272
	struct task_struct *task;
273
267
	if (vfs_permission(inode, mask) != 0)
274
	if (vfs_permission(inode, mask) != 0)
268
		return -EACCES;
275
		return -EACCES;
269
	return proc_check_root(inode);
276
	ret = proc_check_root(inode);
277
278
	if (ret)
279
		return ret;
280
281
	task = inode->u.proc_i.task;
282
283
	if (!task)
284
		return 0;
285
286
	return gr_acl_handle_procpidmem(task);
270
}
287
}
271
288
272
static ssize_t pid_maps_read(struct file * file, char * buf,
289
static ssize_t pid_maps_read(struct file * file, char * buf,
Lines 576-581 Link Here
576
	PROC_PID_STATM,
593
	PROC_PID_STATM,
577
	PROC_PID_MAPS,
594
	PROC_PID_MAPS,
578
	PROC_PID_CPU,
595
	PROC_PID_CPU,
596
#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
597
	PROC_PID_IPADDR,
598
#endif
579
	PROC_PID_MOUNTS,
599
	PROC_PID_MOUNTS,
580
	PROC_PID_FD_DIR = 0x8000,	/* 0x8000-0xffff */
600
	PROC_PID_FD_DIR = 0x8000,	/* 0x8000-0xffff */
581
};
601
};
Lines 591-596 Link Here
591
#ifdef CONFIG_SMP
611
#ifdef CONFIG_SMP
592
  E(PROC_PID_CPU,	"cpu",		S_IFREG|S_IRUGO),
612
  E(PROC_PID_CPU,	"cpu",		S_IFREG|S_IRUGO),
593
#endif
613
#endif
614
#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
615
  E(PROC_PID_IPADDR,	"ipaddr",	S_IFREG|S_IRUSR),
616
#endif
594
  E(PROC_PID_MAPS,	"maps",		S_IFREG|S_IRUGO),
617
  E(PROC_PID_MAPS,	"maps",		S_IFREG|S_IRUGO),
595
  E(PROC_PID_MEM,	"mem",		S_IFREG|S_IRUSR|S_IWUSR),
618
  E(PROC_PID_MEM,	"mem",		S_IFREG|S_IRUSR|S_IWUSR),
596
  E(PROC_PID_CWD,	"cwd",		S_IFLNK|S_IRWXUGO),
619
  E(PROC_PID_CWD,	"cwd",		S_IFLNK|S_IRWXUGO),
Lines 747-756 Link Here
747
	get_task_struct(task);
770
	get_task_struct(task);
748
	inode->u.proc_i.task = task;
771
	inode->u.proc_i.task = task;
749
	inode->i_uid = 0;
772
	inode->i_uid = 0;
773
#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
774
	inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
775
#else
750
	inode->i_gid = 0;
776
	inode->i_gid = 0;
777
#endif
778
751
	if (ino == PROC_PID_INO || task_dumpable(task)) {
779
	if (ino == PROC_PID_INO || task_dumpable(task)) {
752
		inode->i_uid = task->euid;
780
		inode->i_uid = task->euid;
781
#ifndef CONFIG_GRKERNSEC_PROC_USERGROUP
753
		inode->i_gid = task->egid;
782
		inode->i_gid = task->egid;
783
#endif
754
	}
784
	}
755
785
756
out:
786
out:
Lines 958-963 Link Here
958
			inode->u.proc_i.op.proc_read = proc_pid_cpu;
988
			inode->u.proc_i.op.proc_read = proc_pid_cpu;
959
			break;
989
			break;
960
#endif
990
#endif
991
#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
992
		case PROC_PID_IPADDR:
993
			inode->i_fop = &proc_info_file_operations;
994
			inode->u.proc_i.op.proc_read = proc_pid_ipaddr;
995
			break;
996
#endif
961
		case PROC_PID_MEM:
997
		case PROC_PID_MEM:
962
			inode->i_op = &proc_mem_inode_operations;
998
			inode->i_op = &proc_mem_inode_operations;
963
			inode->i_fop = &proc_mem_operations;
999
			inode->i_fop = &proc_mem_operations;
Lines 1056-1068 Link Here
1056
	if (!task)
1092
	if (!task)
1057
		goto out;
1093
		goto out;
1058
1094
1095
	if(gr_check_hidden_task(task)) {
1096
		free_task_struct(task);
1097
		goto out;
1098
	}
1099
	
1100
#ifdef CONFIG_GRKERNSEC_PROC
1101
	if (current->uid && (task->uid != current->uid)
1102
#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
1103
	    && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
1104
#endif
1105
	) {
1106
		free_task_struct(task);
1107
		goto out;
1108
	}	
1109
#endif
1059
	inode = proc_pid_make_inode(dir->i_sb, task, PROC_PID_INO);
1110
	inode = proc_pid_make_inode(dir->i_sb, task, PROC_PID_INO);
1060
1111
1061
	free_task_struct(task);
1112
	free_task_struct(task);
1062
1113
1063
	if (!inode)
1114
	if (!inode)
1064
		goto out;
1115
		goto out;
1116
#ifdef CONFIG_GRKERNSEC_PROC_USER
1117
	inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
1118
#elif CONFIG_GRKERNSEC_PROC_USERGROUP
1119
	inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP;
1120
#else
1065
	inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
1121
	inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
1122
#endif
1066
	inode->i_op = &proc_base_inode_operations;
1123
	inode->i_op = &proc_base_inode_operations;
1067
	inode->i_fop = &proc_base_operations;
1124
	inode->i_fop = &proc_base_operations;
1068
	inode->i_nlink = 3;
1125
	inode->i_nlink = 3;
Lines 1102-1107 Link Here
1102
		int pid = p->pid;
1159
		int pid = p->pid;
1103
		if (!pid)
1160
		if (!pid)
1104
			continue;
1161
			continue;
1162
		if(gr_pid_is_chrooted(p))
1163
			continue;
1164
		if(gr_check_hidden_task(p)) 
1165
			continue;
1166
#ifdef CONFIG_GRKERNSEC_PROC
1167
		if (current->uid && (p->uid != current->uid)
1168
#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
1169
	    		&& !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
1170
#endif
1171
		)
1172
			continue;	
1173
#endif
1105
		if (--index >= 0)
1174
		if (--index >= 0)
1106
			continue;
1175
			continue;
1107
		pids[nr_pids] = pid;
1176
		pids[nr_pids] = pid;
(-)linux-2.4.22-ppc-dev.orig/fs/proc/generic.c (+26 lines)
Lines 503-508 Link Here
503
	return ent;
503
	return ent;
504
}
504
}
505
505
506
#ifdef CONFIG_GRKERNSEC_PROC
507
struct proc_dir_entry *proc_priv_mkdir(const char *name, struct proc_dir_entry *parent)
508
{
509
	struct proc_dir_entry *ent;
510
	mode_t mode = 0;
511
512
#ifdef CONFIG_GRKERNSEC_PROC_USER
513
	mode = S_IFDIR | S_IRUSR | S_IXUSR;
514
#elif CONFIG_GRKERNSEC_PROC_USERGROUP
515
	mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP;
516
#endif
517
518
	ent = proc_create(&parent, name, mode, 2);
519
	if (ent) {
520
		ent->proc_fops = &proc_dir_operations;
521
		ent->proc_iops = &proc_dir_inode_operations;
522
523
		if (proc_register(parent, ent) < 0) {
524
			kfree(ent);
525
			ent = NULL;
526
		}
527
	}
528
	return ent;
529
}
530
#endif
531
506
struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
532
struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
507
					 struct proc_dir_entry *parent)
533
					 struct proc_dir_entry *parent)
508
{
534
{
(-)linux-2.4.22-ppc-dev.orig/fs/proc/inode.c (+4 lines)
Lines 152-158 Link Here
152
		if (de->mode) {
152
		if (de->mode) {
153
			inode->i_mode = de->mode;
153
			inode->i_mode = de->mode;
154
			inode->i_uid = de->uid;
154
			inode->i_uid = de->uid;
155
#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
156
			inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
157
#else
155
			inode->i_gid = de->gid;
158
			inode->i_gid = de->gid;
159
#endif			
156
		}
160
		}
157
		if (de->size)
161
		if (de->size)
158
			inode->i_size = de->size;
162
			inode->i_size = de->size;
(-)linux-2.4.22-ppc-dev.orig/fs/proc/proc_misc.c (-4 / +38 lines)
Lines 569-574 Link Here
569
void __init proc_misc_init(void)
569
void __init proc_misc_init(void)
570
{
570
{
571
	struct proc_dir_entry *entry;
571
	struct proc_dir_entry *entry;
572
	int gr_mode = 0;
572
	static struct {
573
	static struct {
573
		char *name;
574
		char *name;
574
		int (*read_proc)(char*,char**,off_t,int,int*,void*);
575
		int (*read_proc)(char*,char**,off_t,int,int*,void*);
Lines 583-630 Link Here
583
#ifdef CONFIG_STRAM_PROC
584
#ifdef CONFIG_STRAM_PROC
584
		{"stram",	stram_read_proc},
585
		{"stram",	stram_read_proc},
585
#endif
586
#endif
586
#ifdef CONFIG_MODULES
587
#if defined(CONFIG_MODULES) && !defined(CONFIG_GRKERNSEC_PROC)
587
		{"modules",	modules_read_proc},
588
		{"modules",	modules_read_proc},
588
#endif
589
#endif
589
		{"stat",	kstat_read_proc},
590
		{"stat",	kstat_read_proc},
591
#ifndef CONFIG_GRKERNSEC_PROC_ADD
590
		{"devices",	devices_read_proc},
592
		{"devices",	devices_read_proc},
591
#if !defined(CONFIG_ARCH_S390)
593
#endif
594
#if !defined(CONFIG_ARCH_S390) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
592
		{"interrupts",	interrupts_read_proc},
595
		{"interrupts",	interrupts_read_proc},
593
#endif
596
#endif
594
		{"filesystems",	filesystems_read_proc},
597
		{"filesystems",	filesystems_read_proc},
598
#ifndef CONFIG_GRKERNSEC_PROC_ADD
595
		{"dma",		dma_read_proc},
599
		{"dma",		dma_read_proc},
596
		{"ioports",	ioports_read_proc},
600
		{"ioports",	ioports_read_proc},
597
		{"cmdline",	cmdline_read_proc},
601
		{"cmdline",	cmdline_read_proc},
602
#endif
598
#ifdef CONFIG_SGI_DS1286
603
#ifdef CONFIG_SGI_DS1286
599
		{"rtc",		ds1286_read_proc},
604
		{"rtc",		ds1286_read_proc},
600
#endif
605
#endif
601
		{"locks",	locks_read_proc},
606
		{"locks",	locks_read_proc},
602
		{"swaps",	swaps_read_proc},
607
		{"swaps",	swaps_read_proc},
608
#ifndef CONFIG_GRKERNSEC_PROC_ADD
603
		{"iomem",	memory_read_proc},
609
		{"iomem",	memory_read_proc},
610
#endif
604
		{"execdomains",	execdomains_read_proc},
611
		{"execdomains",	execdomains_read_proc},
605
		{NULL,}
612
		{NULL,}
606
	};
613
	};
607
	for (p = simple_ones; p->name; p++)
614
	for (p = simple_ones; p->name; p++)
608
		create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
615
		create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
609
616
617
#ifdef CONFIG_GRKERNSEC_PROC_USER
618
	gr_mode = S_IRUSR;
619
#elif CONFIG_GRKERNSEC_PROC_USERGROUP
620
	gr_mode = S_IRUSR | S_IRGRP;
621
#endif
622
623
#if defined(CONFIG_GRKERNSEC_PROC) && defined(CONFIG_MODULES)
624
	create_proc_read_entry("modules", gr_mode, NULL, &modules_read_proc, NULL);
625
#endif
626
#ifdef CONFIG_GRKERNSEC_PROC_ADD
627
	create_proc_read_entry("devices", gr_mode, NULL, &devices_read_proc, NULL);
628
	create_proc_read_entry("dma", gr_mode, NULL, &dma_read_proc, NULL);
629
	create_proc_read_entry("ioports", gr_mode, NULL, &ioports_read_proc, NULL);
630
	create_proc_read_entry("cmdline", gr_mode, NULL, &cmdline_read_proc, NULL);
631
	create_proc_read_entry("iomem", gr_mode, NULL, &memory_read_proc, NULL);
632
#if !defined(CONFIG_ARCH_S390)
633
	create_proc_read_entry("interrupts", gr_mode, NULL, &interrupts_read_proc, NULL);
634
#endif
635
#endif
636
610
	proc_symlink("mounts", NULL, "self/mounts");
637
	proc_symlink("mounts", NULL, "self/mounts");
611
638
612
	/* And now for trickier ones */
639
	/* And now for trickier ones */
613
	entry = create_proc_entry("kmsg", S_IRUSR, &proc_root);
640
	entry = create_proc_entry("kmsg", S_IRUSR, &proc_root);
614
	if (entry)
641
	if (entry)
615
		entry->proc_fops = &proc_kmsg_operations;
642
		entry->proc_fops = &proc_kmsg_operations;
643
#ifdef CONFIG_GRKERNSEC_PROC_ADD
644
	create_seq_entry("cpuinfo", gr_mode, &proc_cpuinfo_operations);
645
	create_seq_entry("slabinfo", gr_mode,&proc_slabinfo_operations);
646
#else
616
	create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations);
647
	create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations);
617
	create_seq_entry("partitions", 0, &proc_partitions_operations);
618
	create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations);
648
	create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations);
649
#endif
650
	create_seq_entry("partitions", 0, &proc_partitions_operations);
619
#ifdef CONFIG_MODULES
651
#ifdef CONFIG_MODULES
620
	create_seq_entry("ksyms", 0, &proc_ksyms_operations);
652
	create_seq_entry("ksyms", gr_mode, &proc_ksyms_operations);
621
#endif
653
#endif
654
#ifndef CONFIG_GRKERNSEC_PROC_ADD
622
	proc_root_kcore = create_proc_entry("kcore", S_IRUSR, NULL);
655
	proc_root_kcore = create_proc_entry("kcore", S_IRUSR, NULL);
623
	if (proc_root_kcore) {
656
	if (proc_root_kcore) {
624
		proc_root_kcore->proc_fops = &proc_kcore_operations;
657
		proc_root_kcore->proc_fops = &proc_kcore_operations;
625
		proc_root_kcore->size =
658
		proc_root_kcore->size =
626
				(size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
659
				(size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
627
	}
660
	}
661
#endif
628
	if (prof_shift) {
662
	if (prof_shift) {
629
		entry = create_proc_entry("profile", S_IWUSR | S_IRUGO, NULL);
663
		entry = create_proc_entry("profile", S_IWUSR | S_IRUGO, NULL);
630
		if (entry) {
664
		if (entry) {
(-)linux-2.4.22-ppc-dev.orig/fs/proc/proc_tty.c (+4 lines)
Lines 174-180 Link Here
174
	if (!proc_mkdir("tty", 0))
174
	if (!proc_mkdir("tty", 0))
175
		return;
175
		return;
176
	proc_tty_ldisc = proc_mkdir("tty/ldisc", 0);
176
	proc_tty_ldisc = proc_mkdir("tty/ldisc", 0);
177
#ifdef CONFIG_GRKERNSEC_PROC
178
	proc_tty_driver = proc_priv_mkdir("tty/driver", 0);
179
#else
177
	proc_tty_driver = proc_mkdir("tty/driver", 0);
180
	proc_tty_driver = proc_mkdir("tty/driver", 0);
181
#endif
178
182
179
	create_proc_read_entry("tty/ldiscs", 0, 0, tty_ldiscs_read_proc,NULL);
183
	create_proc_read_entry("tty/ldiscs", 0, 0, tty_ldiscs_read_proc,NULL);
180
	create_proc_read_entry("tty/drivers", 0, 0, tty_drivers_read_proc,NULL);
184
	create_proc_read_entry("tty/drivers", 0, 0, tty_drivers_read_proc,NULL);
(-)linux-2.4.22-ppc-dev.orig/fs/proc/root.c (+13 lines)
Lines 37-49 Link Here
37
		return;
37
		return;
38
	}
38
	}
39
	proc_misc_init();
39
	proc_misc_init();
40
#ifdef CONFIG_GRKERNSEC_PROC
41
	proc_net = proc_priv_mkdir("net", 0);
42
#else
40
	proc_net = proc_mkdir("net", 0);
43
	proc_net = proc_mkdir("net", 0);
44
#endif
41
#ifdef CONFIG_SYSVIPC
45
#ifdef CONFIG_SYSVIPC
42
	proc_mkdir("sysvipc", 0);
46
	proc_mkdir("sysvipc", 0);
43
#endif
47
#endif
44
#ifdef CONFIG_SYSCTL
48
#ifdef CONFIG_SYSCTL
49
#ifdef CONFIG_GRKERNSEC_PROC
50
	proc_sys_root = proc_priv_mkdir("sys", 0);
51
#else
45
	proc_sys_root = proc_mkdir("sys", 0);
52
	proc_sys_root = proc_mkdir("sys", 0);
46
#endif
53
#endif
54
#endif
47
#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
55
#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
48
	proc_mkdir("sys/fs", 0);
56
	proc_mkdir("sys/fs", 0);
49
	proc_mkdir("sys/fs/binfmt_misc", 0);
57
	proc_mkdir("sys/fs/binfmt_misc", 0);
Lines 67-73 Link Here
67
#ifdef CONFIG_PPC_RTAS
75
#ifdef CONFIG_PPC_RTAS
68
	proc_rtas_init();
76
	proc_rtas_init();
69
#endif
77
#endif
78
79
#ifdef CONFIG_GRKERNSEC_PROC_ADD
80
	proc_bus = proc_priv_mkdir("bus", 0);
81
#else
70
	proc_bus = proc_mkdir("bus", 0);
82
	proc_bus = proc_mkdir("bus", 0);
83
#endif
71
}
84
}
72
85
73
static struct dentry *proc_root_lookup(struct inode * dir, struct dentry * dentry)
86
static struct dentry *proc_root_lookup(struct inode * dir, struct dentry * dentry)
(-)linux-2.4.22-ppc-dev.orig/fs/readdir.c (+25 lines)
Lines 10-15 Link Here
10
#include <linux/stat.h>
10
#include <linux/stat.h>
11
#include <linux/file.h>
11
#include <linux/file.h>
12
#include <linux/smp_lock.h>
12
#include <linux/smp_lock.h>
13
#include <linux/grsecurity.h>
13
14
14
#include <asm/uaccess.h>
15
#include <asm/uaccess.h>
15
16
Lines 181-186 Link Here
181
struct readdir_callback {
182
struct readdir_callback {
182
	struct old_linux_dirent * dirent;
183
	struct old_linux_dirent * dirent;
183
	int count;
184
	int count;
185
	struct nameidata nd;
184
};
186
};
185
187
186
static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset,
188
static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset,
Lines 191-196 Link Here
191
193
192
	if (buf->count)
194
	if (buf->count)
193
		return -EINVAL;
195
		return -EINVAL;
196
197
	if (!gr_acl_handle_filldir(buf->nd.dentry, buf->nd.mnt, ino))
198
		return 0;
199
	    
194
	buf->count++;
200
	buf->count++;
195
	dirent = buf->dirent;
201
	dirent = buf->dirent;
196
	put_user(ino, &dirent->d_ino);
202
	put_user(ino, &dirent->d_ino);
Lines 215-220 Link Here
215
	buf.count = 0;
221
	buf.count = 0;
216
	buf.dirent = dirent;
222
	buf.dirent = dirent;
217
223
224
	buf.nd.dentry = file->f_dentry;
225
	buf.nd.mnt = file->f_vfsmnt;
226
218
	error = vfs_readdir(file, fillonedir, &buf);
227
	error = vfs_readdir(file, fillonedir, &buf);
219
	if (error >= 0)
228
	if (error >= 0)
220
		error = buf.count;
229
		error = buf.count;
Lines 242-247 Link Here
242
	struct linux_dirent * previous;
251
	struct linux_dirent * previous;
243
	int count;
252
	int count;
244
	int error;
253
	int error;
254
	struct nameidata nd;
245
};
255
};
246
256
247
static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
257
static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
Lines 254-259 Link Here
254
	buf->error = -EINVAL;	/* only used if we fail.. */
264
	buf->error = -EINVAL;	/* only used if we fail.. */
255
	if (reclen > buf->count)
265
	if (reclen > buf->count)
256
		return -EINVAL;
266
		return -EINVAL;
267
268
	if (!gr_acl_handle_filldir(buf->nd.dentry, buf->nd.mnt, ino))
269
		return 0;
270
257
	dirent = buf->previous;
271
	dirent = buf->previous;
258
	if (dirent)
272
	if (dirent)
259
		put_user(offset, &dirent->d_off);
273
		put_user(offset, &dirent->d_off);
Lines 286-291 Link Here
286
	buf.count = count;
300
	buf.count = count;
287
	buf.error = 0;
301
	buf.error = 0;
288
302
303
	buf.nd.dentry = file->f_dentry;
304
	buf.nd.mnt = file->f_vfsmnt;
305
289
	error = vfs_readdir(file, filldir, &buf);
306
	error = vfs_readdir(file, filldir, &buf);
290
	if (error < 0)
307
	if (error < 0)
291
		goto out_putf;
308
		goto out_putf;
Lines 320-325 Link Here
320
	struct linux_dirent64 * previous;
337
	struct linux_dirent64 * previous;
321
	int count;
338
	int count;
322
	int error;
339
	int error;
340
	struct nameidata nd;
323
};
341
};
324
342
325
static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
343
static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
Lines 332-337 Link Here
332
	buf->error = -EINVAL;	/* only used if we fail.. */
350
	buf->error = -EINVAL;	/* only used if we fail.. */
333
	if (reclen > buf->count)
351
	if (reclen > buf->count)
334
		return -EINVAL;
352
		return -EINVAL;
353
354
	if (!gr_acl_handle_filldir(buf->nd.dentry, buf->nd.mnt, ino))
355
		return 0;
356
	
335
	dirent = buf->previous;
357
	dirent = buf->previous;
336
	if (dirent) {
358
	if (dirent) {
337
		d.d_off = offset;
359
		d.d_off = offset;
Lines 369-374 Link Here
369
	buf.count = count;
391
	buf.count = count;
370
	buf.error = 0;
392
	buf.error = 0;
371
393
394
	buf.nd.mnt = file->f_vfsmnt;
395
	buf.nd.dentry = file->f_dentry;
396
372
	error = vfs_readdir(file, filldir64, &buf);
397
	error = vfs_readdir(file, filldir64, &buf);
373
	if (error < 0)
398
	if (error < 0)
374
		goto out_putf;
399
		goto out_putf;
(-)linux-2.4.22-ppc-dev.orig/grsecurity/Config.in (+366 lines)
Line 0 Link Here
1
define_bool CONFIG_CRYPTO y
2
define_bool CONFIG_CRYPTO_SHA256 y
3
choice 'Security level' \
4
        "Low		CONFIG_GRKERNSEC_LOW \
5
         Medium		CONFIG_GRKERNSEC_MID \
6
         High		CONFIG_GRKERNSEC_HI \
7
	  Customized	CONFIG_GRKERNSEC_CUSTOM" Customized
8
if [ "$CONFIG_GRKERNSEC_LOW" = "y" ]; then
9
define_bool CONFIG_GRKERNSEC_RANDSRC n
10
define_bool CONFIG_GRKERNSEC_RANDRPC n
11
define_bool CONFIG_GRKERNSEC_FORKFAIL n
12
define_bool CONFIG_GRKERNSEC_TIME n
13
define_bool CONFIG_GRKERNSEC_SIGNAL n
14
define_bool CONFIG_GRKERNSEC_CHROOT_SHMAT n
15
define_bool CONFIG_GRKERNSEC_CHROOT_MOUNT n
16
define_bool CONFIG_GRKERNSEC_CHROOT_FCHDIR n
17
define_bool CONFIG_GRKERNSEC_CHROOT_DOUBLE n
18
define_bool CONFIG_GRKERNSEC_CHROOT_PIVOT n
19
define_bool CONFIG_GRKERNSEC_CHROOT_MKNOD n
20
define_bool CONFIG_GRKERNSEC_PROC n
21
define_bool CONFIG_GRKERNSEC_PROC_IPADDR n
22
define_bool CONFIG_GRKERNSEC_PROC_MEMMAP n
23
define_bool CONFIG_GRKERNSEC_HIDESYM n
24
define_bool CONFIG_GRKERNSEC_CHROOT_CAPS n
25
define_bool CONFIG_GRKERNSEC_CHROOT_SYSCTL n
26
define_bool CONFIG_GRKERNSEC_PROC_USERGROUP n
27
define_bool CONFIG_GRKERNSEC_KMEM n
28
define_bool CONFIG_GRKERNSEC_PROC_ADD n
29
define_bool CONFIG_GRKERNSEC_CHROOT_CHMOD n
30
define_bool CONFIG_GRKERNSEC_CHROOT_NICE n
31
define_bool CONFIG_GRKERNSEC_CHROOT_FINDTASK n
32
define_bool CONFIG_GRKERNSEC_PAX_RANDUSTACK n
33
define_bool CONFIG_GRKERNSEC_PAX_ASLR n
34
define_bool CONFIG_GRKERNSEC_PAX_RANDMMAP n
35
define_bool CONFIG_GRKERNSEC_PAX_NOEXEC n
36
define_bool CONFIG_GRKERNSEC_PAX_PAGEEXEC n
37
define_bool CONFIG_GRKERNSEC_PAX_NOELFRELOCS n
38
define_bool CONFIG_GRKERNSEC_PAX_ETEXECRELOCS n
39
define_bool CONFIG_GRKERNSEC_PAX_MPROTECT n
40
if [ "$CONFIG_X86" = "y" ]; then
41
define_bool CONFIG_GRKERNSEC_PAX_RANDKSTACK n
42
define_bool CONFIG_GRKERNSEC_PAX_KERNEXEC n
43
define_bool CONFIG_GRKERNSEC_IO n
44
define_bool CONFIG_GRKERNSEC_PAX_RANDEXEC n
45
define_bool CONFIG_GRKERNSEC_PAX_SEGMEXEC n
46
define_bool CONFIG_GRKERNSEC_PAX_EMUTRAMP n
47
define_bool CONFIG_GRKERNSEC_PAX_EMUSIGRT n
48
fi
49
define_bool CONFIG_GRKERNSEC_AUDIT_MOUNT n
50
define_bool CONFIG_GRKERNSEC_ACL_HIDEKERN n
51
define_bool CONFIG_GRKERNSEC_RESLOG n
52
define_int CONFIG_GRKERNSEC_ACL_MAXTRIES 3
53
define_int CONFIG_GRKERNSEC_ACL_TIMEOUT 30
54
55
define_int  CONFIG_GRKERNSEC_FLOODTIME 10
56
define_int  CONFIG_GRKERNSEC_FLOODBURST 4
57
define_bool CONFIG_GRKERNSEC_LINK y
58
define_bool CONFIG_GRKERNSEC_FIFO y
59
define_bool CONFIG_GRKERNSEC_RANDPID y
60
define_bool CONFIG_GRKERNSEC_EXECVE y
61
define_bool CONFIG_GRKERNSEC_RANDNET y
62
define_bool CONFIG_GRKERNSEC_RANDISN n
63
define_bool CONFIG_GRKERNSEC_DMESG y
64
define_bool CONFIG_GRKERNSEC_RANDID y
65
define_bool CONFIG_GRKERNSEC_CHROOT_CHDIR y
66
fi
67
if [ "$CONFIG_GRKERNSEC_MID" = "y" ]; then
68
define_bool CONFIG_GRKERNSEC_KMEM n
69
define_bool CONFIG_GRKERNSEC_PROC_IPADDR n
70
define_bool CONFIG_GRKERNSEC_PROC_MEMMAP n
71
define_bool CONFIG_GRKERNSEC_HIDESYM n
72
define_bool CONFIG_GRKERNSEC_PROC_ADD n
73
define_bool CONFIG_GRKERNSEC_CHROOT_CHMOD n
74
define_bool CONFIG_GRKERNSEC_CHROOT_NICE n
75
define_bool CONFIG_GRKERNSEC_CHROOT_FINDTASK n
76
define_bool CONFIG_GRKERNSEC_PAX_NOEXEC n
77
define_bool CONFIG_GRKERNSEC_PAX_PAGEEXEC n
78
define_bool CONFIG_GRKERNSEC_PAX_NOELFRELOCS n
79
define_bool CONFIG_GRKERNSEC_PAX_ETEXECRELOCS n
80
define_bool CONFIG_GRKERNSEC_PAX_MPROTECT n
81
if [ "$CONFIG_X86" = "y" ]; then
82
define_bool CONFIG_GRKERNSEC_IO n
83
define_bool CONFIG_GRKERNSEC_PAX_RANDEXEC n
84
define_bool CONFIG_GRKERNSEC_PAX_SEGMEXEC n
85
define_bool CONFIG_GRKERNSEC_PAX_EMUTRAMP n
86
define_bool CONFIG_GRKERNSEC_PAX_EMUSIGRT n
87
fi
88
define_bool CONFIG_GRKERNSEC_AUDIT_MOUNT n
89
define_bool CONFIG_GRKERNSEC_CHROOT_CAPS n
90
define_bool CONFIG_GRKERNSEC_CHROOT_SYSCTL y
91
define_bool CONFIG_GRKERNSEC_AUDIT_MOUNT n
92
define_bool CONFIG_GRKERNSEC_CHROOT_FCHDIR n
93
define_bool CONFIG_GRKERNSEC_ACL_HIDEKERN n
94
define_bool CONFIG_GRKERNSEC_RESLOG n
95
define_int CONFIG_GRKERNSEC_ACL_MAXTRIES 3
96
define_int CONFIG_GRKERNSEC_ACL_TIMEOUT 30
97
98
define_int  CONFIG_GRKERNSEC_FLOODTIME 10
99
define_int  CONFIG_GRKERNSEC_FLOODBURST 4
100
define_bool CONFIG_GRKERNSEC_LINK y
101
define_bool CONFIG_GRKERNSEC_FIFO y
102
define_bool CONFIG_GRKERNSEC_RANDPID y
103
define_bool CONFIG_GRKERNSEC_EXECVE y
104
define_bool CONFIG_GRKERNSEC_DMESG y
105
define_bool CONFIG_GRKERNSEC_RANDID y
106
define_bool CONFIG_GRKERNSEC_RANDNET y
107
define_bool CONFIG_GRKERNSEC_RANDISN y
108
define_bool CONFIG_GRKERNSEC_RANDSRC y
109
define_bool CONFIG_GRKERNSEC_RANDRPC y
110
define_bool CONFIG_GRKERNSEC_FORKFAIL y
111
define_bool CONFIG_GRKERNSEC_TIME y
112
define_bool CONFIG_GRKERNSEC_SIGNAL y
113
define_bool CONFIG_GRKERNSEC_CHROOT y
114
define_bool CONFIG_GRKERNSEC_CHROOT_SHMAT n
115
define_bool CONFIG_GRKERNSEC_CHROOT_UNIX y
116
define_bool CONFIG_GRKERNSEC_CHROOT_MOUNT y
117
define_bool CONFIG_GRKERNSEC_CHROOT_PIVOT y
118
define_bool CONFIG_GRKERNSEC_CHROOT_DOUBLE y
119
define_bool CONFIG_GRKERNSEC_CHROOT_CHDIR y
120
define_bool CONFIG_GRKERNSEC_CHROOT_MKNOD y
121
define_bool CONFIG_GRKERNSEC_PROC y
122
define_bool CONFIG_GRKERNSEC_PROC_USERGROUP y
123
define_int  CONFIG_GRKERNSEC_PROC_GID 10
124
define_bool CONFIG_GRKERNSEC_PAX_RANDUSTACK y
125
define_bool CONFIG_GRKERNSEC_PAX_RANDKSTACK n
126
define_bool CONFIG_GRKERNSEC_PAX_KERNEXEC n
127
define_bool CONFIG_GRKERNSEC_PAX_ASLR y
128
define_bool CONFIG_GRKERNSEC_PAX_RANDMMAP y
129
fi
130
if [ "$CONFIG_GRKERNSEC_HI" = "y" ]; then
131
define_int CONFIG_GRKERNSEC_FLOODTIME 10
132
define_int  CONFIG_GRKERNSEC_FLOODBURST 4
133
define_bool CONFIG_GRKERNSEC_LINK y
134
define_bool CONFIG_GRKERNSEC_FIFO y
135
define_bool CONFIG_GRKERNSEC_RANDPID y
136
define_bool CONFIG_GRKERNSEC_EXECVE y
137
define_bool CONFIG_GRKERNSEC_DMESG y
138
define_bool CONFIG_GRKERNSEC_RANDID y
139
define_bool CONFIG_GRKERNSEC_RANDSRC y
140
define_bool CONFIG_GRKERNSEC_RANDRPC y
141
define_bool CONFIG_GRKERNSEC_FORKFAIL y
142
define_bool CONFIG_GRKERNSEC_TIME y
143
define_bool CONFIG_GRKERNSEC_SIGNAL y
144
define_bool CONFIG_GRKERNSEC_CHROOT_SHMAT y
145
define_bool CONFIG_GRKERNSEC_CHROOT_UNIX y
146
define_bool CONFIG_GRKERNSEC_CHROOT_MOUNT y
147
define_bool CONFIG_GRKERNSEC_CHROOT_FCHDIR y
148
define_bool CONFIG_GRKERNSEC_CHROOT_PIVOT y
149
define_bool CONFIG_GRKERNSEC_CHROOT_DOUBLE y
150
define_bool CONFIG_GRKERNSEC_CHROOT_CHDIR y
151
define_bool CONFIG_GRKERNSEC_CHROOT_MKNOD y
152
define_bool CONFIG_GRKERNSEC_CHROOT_CAPS y
153
define_bool CONFIG_GRKERNSEC_CHROOT_SYSCTL y
154
define_bool CONFIG_GRKERNSEC_CHROOT_FINDTASK y
155
define_bool CONFIG_GRKERNSEC_PROC y
156
define_bool CONFIG_GRKERNSEC_PROC_IPADDR n
157
define_bool CONFIG_GRKERNSEC_PROC_MEMMAP y
158
define_bool CONFIG_GRKERNSEC_HIDESYM y
159
define_bool CONFIG_GRKERNSEC_PROC_USERGROUP y
160
define_int  CONFIG_GRKERNSEC_PROC_GID 10
161
define_bool CONFIG_GRKERNSEC_KMEM y
162
define_bool CONFIG_GRKERNSEC_RESLOG y
163
define_bool CONFIG_GRKERNSEC_RANDNET y
164
define_bool CONFIG_GRKERNSEC_RANDISN y
165
166
define_bool CONFIG_GRKERNSEC_AUDIT_MOUNT n
167
define_bool CONFIG_GRKERNSEC_ACL_HIDEKERN n
168
define_int CONFIG_GRKERNSEC_ACL_MAXTRIES 3
169
define_int CONFIG_GRKERNSEC_ACL_TIMEOUT 30
170
171
define_bool CONFIG_GRKERNSEC_PROC_ADD y
172
define_bool CONFIG_GRKERNSEC_CHROOT_CHMOD y
173
define_bool CONFIG_GRKERNSEC_CHROOT_NICE y
174
define_bool CONFIG_GRKERNSEC_PAX_RANDUSTACK y
175
define_bool CONFIG_GRKERNSEC_PAX_ASLR y
176
define_bool CONFIG_GRKERNSEC_PAX_RANDMMAP y
177
define_bool CONFIG_GRKERNSEC_PAX_NOEXEC y
178
define_bool CONFIG_GRKERNSEC_PAX_PAGEEXEC n
179
define_bool CONFIG_GRKERNSEC_PAX_NOELFRELOCS n
180
define_bool CONFIG_GRKERNSEC_PAX_MPROTECT y
181
define_bool CONFIG_GRKERNSEC_PAX_ETEXECRELOCS n
182
if [ "$CONFIG_X86" = "y" ]; then
183
define_bool CONFIG_GRKERNSEC_IO n
184
if [ "$CONFIG_MODULES" = "n" ]; then
185
define_bool CONFIG_GRKERNSEC_PAX_KERNEXEC y
186
fi
187
define_bool CONFIG_GRKERNSEC_PAX_RANDKSTACK y
188
define_bool CONFIG_GRKERNSEC_PAX_RANDEXEC y
189
define_bool CONFIG_GRKERNSEC_PAX_SEGMEXEC y
190
define_bool CONFIG_GRKERNSEC_PAX_EMUTRAMP n
191
define_bool CONFIG_GRKERNSEC_PAX_EMUSIGRT n
192
fi
193
if [ "$CONFIG_PARISC" = "y" ]; then
194
define_bool CONFIG_GRKERNSEC_PAX_EMUTRAMP y
195
define_bool CONFIG_GRKERNSEC_PAX_EMUSIGRT y
196
fi
197
define_bool CONFIG_GRKERNSEC_AUDIT_MOUNT y
198
fi
199
if [ "$CONFIG_GRKERNSEC_CUSTOM" = "y" ]; then
200
mainmenu_option next_comment
201
comment 'Address Space Protection'
202
bool 'Enforce non-executable pages' CONFIG_GRKERNSEC_PAX_NOEXEC
203
if [ "$CONFIG_GRKERNSEC_PAX_NOEXEC" = "y" ]; then
204
  bool 'Paging based non-executable pages' CONFIG_GRKERNSEC_PAX_PAGEEXEC
205
  if [ "$CONFIG_X86" = "y" ]; then
206
    bool 'Segmentation based non-executable pages' CONFIG_GRKERNSEC_PAX_SEGMEXEC
207
  fi
208
  if [ "$CONFIG_X86" = "y" -o "$CONFIG_PARISC" = "y" -o "$CONFIG_PPC32" = "y" ]; then
209
    if [ "$CONFIG_GRKERNSEC_PAX_PAGEEXEC" = "y" -o "$CONFIG_GRKERNSEC_PAX_SEGMEXEC" = "y" ]; then
210
      bool '   Emulate trampolines' CONFIG_GRKERNSEC_PAX_EMUTRAMP
211
      if [ "$CONFIG_GRKERNSEC_PAX_EMUTRAMP" = "y" ]; then
212
        bool '    Automatically emulate sigreturn trampolines' CONFIG_GRKERNSEC_PAX_EMUSIGRT
213
      fi
214
    fi
215
  fi
216
  bool '   Restrict mprotect()' CONFIG_GRKERNSEC_PAX_MPROTECT
217
  if [ "$CONFIG_GRKERNSEC_PAX_MPROTECT" = "y" ]; then
218
    if [ "$CONFIG_X86" = "y" ]; then
219
      bool '    Disallow ELF text relocations (DANGEROUS)' CONFIG_GRKERNSEC_PAX_NOELFRELOCS
220
    else
221
    if [ "$CONFIG_ALPHA" = "y" -o "$CONFIG_PARISC" = "y" ]; then
222
      bool '    Allow ELF ET_EXEC text relocations' CONFIG_GRKERNSEC_PAX_ETEXECRELOCS
223
    fi
224
    if [ "$CONFIG_PPC32" = "y" ]; then
225
      define_bool CONFIG_GRKERNSEC_PAX_SYSCALL y
226
    fi
227
    if [ "$CONFIG_ALPHA" = "y" -o "$CONFIG_PARISC" = "y" -o "$CONFIG_SPARC32" = "y" -o "$CONFIG_SPARC64" = "y" -o "$CONFIG_PPC32" = "y" ]; then
228
      bool '    Automatically emulate ELF PLT' CONFIG_GRKERNSEC_PAX_EMUPLT
229
      if [ "$CONFIG_GRKERNSEC_PAX_EMUPLT" = "y" ]; then
230
        if [ "$CONFIG_SPARC32" = "y" -o "$CONFIG_SPARC64" = "y" ]; then
231
    	  define_bool CONFIG_GRKERNSEC_PAX_DLRESOLVE y
232
        fi
233
      fi
234
    fi
235
    fi
236
  fi
237
fi
238
if [ "$CONFIG_X86" = "y" -a "$CONFIG_MODULES" = "n" ]; then
239
  bool 'Enforce non-executable kernel pages' CONFIG_GRKERNSEC_PAX_KERNEXEC
240
fi
241
bool 'Address Space Layout Randomization' CONFIG_GRKERNSEC_PAX_ASLR
242
if [ "$CONFIG_GRKERNSEC_PAX_ASLR" = "y" ]; then
243
  if [ "$CONFIG_X86_TSC" = "y" ]; then
244
    bool '  Randomize kernel stack base' CONFIG_GRKERNSEC_PAX_RANDKSTACK
245
  fi
246
  bool '  Randomize user stack base' CONFIG_GRKERNSEC_PAX_RANDUSTACK
247
  bool '  Randomize mmap() base' CONFIG_GRKERNSEC_PAX_RANDMMAP
248
  if [ "$CONFIG_GRKERNSEC_PAX_RANDMMAP" = "y" -a "$CONFIG_GRKERNSEC_PAX_NOEXEC" = "y" ]; then
249
    if [ "$CONFIG_GRKERNSEC_PAX_PAGEEXEC" = "y" -o "$CONFIG_GRKERNSEC_PAX_SEGMEXEC" = "y" ]; then
250
      bool '  Randomize ET_EXEC base' CONFIG_GRKERNSEC_PAX_RANDEXEC
251
    fi
252
  fi
253
fi
254
bool 'Deny writing to /dev/kmem, /dev/mem, and /dev/port' CONFIG_GRKERNSEC_KMEM
255
if [ "$CONFIG_X86" = "y" ]; then
256
  bool 'Disable privileged I/O' CONFIG_GRKERNSEC_IO
257
  if [ "$CONFIG_GRKERNSEC_IO" = "y" ]; then
258
    define_bool CONFIG_RTC y
259
  fi
260
fi
261
bool 'Remove addresses from /proc/pid/[maps|stat]' CONFIG_GRKERNSEC_PROC_MEMMAP
262
bool 'Hide kernel symbols' CONFIG_GRKERNSEC_HIDESYM
263
endmenu
264
mainmenu_option next_comment
265
comment 'Role Based Access Control Options'
266
bool 'Hide kernel processes' CONFIG_GRKERNSEC_ACL_HIDEKERN
267
int 'Maximum tries before password lockout' CONFIG_GRKERNSEC_ACL_MAXTRIES 3
268
int 'Time to wait after max password tries, in seconds' CONFIG_GRKERNSEC_ACL_TIMEOUT 30
269
endmenu
270
mainmenu_option next_comment
271
comment 'Filesystem Protections'
272
bool 'Proc restrictions' CONFIG_GRKERNSEC_PROC
273
if [ "$CONFIG_GRKERNSEC_PROC" != "n" ]; then
274
 bool '   Restrict to user only' CONFIG_GRKERNSEC_PROC_USER
275
 if [ "$CONFIG_GRKERNSEC_PROC_USER" != "y" ]; then
276
  bool '   Allow special group' CONFIG_GRKERNSEC_PROC_USERGROUP
277
  if [ "$CONFIG_GRKERNSEC_PROC_USERGROUP" != "n" ]; then
278
   int  '   GID for special group' CONFIG_GRKERNSEC_PROC_GID 1001
279
  fi
280
 fi
281
 if [ "$CONFIG_GRKERNSEC_PROC_USER" != "n" -o "$CONFIG_GRKERNSEC_PROC_USERGROUP" != "n" ]; then
282
  bool '   Additional restrictions' CONFIG_GRKERNSEC_PROC_ADD
283
 fi
284
fi
285
bool 'Linking restrictions' CONFIG_GRKERNSEC_LINK
286
bool 'FIFO restrictions' CONFIG_GRKERNSEC_FIFO
287
bool 'Chroot jail restrictions' CONFIG_GRKERNSEC_CHROOT
288
if [ "$CONFIG_GRKERNSEC_CHROOT" != "n" ]; then
289
bool '   Deny mounts' CONFIG_GRKERNSEC_CHROOT_MOUNT
290
bool '   Deny double-chroots' CONFIG_GRKERNSEC_CHROOT_DOUBLE
291
bool '   Deny pivot_root in chroot' CONFIG_GRKERNSEC_CHROOT_PIVOT
292
bool '   Enforce chdir("/") on all chroots' CONFIG_GRKERNSEC_CHROOT_CHDIR
293
bool '   Deny (f)chmod +s' CONFIG_GRKERNSEC_CHROOT_CHMOD
294
bool '   Deny fchdir out of chroot' CONFIG_GRKERNSEC_CHROOT_FCHDIR
295
bool '   Deny mknod' CONFIG_GRKERNSEC_CHROOT_MKNOD
296
bool '   Deny shmat() out of chroot' CONFIG_GRKERNSEC_CHROOT_SHMAT
297
bool '   Deny access to abstract AF_UNIX sockets out of chroot' CONFIG_GRKERNSEC_CHROOT_UNIX
298
bool '   Protect outside processes' CONFIG_GRKERNSEC_CHROOT_FINDTASK
299
bool '   Restrict priority changes' CONFIG_GRKERNSEC_CHROOT_NICE
300
bool '   Deny sysctl writes in chroot' CONFIG_GRKERNSEC_CHROOT_SYSCTL
301
bool '   Capability restrictions within chroot' CONFIG_GRKERNSEC_CHROOT_CAPS
302
fi
303
endmenu
304
mainmenu_option next_comment
305
comment 'Kernel Auditing'
306
bool 'Single group for auditing' CONFIG_GRKERNSEC_AUDIT_GROUP
307
if [ "$CONFIG_GRKERNSEC_AUDIT_GROUP" != "n" ]; then
308
int  '   GID for auditing' CONFIG_GRKERNSEC_AUDIT_GID 1007
309
fi
310
bool 'Exec logging' CONFIG_GRKERNSEC_EXECLOG
311
bool 'Resource logging' CONFIG_GRKERNSEC_RESLOG
312
bool 'Log execs within chroot' CONFIG_GRKERNSEC_CHROOT_EXECLOG
313
bool 'Chdir logging' CONFIG_GRKERNSEC_AUDIT_CHDIR
314
bool '(Un)Mount logging' CONFIG_GRKERNSEC_AUDIT_MOUNT
315
bool 'IPC logging' CONFIG_GRKERNSEC_AUDIT_IPC
316
bool 'Signal logging' CONFIG_GRKERNSEC_SIGNAL
317
bool 'Fork failure logging' CONFIG_GRKERNSEC_FORKFAIL
318
bool 'Time change logging' CONFIG_GRKERNSEC_TIME
319
bool '/proc/<pid>/ipaddr support' CONFIG_GRKERNSEC_PROC_IPADDR
320
endmenu
321
mainmenu_option next_comment
322
comment 'Executable Protections'
323
bool 'Enforce RLIMIT_NPROC on execs' CONFIG_GRKERNSEC_EXECVE
324
bool 'Dmesg(8) restriction' CONFIG_GRKERNSEC_DMESG
325
bool 'Randomized PIDs' CONFIG_GRKERNSEC_RANDPID
326
bool 'Trusted path execution' CONFIG_GRKERNSEC_TPE
327
if [ "$CONFIG_GRKERNSEC_TPE" != "n" ]; then
328
bool '   Partially restrict non-root users' CONFIG_GRKERNSEC_TPE_ALL
329
int  '   GID for untrusted users:' CONFIG_GRKERNSEC_TPE_GID 1005
330
fi
331
endmenu
332
mainmenu_option next_comment
333
comment 'Network Protections'
334
bool 'Larger entropy pools' CONFIG_GRKERNSEC_RANDNET
335
bool 'Truly random TCP ISN selection' CONFIG_GRKERNSEC_RANDISN
336
bool 'Randomized IP IDs' CONFIG_GRKERNSEC_RANDID
337
bool 'Randomized TCP source ports' CONFIG_GRKERNSEC_RANDSRC
338
bool 'Randomized RPC XIDs' CONFIG_GRKERNSEC_RANDRPC
339
bool 'Socket restrictions' CONFIG_GRKERNSEC_SOCKET
340
if [ "$CONFIG_GRKERNSEC_SOCKET" != "n" ]; then
341
bool '  Deny any sockets to group' CONFIG_GRKERNSEC_SOCKET_ALL
342
if [ "$CONFIG_GRKERNSEC_SOCKET_ALL" != "n" ]; then
343
int  '   GID to deny all sockets for:' CONFIG_GRKERNSEC_SOCKET_ALL_GID 1004
344
fi
345
bool '  Deny client sockets to group' CONFIG_GRKERNSEC_SOCKET_CLIENT
346
if [ "$CONFIG_GRKERNSEC_SOCKET_CLIENT" != "n" ]; then
347
int  '   GID to deny client sockets for:' CONFIG_GRKERNSEC_SOCKET_CLIENT_GID 1003
348
fi
349
bool '  Deny server sockets to group' CONFIG_GRKERNSEC_SOCKET_SERVER
350
if [ "$CONFIG_GRKERNSEC_SOCKET_SERVER" != "n" ]; then
351
int  '   GID to deny server sockets for:' CONFIG_GRKERNSEC_SOCKET_SERVER_GID 1002
352
fi
353
fi
354
endmenu
355
if [ "$CONFIG_SYSCTL" != "n" ]; then
356
mainmenu_option next_comment
357
comment 'Sysctl support'
358
bool 'Sysctl support' CONFIG_GRKERNSEC_SYSCTL
359
endmenu
360
fi
361
mainmenu_option next_comment
362
comment 'Logging options'
363
int 'Seconds in between log messages (minimum)' CONFIG_GRKERNSEC_FLOODTIME 10
364
int 'Number of messages in a burst (maximum)' CONFIG_GRKERNSEC_FLOODBURST 4
365
endmenu
366
fi
(-)linux-2.4.22-ppc-dev.orig/grsecurity/Makefile (+24 lines)
Line 0 Link Here
1
# grsecurity's ACL system was originally written in 2001 by Michael Dalton
2
# during 2001, 2002, and 2003 it has been completely redesigned by
3
# Brad Spengler
4
#
5
# All code in this directory and various hooks inserted throughout the kernel
6
# are copyright Brad Spengler, and released under the GPL, unless otherwise
7
# noted (as in obsd_rand.c)
8
9
O_TARGET := grsec.o
10
11
obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
12
	grsec_mount.o grsec_rand.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
13
	grsec_time.o grsec_tpe.o grsec_ipc.o grsec_link.o
14
15
ifeq ($(CONFIG_GRKERNSEC),y)
16
obj-y += grsec_init.o grsum.o gracl.o gracl_ip.o gracl_segv.o obsd_rand.o \
17
	gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
18
	gracl_learn.o
19
obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
20
else
21
obj-y += grsec_disabled.o
22
endif
23
24
include $(TOPDIR)/Rules.make
(-)linux-2.4.22-ppc-dev.orig/grsecurity/gracl.c (+2766 lines)
Line 0 Link Here
1
/* 
2
 * grsecurity/gracl.c
3
 * Copyright Brad Spengler 2001, 2002, 2003
4
 *
5
 */
6
7
#include <linux/kernel.h>
8
#include <linux/sched.h>
9
#include <linux/mm.h>
10
#include <linux/file.h>
11
#include <linux/fs.h>
12
#include <linux/proc_fs.h>
13
#include <linux/smp_lock.h>
14
#include <linux/slab.h>
15
#include <linux/vmalloc.h>
16
#include <linux/types.h>
17
#include <linux/capability.h>
18
#include <linux/sysctl.h>
19
#include <linux/gracl.h>
20
#include <linux/gralloc.h>
21
#include <linux/grsecurity.h>
22
#include <linux/grinternal.h>
23
24
#include <asm/uaccess.h>
25
#include <asm/errno.h>
26
#include <asm/mman.h>
27
28
static struct acl_role_db acl_role_set;
29
static struct acl_role_label *role_list_head;
30
static struct name_db name_set;
31
static struct name_db inodev_set;
32
33
static struct acl_role_label *default_role;
34
35
static u16 acl_sp_role_value;
36
37
static DECLARE_MUTEX(gr_dev_sem);
38
rwlock_t gr_inode_lock = RW_LOCK_UNLOCKED;
39
40
extern char *gr_shared_page[4][NR_CPUS];
41
struct gr_arg *gr_usermode;
42
43
static unsigned long gr_status = GR_STATUS_INIT;
44
45
extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
46
extern void gr_clear_learn_entries(void);
47
48
#ifdef CONFIG_GRKERNSEC_RESLOG
49
extern __inline__ void gr_log_resource(const struct task_struct *task,
50
				       const int res,
51
				       const unsigned long wanted);
52
#endif
53
54
unsigned char *gr_system_salt;
55
unsigned char *gr_system_sum;
56
57
static struct sprole_pw **acl_special_roles = NULL;
58
static __u16 num_sprole_pws = 0;
59
60
static struct acl_role_label *kernel_role = NULL;
61
62
/* The following are used to keep a place held in the hash table when we move
63
   entries around.  They can be replaced during insert. */
64
65
static struct acl_subject_label *deleted_subject;
66
static struct acl_object_label *deleted_object;
67
static struct name_entry *deleted_inodev;
68
69
/* for keeping track of the last and final allocated subjects, since
70
   nested subject parsing is tricky
71
*/
72
static struct acl_subject_label *s_last = NULL;
73
static struct acl_subject_label *s_final = NULL;
74
75
static unsigned int gr_auth_attempts = 0;
76
static unsigned long gr_auth_expires = 0UL;
77
78
extern int gr_init_uidset(void);
79
extern void gr_free_uidset(void);
80
extern void gr_remove_uid(uid_t uid);
81
extern int gr_find_uid(uid_t uid);
82
83
__inline__ int
84
gr_acl_is_enabled(void)
85
{
86
	return (gr_status & GR_READY);
87
}
88
89
__inline__ int
90
gr_acl_tpe_check(void)
91
{
92
	if (unlikely(!(gr_status & GR_READY)))
93
		return 0;
94
	if (current->role->roletype & GR_ROLE_TPE)
95
		return 1;
96
	else
97
		return 0;
98
}
99
100
int
101
gr_handle_rawio(const struct inode *inode)
102
{
103
	if (inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO) &&
104
	    ((gr_status & GR_READY)
105
#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
106
	     || (grsec_enable_chroot_caps && proc_is_chrooted(current))
107
#endif
108
	    ))
109
		return 1;
110
	return 0;
111
}
112
113
114
static __inline__ int
115
gr_streq(const char *a, const char *b, const __u16 lena, const __u16 lenb)
116
{
117
	int i;
118
	unsigned long *l1;
119
	unsigned long *l2;
120
	unsigned char *c1;
121
	unsigned char *c2;
122
	int num_longs;
123
124
	if (likely(lena != lenb))
125
		return 0;
126
127
	l1 = (unsigned long *)a;
128
	l2 = (unsigned long *)b;
129
130
	num_longs = lena / sizeof(unsigned long);
131
132
	for (i = num_longs; i--; l1++, l2++) {
133
		if (unlikely(*l1 != *l2))
134
			return 0;
135
	}
136
137
	c1 = (unsigned char *) l1;
138
	c2 = (unsigned char *) l2;
139
140
	i = lena - (num_longs * sizeof(unsigned long));	
141
142
	for (; i--; c1++, c2++) {
143
		if (unlikely(*c1 != *c2))
144
			return 0;
145
	}
146
147
	return 1;
148
}
149
		
150
static __inline__ char *
151
d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
152
	    char *buf, int buflen)
153
{
154
	char *res;
155
	struct dentry *our_dentry;
156
	struct vfsmount *our_mount;
157
	struct vfsmount *rootmnt;
158
	struct dentry *root;
159
160
	our_dentry = (struct dentry *) dentry;
161
	our_mount = (struct vfsmount *) vfsmnt;
162
163
	read_lock(&child_reaper->fs->lock);
164
	rootmnt = mntget(child_reaper->fs->rootmnt);
165
	root = dget(child_reaper->fs->root);
166
	read_unlock(&child_reaper->fs->lock);
167
168
	spin_lock(&dcache_lock);
169
	res = __d_path(our_dentry, our_mount, root, rootmnt, buf, buflen);
170
	spin_unlock(&dcache_lock);
171
	dput(root);
172
	mntput(rootmnt);
173
	return res;
174
}
175
176
char *
177
gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
178
{
179
	return d_real_path(dentry, mnt, gr_shared_page[0][smp_processor_id()],
180
			   PAGE_SIZE);
181
}
182
183
char *
184
gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
185
{
186
	return d_real_path(dentry, mnt, gr_shared_page[1][smp_processor_id()],
187
			   PAGE_SIZE);
188
}
189
190
char *
191
gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
192
{
193
	return d_real_path(dentry, mnt, gr_shared_page[2][smp_processor_id()],
194
			   PAGE_SIZE);
195
}
196
197
char *
198
gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
199
{
200
	return d_real_path(dentry, mnt, gr_shared_page[3][smp_processor_id()],
201
			   PAGE_SIZE);
202
}
203
204
__inline__ __u32
205
to_gr_audit(const __u32 reqmode)
206
{
207
	__u32 retmode = 0;
208
209
	retmode |= (reqmode & GR_READ) ? GR_AUDIT_READ : 0;
210
	retmode |= (reqmode & GR_WRITE) ? GR_AUDIT_WRITE | GR_AUDIT_APPEND : 0;
211
	retmode |= (reqmode & GR_APPEND) ? GR_AUDIT_APPEND : 0;
212
	retmode |= (reqmode & GR_EXEC) ? GR_AUDIT_EXEC : 0;
213
	retmode |= (reqmode & GR_INHERIT) ? GR_AUDIT_INHERIT : 0;
214
	retmode |= (reqmode & GR_FIND) ? GR_AUDIT_FIND : 0;
215
	retmode |= (reqmode & GR_SETID) ? GR_AUDIT_SETID : 0;
216
	retmode |= (reqmode & GR_CREATE) ? GR_AUDIT_CREATE : 0;
217
	retmode |= (reqmode & GR_DELETE) ? GR_AUDIT_DELETE : 0;
218
219
	return retmode;
220
}
221
222
__inline__ struct acl_role_label *
223
lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
224
		      const gid_t gid)
225
{
226
	unsigned long index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
227
	struct acl_role_label *match;
228
	struct role_allowed_ip *ipp;
229
	__u8 i = 0;
230
231
	match = acl_role_set.r_hash[index];
232
233
	while (match
234
	       && (match->uidgid != uid || !(match->roletype & GR_ROLE_USER))) {
235
		index = (index + (1 << i)) % acl_role_set.r_size;
236
		match = acl_role_set.r_hash[index];
237
		i = (i + 1) % 32;
238
	}
239
240
	if (!match || match->uidgid != uid || !(match->roletype & GR_ROLE_USER)) {
241
	      try_group:
242
		index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
243
		match = acl_role_set.r_hash[index];
244
		i = 0;
245
246
		while (match
247
		       && (match->uidgid != gid
248
			   || !(match->roletype & GR_ROLE_GROUP))) {
249
			index = (index + (1 << i)) % acl_role_set.r_size;
250
			match = acl_role_set.r_hash[index];
251
			i = (i + 1) % 32;
252
		}
253
254
		if (!match || match->uidgid != gid
255
		    || !(match->roletype & GR_ROLE_GROUP))
256
			match = default_role;
257
		else if (likely(!match->allowed_ips)) {
258
			return match;
259
		} else {
260
			for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
261
				if (likely
262
				    ((task->curr_ip & ipp->netmask) ==
263
				     (ipp->addr & ipp->netmask)))
264
					return match;
265
			}
266
			match = default_role;
267
		}
268
	} else if (likely(!match->allowed_ips)) {
269
		return match;
270
	} else {
271
		for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
272
			if (likely
273
			    ((task->curr_ip & ipp->netmask) ==
274
			     (ipp->addr & ipp->netmask)))
275
				return match;
276
		}
277
		goto try_group;
278
	}
279
280
	return match;
281
}
282
283
__inline__ struct acl_subject_label *
284
lookup_acl_subj_label(const ino_t ino, const kdev_t dev,
285
		      const struct acl_role_label *role)
286
{
287
	unsigned long subj_size = role->subj_hash_size;
288
	struct acl_subject_label **s_hash = role->subj_hash;
289
	unsigned long index = fhash(ino, dev, subj_size);
290
	struct acl_subject_label *match;
291
	__u8 i = 0;
292
293
	match = s_hash[index];
294
295
	while (match && (match->inode != ino || match->device != dev ||
296
	       (match->mode & GR_DELETED))) {
297
		index = (index + (1 << i)) % subj_size;
298
		match = s_hash[index];
299
		i = (i + 1) % 32;
300
	}
301
302
	if (unlikely(match && (match != deleted_subject) &&
303
		     (match->inode == ino) && (match->device == dev) &&
304
		     !(match->mode & GR_DELETED)))
305
		return match;
306
	else
307
		return NULL;
308
}
309
310
static __inline__ struct acl_object_label *
311
lookup_acl_obj_label(const ino_t ino, const kdev_t dev,
312
		     const struct acl_subject_label *subj)
313
{
314
	unsigned long obj_size = subj->obj_hash_size;
315
	struct acl_object_label **o_hash = subj->obj_hash;
316
	unsigned long index = fhash(ino, dev, obj_size);
317
	struct acl_object_label *match;
318
	__u8 i = 0;
319
320
	match = o_hash[index];
321
322
	while (match && (match->inode != ino || match->device != dev ||
323
	       (match->mode & GR_DELETED))) {
324
		index = (index + (1 << i)) % obj_size;
325
		match = o_hash[index];
326
		i = (i + 1) % 32;
327
	}
328
329
	if (unlikely(match && (match != deleted_object) &&
330
		     (match->inode == ino) && (match->device == dev) &&
331
		     !(match->mode & GR_DELETED)))
332
		return match;
333
	else
334
		return NULL;
335
}
336
337
static __inline__ struct acl_object_label *
338
lookup_acl_obj_label_create(const ino_t ino, const kdev_t dev,
339
		     const struct acl_subject_label *subj)
340
{
341
	unsigned long obj_size = subj->obj_hash_size;
342
	struct acl_object_label **o_hash = subj->obj_hash;
343
	unsigned long index = fhash(ino, dev, obj_size);
344
	struct acl_object_label *match;
345
	__u8 i = 0;
346
347
	match = o_hash[index];
348
349
	while (match && (match->inode != ino || match->device != dev ||
350
	       !(match->mode & GR_DELETED))) {
351
		index = (index + (1 << i)) % obj_size;
352
		match = o_hash[index];
353
		i = (i + 1) % 32;
354
	}
355
356
	if (unlikely(match && (match != deleted_object) &&
357
		     (match->inode == ino) && (match->device == dev) &&
358
		     (match->mode & GR_DELETED)))
359
		return match;
360
361
	i = 0;
362
	index = fhash(ino, dev, obj_size);
363
	match = o_hash[index];
364
365
	while (match && (match->inode != ino || match->device != dev ||
366
	       (match->mode & GR_DELETED))) {
367
		index = (index + (1 << i)) % obj_size;
368
		match = o_hash[index];
369
		i = (i + 1) % 32;
370
	}
371
372
	if (unlikely(match && (match != deleted_object) &&
373
		     (match->inode == ino) && (match->device == dev) &&
374
		     !(match->mode & GR_DELETED)))
375
		return match;
376
	else
377
		return NULL;
378
}
379
380
static __inline__ struct name_entry *
381
lookup_name_entry(const char *name)
382
{
383
	__u16 len = strlen(name);
384
	unsigned long index = nhash(name, len, name_set.n_size);
385
	struct name_entry *match;
386
	__u8 i = 0;
387
388
	match = name_set.n_hash[index];
389
390
	while (match && !gr_streq(match->name, name, match->len, len)) {
391
		index = (index + (1 << i)) % name_set.n_size;
392
		match = name_set.n_hash[index];
393
		i = (i + 1) % 32;
394
	}
395
396
	if (unlikely(!match || !gr_streq(match->name, name, match->len, len)))
397
		return NULL;
398
	else
399
		return match;
400
}
401
402
static __inline__ struct name_entry *
403
lookup_inodev_entry(const ino_t ino, const kdev_t dev)
404
{
405
	unsigned long index = fhash(ino, dev, inodev_set.n_size);
406
	struct name_entry *match;
407
	__u8 i = 0;
408
409
	match = inodev_set.n_hash[index];
410
411
	while (match && (match->inode != ino || match->device != dev)) {
412
		index = (index + (1 << i)) % inodev_set.n_size;
413
		match = inodev_set.n_hash[index];
414
		i = (i + 1) % 32;
415
	}
416
417
	if (unlikely(match && (match != deleted_inodev) &&
418
		     (match->inode == ino) && (match->device == dev)))
419
		return match;
420
	else
421
		return NULL;
422
}
423
424
static void
425
insert_inodev_entry(struct name_entry *nentry)
426
{
427
	unsigned long index = fhash(nentry->inode, nentry->device,
428
				    inodev_set.n_size);
429
	struct name_entry **curr;
430
	__u8 i = 0;
431
432
	curr = &inodev_set.n_hash[index];
433
434
	while (*curr && *curr != deleted_inodev) {
435
		index = (index + (1 << i)) % inodev_set.n_size;
436
		curr = &inodev_set.n_hash[index];
437
		i = (i + 1) % 32;
438
	}
439
440
	*curr = nentry;
441
442
	return;
443
}
444
445
static void
446
insert_acl_role_label(struct acl_role_label *role)
447
{
448
	unsigned long index =
449
	    rhash(role->uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
450
	struct acl_role_label **curr;
451
	__u8 i = 0;
452
453
	curr = &acl_role_set.r_hash[index];
454
455
	while (*curr) {
456
		index = (index + (1 << i)) % acl_role_set.r_size;
457
		curr = &acl_role_set.r_hash[index];
458
		i = (i + 1) % 32;
459
	}
460
461
	*curr = role;
462
463
	return;
464
}
465
466
static int
467
insert_name_entry(char *name, const ino_t inode, const kdev_t device)
468
{
469
	struct name_entry **curr;
470
	__u8 i = 0;
471
	__u16 len = strlen(name);
472
	unsigned long index = nhash(name, len, name_set.n_size);
473
474
	curr = &name_set.n_hash[index];
475
476
	while (*curr && !gr_streq((*curr)->name, name, (*curr)->len, len)) {
477
		index = (index + (1 << i)) % name_set.n_size;
478
		curr = &name_set.n_hash[index];
479
		i = (i + 1) % 32;
480
	}
481
482
	if (!(*curr)) {
483
		struct name_entry *nentry =
484
		    acl_alloc(sizeof (struct name_entry));
485
		if (!nentry)
486
			return 0;
487
		nentry->name = name;
488
		nentry->inode = inode;
489
		nentry->device = device;
490
		nentry->len = len;
491
		*curr = nentry;
492
		/* insert us into the table searchable by inode/dev */
493
		insert_inodev_entry(nentry);
494
	}
495
496
	return 1;
497
}
498
499
static void
500
insert_acl_obj_label(struct acl_object_label *obj,
501
		     struct acl_subject_label *subj)
502
{
503
	unsigned long index =
504
	    fhash(obj->inode, obj->device, subj->obj_hash_size);
505
	struct acl_object_label **curr;
506
	__u8 i = 0;
507
508
	curr = &subj->obj_hash[index];
509
510
	while (*curr && *curr != deleted_object) {
511
		index = (index + (1 << i)) % subj->obj_hash_size;
512
		curr = &subj->obj_hash[index];
513
		i = (i + 1) % 32;
514
	}
515
516
	*curr = obj;
517
518
	return;
519
}
520
521
static void
522
insert_acl_subj_label(struct acl_subject_label *obj,
523
		      struct acl_role_label *role)
524
{
525
	unsigned long subj_size = role->subj_hash_size;
526
	struct acl_subject_label **s_hash = role->subj_hash;
527
	unsigned long index = fhash(obj->inode, obj->device, subj_size);
528
	struct acl_subject_label **curr;
529
	__u8 i = 0;
530
531
	curr = &s_hash[index];
532
533
	while (*curr && *curr != deleted_subject) {
534
		index = (index + (1 << i)) % subj_size;
535
		curr = &s_hash[index];
536
		i = (i + 1) % 32;
537
	}
538
539
	*curr = obj;
540
541
	return;
542
}
543
544
static void **
545
create_table(__u32 * len)
546
{
547
	unsigned long table_sizes[] = {
548
		7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
549
		32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
550
		4194301, 8388593, 16777213, 33554393, 67108859, 134217689,
551
		268435399, 536870909, 1073741789, 2147483647
552
	};
553
	void *newtable = NULL;
554
	unsigned int pwr = 0;
555
556
	while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
557
	       table_sizes[pwr] <= (2 * (*len)))
558
		pwr++;
559
560
	if (table_sizes[pwr] <= (2 * (*len)))
561
		return newtable;
562
563
	if ((table_sizes[pwr] * sizeof (void *)) <= PAGE_SIZE)
564
		newtable =
565
		    kmalloc(table_sizes[pwr] * sizeof (void *), GFP_KERNEL);
566
	else
567
		newtable = vmalloc(table_sizes[pwr] * sizeof (void *));
568
569
	*len = table_sizes[pwr];
570
571
	return newtable;
572
}
573
574
static int
575
init_variables(const unsigned long acl_obj_size,
576
	       const unsigned long acl_subj_size,
577
	       const unsigned long acl_ip_size,
578
	       const unsigned long acl_role_size,
579
	       const unsigned long allowed_ip_size,
580
	       const unsigned long acl_trans_size,
581
	       const __u16 num_sprole_pws)
582
{
583
	unsigned long stacksize;
584
585
	acl_role_set.r_size = acl_role_size;
586
	name_set.n_size = (acl_obj_size + acl_subj_size);
587
	inodev_set.n_size = (acl_obj_size + acl_subj_size);
588
589
	if (!gr_init_uidset())
590
		return 1;
591
592
	/* set up the stack that holds allocation info */
593
594
	stacksize = (3 * acl_obj_size) + (2 * acl_role_size) +
595
	    (4 * acl_subj_size) + acl_ip_size + (2 * acl_trans_size) +
596
	    allowed_ip_size + (2 * num_sprole_pws) + 5;
597
598
	if (!acl_alloc_stack_init(stacksize))
599
		return 1;
600
601
	/* create our empty, fake deleted acls */
602
	deleted_subject =
603
	    (struct acl_subject_label *)
604
	    acl_alloc(sizeof (struct acl_subject_label));
605
	deleted_object =
606
	    (struct acl_object_label *)
607
	    acl_alloc(sizeof (struct acl_object_label));
608
	deleted_inodev =
609
	    (struct name_entry *) acl_alloc(sizeof (struct name_entry));
610
611
	if (!deleted_subject || !deleted_object || !deleted_inodev)
612
		return 1;
613
614
	memset(deleted_subject, 0, sizeof (struct acl_subject_label));
615
	memset(deleted_object, 0, sizeof (struct acl_object_label));
616
	memset(deleted_inodev, 0, sizeof (struct name_entry));
617
618
	/* We only want 50% full tables for now */
619
620
	acl_role_set.r_hash =
621
	    (struct acl_role_label **) create_table(&acl_role_set.r_size);
622
	name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size);
623
	inodev_set.n_hash =
624
	    (struct name_entry **) create_table(&inodev_set.n_size);
625
626
	if (!acl_role_set.r_hash || !name_set.n_hash || !inodev_set.n_hash)
627
		return 1;
628
	memset(acl_role_set.r_hash, 0,
629
	       sizeof (struct acl_role_label *) * acl_role_set.r_size);
630
	memset(name_set.n_hash, 0,
631
	       sizeof (struct name_entry *) * name_set.n_size);
632
	memset(inodev_set.n_hash, 0,
633
	       sizeof (struct name_entry *) * inodev_set.n_size);
634
635
	return 0;
636
}
637
638
static void
639
free_variables(void)
640
{
641
	struct acl_subject_label *s;
642
	struct acl_role_label *r;
643
	struct task_struct *task;
644
645
	gr_clear_learn_entries();
646
647
	read_lock(&tasklist_lock);
648
	for_each_task(task) {
649
		task->acl_sp_role = 0;
650
		task->acl_role_id = 0;
651
		task->acl = NULL;
652
		task->role = NULL;
653
	}
654
	read_unlock(&tasklist_lock);
655
656
	/* free all object hash tables */
657
658
	if (role_list_head) {
659
		for (r = role_list_head; r; r = r->next) {
660
			if (!r->subj_hash)
661
				break;
662
			for (s = r->proc_subject; s; s = s->next) {
663
				if (!s->obj_hash)
664
					break;
665
				if ((s->obj_hash_size *
666
				     sizeof (struct acl_object_label *)) <=
667
				    PAGE_SIZE)
668
					kfree(s->obj_hash);
669
				else
670
					vfree(s->obj_hash);
671
			}
672
			if ((r->subj_hash_size *
673
			     sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
674
				kfree(r->subj_hash);
675
			else
676
				vfree(r->subj_hash);
677
		}
678
	}
679
680
	acl_free_all();
681
682
	if (acl_role_set.r_hash) {
683
		if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
684
		    PAGE_SIZE)
685
			kfree(acl_role_set.r_hash);
686
		else
687
			vfree(acl_role_set.r_hash);
688
	}
689
	if (name_set.n_hash) {
690
		if ((name_set.n_size * sizeof (struct name_entry *)) <=
691
		    PAGE_SIZE)
692
			kfree(name_set.n_hash);
693
		else
694
			vfree(name_set.n_hash);
695
	}
696
697
	if (inodev_set.n_hash) {
698
		if ((inodev_set.n_size * sizeof (struct name_entry *)) <=
699
		    PAGE_SIZE)
700
			kfree(inodev_set.n_hash);
701
		else
702
			vfree(inodev_set.n_hash);
703
	}
704
705
	gr_free_uidset();
706
707
	memset(&name_set, 0, sizeof (struct name_db));
708
	memset(&inodev_set, 0, sizeof (struct name_db));
709
	memset(&acl_role_set, 0, sizeof (struct acl_role_db));
710
711
	role_list_head = NULL;
712
	default_role = NULL;
713
714
	return;
715
}
716
717
static __u32
718
count_user_objs(struct acl_object_label *userp)
719
{
720
	struct acl_object_label o_tmp;
721
	__u32 num = 0;
722
723
	while (userp) {
724
		if (copy_from_user(&o_tmp, userp,
725
				   sizeof (struct acl_object_label)))
726
			break;
727
728
		userp = o_tmp.prev;
729
		num++;
730
	}
731
732
	return num;
733
}
734
735
static struct acl_subject_label *
736
do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
737
738
static int
739
copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
740
	       struct acl_role_label *role)
741
{
742
	struct acl_object_label *o_tmp;
743
	unsigned int len;
744
	char *tmp;
745
746
	while (userp) {
747
		if ((o_tmp = (struct acl_object_label *)
748
		     acl_alloc(sizeof (struct acl_object_label))) == NULL)
749
			return -ENOMEM;
750
751
		if (copy_from_user(o_tmp, userp,
752
				   sizeof (struct acl_object_label)))
753
			return -EFAULT;
754
755
		userp = o_tmp->prev;
756
757
		len = strnlen_user(o_tmp->filename, PATH_MAX);
758
759
		if (!len || len >= PATH_MAX)
760
			return -EINVAL;
761
762
		if ((tmp = (char *) acl_alloc(len)) == NULL)
763
			return -ENOMEM;
764
765
		if (copy_from_user(tmp, o_tmp->filename, len))
766
			return -EFAULT;
767
768
		o_tmp->filename = tmp;
769
770
		insert_acl_obj_label(o_tmp, subj);
771
		if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
772
				       o_tmp->device))
773
			return -ENOMEM;
774
775
		if (o_tmp->nested) {
776
			o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
777
			if (IS_ERR(o_tmp->nested))
778
				return PTR_ERR(o_tmp->nested);
779
780
			s_final = o_tmp->nested;
781
		}
782
	}
783
784
	return 0;
785
}
786
787
static __u32
788
count_user_subjs(struct acl_subject_label *userp)
789
{
790
	struct acl_subject_label s_tmp;
791
	__u32 num = 0;
792
793
	while (userp) {
794
		if (copy_from_user(&s_tmp, userp,
795
				   sizeof (struct acl_subject_label)))
796
			break;
797
798
		userp = s_tmp.prev;
799
		/* do not count nested subjects against this count, since
800
		   they are not included in the hash table, but are
801
		   attached to objects.  We have already counted
802
		   the subjects in userspace for the allocation 
803
		   stack
804
		*/
805
		if (!s_tmp.parent_subject)
806
			num++;
807
	}
808
809
	return num;
810
}
811
812
static int
813
copy_user_allowedips(struct acl_role_label *rolep)
814
{
815
	struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
816
817
	ruserip = rolep->allowed_ips;
818
819
	while (ruserip) {
820
		rlast = rtmp;
821
822
		if ((rtmp = (struct role_allowed_ip *)
823
		     acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
824
			return -ENOMEM;
825
826
		if (copy_from_user(rtmp, ruserip,
827
				   sizeof (struct role_allowed_ip)))
828
			return -EFAULT;
829
830
		ruserip = rtmp->prev;
831
832
		if (!rlast) {
833
			rtmp->prev = NULL;
834
			rolep->allowed_ips = rtmp;
835
		} else {
836
			rlast->next = rtmp;
837
			rtmp->prev = rlast;
838
		}
839
840
		if (!ruserip)
841
			rtmp->next = NULL;
842
	}
843
844
	return 0;
845
}
846
847
static int
848
copy_user_transitions(struct acl_role_label *rolep)
849
{
850
	struct role_transition *rusertp, *rtmp = NULL, *rlast;
851
	unsigned int len;
852
	char *tmp;
853
854
	rusertp = rolep->transitions;
855
856
	while (rusertp) {
857
		rlast = rtmp;
858
859
		if ((rtmp = (struct role_transition *)
860
		     acl_alloc(sizeof (struct role_transition))) == NULL)
861
			return -ENOMEM;
862
863
		if (copy_from_user(rtmp, rusertp,
864
				   sizeof (struct role_transition)))
865
			return -EFAULT;
866
867
		rusertp = rtmp->prev;
868
869
		len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
870
871
		if (!len || len >= GR_SPROLE_LEN)
872
			return -EINVAL;
873
874
		if ((tmp = (char *) acl_alloc(len)) == NULL)
875
			return -ENOMEM;
876
877
		if (copy_from_user(tmp, rtmp->rolename, len))
878
			return -EFAULT;
879
880
		rtmp->rolename = tmp;
881
882
		if (!rlast) {
883
			rtmp->prev = NULL;
884
			rolep->transitions = rtmp;
885
		} else {
886
			rlast->next = rtmp;
887
			rtmp->prev = rlast;
888
		}
889
890
		if (!rusertp)
891
			rtmp->next = NULL;
892
	}
893
894
	return 0;
895
}
896
897
static struct acl_subject_label *
898
do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
899
{
900
	struct acl_subject_label *s_tmp = NULL;
901
	unsigned int len;
902
	char *tmp;
903
	__u32 num_objs;
904
	struct acl_ip_label **i_tmp, *i_utmp2;
905
	unsigned long i_num;
906
	int err;
907
908
909
	if ((s_tmp = (struct acl_subject_label *)
910
	    acl_alloc(sizeof (struct acl_subject_label))) == NULL)
911
		return ERR_PTR(-ENOMEM);
912
913
	if (copy_from_user(s_tmp, userp,
914
			   sizeof (struct acl_subject_label)))
915
		return ERR_PTR(-EFAULT);
916
917
	if (!s_last) {
918
		s_tmp->prev = NULL;
919
		role->proc_subject = s_tmp;
920
	} else {
921
		s_last->next = s_tmp;
922
		s_tmp->prev = s_last;
923
	}
924
925
	s_last = s_tmp;
926
927
	len = strnlen_user(s_tmp->filename, PATH_MAX);
928
929
	if (!len || len >= PATH_MAX)
930
		return ERR_PTR(-EINVAL);
931
932
	if ((tmp = (char *) acl_alloc(len)) == NULL)
933
		return ERR_PTR(-ENOMEM);
934
935
	if (copy_from_user(tmp, s_tmp->filename, len))
936
		return ERR_PTR(-EFAULT);
937
938
	s_tmp->filename = tmp;
939
940
	if (!strcmp(s_tmp->filename, "/"))
941
		role->root_label = s_tmp;
942
943
	/* set up object hash table */
944
	num_objs = count_user_objs(s_tmp->proc_object);
945
946
	s_tmp->obj_hash_size = num_objs;
947
	s_tmp->obj_hash =
948
	    (struct acl_object_label **)
949
	    create_table(&(s_tmp->obj_hash_size));
950
951
	if (!s_tmp->obj_hash)
952
		return ERR_PTR(-ENOMEM);
953
954
	memset(s_tmp->obj_hash, 0,
955
	       s_tmp->obj_hash_size *
956
	       sizeof (struct acl_object_label *));
957
958
	/* copy before adding in objects, since a nested
959
	   acl could be found and be the final subject
960
	   copied
961
	*/
962
963
	s_final = s_tmp;
964
965
	/* add in objects */
966
	err = copy_user_objs(s_tmp->proc_object, s_tmp, role);
967
968
	if (err)
969
		return ERR_PTR(err);
970
971
	/* add in ip acls */
972
973
	if (!s_tmp->ip_num) {
974
		s_tmp->ips = NULL;
975
		goto insert;
976
	}
977
978
	i_tmp =
979
	    (struct acl_ip_label **) acl_alloc(s_tmp->ip_num *
980
					       sizeof (struct
981
						       acl_ip_label *));
982
983
	if (!i_tmp)
984
		return ERR_PTR(-ENOMEM);
985
986
	for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
987
		*(i_tmp + i_num) =
988
		    (struct acl_ip_label *)
989
		    acl_alloc(sizeof (struct acl_ip_label));
990
		if (!*(i_tmp + i_num))
991
			return ERR_PTR(-ENOMEM);
992
993
		if (copy_from_user
994
		    (&i_utmp2, s_tmp->ips + i_num,
995
		     sizeof (struct acl_ip_label *)))
996
			return ERR_PTR(-EFAULT);
997
998
		if (copy_from_user
999
		    (*(i_tmp + i_num), i_utmp2,
1000
		     sizeof (struct acl_ip_label)))
1001
			return ERR_PTR(-EFAULT);
1002
	}
1003
1004
	s_tmp->ips = i_tmp;
1005
1006
insert:
1007
	if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
1008
			       s_tmp->device))
1009
		return ERR_PTR(-ENOMEM);
1010
1011
	return s_tmp;
1012
}
1013
1014
static int
1015
copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
1016
{
1017
	struct acl_subject_label s_pre;
1018
	struct acl_subject_label * ret;
1019
	int err;
1020
1021
	while (userp) {
1022
		if (copy_from_user(&s_pre, userp,
1023
				   sizeof (struct acl_subject_label)))
1024
			return -EFAULT;
1025
		
1026
		/* do not add nested subjects here, add
1027
		   while parsing objects
1028
		*/
1029
1030
		if (s_pre.parent_subject) {
1031
			userp = s_pre.prev;
1032
			continue;
1033
		}
1034
1035
		ret = do_copy_user_subj(userp, role);
1036
1037
		err = PTR_ERR(ret);
1038
		if (IS_ERR(ret))
1039
			return err;
1040
1041
		insert_acl_subj_label(ret, role);
1042
1043
		userp = s_pre.prev;
1044
	}
1045
1046
	s_final->next = NULL;
1047
1048
	return 0;
1049
}
1050
1051
static int
1052
copy_user_acl(struct gr_arg *arg)
1053
{
1054
	struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2, *r_last;
1055
	struct sprole_pw *sptmp;
1056
	unsigned long r_num;
1057
	unsigned int len;
1058
	char *tmp;
1059
	int err = 0;
1060
	__u16 i;
1061
	__u32 num_subjs;
1062
1063
	/* we need a default and kernel role */
1064
	if (arg->role_db.r_entries < 2)
1065
		return -EINVAL;
1066
1067
	/* copy special role authentication info from userspace */
1068
1069
	num_sprole_pws = arg->num_sprole_pws;
1070
	acl_special_roles = (struct sprole_pw **) acl_alloc(num_sprole_pws * sizeof(struct sprole_pw *));
1071
1072
	if (!acl_special_roles) {
1073
		err = -ENOMEM;
1074
		goto cleanup;
1075
	}
1076
1077
	for (i = 0; i < num_sprole_pws; i++) {
1078
		sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
1079
		if (!sptmp) {
1080
			err = -ENOMEM;
1081
			goto cleanup;
1082
		}
1083
		if (copy_from_user(sptmp, arg->sprole_pws + i,
1084
				   sizeof (struct sprole_pw))) {
1085
			err = -EFAULT;
1086
			goto cleanup;
1087
		}
1088
1089
		len =
1090
		    strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
1091
1092
		if (!len || len >= GR_SPROLE_LEN) {
1093
			err = -EINVAL;
1094
			goto cleanup;
1095
		}
1096
1097
		if ((tmp = (char *) acl_alloc(len)) == NULL) {
1098
			err = -ENOMEM;
1099
			goto cleanup;
1100
		}
1101
1102
		if (copy_from_user(tmp, sptmp->rolename, len)) {
1103
			err = -EFAULT;
1104
			goto cleanup;
1105
		}
1106
1107
#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
1108
		printk(KERN_ALERT "Copying special role %s\n", tmp);
1109
#endif
1110
		sptmp->rolename = tmp;
1111
		acl_special_roles[i] = sptmp;
1112
	}
1113
1114
	r_utmp = (struct acl_role_label **) arg->role_db.r_table;
1115
1116
	for (r_num = 0; r_num < arg->role_db.r_entries; r_num++) {
1117
		r_last = r_tmp;
1118
1119
		r_tmp = acl_alloc(sizeof (struct acl_role_label));
1120
1121
		if (!r_tmp) {
1122
			err = -ENOMEM;
1123
			goto cleanup;
1124
		}
1125
1126
		if (copy_from_user(&r_utmp2, r_utmp + r_num,
1127
				   sizeof (struct acl_role_label *))) {
1128
			err = -EFAULT;
1129
			goto cleanup;
1130
		}
1131
1132
		if (copy_from_user(r_tmp, r_utmp2,
1133
				   sizeof (struct acl_role_label))) {
1134
			err = -EFAULT;
1135
			goto cleanup;
1136
		}
1137
1138
		if (!r_last) {
1139
			r_tmp->prev = NULL;
1140
			role_list_head = r_tmp;
1141
		} else {
1142
			r_last->next = r_tmp;
1143
			r_tmp->prev = r_last;
1144
		}
1145
1146
		if (r_num == (arg->role_db.r_entries - 1))
1147
			r_tmp->next = NULL;
1148
1149
		len = strnlen_user(r_tmp->rolename, PATH_MAX);
1150
1151
		if (!len || len >= PATH_MAX) {
1152
			err = -EINVAL;
1153
			goto cleanup;
1154
		}
1155
1156
		if ((tmp = (char *) acl_alloc(len)) == NULL) {
1157
			err = -ENOMEM;
1158
			goto cleanup;
1159
		}
1160
		if (copy_from_user(tmp, r_tmp->rolename, len)) {
1161
			err = -EFAULT;
1162
			goto cleanup;
1163
		}
1164
		r_tmp->rolename = tmp;
1165
1166
		if (!strcmp(r_tmp->rolename, "default")
1167
		    && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
1168
			default_role = r_tmp;
1169
		} else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
1170
			kernel_role = r_tmp;
1171
		}
1172
1173
		num_subjs = count_user_subjs(r_tmp->proc_subject);
1174
1175
		r_tmp->subj_hash_size = num_subjs;
1176
		r_tmp->subj_hash =
1177
		    (struct acl_subject_label **)
1178
		    create_table(&(r_tmp->subj_hash_size));
1179
1180
		if (!r_tmp->subj_hash) {
1181
			err = -ENOMEM;
1182
			goto cleanup;
1183
		}
1184
1185
		err = copy_user_allowedips(r_tmp);
1186
		if (err)
1187
			goto cleanup;
1188
1189
		err = copy_user_transitions(r_tmp);
1190
		if (err)
1191
			goto cleanup;
1192
1193
		memset(r_tmp->subj_hash, 0,
1194
		       r_tmp->subj_hash_size *
1195
		       sizeof (struct acl_subject_label *));
1196
1197
		s_last = NULL;
1198
1199
		err = copy_user_subjs(r_tmp->proc_subject, r_tmp);
1200
1201
		if (err)
1202
			goto cleanup;
1203
1204
		insert_acl_role_label(r_tmp);
1205
	}
1206
1207
	goto return_err;
1208
      cleanup:
1209
	free_variables();
1210
      return_err:
1211
	return err;
1212
1213
}
1214
1215
static int
1216
gracl_init(struct gr_arg *args)
1217
{
1218
	int error = 0;
1219
1220
	memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
1221
	memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
1222
1223
	if (init_variables(args->role_db.o_entries, args->role_db.s_entries,
1224
			   args->role_db.i_entries, args->role_db.r_entries,
1225
			   args->role_db.a_entries, args->role_db.t_entries,
1226
			   args->num_sprole_pws)) {
1227
		security_alert_good(GR_INITF_ACL_MSG, GR_VERSION);
1228
		error = -ENOMEM;
1229
		free_variables();
1230
		goto out;
1231
	}
1232
1233
	error = copy_user_acl(args);
1234
	if (error)
1235
		goto out;
1236
1237
	if ((error = gr_set_acls(0))) {
1238
		free_variables();
1239
		goto out;
1240
	}
1241
1242
	gr_status |= GR_READY;
1243
      out:
1244
	return error;
1245
}
1246
1247
static struct acl_object_label *
1248
chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
1249
	      const struct acl_subject_label *subj)
1250
{
1251
	struct dentry *dentry = (struct dentry *) l_dentry;
1252
	struct vfsmount *mnt = (struct vfsmount *) l_mnt;
1253
	struct dentry *root;
1254
	struct vfsmount *rootmnt;
1255
	struct acl_object_label *retval;
1256
1257
	read_lock(&child_reaper->fs->lock);
1258
	rootmnt = mntget(child_reaper->fs->rootmnt);
1259
	root = dget(child_reaper->fs->root);
1260
	read_unlock(&child_reaper->fs->lock);
1261
	spin_lock(&dcache_lock);
1262
1263
	for (;;) {
1264
		if (unlikely(dentry == root && mnt == rootmnt))
1265
			break;
1266
		if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
1267
			if (mnt->mnt_parent == mnt)
1268
				break;
1269
1270
			read_lock(&gr_inode_lock);
1271
			retval =
1272
			    lookup_acl_obj_label(dentry->d_inode->i_ino,
1273
						 dentry->d_inode->i_dev, subj);
1274
			read_unlock(&gr_inode_lock);
1275
			if (unlikely(retval != NULL))
1276
				goto out;
1277
1278
			dentry = mnt->mnt_mountpoint;
1279
			mnt = mnt->mnt_parent;
1280
			continue;
1281
		}
1282
1283
		read_lock(&gr_inode_lock);
1284
		retval =
1285
		    lookup_acl_obj_label(dentry->d_inode->i_ino,
1286
					 dentry->d_inode->i_dev, subj);
1287
		read_unlock(&gr_inode_lock);
1288
		if (unlikely(retval != NULL))
1289
			goto out;
1290
1291
		dentry = dentry->d_parent;
1292
	}
1293
1294
	read_lock(&gr_inode_lock);
1295
	retval =
1296
	    lookup_acl_obj_label(dentry->d_inode->i_ino, dentry->d_inode->i_dev,
1297
				 subj);
1298
	read_unlock(&gr_inode_lock);
1299
1300
	if (unlikely(retval == NULL)) {
1301
		read_lock(&gr_inode_lock);
1302
		retval =
1303
		    lookup_acl_obj_label(root->d_inode->i_ino,
1304
					 root->d_inode->i_dev, subj);
1305
		read_unlock(&gr_inode_lock);
1306
	}
1307
      out:
1308
	spin_unlock(&dcache_lock);
1309
	dput(root);
1310
	mntput(rootmnt);
1311
1312
	return retval;
1313
}
1314
1315
static struct acl_subject_label *
1316
chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
1317
	       const struct acl_role_label *role)
1318
{
1319
	struct dentry *dentry = (struct dentry *) l_dentry;
1320
	struct vfsmount *mnt = (struct vfsmount *) l_mnt;
1321
	struct dentry *root;
1322
	struct vfsmount *rootmnt;
1323
	struct acl_subject_label *retval;
1324
1325
	read_lock(&child_reaper->fs->lock);
1326
	rootmnt = mntget(child_reaper->fs->rootmnt);
1327
	root = dget(child_reaper->fs->root);
1328
	read_unlock(&child_reaper->fs->lock);
1329
	spin_lock(&dcache_lock);
1330
1331
	for (;;) {
1332
		if (unlikely(dentry == root && mnt == rootmnt))
1333
			break;
1334
		if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
1335
			if (mnt->mnt_parent == mnt)
1336
				break;
1337
1338
			read_lock(&gr_inode_lock);
1339
			retval =
1340
			    lookup_acl_subj_label(dentry->d_inode->i_ino,
1341
						  dentry->d_inode->i_dev, role);
1342
			read_unlock(&gr_inode_lock);
1343
			if (unlikely(retval != NULL))
1344
				goto out;
1345
1346
			dentry = mnt->mnt_mountpoint;
1347
			mnt = mnt->mnt_parent;
1348
			continue;
1349
		}
1350
1351
		read_lock(&gr_inode_lock);
1352
		retval =
1353
		    lookup_acl_subj_label(dentry->d_inode->i_ino,
1354
					  dentry->d_inode->i_dev, role);
1355
		read_unlock(&gr_inode_lock);
1356
		if (unlikely(retval != NULL))
1357
			goto out;
1358
1359
		dentry = dentry->d_parent;
1360
	}
1361
1362
	read_lock(&gr_inode_lock);
1363
	retval =
1364
	    lookup_acl_subj_label(dentry->d_inode->i_ino,
1365
				  dentry->d_inode->i_dev, role);
1366
	read_unlock(&gr_inode_lock);
1367
1368
	if (unlikely(retval == NULL)) {
1369
		read_lock(&gr_inode_lock);
1370
		retval =
1371
		    lookup_acl_subj_label(root->d_inode->i_ino,
1372
					  root->d_inode->i_dev, role);
1373
		read_unlock(&gr_inode_lock);
1374
	}
1375
      out:
1376
	spin_unlock(&dcache_lock);
1377
	dput(root);
1378
	mntput(rootmnt);
1379
1380
	return retval;
1381
}
1382
1383
static __inline__ void
1384
gr_log_learn(const struct acl_role_label *role, const uid_t uid, const gid_t gid,
1385
	     const struct task_struct *task, const char *pathname,
1386
	     const __u32 mode)
1387
{
1388
	security_learn(GR_LEARN_AUDIT_MSG, role->rolename, role->roletype,
1389
		       uid, gid, task->exec_file ? gr_to_filename1(task->exec_file->f_dentry,
1390
		       task->exec_file->f_vfsmnt) : task->acl->filename, task->acl->filename,
1391
		       1, 1, pathname, (unsigned long) mode, NIPQUAD(task->curr_ip));
1392
1393
	return;
1394
}
1395
1396
__u32
1397
gr_check_link(const struct dentry * new_dentry,
1398
	      const struct dentry * parent_dentry,
1399
	      const struct vfsmount * parent_mnt,
1400
	      const struct dentry * old_dentry, const struct vfsmount * old_mnt)
1401
{
1402
	struct acl_object_label *obj;
1403
	__u32 oldmode, newmode;
1404
1405
	if (unlikely(!(gr_status & GR_READY)))
1406
		return (GR_WRITE | GR_CREATE);
1407
1408
	obj = chk_obj_label(old_dentry, old_mnt, current->acl);
1409
	oldmode = obj->mode;
1410
1411
	if (current->acl->mode & GR_LEARN)
1412
		oldmode |= (GR_WRITE | GR_CREATE);
1413
	newmode =
1414
	    gr_check_create(new_dentry, parent_dentry, parent_mnt,
1415
			    oldmode | GR_CREATE | GR_AUDIT_CREATE |
1416
			    GR_AUDIT_WRITE | GR_SUPPRESS);
1417
1418
	if ((newmode & oldmode) == oldmode)
1419
		return newmode;
1420
	else if (current->acl->mode & GR_LEARN) {
1421
		gr_log_learn(current->role, current->uid, current->gid,
1422
			current, gr_to_filename(old_dentry, old_mnt), oldmode);
1423
		return (GR_WRITE | GR_CREATE);
1424
	} else if (newmode & GR_SUPPRESS)
1425
		return GR_SUPPRESS;
1426
	else
1427
		return 0;
1428
}
1429
1430
__u32
1431
gr_search_file(const struct dentry * dentry, const __u32 mode,
1432
	       const struct vfsmount * mnt)
1433
{
1434
	__u32 retval = mode;
1435
	struct acl_subject_label *curracl;
1436
	struct acl_object_label *currobj;
1437
1438
	if (unlikely(!(gr_status & GR_READY)))
1439
		return (mode & ~GR_AUDITS);
1440
1441
	curracl = current->acl;
1442
1443
	currobj = chk_obj_label(dentry, mnt, curracl);
1444
	retval = currobj->mode & mode;
1445
1446
	if (unlikely
1447
	    ((curracl->mode & GR_LEARN) && (mode != GR_PTRACERD)
1448
	     && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
1449
		__u32 new_mode = mode;
1450
1451
		new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
1452
1453
		retval = new_mode;
1454
1455
		if (!(mode & GR_NOLEARN))
1456
			gr_log_learn(current->role, current->uid, current->gid,
1457
				     current, gr_to_filename(dentry, mnt), new_mode);
1458
	}
1459
1460
	return retval;
1461
}
1462
1463
__u32
1464
gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
1465
		const struct vfsmount * mnt, const __u32 mode)
1466
{
1467
	struct name_entry *match;
1468
	struct acl_object_label *matchpo;
1469
	struct acl_subject_label *curracl;
1470
	__u32 retval;
1471
1472
	if (unlikely(!(gr_status & GR_READY)))
1473
		return (mode & ~GR_AUDITS);
1474
1475
	match = lookup_name_entry(gr_to_filename(new_dentry, mnt));
1476
1477
	if (!match)
1478
		goto check_parent;
1479
1480
	curracl = current->acl;
1481
1482
	read_lock(&gr_inode_lock);
1483
	matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
1484
	read_unlock(&gr_inode_lock);
1485
1486
	if (matchpo) {
1487
		if ((matchpo->mode & mode) !=
1488
		    (mode & ~(GR_AUDITS | GR_SUPPRESS))
1489
		    && curracl->mode & GR_LEARN) {
1490
			__u32 new_mode = mode;
1491
1492
			new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
1493
1494
			gr_log_learn(current->role, current->uid, current->gid,
1495
				     current, gr_to_filename(new_dentry, mnt), new_mode);
1496
1497
			return new_mode;
1498
		}
1499
		return (matchpo->mode & mode);
1500
	}
1501
1502
      check_parent:
1503
	curracl = current->acl;
1504
1505
	matchpo = chk_obj_label(parent, mnt, curracl);
1506
	retval = matchpo->mode & mode;
1507
1508
	if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
1509
	    && (curracl->mode & GR_LEARN)) {
1510
		__u32 new_mode = mode;
1511
1512
		new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
1513
1514
		gr_log_learn(current->role, current->uid, current->gid, 
1515
			     current, gr_to_filename(new_dentry, mnt), new_mode);
1516
		return new_mode;
1517
	}
1518
1519
	return retval;
1520
}
1521
1522
int
1523
gr_check_hidden_task(const struct task_struct *task)
1524
{
1525
	if (unlikely(!(gr_status & GR_READY)))
1526
		return 0;
1527
1528
	if (!(task->acl->mode & GR_FIND) && !(current->acl->mode & GR_VIEW))
1529
		return 1;
1530
1531
	return 0;
1532
}
1533
1534
int
1535
gr_check_protected_task(const struct task_struct *task)
1536
{
1537
	if (unlikely(!(gr_status & GR_READY) || !task))
1538
		return 0;
1539
1540
	if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL))
1541
		return 1;
1542
1543
	return 0;
1544
}
1545
1546
__inline__ void
1547
gr_copy_label(struct task_struct *tsk)
1548
{
1549
	tsk->used_accept = 0;
1550
	tsk->used_connect = 0;
1551
	tsk->acl_sp_role = 0;
1552
	tsk->acl_role_id = current->acl_role_id;
1553
	tsk->acl = current->acl;
1554
	tsk->role = current->role;
1555
	tsk->curr_ip = current->curr_ip;
1556
	if (current->exec_file)
1557
		get_file(current->exec_file);
1558
	tsk->exec_file = current->exec_file;
1559
	tsk->is_writable = current->is_writable;
1560
	if (unlikely(current->used_accept))
1561
		current->curr_ip = 0;
1562
1563
	return;
1564
}
1565
1566
static __inline__ void
1567
gr_set_proc_res(void)
1568
{
1569
	struct acl_subject_label *proc;
1570
	unsigned short i;
1571
1572
	proc = current->acl;
1573
1574
	if (proc->mode & GR_LEARN)
1575
		return;
1576
1577
	for (i = 0; i < RLIM_NLIMITS; i++) {
1578
		if (!(proc->resmask & (1 << i)))
1579
			continue;
1580
1581
		current->rlim[i].rlim_cur = proc->res[i].rlim_cur;
1582
		current->rlim[i].rlim_max = proc->res[i].rlim_max;
1583
	}
1584
1585
	return;
1586
}
1587
1588
void
1589
gr_set_pax_flags(struct task_struct *task)
1590
{
1591
	struct acl_subject_label *proc;
1592
1593
	if (unlikely(!(gr_status & GR_READY)))
1594
		return;
1595
1596
	proc = task->acl;
1597
1598
	if (proc->mode & GR_PAXPAGE)
1599
		task->flags &= ~PF_PAX_PAGEEXEC;
1600
	if (proc->mode & GR_PAXSEGM)
1601
		task->flags &= ~PF_PAX_SEGMEXEC;
1602
	if (proc->mode & GR_PAXGCC)
1603
		task->flags |= PF_PAX_EMUTRAMP;
1604
	if (proc->mode & GR_PAXMPROTECT)
1605
		task->flags &= ~PF_PAX_MPROTECT;
1606
	if (proc->mode & GR_PAXRANDMMAP)
1607
		task->flags &= ~PF_PAX_RANDMMAP;
1608
	if (proc->mode & GR_PAXRANDEXEC)
1609
		task->flags |= PF_PAX_RANDEXEC;
1610
1611
	return;
1612
}
1613
1614
static __inline__ void
1615
do_set_role_label(struct task_struct *task, const uid_t uid, const gid_t gid)
1616
{
1617
	task->role = lookup_acl_role_label(task, uid, gid);
1618
1619
	return;
1620
}
1621
1622
void
1623
gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
1624
{
1625
	struct acl_object_label *obj;
1626
	struct file *filp;
1627
1628
	if (unlikely(!(gr_status & GR_READY)))
1629
		return;
1630
1631
	filp = task->exec_file;
1632
1633
	/* kernel process, we'll give them the kernel role */
1634
	if (unlikely(!filp)) {
1635
		task->role = kernel_role;
1636
		task->acl = kernel_role->root_label;
1637
		return;
1638
	} else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
1639
		do_set_role_label(task, uid, gid);
1640
1641
	task->acl =
1642
	    chk_subj_label(filp->f_dentry, filp->f_vfsmnt, task->role);
1643
1644
	task->is_writable = 0;
1645
1646
	/* ignore additional mmap checks for processes that are writable 
1647
	   by the default ACL */
1648
	obj = chk_obj_label(filp->f_dentry, filp->f_vfsmnt, default_role->root_label);
1649
	if (unlikely(obj->mode & GR_WRITE))
1650
		task->is_writable = 1;
1651
	obj = chk_obj_label(filp->f_dentry, filp->f_vfsmnt, task->role->root_label);
1652
	if (unlikely(obj->mode & GR_WRITE))
1653
		task->is_writable = 1;
1654
1655
#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
1656
	printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
1657
#endif
1658
1659
	gr_set_proc_res();
1660
1661
	return;
1662
}
1663
1664
void
1665
gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt)
1666
{
1667
	struct acl_subject_label *newacl;
1668
	struct acl_object_label *obj;
1669
	__u32 retmode;
1670
1671
	if (unlikely(!(gr_status & GR_READY)))
1672
		return;
1673
1674
	newacl = chk_subj_label(dentry, mnt, current->role);
1675
1676
	obj = chk_obj_label(dentry, mnt, current->acl);
1677
	retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
1678
1679
	if ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT)) {
1680
		if (obj->nested)
1681
			current->acl = obj->nested;
1682
		else
1683
			current->acl = newacl;
1684
	} else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
1685
		security_audit(GR_INHERIT_ACL_MSG, current->acl->filename,
1686
			       gr_to_filename(dentry, mnt), DEFAULTSECARGS);
1687
1688
	current->is_writable = 0;
1689
1690
	/* ignore additional mmap checks for processes that are writable 
1691
	   by the default ACL */
1692
	obj = chk_obj_label(dentry, mnt, default_role->root_label);
1693
	if (unlikely(obj->mode & GR_WRITE))
1694
		current->is_writable = 1;
1695
	obj = chk_obj_label(dentry, mnt, current->role->root_label);
1696
	if (unlikely(obj->mode & GR_WRITE))
1697
		current->is_writable = 1;
1698
1699
	gr_set_proc_res();
1700
1701
#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
1702
	printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", current->comm, current->pid, current->role->rolename, current->acl->filename);
1703
#endif
1704
	return;
1705
}
1706
1707
static __inline__ void
1708
do_handle_delete(const ino_t ino, const kdev_t dev)
1709
{
1710
	struct acl_object_label *matchpo;
1711
	struct acl_subject_label *matchps;
1712
	struct acl_subject_label *i;
1713
	struct acl_role_label *role;
1714
1715
	for (role = role_list_head; role; role = role->next) {
1716
		for (i = role->proc_subject; i; i = i->next) {
1717
			if (unlikely(i->parent_subject &&
1718
				     (i->inode == ino) &&
1719
				     (i->device == dev)))
1720
				i->mode |= GR_DELETED;
1721
			if (unlikely((matchpo =
1722
			     lookup_acl_obj_label(ino, dev, i)) != NULL))
1723
				matchpo->mode |= GR_DELETED;
1724
		}
1725
1726
		if (unlikely((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL))
1727
			matchps->mode |= GR_DELETED;
1728
	}
1729
1730
	return;
1731
}
1732
1733
void
1734
gr_handle_delete(const ino_t ino, const kdev_t dev)
1735
{
1736
	if (unlikely(!(gr_status & GR_READY)))
1737
		return;
1738
1739
	write_lock(&gr_inode_lock);
1740
	if (unlikely((unsigned long)lookup_inodev_entry(ino, dev)))
1741
		do_handle_delete(ino, dev);
1742
	write_unlock(&gr_inode_lock);
1743
1744
	return;
1745
}
1746
1747
static __inline__ void
1748
update_acl_obj_label(const ino_t oldinode, const kdev_t olddevice,
1749
		     const ino_t newinode, const kdev_t newdevice,
1750
		     struct acl_subject_label *subj)
1751
{
1752
	unsigned long index = fhash(oldinode, olddevice, subj->obj_hash_size);
1753
	struct acl_object_label **match;
1754
	struct acl_object_label *tmp;
1755
	__u8 i = 0;
1756
1757
	match = &subj->obj_hash[index];
1758
1759
	while (*match && ((*match)->inode != oldinode ||
1760
	       (*match)->device != olddevice ||
1761
	       !((*match)->mode & GR_DELETED))) {
1762
		index = (index + (1 << i)) % subj->obj_hash_size;
1763
		match = &subj->obj_hash[index];
1764
		i = (i + 1) % 32;
1765
	}
1766
1767
	if (*match && ((*match) != deleted_object)
1768
	    && ((*match)->inode == oldinode)
1769
	    && ((*match)->device == olddevice)
1770
	    && ((*match)->mode & GR_DELETED)) {
1771
		tmp = *match;
1772
		tmp->inode = newinode;
1773
		tmp->device = newdevice;
1774
		tmp->mode &= ~GR_DELETED;
1775
1776
		*match = deleted_object;
1777
1778
		insert_acl_obj_label(tmp, subj);
1779
	}
1780
1781
	return;
1782
}
1783
1784
static __inline__ void
1785
update_acl_subj_label(const ino_t oldinode, const kdev_t olddevice,
1786
		      const ino_t newinode, const kdev_t newdevice,
1787
		      struct acl_role_label *role)
1788
{
1789
	struct acl_subject_label **s_hash = role->subj_hash;
1790
	unsigned long subj_size = role->subj_hash_size;
1791
	unsigned long index = fhash(oldinode, olddevice, subj_size);
1792
	struct acl_subject_label **match;
1793
	struct acl_subject_label *tmp;
1794
	__u8 i = 0;
1795
1796
	match = &s_hash[index];
1797
1798
	while (*match && ((*match)->inode != oldinode ||
1799
	       (*match)->device != olddevice ||
1800
	       !((*match)->mode & GR_DELETED))) {
1801
		index = (index + (1 << i)) % subj_size;
1802
		i = (i + 1) % 32;
1803
		match = &s_hash[index];
1804
	}
1805
1806
	if (*match && (*match != deleted_subject)
1807
	    && ((*match)->inode == oldinode)
1808
	    && ((*match)->device == olddevice)
1809
	    && ((*match)->mode & GR_DELETED)) {
1810
		tmp = *match;
1811
1812
		tmp->inode = newinode;
1813
		tmp->device = newdevice;
1814
		tmp->mode &= ~GR_DELETED;
1815
1816
		*match = deleted_subject;
1817
1818
		insert_acl_subj_label(tmp, role);
1819
	}
1820
1821
	return;
1822
}
1823
1824
static __inline__ void
1825
update_inodev_entry(const ino_t oldinode, const kdev_t olddevice,
1826
		    const ino_t newinode, const kdev_t newdevice)
1827
{
1828
	unsigned long index = fhash(oldinode, olddevice, inodev_set.n_size);
1829
	struct name_entry **match;
1830
	struct name_entry *tmp;
1831
	__u8 i = 0;
1832
1833
	match = &inodev_set.n_hash[index];
1834
1835
	while (*match
1836
	       && ((*match)->inode != oldinode
1837
		   || (*match)->device != olddevice)) {
1838
		index = (index + (1 << i)) % inodev_set.n_size;
1839
		i = (i + 1) % 32;
1840
		match = &inodev_set.n_hash[index];
1841
	}
1842
1843
	if (*match && (*match != deleted_inodev)
1844
	    && ((*match)->inode == oldinode)
1845
	    && ((*match)->device == olddevice)) {
1846
		tmp = *match;
1847
1848
		tmp->inode = newinode;
1849
		tmp->device = newdevice;
1850
1851
		*match = deleted_inodev;
1852
1853
		insert_inodev_entry(tmp);
1854
	}
1855
1856
	return;
1857
}
1858
1859
static __inline__ void
1860
do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
1861
		 const struct vfsmount *mnt)
1862
{
1863
	struct acl_subject_label *i;
1864
	struct acl_role_label *role;
1865
1866
	for (role = role_list_head; role; role = role->next) {
1867
		update_acl_subj_label(matchn->inode, matchn->device,
1868
				      dentry->d_inode->i_ino,
1869
				      dentry->d_inode->i_dev, role);
1870
1871
		for (i = role->proc_subject; i; i = i->next) {
1872
			if (unlikely(i->parent_subject &&
1873
				     (i->inode == dentry->d_inode->i_ino) &&
1874
				     (i->device == dentry->d_inode->i_dev))) {
1875
				i->inode = dentry->d_inode->i_ino;
1876
				i->device = dentry->d_inode->i_dev;
1877
			}
1878
			update_acl_obj_label(matchn->inode, matchn->device,
1879
					     dentry->d_inode->i_ino,
1880
					     dentry->d_inode->i_dev, i);
1881
		}
1882
	}
1883
1884
	update_inodev_entry(matchn->inode, matchn->device,
1885
			    dentry->d_inode->i_ino, dentry->d_inode->i_dev);
1886
1887
	return;
1888
}
1889
1890
void
1891
gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
1892
{
1893
	struct name_entry *matchn;
1894
1895
	if (unlikely(!(gr_status & GR_READY)))
1896
		return;
1897
1898
	matchn = lookup_name_entry(gr_to_filename(dentry, mnt));
1899
1900
	if (unlikely((unsigned long)matchn)) {
1901
		write_lock(&gr_inode_lock);
1902
		do_handle_create(matchn, dentry, mnt);
1903
		write_unlock(&gr_inode_lock);
1904
	}
1905
1906
	return;
1907
}
1908
1909
int
1910
gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
1911
		 struct dentry *old_dentry,
1912
		 struct dentry *new_dentry,
1913
		 struct vfsmount *mnt, const __u8 replace)
1914
{
1915
	struct name_entry *matchn;
1916
	int error = 0;
1917
1918
	matchn = lookup_name_entry(gr_to_filename(new_dentry, mnt));
1919
1920
	lock_kernel();
1921
	error = vfs_rename(old_dir, old_dentry, new_dir, new_dentry);
1922
	unlock_kernel();
1923
1924
	if (unlikely(error))
1925
		return error;
1926
1927
	/* we wouldn't have to check d_inode if it weren't for
1928
	   NFS silly-renaming
1929
	 */
1930
1931
	write_lock(&gr_inode_lock);
1932
	if (unlikely(replace && new_dentry->d_inode)) {
1933
		if (unlikely(lookup_inodev_entry(new_dentry->d_inode->i_ino,
1934
					new_dentry->d_inode->i_dev) &&
1935
		    (old_dentry->d_inode->i_nlink <= 1)))
1936
			do_handle_delete(new_dentry->d_inode->i_ino,
1937
					 new_dentry->d_inode->i_dev);
1938
	}
1939
1940
	if (unlikely(lookup_inodev_entry(old_dentry->d_inode->i_ino,
1941
				old_dentry->d_inode->i_dev) &&
1942
	    (old_dentry->d_inode->i_nlink <= 1)))
1943
		do_handle_delete(old_dentry->d_inode->i_ino,
1944
				 old_dentry->d_inode->i_dev);
1945
1946
	if (unlikely((unsigned long)matchn))
1947
		do_handle_create(matchn, old_dentry, mnt);
1948
	write_unlock(&gr_inode_lock);
1949
1950
	return error;
1951
}
1952
1953
static int
1954
lookup_special_role_auth(const char *rolename, unsigned char **salt,
1955
			 unsigned char **sum)
1956
{
1957
	struct acl_role_label *r;
1958
	struct role_transition *trans;
1959
	__u16 i;
1960
	int found = 0;
1961
1962
	/* check transition table */
1963
1964
	for (trans = current->role->transitions; trans; trans = trans->next) {
1965
		if (!strcmp(rolename, trans->rolename)) {
1966
			found = 1;
1967
			break;
1968
		}
1969
	}
1970
1971
	if (!found)
1972
		return 0;
1973
1974
	/* handle special roles that do not require authentication */
1975
1976
	for (r = role_list_head; r; r = r->next) {
1977
		if (!strcmp(rolename, r->rolename)
1978
		    && (r->roletype & GR_ROLE_NOPW)) {
1979
			*salt = NULL;
1980
			*sum = NULL;
1981
			return 1;
1982
		}
1983
	}
1984
1985
	for (i = 0; i < num_sprole_pws; i++) {
1986
		if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
1987
			*salt = acl_special_roles[i]->salt;
1988
			*sum = acl_special_roles[i]->sum;
1989
			return 1;
1990
		}
1991
	}
1992
1993
	return 0;
1994
}
1995
1996
static void
1997
assign_special_role(char *rolename)
1998
{
1999
	struct acl_object_label *obj;
2000
	struct acl_role_label *r;
2001
	struct acl_role_label *assigned = NULL;
2002
	struct task_struct *tsk;
2003
	struct file *filp;
2004
2005
	for (r = role_list_head; r; r = r->next)
2006
		if (!strcmp(rolename, r->rolename) &&
2007
		    (r->roletype & GR_ROLE_SPECIAL))
2008
			assigned = r;
2009
2010
	if (!assigned)
2011
		return;
2012
2013
	tsk = current->p_pptr;
2014
	filp = tsk->exec_file;
2015
2016
	if (tsk && filp) {
2017
		tsk->is_writable = 0;
2018
2019
		acl_sp_role_value = (acl_sp_role_value % 65535) + 1;
2020
		tsk->acl_sp_role = 1;
2021
		tsk->acl_role_id = acl_sp_role_value;
2022
		tsk->role = assigned;
2023
		tsk->acl =
2024
		    chk_subj_label(filp->f_dentry, filp->f_vfsmnt, tsk->role);
2025
2026
		/* ignore additional mmap checks for processes that are writable 
2027
		   by the default ACL */
2028
		obj = chk_obj_label(filp->f_dentry, filp->f_vfsmnt, default_role->root_label);
2029
		if (unlikely(obj->mode & GR_WRITE))
2030
			tsk->is_writable = 1;
2031
		obj = chk_obj_label(filp->f_dentry, filp->f_vfsmnt, tsk->role->root_label);
2032
		if (unlikely(obj->mode & GR_WRITE))
2033
			tsk->is_writable = 1;
2034
2035
#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
2036
		printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
2037
#endif
2038
	}
2039
2040
	return;
2041
}
2042
2043
ssize_t
2044
write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
2045
{
2046
	struct gr_arg *arg;
2047
	unsigned char *sprole_salt;
2048
	unsigned char *sprole_sum;
2049
	int error = sizeof (struct gr_arg);
2050
	int error2 = 0;
2051
2052
	down(&gr_dev_sem);
2053
2054
	arg = (struct gr_arg *) buf;
2055
2056
	if (count != sizeof (struct gr_arg)) {
2057
		security_alert_good(GR_DEV_ACL_MSG, count,
2058
				    (int) sizeof (struct gr_arg));
2059
		error = -EINVAL;
2060
		goto out;
2061
	}
2062
2063
	if ((gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES)
2064
	    && time_before_eq(gr_auth_expires, jiffies)) {
2065
		gr_auth_expires = 0;
2066
		gr_auth_attempts = 0;
2067
	}
2068
2069
	if (copy_from_user(gr_usermode, arg, sizeof (struct gr_arg))) {
2070
		error = -EFAULT;
2071
		goto out;
2072
	}
2073
2074
	if (gr_usermode->mode != SPROLE && time_after(gr_auth_expires, jiffies)) {
2075
		error = -EBUSY;
2076
		goto out;
2077
	}
2078
2079
	/* if non-root trying to do anything other than use a special role,
2080
	   do not attempt authentication, do not count towards authentication
2081
	   locking
2082
	 */
2083
2084
	if (gr_usermode->mode != SPROLE && current->uid) {
2085
		error = -EPERM;
2086
		goto out;
2087
	}
2088
2089
	/* ensure pw and special role name are null terminated */
2090
2091
	gr_usermode->pw[GR_PW_LEN - 1] = '\0';
2092
	gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
2093
2094
	/* Okay. 
2095
	 * We have our enough of the argument structure..(we have yet
2096
	 * to copy_from_user the tables themselves) . Copy the tables
2097
	 * only if we need them, i.e. for loading operations. */
2098
2099
	switch (gr_usermode->mode) {
2100
	case STATUS:
2101
			if (gr_status & GR_READY)
2102
				error = 1;
2103
			else
2104
				error = 2;
2105
			goto out;
2106
	case SHUTDOWN:
2107
		if ((gr_status & GR_READY)
2108
		    && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
2109
			gr_status &= ~GR_READY;
2110
			security_alert_good(GR_SHUTS_ACL_MSG, DEFAULTSECARGS);
2111
			free_variables();
2112
			memset(gr_usermode, 0, sizeof (struct gr_arg));
2113
			memset(gr_system_salt, 0, GR_SALT_LEN);
2114
			memset(gr_system_sum, 0, GR_SHA_LEN);
2115
		} else if (gr_status & GR_READY) {
2116
			security_alert(GR_SHUTF_ACL_MSG, DEFAULTSECARGS);
2117
			error = -EPERM;
2118
		} else {
2119
			security_alert_good(GR_SHUTI_ACL_MSG, DEFAULTSECARGS);
2120
			error = -EAGAIN;
2121
		}
2122
		break;
2123
	case ENABLE:
2124
		if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
2125
			security_alert_good(GR_ENABLE_ACL_MSG, GR_VERSION);
2126
		else {
2127
			if (gr_status & GR_READY)
2128
				error = -EAGAIN;
2129
			else
2130
				error = error2;
2131
			security_alert(GR_ENABLEF_ACL_MSG, GR_VERSION,
2132
				       DEFAULTSECARGS);
2133
		}
2134
		break;
2135
	case RELOAD:
2136
		if (!(gr_status & GR_READY)) {
2137
			security_alert_good(GR_RELOADI_ACL_MSG);
2138
			error = -EAGAIN;
2139
		} else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
2140
			lock_kernel();
2141
			gr_status &= ~GR_READY;
2142
			free_variables();
2143
			if (!(error2 = gracl_init(gr_usermode))) {
2144
				unlock_kernel();
2145
				security_alert_good(GR_RELOAD_ACL_MSG,
2146
						    GR_VERSION);
2147
			} else {
2148
				unlock_kernel();
2149
				error = error2;
2150
				security_alert(GR_RELOADF_ACL_MSG, GR_VERSION,
2151
					       DEFAULTSECARGS);
2152
			}
2153
		} else {
2154
			security_alert(GR_RELOADF_ACL_MSG, GR_VERSION,
2155
				       DEFAULTSECARGS);
2156
			error = -EPERM;
2157
		}
2158
		break;
2159
	case SEGVMOD:
2160
		if (unlikely(!(gr_status & GR_READY))) {
2161
			security_alert_good(GR_SEGVMODI_ACL_MSG,
2162
					    DEFAULTSECARGS);
2163
			error = -EAGAIN;
2164
			break;
2165
		}
2166
2167
		if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
2168
			security_alert_good(GR_SEGVMODS_ACL_MSG,
2169
					    DEFAULTSECARGS);
2170
			if (gr_usermode->segv_device && gr_usermode->segv_inode) {
2171
				struct acl_subject_label *segvacl;
2172
				segvacl =
2173
				    lookup_acl_subj_label(gr_usermode->segv_inode,
2174
							  gr_usermode->segv_device,
2175
							  current->role);
2176
				if (segvacl) {
2177
					segvacl->crashes = 0;
2178
					segvacl->expires = 0;
2179
				}
2180
			} else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
2181
				gr_remove_uid(gr_usermode->segv_uid);
2182
			}
2183
		} else {
2184
			security_alert(GR_SEGVMODF_ACL_MSG, DEFAULTSECARGS);
2185
			error = -EPERM;
2186
		}
2187
		break;
2188
	case SPROLE:
2189
		if (unlikely(!(gr_status & GR_READY))) {
2190
			security_alert_good(GR_SPROLEI_ACL_MSG, DEFAULTSECARGS);
2191
			error = -EAGAIN;
2192
			break;
2193
		}
2194
2195
		if ((current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES)
2196
		    && time_before_eq(current->role->expires, jiffies)) {
2197
			current->role->expires = 0;
2198
			current->role->auth_attempts = 0;
2199
		}
2200
2201
		if (time_after(current->role->expires, jiffies)) {
2202
			error = -EBUSY;
2203
			goto out;
2204
		}
2205
2206
		if (lookup_special_role_auth
2207
		    (gr_usermode->sp_role, &sprole_salt, &sprole_sum)
2208
		    && ((!sprole_salt && !sprole_sum)
2209
			|| !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
2210
			assign_special_role(gr_usermode->sp_role);
2211
			security_alert_good(GR_SPROLES_ACL_MSG,
2212
					    (current->p_pptr) ? current->
2213
					    p_pptr->role->rolename : "",
2214
					    acl_sp_role_value, DEFAULTSECARGS);
2215
		} else {
2216
			security_alert(GR_SPROLEF_ACL_MSG, gr_usermode->sp_role,
2217
				       DEFAULTSECARGS);
2218
			error = -EPERM;
2219
			current->role->auth_attempts++;
2220
			if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES) {
2221
				current->role->expires =
2222
				    jiffies + CONFIG_GRKERNSEC_ACL_TIMEOUT * HZ;
2223
				security_alert(GR_MAXROLEPW_ACL_MSG,
2224
				       CONFIG_GRKERNSEC_ACL_MAXTRIES,
2225
				       gr_usermode->sp_role, DEFAULTSECARGS);
2226
			}
2227
2228
			goto out;
2229
		}
2230
		break;
2231
	case UNSPROLE:
2232
		if (unlikely(!(gr_status & GR_READY))) {
2233
			security_alert_good(GR_UNSPROLEI_ACL_MSG, DEFAULTSECARGS);
2234
			error = -EAGAIN;
2235
			break;
2236
		}
2237
2238
		if ((current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES)
2239
		    && time_before_eq(current->role->expires, jiffies)) {
2240
			current->role->expires = 0;
2241
			current->role->auth_attempts = 0;
2242
		}
2243
2244
		if (time_after(current->role->expires, jiffies)) {
2245
			error = -EBUSY;
2246
			goto out;
2247
		}
2248
2249
		if ((current->role->roletype & GR_ROLE_SPECIAL) && 
2250
		    lookup_special_role_auth
2251
		    (current->role->rolename, &sprole_salt, &sprole_sum)
2252
		    && ((!sprole_salt && !sprole_sum)
2253
			|| !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
2254
			security_alert_good(GR_UNSPROLES_ACL_MSG,
2255
					    (current->p_pptr) ? current->
2256
					    p_pptr->role->rolename : "",
2257
					    (current->p_pptr) ? current->
2258
					    p_pptr->acl_role_id : 0, DEFAULTSECARGS);
2259
			gr_set_acls(1);
2260
			if (current->p_pptr)
2261
				current->p_pptr->acl_sp_role = 0;
2262
		} else {
2263
			security_alert(GR_UNSPROLEF_ACL_MSG, gr_usermode->sp_role,
2264
				       DEFAULTSECARGS);
2265
			error = -EPERM;
2266
			current->role->auth_attempts++;
2267
			if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES) {
2268
				current->role->expires =
2269
				    jiffies + CONFIG_GRKERNSEC_ACL_TIMEOUT * HZ;
2270
				security_alert(GR_MAXROLEPW_ACL_MSG,
2271
				       CONFIG_GRKERNSEC_ACL_MAXTRIES,
2272
				       current->role->rolename, DEFAULTSECARGS);
2273
			}
2274
2275
			goto out;
2276
		}
2277
		break;
2278
	default:
2279
		security_alert(GR_INVMODE_ACL_MSG, gr_usermode->mode,
2280
			       DEFAULTSECARGS);
2281
		error = -EINVAL;
2282
		break;
2283
	}
2284
2285
	if (error != -EPERM)
2286
		goto out;
2287
2288
	gr_auth_attempts++;
2289
2290
	if (gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES) {
2291
		security_alert(GR_MAXPW_ACL_MSG, CONFIG_GRKERNSEC_ACL_MAXTRIES);
2292
		gr_auth_expires = jiffies + CONFIG_GRKERNSEC_ACL_TIMEOUT * HZ;
2293
	}
2294
2295
      out:
2296
	up(&gr_dev_sem);
2297
	return error;
2298
}
2299
2300
int
2301
gr_set_acls(const int type)
2302
{
2303
	struct acl_object_label *obj;
2304
	struct task_struct *task;
2305
	struct file *filp;
2306
	unsigned short i;
2307
2308
	read_lock(&tasklist_lock);
2309
	for_each_task(task) {
2310
		/* check to see if we're called from the exit handler,
2311
		   if so, only replace ACLs that have inherited the admin
2312
		   ACL */
2313
2314
		if (type && (task->role != current->role ||
2315
			     task->acl_role_id != current->acl_role_id))
2316
			continue;
2317
2318
		task->acl_role_id = 0;
2319
2320
		if ((filp = task->exec_file)) {
2321
			do_set_role_label(task, task->uid, task->gid);
2322
2323
			task->acl =
2324
			    chk_subj_label(filp->f_dentry, filp->f_vfsmnt,
2325
					   task->role);
2326
			if (task->acl) {
2327
				struct acl_subject_label *curr;
2328
				curr = task->acl;
2329
2330
				task->is_writable = 0;
2331
				/* ignore additional mmap checks for processes that are writable 
2332
				   by the default ACL */
2333
				obj = chk_obj_label(filp->f_dentry, filp->f_vfsmnt, default_role->root_label);
2334
				if (unlikely(obj->mode & GR_WRITE))
2335
					task->is_writable = 1;
2336
				obj = chk_obj_label(filp->f_dentry, filp->f_vfsmnt, task->role->root_label);
2337
				if (unlikely(obj->mode & GR_WRITE))
2338
					task->is_writable = 1;
2339
2340
#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
2341
				printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
2342
#endif
2343
				if (!(curr->mode & GR_LEARN))
2344
					for (i = 0; i < RLIM_NLIMITS; i++) {
2345
						if (!(curr->resmask & (1 << i)))
2346
							continue;
2347
2348
						task->rlim[i].rlim_cur =
2349
						    curr->res[i].rlim_cur;
2350
						task->rlim[i].rlim_max =
2351
						    curr->res[i].rlim_max;
2352
					}
2353
			} else {
2354
				read_unlock(&tasklist_lock);
2355
				security_alert_good(GR_DEFACL_MSG, task->comm,
2356
						    task->pid);
2357
				return 1;
2358
			}
2359
		} else {
2360
			// it's a kernel process
2361
			task->role = kernel_role;
2362
			task->acl = kernel_role->root_label;
2363
#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
2364
			task->acl->mode &= ~GR_FIND;
2365
#endif
2366
		}
2367
	}
2368
	read_unlock(&tasklist_lock);
2369
	return 0;
2370
}
2371
2372
void
2373
gr_learn_resource(const struct task_struct *task,
2374
		  const int res, const unsigned long wanted)
2375
{
2376
	struct acl_subject_label *acl;
2377
2378
	if (unlikely((gr_status & GR_READY) &&
2379
		     task->acl && (task->acl->mode & GR_LEARN)))
2380
		goto skip_reslog;
2381
2382
#ifdef CONFIG_GRKERNSEC_RESLOG
2383
	gr_log_resource(task, res, wanted);
2384
#endif
2385
      skip_reslog:
2386
2387
	if (unlikely(!(gr_status & GR_READY) || !wanted))
2388
		return;
2389
2390
	acl = task->acl;
2391
2392
	if (likely(!acl || !(acl->mode & GR_LEARN) ||
2393
		   !(acl->resmask & (1 << (unsigned short) res))))
2394
		return;
2395
2396
	if (wanted >= acl->res[res].rlim_cur) {
2397
		unsigned long res_add;
2398
2399
		res_add = wanted;
2400
		switch (res) {
2401
		case RLIMIT_CPU:
2402
			res_add += GR_RLIM_CPU_BUMP;
2403
			break;
2404
		case RLIMIT_FSIZE:
2405
			res_add += GR_RLIM_FSIZE_BUMP;
2406
			break;
2407
		case RLIMIT_DATA:
2408
			res_add += GR_RLIM_DATA_BUMP;
2409
			break;
2410
		case RLIMIT_STACK:
2411
			res_add += GR_RLIM_STACK_BUMP;
2412
			break;
2413
		case RLIMIT_CORE:
2414
			res_add += GR_RLIM_CORE_BUMP;
2415
			break;
2416
		case RLIMIT_RSS:
2417
			res_add += GR_RLIM_RSS_BUMP;
2418
			break;
2419
		case RLIMIT_NPROC:
2420
			res_add += GR_RLIM_NPROC_BUMP;
2421
			break;
2422
		case RLIMIT_NOFILE:
2423
			res_add += GR_RLIM_NOFILE_BUMP;
2424
			break;
2425
		case RLIMIT_MEMLOCK:
2426
			res_add += GR_RLIM_MEMLOCK_BUMP;
2427
			break;
2428
		case RLIMIT_AS:
2429
			res_add += GR_RLIM_AS_BUMP;
2430
			break;
2431
		case RLIMIT_LOCKS:
2432
			res_add += GR_RLIM_LOCKS_BUMP;
2433
			break;
2434
		}
2435
2436
		acl->res[res].rlim_cur = res_add;
2437
2438
		if (wanted > acl->res[res].rlim_max)
2439
			acl->res[res].rlim_max = res_add;
2440
2441
		security_learn(GR_LEARN_AUDIT_MSG, current->role->rolename,
2442
			       current->role->roletype, acl->filename,
2443
			       acl->res[res].rlim_cur, acl->res[res].rlim_max,
2444
			       "", (unsigned long) res);
2445
	}
2446
2447
	return;
2448
}
2449
2450
#ifdef CONFIG_SYSCTL
2451
extern struct proc_dir_entry *proc_sys_root;
2452
2453
__u32
2454
gr_handle_sysctl(const struct ctl_table *table, const void *oldval,
2455
		 const void *newval)
2456
{
2457
	struct proc_dir_entry *tmp;
2458
	struct nameidata nd;
2459
	const char *proc_sys = "/proc/sys";
2460
	char *path = gr_shared_page[0][smp_processor_id()];
2461
	struct acl_object_label *obj;
2462
	unsigned short len = 0, pos = 0, depth = 0, i;
2463
	__u32 err = 0;
2464
	__u32 mode = 0;
2465
2466
	if (unlikely(!(gr_status & GR_READY)))
2467
		return 1;
2468
2469
	if (oldval)
2470
		mode |= GR_READ;
2471
	if (newval)
2472
		mode |= GR_WRITE;
2473
2474
	/* convert the requested sysctl entry into a pathname */
2475
2476
	for (tmp = table->de; tmp != proc_sys_root; tmp = tmp->parent) {
2477
		len += strlen(tmp->name);
2478
		len++;
2479
		depth++;
2480
	}
2481
2482
	if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE)
2483
		return 0;	// deny
2484
2485
	memset(path, 0, PAGE_SIZE);
2486
2487
	memcpy(path, proc_sys, strlen(proc_sys));
2488
2489
	pos += strlen(proc_sys);
2490
2491
	for (; depth > 0; depth--) {
2492
		path[pos] = '/';
2493
		pos++;
2494
		for (i = 1, tmp = table->de; tmp != proc_sys_root;
2495
		     tmp = tmp->parent) {
2496
			if (depth == i) {
2497
				memcpy(path + pos, tmp->name,
2498
				       strlen(tmp->name));
2499
				pos += strlen(tmp->name);
2500
			}
2501
			i++;
2502
		}
2503
	}
2504
2505
	if (path_init(path, LOOKUP_FOLLOW, &nd))
2506
		err = path_walk(path, &nd);
2507
2508
	if (err)
2509
		goto out;
2510
2511
	obj = chk_obj_label(nd.dentry, nd.mnt, current->acl);
2512
	err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
2513
2514
	if (unlikely((current->acl->mode & GR_LEARN) && ((err & mode) != mode))) {
2515
		__u32 new_mode = mode;
2516
2517
		new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
2518
2519
		err = new_mode;
2520
		gr_log_learn(current->role, current->uid, current->gid,
2521
			     current, path, new_mode);
2522
	} else if ((err & mode) != mode && !(err & GR_SUPPRESS)) {
2523
		security_alert(GR_SYSCTL_ACL_MSG, "denied", path,
2524
			       (mode & GR_READ) ? " reading" : "",
2525
			       (mode & GR_WRITE) ? " writing" : "",
2526
			       DEFAULTSECARGS);
2527
		err = 0;
2528
	} else if ((err & mode) != mode) {
2529
		err = 0;
2530
	} else if (((err & mode) == mode) && (err & GR_AUDITS)) {
2531
		security_audit(GR_SYSCTL_ACL_MSG, "successful",
2532
			       path, (mode & GR_READ) ? " reading" : "",
2533
			       (mode & GR_WRITE) ? " writing" : "",
2534
			       DEFAULTSECARGS);
2535
	}
2536
2537
	path_release(&nd);
2538
2539
      out:
2540
	return err;
2541
}
2542
#endif
2543
2544
int
2545
gr_handle_ptrace(struct task_struct *task, const long request)
2546
{
2547
	struct file *filp;
2548
	__u32 retmode;
2549
2550
	if (unlikely(!(gr_status & GR_READY)))
2551
		return 0;
2552
2553
	filp = task->exec_file;
2554
2555
	if (unlikely(!filp))
2556
		return 0;
2557
2558
	retmode = gr_search_file(filp->f_dentry, GR_PTRACERD, filp->f_vfsmnt);
2559
2560
	if (retmode & GR_PTRACERD) {
2561
		switch (request) {
2562
		case PTRACE_POKETEXT:
2563
		case PTRACE_POKEDATA:
2564
		case PTRACE_POKEUSR:
2565
#if !defined(CONFIG_PPC32) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA)
2566
		case PTRACE_SETREGS:
2567
		case PTRACE_SETFPREGS:
2568
#endif
2569
#ifdef CONFIG_X86
2570
		case PTRACE_SETFPXREGS:
2571
#endif
2572
#ifdef CONFIG_ALTIVEC
2573
		case PTRACE_SETVRREGS:
2574
#endif
2575
			return 1;
2576
		default:
2577
			return 0;
2578
		}
2579
	} else if (!(current->acl->mode & GR_OVERRIDE) &&
2580
		   !(current->role->roletype & GR_ROLE_GOD)
2581
		   && (current->acl != task->acl
2582
		       || (current->acl != current->role->root_label
2583
			   && current->pid != task->pid))) {
2584
		security_alert(GR_PTRACE_ACL_MSG,
2585
			       gr_to_filename(filp->f_dentry, filp->f_vfsmnt),
2586
			       task->comm, task->pid, DEFAULTSECARGS);
2587
		return 1;
2588
	}
2589
2590
	return 0;
2591
}
2592
2593
int
2594
gr_handle_ptrace_exec(const struct dentry *dentry, const struct vfsmount *mnt)
2595
{
2596
	__u32 retmode;
2597
	struct acl_subject_label *subj;
2598
2599
	if (unlikely(!(gr_status & GR_READY)))
2600
		return 0;
2601
2602
	if (unlikely
2603
	    ((current->ptrace & PT_PTRACED)
2604
	     && !(current->acl->mode & GR_OVERRIDE)))
2605
		retmode = gr_search_file(dentry, GR_PTRACERD, mnt);
2606
	else
2607
		return 0;
2608
2609
	subj = chk_subj_label(dentry, mnt, current->role);
2610
2611
	if (!(retmode & GR_PTRACERD) &&
2612
	    !(current->role->roletype & GR_ROLE_GOD) &&
2613
	    (current->acl != subj)) {
2614
		security_alert(GR_PTRACE_EXEC_ACL_MSG,
2615
			       gr_to_filename(dentry, mnt), DEFAULTSECARGS);
2616
		return 1;
2617
	}
2618
2619
	return 0;
2620
}
2621
2622
int
2623
gr_handle_mmap(const struct file *filp, const unsigned long prot)
2624
{
2625
	struct acl_object_label *obj, *obj2;
2626
2627
	if (unlikely(!(gr_status & GR_READY) ||
2628
		     (current->acl->mode & GR_OVERRIDE) || !filp ||
2629
		     !(prot & PROT_EXEC)))
2630
		return 0;
2631
2632
	if (unlikely(current->is_writable))
2633
		return 0;
2634
2635
	obj = chk_obj_label(filp->f_dentry, filp->f_vfsmnt, default_role->root_label);
2636
	obj2 = chk_obj_label(filp->f_dentry, filp->f_vfsmnt,
2637
			     current->role->root_label);
2638
	if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
2639
		security_alert(GR_WRITLIB_ACL_MSG,
2640
			       gr_to_filename(filp->f_dentry, filp->f_vfsmnt),
2641
			       DEFAULTSECARGS);
2642
		return 1;
2643
	}
2644
2645
	return 0;
2646
}
2647
2648
int
2649
gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
2650
{
2651
	__u32 mode;
2652
2653
	if (unlikely(!file || !(prot & PROT_EXEC)))
2654
		return 1;
2655
2656
	mode =
2657
	    gr_search_file(file->f_dentry,
2658
			   GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
2659
			   file->f_vfsmnt);
2660
2661
	if (unlikely(!gr_tpe_allow(file) || (!(mode & GR_EXEC) && !(mode & GR_SUPPRESS)))) {
2662
		security_alert(GR_MMAP_ACL_MSG, "denied",
2663
			       gr_to_filename(file->f_dentry, file->f_vfsmnt),
2664
			       DEFAULTSECARGS);
2665
		return 0;
2666
	} else if (unlikely(!gr_tpe_allow(file) || !(mode & GR_EXEC))) {
2667
		return 0;
2668
	} else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
2669
		security_audit(GR_MMAP_ACL_MSG, "successful",
2670
			       gr_to_filename(file->f_dentry, file->f_vfsmnt),
2671
			       DEFAULTSECARGS);
2672
		return 1;
2673
	}
2674
2675
	return 1;
2676
}
2677
2678
int
2679
gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
2680
{
2681
	__u32 mode;
2682
2683
	if (unlikely(!file || !(prot & PROT_EXEC)))
2684
		return 1;
2685
2686
	mode =
2687
	    gr_search_file(file->f_dentry,
2688
			   GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
2689
			   file->f_vfsmnt);
2690
2691
	if (unlikely(!gr_tpe_allow(file) || (!(mode & GR_EXEC) && !(mode & GR_SUPPRESS)))) {
2692
		security_alert(GR_MPROTECT_ACL_MSG, "denied",
2693
			       gr_to_filename(file->f_dentry, file->f_vfsmnt),
2694
			       DEFAULTSECARGS);
2695
		return 0;
2696
	} else if (unlikely(!gr_tpe_allow(file) || !(mode & GR_EXEC))) {
2697
		return 0;
2698
	} else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
2699
		security_audit(GR_MPROTECT_ACL_MSG, "successful",
2700
			       gr_to_filename(file->f_dentry, file->f_vfsmnt),
2701
			       DEFAULTSECARGS);
2702
		return 1;
2703
	}
2704
2705
	return 1;
2706
}
2707
2708
void
2709
gr_acl_handle_psacct(struct task_struct *task, const long code)
2710
{
2711
	unsigned long runtime;
2712
	unsigned long cputime;
2713
	unsigned int wday, cday;
2714
	__u8 whr, chr;
2715
	__u8 wmin, cmin;
2716
	__u8 wsec, csec;
2717
	char cur_tty[64] = { 0 };
2718
	char parent_tty[64] = { 0 };
2719
2720
	if (unlikely(!(gr_status & GR_READY) || !task->acl ||
2721
		     !(task->acl->mode & GR_PROCACCT)))
2722
		return;
2723
2724
	runtime = (jiffies - task->start_time) / HZ;
2725
	wday = runtime / (3600 * 24);
2726
	runtime -= wday * (3600 * 24);
2727
	whr = runtime / 3600;
2728
	runtime -= whr * 3600;
2729
	wmin = runtime / 60;
2730
	runtime -= wmin * 60;
2731
	wsec = runtime;
2732
2733
	cputime = (task->times.tms_utime + task->times.tms_stime) / HZ;
2734
	cday = cputime / (3600 * 24);
2735
	cputime -= cday * (3600 * 24);
2736
	chr = cputime / 3600;
2737
	cputime -= chr * 3600;
2738
	cmin = cputime / 60;
2739
	cputime -= cmin * 60;
2740
	csec = cputime;
2741
2742
	security_audit(GR_ACL_PROCACCT_MSG, gr_task_fullpath(task), task->comm,
2743
		       task->pid, NIPQUAD(task->curr_ip), tty_name(task->tty,
2744
								   cur_tty),
2745
		       task->uid, task->euid, task->gid, task->egid, wday, whr,
2746
		       wmin, wsec, cday, chr, cmin, csec,
2747
		       (task->
2748
			flags & PF_SIGNALED) ? "killed by signal" : "exited",
2749
		       code, gr_parent_task_fullpath(task), 
2750
		       task->p_pptr->comm, task->p_pptr->pid,
2751
		       NIPQUAD(task->p_pptr->curr_ip),
2752
		       tty_name(task->p_pptr->tty, parent_tty),
2753
		       task->p_pptr->uid, task->p_pptr->euid, task->p_pptr->gid,
2754
		       task->p_pptr->egid);
2755
2756
	return;
2757
}
2758
2759
void gr_set_kernel_label(struct task_struct *task)
2760
{
2761
	if (gr_status & GR_READY) {
2762
		task->role = kernel_role;
2763
		task->acl = kernel_role->root_label;
2764
	}
2765
	return;
2766
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/gracl_alloc.c (+94 lines)
Line 0 Link Here
1
/* stack-based acl allocation tracking (c) Brad Spengler 2002,2003 */
2
3
#include <linux/kernel.h>
4
#include <linux/mm.h>
5
#include <linux/slab.h>
6
#include <linux/vmalloc.h>
7
#include <linux/gracl.h>
8
#include <linux/grsecurity.h>
9
10
static unsigned long alloc_stack_next = 1;
11
static unsigned long alloc_stack_size = 1;
12
static void **alloc_stack;
13
14
static __inline__ int
15
alloc_pop(void)
16
{
17
	if ((alloc_stack_next - 1) == 0)
18
		return 0;
19
20
	if (*(alloc_stack + alloc_stack_next - 2))
21
		kfree(*(alloc_stack + alloc_stack_next - 2));
22
23
	alloc_stack_next--;
24
25
	return 1;
26
}
27
28
static __inline__ void
29
alloc_push(void *buf)
30
{
31
	if (alloc_stack_next >= alloc_stack_size)
32
		BUG();
33
34
	*(alloc_stack + alloc_stack_next - 1) = buf;
35
36
	alloc_stack_next++;
37
38
	return;
39
}
40
41
void *
42
acl_alloc(unsigned long len)
43
{
44
	void *ret;
45
46
	if (len > PAGE_SIZE)
47
		BUG();
48
49
	ret = kmalloc(len, GFP_KERNEL);
50
51
	if (ret)
52
		alloc_push(ret);
53
54
	return ret;
55
}
56
57
void
58
acl_free_all(void)
59
{
60
	if (gr_acl_is_enabled() || !alloc_stack)
61
		return;
62
63
	while (alloc_pop()) ;
64
65
	if (alloc_stack) {
66
		if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
67
			kfree(alloc_stack);
68
		else
69
			vfree(alloc_stack);
70
	}
71
72
	alloc_stack = NULL;
73
	alloc_stack_size = 1;
74
	alloc_stack_next = 1;
75
76
	return;
77
}
78
79
int
80
acl_alloc_stack_init(unsigned long size)
81
{
82
	if ((size * sizeof (void *)) <= PAGE_SIZE)
83
		alloc_stack =
84
		    (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
85
	else
86
		alloc_stack = (void **) vmalloc(size * sizeof (void *));
87
88
	alloc_stack_size = size;
89
90
	if (!alloc_stack)
91
		return 0;
92
	else
93
		return 1;
94
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/gracl_cap.c (+71 lines)
Line 0 Link Here
1
/* capability handling routines, (c) Brad Spengler 2002,2003 */
2
3
#include <linux/kernel.h>
4
#include <linux/sched.h>
5
#include <linux/capability.h>
6
#include <linux/gracl.h>
7
#include <linux/grsecurity.h>
8
#include <linux/grinternal.h>
9
10
static const char *captab_log[29] = {
11
	"CAP_CHOWN",
12
	"CAP_DAC_OVERRIDE",
13
	"CAP_DAC_READ_SEARCH",
14
	"CAP_FOWNER",
15
	"CAP_FSETID",
16
	"CAP_KILL",
17
	"CAP_SETGID",
18
	"CAP_SETUID",
19
	"CAP_SETPCAP",
20
	"CAP_LINUX_IMMUTABLE",
21
	"CAP_NET_BIND_SERVICE",
22
	"CAP_NET_BROADCAST",
23
	"CAP_NET_ADMIN",
24
	"CAP_NET_RAW",
25
	"CAP_IPC_LOCK",
26
	"CAP_IPC_OWNER",
27
	"CAP_SYS_MODULE",
28
	"CAP_SYS_RAWIO",
29
	"CAP_SYS_CHROOT",
30
	"CAP_SYS_PTRACE",
31
	"CAP_SYS_PACCT",
32
	"CAP_SYS_ADMIN",
33
	"CAP_SYS_BOOT",
34
	"CAP_SYS_NICE",
35
	"CAP_SYS_RESOURCE",
36
	"CAP_SYS_TIME",
37
	"CAP_SYS_TTY_CONFIG",
38
	"CAP_MKNOD",
39
	"CAP_LEASE"
40
};
41
42
int
43
gr_is_capable(const int cap)
44
{
45
	struct acl_subject_label *curracl;
46
47
	if (!gr_acl_is_enabled())
48
		return 1;
49
50
	curracl = current->acl;
51
52
	if (!cap_raised(curracl->cap_lower, cap))
53
		return 1;
54
55
	if ((curracl->mode & GR_LEARN)
56
	    && cap_raised(current->cap_effective, cap)) {
57
		security_learn(GR_LEARN_AUDIT_MSG, current->role->rolename,
58
			       current->role->roletype, current->uid,
59
			       current->gid, current->exec_file ?
60
			       gr_to_filename(current->exec_file->f_dentry,
61
			       current->exec_file->f_vfsmnt) : curracl->filename,
62
			       curracl->filename, 0UL,
63
			       0UL, "", (unsigned long) cap, NIPQUAD(current->curr_ip));
64
		return 1;
65
	}
66
67
	if ((cap >= 0) && (cap < 29) && cap_raised(current->cap_effective, cap))
68
		security_alert(GR_CAP_ACL_MSG, captab_log[cap], DEFAULTSECARGS);
69
70
	return 0;
71
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/gracl_fs.c (+469 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/types.h>
4
#include <linux/fs.h>
5
#include <linux/file.h>
6
#include <linux/grsecurity.h>
7
#include <linux/grinternal.h>
8
#include <linux/gracl.h>
9
10
__u32
11
gr_acl_handle_hidden_file(const struct dentry * dentry,
12
			  const struct vfsmount * mnt)
13
{
14
	__u32 mode;
15
16
	if (unlikely(!dentry->d_inode))
17
		return GR_FIND;
18
19
	mode =
20
	    gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
21
22
	if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
23
		security_audit(GR_HIDDEN_ACL_MSG, "successful",
24
			       gr_to_filename(dentry, mnt), DEFAULTSECARGS);
25
		return mode;
26
	} else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
27
		security_alert(GR_HIDDEN_ACL_MSG, "denied",
28
			       gr_to_filename(dentry, mnt),
29
			       DEFAULTSECARGS);
30
		return 0;
31
	} else if (unlikely(!(mode & GR_FIND)))
32
		return 0;
33
34
	return GR_FIND;
35
}
36
37
__u32
38
gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
39
		   const int fmode)
40
{
41
	__u32 reqmode = GR_FIND;
42
	__u32 mode;
43
44
	if (unlikely(!dentry->d_inode))
45
		return reqmode;
46
47
	if (unlikely(fmode & O_APPEND))
48
		reqmode |= GR_APPEND;
49
	else if (unlikely(fmode & FMODE_WRITE))
50
		reqmode |= GR_WRITE;
51
	if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
52
		reqmode |= GR_READ;
53
54
	mode =
55
	    gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56
			   mnt);
57
58
	if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
59
		security_audit(GR_OPEN_ACL_MSG, "successful",
60
			       gr_to_filename(dentry, mnt),
61
			       reqmode & GR_READ ? " reading" : "",
62
			       reqmode & GR_WRITE ? " writing" :
63
			       reqmode & GR_APPEND ? " appending" : "",
64
			       DEFAULTSECARGS);
65
		return reqmode;
66
	} else
67
	    if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68
	{
69
		security_alert(GR_OPEN_ACL_MSG, "denied",
70
			       gr_to_filename(dentry, mnt),
71
			       reqmode & GR_READ ? " reading" : "",
72
			       reqmode & GR_WRITE ? " writing" : reqmode &
73
			       GR_APPEND ? " appending" : "", DEFAULTSECARGS);
74
		return 0;
75
	} else if (unlikely((mode & reqmode) != reqmode))
76
		return 0;
77
78
	return reqmode;
79
}
80
81
__u32
82
gr_acl_handle_creat(const struct dentry * dentry,
83
		    const struct dentry * p_dentry,
84
		    const struct vfsmount * p_mnt, const int fmode,
85
		    const int imode)
86
{
87
	__u32 reqmode = GR_WRITE | GR_CREATE;
88
	__u32 mode;
89
90
	if (unlikely(fmode & O_APPEND))
91
		reqmode |= GR_APPEND;
92
	if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
93
		reqmode |= GR_READ;
94
	if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
95
		reqmode |= GR_SETID;
96
97
	mode =
98
	    gr_check_create(dentry, p_dentry, p_mnt,
99
			    reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
100
101
	if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
102
		security_audit(GR_CREATE_ACL_MSG, "successful",
103
			       gr_to_filename(dentry, p_mnt),
104
			       reqmode & GR_READ ? " reading" : "",
105
			       reqmode & GR_WRITE ? " writing" :
106
			       reqmode & GR_APPEND ? " appending" : "",
107
			       DEFAULTSECARGS);
108
		return reqmode;
109
	} else
110
	    if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
111
	{
112
		security_alert(GR_CREATE_ACL_MSG, "denied",
113
			       gr_to_filename(dentry, p_mnt),
114
			       reqmode & GR_READ ? " reading" : "",
115
			       reqmode & GR_WRITE ? " writing" : reqmode &
116
			       GR_APPEND ? " appending" : "", DEFAULTSECARGS);
117
		return 0;
118
	} else if (unlikely((mode & reqmode) != reqmode))
119
		return 0;
120
121
	return reqmode;
122
}
123
124
__u32
125
gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
126
		     const int fmode)
127
{
128
	__u32 mode, reqmode = GR_FIND;
129
130
	if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
131
		reqmode |= GR_EXEC;
132
	if (fmode & S_IWOTH)
133
		reqmode |= GR_WRITE;
134
	if (fmode & S_IROTH)
135
		reqmode |= GR_READ;
136
137
	mode =
138
	    gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
139
			   mnt);
140
141
	if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
142
		security_audit(GR_ACCESS_ACL_MSG, "successful",
143
			       gr_to_filename(dentry, mnt),
144
			       reqmode & GR_READ ? " reading" : "",
145
			       reqmode & GR_WRITE ? " writing" : "",
146
			       reqmode & GR_EXEC ? " executing" : "",
147
			       DEFAULTSECARGS);
148
		return reqmode;
149
	} else
150
	    if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
151
	{
152
		security_alert(GR_ACCESS_ACL_MSG, "denied",
153
			       gr_to_filename(dentry, mnt),
154
			       reqmode & GR_READ ? " reading" : "",
155
			       reqmode & GR_WRITE ? " writing" : "",
156
			       reqmode & GR_EXEC ? " executing" : "",
157
			       DEFAULTSECARGS);
158
		return 0;
159
	} else if (unlikely((mode & reqmode) != reqmode))
160
		return 0;
161
162
	return reqmode;
163
}
164
165
#define generic_fs_handler(dentry, mnt, reqmode, fmt) \
166
{ \
167
	__u32 mode; \
168
	\
169
	mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt); \
170
	\
171
	if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) { \
172
		security_audit(fmt, "successful", \
173
				gr_to_filename(dentry, mnt), DEFAULTSECARGS); \
174
		return mode; \
175
	} else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) { \
176
		security_alert(fmt, "denied", gr_to_filename(dentry, mnt), \
177
				DEFAULTSECARGS); \
178
		return 0; \
179
	} else if (unlikely((mode & (reqmode)) != (reqmode))) \
180
		return 0; \
181
	\
182
	return (reqmode); \
183
}
184
185
__u32
186
gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
187
{
188
	generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
189
}
190
191
__u32
192
gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
193
{
194
	generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
195
}
196
197
__u32
198
gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
199
{
200
	generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
201
}
202
203
__u32
204
gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
205
{
206
	generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
207
}
208
209
__u32
210
gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
211
		     mode_t mode)
212
{
213
	if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
214
		generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
215
				   GR_FCHMOD_ACL_MSG);
216
	} else {
217
		generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
218
	}
219
}
220
221
__u32
222
gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
223
		    mode_t mode)
224
{
225
	if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
226
		generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
227
				   GR_CHMOD_ACL_MSG);
228
	} else {
229
		generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
230
	}
231
}
232
233
__u32
234
gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
235
{
236
	generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
237
}
238
239
__u32
240
gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
241
{
242
	generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
243
}
244
245
__u32
246
gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
247
{
248
	generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
249
			   GR_UNIXCONNECT_ACL_MSG);
250
}
251
252
__u32
253
gr_acl_handle_filldir(const struct dentry *dentry, const struct vfsmount *mnt,
254
		      const ino_t ino)
255
{
256
	if (likely((unsigned long)(dentry->d_inode))) {
257
		struct dentry d = *dentry;
258
		struct inode inode = *(dentry->d_inode);
259
260
		inode.i_ino = ino;
261
		d.d_inode = &inode;
262
263
		if (unlikely(!gr_search_file(&d, GR_FIND | GR_NOLEARN, mnt)))
264
			return 0;
265
	}
266
267
	return 1;
268
}
269
270
__u32
271
gr_acl_handle_link(const struct dentry * new_dentry,
272
		   const struct dentry * parent_dentry,
273
		   const struct vfsmount * parent_mnt,
274
		   const struct dentry * old_dentry,
275
		   const struct vfsmount * old_mnt, const char *to)
276
{
277
	__u32 needmode = GR_WRITE | GR_CREATE;
278
	__u32 mode;
279
280
	mode =
281
	    gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
282
			  old_mnt);
283
284
	if (unlikely(((mode & needmode) == needmode) && mode & GR_AUDITS)) {
285
		security_audit(GR_LINK_ACL_MSG, "successful",
286
			       gr_to_filename(old_dentry, old_mnt), to,
287
			       DEFAULTSECARGS);
288
		return mode;
289
	} else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
290
		security_alert(GR_LINK_ACL_MSG, "denied",
291
			       gr_to_filename(old_dentry, old_mnt), to,
292
			       DEFAULTSECARGS);
293
		return 0;
294
	} else if (unlikely((mode & needmode) != needmode))
295
		return 0;
296
297
	return (GR_WRITE | GR_CREATE);
298
}
299
300
__u32
301
gr_acl_handle_symlink(const struct dentry * new_dentry,
302
		      const struct dentry * parent_dentry,
303
		      const struct vfsmount * parent_mnt, const char *from)
304
{
305
	__u32 needmode = GR_WRITE | GR_CREATE;
306
	__u32 mode;
307
308
	mode =
309
	    gr_check_create(new_dentry, parent_dentry, parent_mnt,
310
			    GR_CREATE | GR_AUDIT_CREATE |
311
			    GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
312
313
	if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
314
		security_audit(GR_SYMLINK_ACL_MSG, "successful",
315
			       from, gr_to_filename(new_dentry, parent_mnt),
316
			       DEFAULTSECARGS);
317
		return mode;
318
	} else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
319
		security_alert(GR_SYMLINK_ACL_MSG, "denied",
320
			       from, gr_to_filename(new_dentry, parent_mnt),
321
			       DEFAULTSECARGS);
322
		return 0;
323
	} else if (unlikely((mode & needmode) != needmode))
324
		return 0;
325
326
	return (GR_WRITE | GR_CREATE);
327
}
328
329
#define generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt, reqmode, fmt) \
330
{ \
331
	__u32 mode; \
332
	\
333
	mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS); \
334
	\
335
	if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) { \
336
		security_audit(fmt, "successful", \
337
				gr_to_filename(new_dentry, parent_mnt), \
338
				DEFAULTSECARGS); \
339
		return mode; \
340
	} else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) { \
341
		security_alert(fmt, "denied", \
342
				gr_to_filename(new_dentry, parent_mnt), \
343
				DEFAULTSECARGS); \
344
		return 0; \
345
	} else if (unlikely((mode & (reqmode)) != (reqmode))) \
346
		return 0; \
347
	\
348
	return (reqmode); \
349
}
350
351
__u32
352
gr_acl_handle_mknod(const struct dentry * new_dentry,
353
		    const struct dentry * parent_dentry,
354
		    const struct vfsmount * parent_mnt,
355
		    const int mode)
356
{
357
	__u32 reqmode = GR_WRITE | GR_CREATE;
358
	if (unlikely(mode & (S_ISUID | S_ISGID)))
359
		reqmode |= GR_SETID;
360
361
	generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
362
				  reqmode, GR_MKNOD_ACL_MSG);
363
}
364
365
__u32
366
gr_acl_handle_mkdir(const struct dentry *new_dentry,
367
		    const struct dentry *parent_dentry,
368
		    const struct vfsmount *parent_mnt)
369
{
370
	generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
371
				  GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
372
}
373
374
#define RENAME_CHECK_SUCCESS(old, new) \
375
	(((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
376
	 ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
377
378
int
379
gr_acl_handle_rename(struct dentry *new_dentry,
380
		     struct dentry *parent_dentry,
381
		     const struct vfsmount *parent_mnt,
382
		     struct dentry *old_dentry,
383
		     struct inode *old_parent_inode,
384
		     struct vfsmount *old_mnt, const char *newname)
385
{
386
	__u8 gr_replace = 1;
387
	__u32 comp1, comp2;
388
	int error = 0;
389
390
	if (unlikely(!gr_acl_is_enabled()))
391
		return 1;
392
393
	if (!new_dentry->d_inode) {
394
		gr_replace = 0;
395
396
		comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
397
					GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
398
					GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
399
		comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
400
				       GR_DELETE | GR_AUDIT_DELETE |
401
				       GR_AUDIT_READ | GR_AUDIT_WRITE |
402
				       GR_SUPPRESS, old_mnt);
403
	} else {
404
		comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
405
				       GR_CREATE | GR_DELETE |
406
				       GR_AUDIT_CREATE | GR_AUDIT_DELETE |
407
				       GR_AUDIT_READ | GR_AUDIT_WRITE |
408
				       GR_SUPPRESS, parent_mnt);
409
		comp2 =
410
		    gr_search_file(old_dentry,
411
				   GR_READ | GR_WRITE | GR_AUDIT_READ |
412
				   GR_DELETE | GR_AUDIT_DELETE |
413
				   GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
414
	}
415
416
	if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
417
	    ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
418
		security_audit(GR_RENAME_ACL_MSG, "successful",
419
			       gr_to_filename(old_dentry, old_mnt),
420
			       newname, DEFAULTSECARGS);
421
	else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
422
		 && !(comp2 & GR_SUPPRESS)) {
423
		security_alert(GR_RENAME_ACL_MSG, "denied",
424
			       gr_to_filename(old_dentry, old_mnt), newname,
425
			       DEFAULTSECARGS);
426
		error = -EACCES;
427
	} else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
428
		error = -EACCES;
429
430
	if (error)
431
		return error;
432
433
	error = gr_handle_rename(old_parent_inode, parent_dentry->d_inode,
434
				 old_dentry, new_dentry, old_mnt, gr_replace);
435
436
	return error;
437
}
438
439
void
440
gr_acl_handle_exit(void)
441
{
442
	u16 id;
443
	char *rolename;
444
445
	if (unlikely(current->acl_sp_role && gr_acl_is_enabled())) {
446
		id = current->acl_role_id;
447
		rolename = current->role->rolename;
448
		gr_set_acls(1);
449
		security_alert_good(GR_SPROLEL_ACL_MSG,
450
				    rolename, id, DEFAULTSECARGS);
451
	}
452
453
	if (current->exec_file) {
454
		fput(current->exec_file);
455
		current->exec_file = NULL;
456
	}
457
}
458
459
int
460
gr_acl_handle_procpidmem(const struct task_struct *task)
461
{
462
	if (unlikely(!gr_acl_is_enabled()))
463
		return 0;
464
465
	if (task->acl->mode & GR_PROTPROCFD)
466
		return -EACCES;
467
468
	return 0;
469
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/gracl_ip.c (+235 lines)
Line 0 Link Here
1
/* 
2
 * grsecurity/gracl_ip.c
3
 * Copyright Brad Spengler 2002, 2003
4
 *
5
 */
6
7
#include <linux/kernel.h>
8
#include <asm/uaccess.h>
9
#include <asm/errno.h>
10
#include <net/sock.h>
11
#include <linux/file.h>
12
#include <linux/fs.h>
13
#include <linux/net.h>
14
#include <linux/in.h>
15
#include <linux/skbuff.h>
16
#include <linux/ip.h>
17
#include <linux/udp.h>
18
#include <linux/smp_lock.h>
19
#include <linux/types.h>
20
#include <linux/sched.h>
21
#include <linux/gracl.h>
22
#include <linux/grsecurity.h>
23
#include <linux/grinternal.h>
24
25
#define GR_BIND 	0x01
26
#define GR_CONNECT 	0x02
27
28
static const char * gr_protocols[256] = {
29
	"ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
30
	"egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
31
	"chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
32
	"trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
33
	"merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
34
	"il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
35
	"mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
36
	"tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
37
	"sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
38
	"cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak", 
39
	"iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf", 
40
	"eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
41
	"scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
42
	"aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
43
	"vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
44
	"uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
45
	"sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
46
	"unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
47
	"unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
48
	"unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
49
	"unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
50
	"unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
51
	"unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
52
	"unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
53
	"unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
54
	"unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55
	"unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56
	"unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
57
	"unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
58
	"unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
59
	"unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
60
	"unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
61
	};
62
63
static const char * gr_socktypes[11] = {
64
	"unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6", 
65
	"unknown:7", "unknown:8", "unknown:9", "packet"
66
	};
67
68
static __inline__ const char *
69
gr_proto_to_name(unsigned char proto)
70
{
71
	return gr_protocols[proto];
72
}
73
74
static __inline__ const char *
75
gr_socktype_to_name(unsigned char type)
76
{
77
	return gr_socktypes[type];
78
}
79
80
int
81
gr_search_socket(const int domain, const int type, const int protocol)
82
{
83
	struct acl_subject_label *curr;
84
85
	if (unlikely(!gr_acl_is_enabled()))
86
		goto exit;
87
88
	if ((domain < 0) || (type < 0) || (protocol < 0) || (domain != PF_INET)
89
	    || (domain >= NPROTO) || (type >= SOCK_MAX) || (protocol > 255))
90
		goto exit;	// let the kernel handle it
91
92
	curr = current->acl;
93
94
	if (!curr->ips)
95
		goto exit;
96
97
	if ((curr->ip_type & (1 << type)) &&
98
	    (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
99
		goto exit;
100
101
	if (curr->mode & GR_LEARN) {
102
		/* we don't place acls on raw sockets , and sometimes
103
		   dgram/ip sockets are opened for ioctl and not
104
		   bind/connect, so we'll fake a bind learn log */
105
		if (type == SOCK_RAW || type == SOCK_PACKET) {
106
			__u32 fakeip = 0;
107
			security_learn(GR_IP_LEARN_MSG, current->role->rolename,
108
				       current->role->roletype, current->uid,
109
				       current->gid, current->exec_file ?
110
				       gr_to_filename(current->exec_file->f_dentry,
111
				       current->exec_file->f_vfsmnt) :
112
				       curr->filename, curr->filename,
113
				       NIPQUAD(fakeip), 0, type,
114
				       protocol, GR_CONNECT, NIPQUAD(current->curr_ip));
115
		} else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
116
			__u32 fakeip = 0;
117
			security_learn(GR_IP_LEARN_MSG, current->role->rolename,
118
				       current->role->roletype, current->uid,
119
				       current->gid, current->exec_file ?
120
				       gr_to_filename(current->exec_file->f_dentry,
121
				       current->exec_file->f_vfsmnt) :
122
				       curr->filename, curr->filename,
123
				       NIPQUAD(fakeip), 0, type,
124
				       protocol, GR_BIND, NIPQUAD(current->curr_ip));
125
		}
126
		/* we'll log when they use connect or bind */
127
		goto exit;
128
	}
129
130
	security_alert(GR_SOCK_MSG, "inet", gr_socktype_to_name(type),
131
		       gr_proto_to_name(protocol), DEFAULTSECARGS);
132
133
	return 0;
134
      exit:
135
	return 1;
136
}
137
138
static __inline__ int
139
gr_search_connectbind(const int mode, const struct sock *sk,
140
		      const struct sockaddr_in *addr, const int type)
141
{
142
	struct acl_subject_label *curr;
143
	struct acl_ip_label *ip;
144
	unsigned long i;
145
	__u32 ip_addr = 0;
146
	__u16 ip_port = 0;
147
148
	if (unlikely(!gr_acl_is_enabled() || sk->family != PF_INET))
149
		return 1;
150
151
	curr = current->acl;
152
153
	if (!curr->ips)
154
		return 1;
155
156
	ip_addr = addr->sin_addr.s_addr;
157
	ip_port = ntohs(addr->sin_port);
158
159
	for (i = 0; i < curr->ip_num; i++) {
160
		ip = *(curr->ips + i);
161
		if ((ip->mode & mode) &&
162
		    (ip_port >= ip->low) &&
163
		    (ip_port <= ip->high) &&
164
		    ((ntohl(ip_addr) & ip->netmask) ==
165
		     (ntohl(ip->addr) & ip->netmask))
166
		    && (ip->
167
			proto[sk->protocol / 32] & (1 << (sk->protocol % 32)))
168
		    && (ip->type & (1 << type)))
169
			return 1;
170
	}
171
172
	if (curr->mode & GR_LEARN) {
173
		security_learn(GR_IP_LEARN_MSG, current->role->rolename,
174
			       current->role->roletype, current->uid,
175
			       current->gid, current->exec_file ?
176
			       gr_to_filename(current->exec_file->f_dentry,
177
			       current->exec_file->f_vfsmnt) :
178
			       curr->filename, curr->filename,
179
			       NIPQUAD(ip_addr), ip_port, type,
180
			       sk->protocol, mode, NIPQUAD(current->curr_ip));
181
		return 1;
182
	}
183
184
	if (mode == GR_BIND)
185
		security_alert(GR_BIND_ACL_MSG, NIPQUAD(ip_addr), ip_port,
186
			       gr_socktype_to_name(type), gr_proto_to_name(sk->protocol),
187
			       DEFAULTSECARGS);
188
	else if (mode == GR_CONNECT)
189
		security_alert(GR_CONNECT_ACL_MSG, NIPQUAD(ip_addr), ip_port,
190
			       gr_socktype_to_name(type), gr_proto_to_name(sk->protocol),
191
			       DEFAULTSECARGS);
192
193
	return 0;
194
}
195
196
int
197
gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
198
{
199
	return gr_search_connectbind(GR_CONNECT, sock->sk, addr, sock->type);
200
}
201
202
int
203
gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
204
{
205
	return gr_search_connectbind(GR_BIND, sock->sk, addr, sock->type);
206
}
207
208
int
209
gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
210
{
211
	if (addr)
212
		return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
213
	else {
214
		struct sockaddr_in sin;
215
216
		sin.sin_addr.s_addr = sk->daddr;
217
		sin.sin_port = sk->dport;
218
219
		return gr_search_connectbind(GR_CONNECT, sk, &sin, SOCK_DGRAM);
220
	}
221
}
222
223
int
224
gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
225
{
226
	struct sockaddr_in sin;
227
228
	if (unlikely(skb->len < sizeof (struct udphdr)))
229
		return 1;	// skip this packet
230
231
	sin.sin_addr.s_addr = skb->nh.iph->saddr;
232
	sin.sin_port = skb->h.uh->source;
233
234
	return gr_search_connectbind(GR_CONNECT, sk, &sin, SOCK_DGRAM);
235
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/gracl_learn.c (+228 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/mm.h>
3
#include <linux/sched.h>
4
#include <linux/poll.h>
5
#include <linux/smp_lock.h>
6
#include <linux/string.h>
7
#include <linux/file.h>
8
#include <linux/types.h>
9
#include <linux/vmalloc.h>
10
#include <linux/grinternal.h>
11
12
extern ssize_t write_grsec_handler(struct file * file, const char * buf,
13
				   size_t count, loff_t *ppos);
14
extern int gr_acl_is_enabled(void);
15
16
static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
17
static DECLARE_WAIT_QUEUE_HEAD(input_wait);
18
static atomic_t learn_buffer_count = ATOMIC_INIT(0);
19
static int gr_learn_attached;
20
21
#define LEARN_BUFFER_SLOTS 256
22
#define LEARN_BUFFER_SIZE 16384
23
24
static spinlock_t learn_buffer_lock[LEARN_BUFFER_SLOTS] = { [0 ... (LEARN_BUFFER_SLOTS - 1)] = SPIN_LOCK_UNLOCKED };
25
static char *learn_buffer[LEARN_BUFFER_SLOTS];
26
static int learn_buffer_len[LEARN_BUFFER_SLOTS];
27
28
static ssize_t
29
read_learn(struct file *file, char * buf, size_t count, loff_t * ppos)
30
{
31
	DECLARE_WAITQUEUE(wait, current);
32
	ssize_t retval = 0;
33
	char *tmp;
34
	unsigned int len;
35
	int i;
36
37
	add_wait_queue(&learn_wait, &wait);
38
	set_current_state(TASK_INTERRUPTIBLE);
39
	do {
40
		if (atomic_read(&learn_buffer_count) > 1)
41
			break;
42
43
		if (file->f_flags & O_NONBLOCK) {
44
			retval = -EAGAIN;
45
			goto out;
46
		}
47
		if (signal_pending(current)) {
48
			retval = -ERESTARTSYS;
49
			goto out;
50
		}
51
52
		schedule();
53
	} while (1);
54
55
56
	for (i = 0; i < LEARN_BUFFER_SLOTS; i++) {
57
		spin_lock(&learn_buffer_lock[i]);
58
		len = learn_buffer_len[i];
59
		tmp = learn_buffer[i];
60
		if (!len || !tmp) {
61
			spin_unlock(&learn_buffer_lock[i]);
62
			continue;
63
		}
64
		learn_buffer[i] = NULL;
65
		learn_buffer_len[i] = 0;
66
		spin_unlock(&learn_buffer_lock[i]);
67
68
		if (count < ((i * LEARN_BUFFER_SIZE) + len)) {
69
			retval = -EINVAL;
70
			vfree(tmp);
71
			goto out;
72
		}
73
		if (copy_to_user(buf + (i * LEARN_BUFFER_SIZE), tmp, len)) {
74
			retval = -EFAULT;
75
			vfree(tmp);
76
			goto out;
77
		}
78
79
		retval += len;
80
		vfree(tmp);
81
		atomic_dec(&learn_buffer_count);
82
		atomic_dec(&learn_buffer_count);
83
	}
84
85
	wake_up(&input_wait);
86
out:
87
	set_current_state(TASK_RUNNING);
88
	remove_wait_queue(&learn_wait, &wait);
89
	return retval;
90
}
91
92
static unsigned int
93
poll_learn(struct file * file, poll_table * wait)
94
{
95
	poll_wait(file, &learn_wait, wait);
96
97
	if (atomic_read(&learn_buffer_count) > 1)
98
		return (POLLIN | POLLRDNORM);
99
100
	return 0;
101
}
102
103
void
104
gr_clear_learn_entries(void)
105
{
106
	int i;
107
108
	atomic_set(&learn_buffer_count, 0);
109
	wake_up(&input_wait);
110
	
111
	for (i = 0; i < LEARN_BUFFER_SLOTS; i++) {
112
		if (learn_buffer_len[i]) {
113
			vfree(learn_buffer[i]);
114
			learn_buffer[i] = NULL;
115
			learn_buffer_len[i] = 0;
116
		}
117
	}
118
119
	return;
120
}
121
122
void
123
gr_add_learn_entry(const char *fmt, ...)
124
{
125
	DECLARE_WAITQUEUE(wait, current);
126
	va_list args;
127
	char *tmpbuf;
128
	char *buf;
129
	int i;
130
	unsigned int len;
131
132
	if (!gr_learn_attached)
133
		return;
134
135
	tmpbuf = vmalloc(LEARN_BUFFER_SIZE);
136
137
	if (tmpbuf == NULL)
138
		return;
139
140
	va_start(args, fmt);
141
	len = vsnprintf(tmpbuf, LEARN_BUFFER_SIZE, fmt, args);
142
	va_end(args);
143
144
	if (len < 0)
145
		len = LEARN_BUFFER_SIZE - 1;
146
147
	buf = vmalloc(len + 1);
148
149
	if (buf == NULL) {
150
		vfree(tmpbuf);
151
		return;
152
	}
153
154
	memcpy(buf, tmpbuf, len);
155
	buf[len] = '\0';
156
	vfree(tmpbuf);
157
158
	add_wait_queue(&input_wait, &wait);
159
160
	atomic_inc(&learn_buffer_count);
161
	if (atomic_read(&learn_buffer_count) > ((2 * (LEARN_BUFFER_SLOTS - 1)) + 1)) {
162
		/* don't sleep under the BKL */
163
//		if (unlikely(current->lock_depth >= 0)) {
164
		remove_wait_queue(&input_wait, &wait);
165
		atomic_dec(&learn_buffer_count);
166
		vfree(buf);
167
		return;
168
//		}
169
//		sleep_on(&input_wait);
170
	}
171
172
	if (!gr_acl_is_enabled()) {
173
		remove_wait_queue(&input_wait, &wait);
174
		atomic_dec(&learn_buffer_count);
175
		vfree(buf);
176
		return;
177
	}
178
179
	for (i = 0; i < LEARN_BUFFER_SLOTS; i++) {
180
		spin_lock(&learn_buffer_lock[i]);
181
182
		if (learn_buffer_len[i]) {
183
			spin_unlock(&learn_buffer_lock[i]);
184
			continue;
185
		}
186
187
		learn_buffer[i] = buf;
188
189
		learn_buffer_len[i] = len + 1;
190
191
		atomic_inc(&learn_buffer_count);
192
		spin_unlock(&learn_buffer_lock[i]);
193
		break;
194
	}
195
196
	remove_wait_queue(&input_wait, &wait);
197
	wake_up_interruptible(&learn_wait);
198
199
	return;
200
}
201
202
static int
203
open_learn(struct inode *inode, struct file *file)
204
{
205
	if (file->f_mode & FMODE_READ && gr_learn_attached)
206
		return -EBUSY;
207
	else if (file->f_mode & FMODE_READ)
208
		gr_learn_attached = 1;
209
210
	return 0;
211
}
212
213
static int
214
close_learn(struct inode *inode, struct file *file)
215
{
216
	if (file->f_mode & FMODE_READ)
217
		gr_learn_attached = 0;
218
219
	return 0;
220
}
221
		
222
struct file_operations grsec_fops = {
223
	read:		read_learn,
224
	write:		write_grsec_handler,
225
	open:		open_learn,
226
	release:	close_learn,
227
	poll:		poll_learn,
228
};
(-)linux-2.4.22-ppc-dev.orig/grsecurity/gracl_res.c (+45 lines)
Line 0 Link Here
1
/* resource handling routines (c) Brad Spengler 2002, 2003 */
2
3
#include <linux/kernel.h>
4
#include <linux/sched.h>
5
#include <linux/gracl.h>
6
#include <linux/grinternal.h>
7
8
static const char *restab_log[11] = {
9
	"RLIMIT_CPU",
10
	"RLIMIT_FSIZE",
11
	"RLIMIT_DATA",
12
	"RLIMIT_STACK",
13
	"RLIMIT_CORE",
14
	"RLIMIT_RSS",
15
	"RLIMIT_NPROC",
16
	"RLIMIT_NOFILE",
17
	"RLIMIT_MEMLOCK",
18
	"RLIMIT_AS",
19
	"RLIMIT_LOCKS"
20
};
21
22
__inline__ void
23
gr_log_resource(const struct task_struct *task,
24
		const int res, const unsigned long wanted)
25
{
26
	if (unlikely(res == RLIMIT_NPROC && 
27
	    (cap_raised(task->cap_effective, CAP_SYS_ADMIN) || 
28
	     cap_raised(task->cap_effective, CAP_SYS_RESOURCE))))
29
		return;
30
31
	if (unlikely(wanted >= task->rlim[res].rlim_cur &&
32
		     task->rlim[res].rlim_cur != RLIM_INFINITY))
33
		security_alert(GR_RESOURCE_MSG, wanted, restab_log[res],
34
			       task->rlim[res].rlim_cur,
35
			       gr_task_fullpath(task), task->comm,
36
			       task->pid, task->uid, task->euid,
37
			       task->gid, task->egid,
38
			       gr_parent_task_fullpath(task),
39
			       task->p_pptr->comm,
40
			       task->p_pptr->pid, task->p_pptr->uid, 
41
			       task->p_pptr->euid, task->p_pptr->gid,
42
			       task->p_pptr->egid);
43
44
	return;
45
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/gracl_segv.c (+327 lines)
Line 0 Link Here
1
/* 
2
 * grsecurity/gracl_segv.c
3
 * Copyright Brad Spengler 2002, 2003
4
 *
5
 */
6
7
#include <linux/kernel.h>
8
#include <linux/mm.h>
9
#include <asm/uaccess.h>
10
#include <asm/errno.h>
11
#include <asm/mman.h>
12
#include <net/sock.h>
13
#include <linux/file.h>
14
#include <linux/fs.h>
15
#include <linux/net.h>
16
#include <linux/in.h>
17
#include <linux/smp_lock.h>
18
#include <linux/slab.h>
19
#include <linux/types.h>
20
#include <linux/sched.h>
21
#include <linux/timer.h>
22
#include <linux/gracl.h>
23
#include <linux/grsecurity.h>
24
#include <linux/grinternal.h>
25
26
static struct crash_uid *uid_set;
27
static unsigned short uid_used;
28
static rwlock_t gr_uid_lock = RW_LOCK_UNLOCKED;
29
extern rwlock_t gr_inode_lock;
30
extern __inline__ struct acl_subject_label *lookup_acl_subj_label(const ino_t
31
								  inode,
32
								  const kdev_t
33
								  dev,
34
								  struct
35
								  acl_role_label
36
								  *role);
37
38
int
39
gr_init_uidset(void)
40
{
41
	uid_set =
42
	    kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
43
	uid_used = 0;
44
45
	return uid_set ? 1 : 0;
46
}
47
48
void
49
gr_free_uidset(void)
50
{
51
	if (uid_set)
52
		kfree(uid_set);
53
54
	return;
55
}
56
57
int
58
gr_find_uid(const uid_t uid)
59
{
60
	struct crash_uid *tmp = uid_set;
61
	uid_t buid;
62
	int low = 0, high = uid_used - 1, mid;
63
64
	while (high >= low) {
65
		mid = (low + high) >> 1;
66
		buid = tmp[mid].uid;
67
		if (buid == uid)
68
			return mid;
69
		if (buid > uid)
70
			high = mid - 1;
71
		if (buid < uid)
72
			low = mid + 1;
73
	}
74
75
	return -1;
76
}
77
78
static __inline__ void
79
gr_insertsort(void)
80
{
81
	unsigned short i, j;
82
	struct crash_uid index;
83
84
	for (i = 1; i < uid_used; i++) {
85
		index = uid_set[i];
86
		j = i;
87
		while ((j > 0) && uid_set[j - 1].uid > index.uid) {
88
			uid_set[j] = uid_set[j - 1];
89
			j--;
90
		}
91
		uid_set[j] = index;
92
	}
93
94
	return;
95
}
96
97
static __inline__ void
98
gr_insert_uid(const uid_t uid, const unsigned long expires)
99
{
100
	int loc;
101
102
	if (uid_used == GR_UIDTABLE_MAX)
103
		return;
104
105
	loc = gr_find_uid(uid);
106
107
	if (loc >= 0) {
108
		uid_set[loc].expires = expires;
109
		return;
110
	}
111
112
	uid_set[uid_used].uid = uid;
113
	uid_set[uid_used].expires = expires;
114
	uid_used++;
115
116
	gr_insertsort();
117
118
	return;
119
}
120
121
void
122
gr_remove_uid(const unsigned short loc)
123
{
124
	unsigned short i;
125
126
	for (i = loc + 1; i < uid_used; i++)
127
		uid_set[i - i] = uid_set[i];
128
129
	uid_used--;
130
131
	return;
132
}
133
134
int
135
gr_check_crash_uid(const uid_t uid)
136
{
137
	int loc;
138
139
	if (unlikely(!gr_acl_is_enabled()))
140
		return 0;
141
142
	read_lock(&gr_uid_lock);
143
	loc = gr_find_uid(uid);
144
	read_unlock(&gr_uid_lock);
145
146
	if (loc < 0)
147
		return 0;
148
149
	write_lock(&gr_uid_lock);
150
	if (time_before_eq(uid_set[loc].expires, jiffies))
151
		gr_remove_uid(loc);
152
	else {
153
		write_unlock(&gr_uid_lock);
154
		return 1;
155
	}
156
157
	write_unlock(&gr_uid_lock);
158
	return 0;
159
}
160
161
static __inline__ int
162
proc_is_setxid(const struct task_struct *task)
163
{
164
	if (task->uid != task->euid || task->uid != task->suid ||
165
	    task->uid != task->fsuid)
166
		return 1;
167
	if (task->gid != task->egid || task->gid != task->sgid ||
168
	    task->gid != task->fsgid)
169
		return 1;
170
171
	return 0;
172
}
173
static __inline__ int
174
gr_fake_force_sig(int sig, struct task_struct *t)
175
{
176
	unsigned long int flags;
177
178
	spin_lock_irqsave(&t->sigmask_lock, flags);
179
	if (t->sig == NULL) {
180
		spin_unlock_irqrestore(&t->sigmask_lock, flags);
181
		return -ESRCH;
182
	}
183
184
	if (t->sig->action[sig - 1].sa.sa_handler == SIG_IGN)
185
		t->sig->action[sig - 1].sa.sa_handler = SIG_DFL;
186
	sigdelset(&t->blocked, sig);
187
	recalc_sigpending(t);
188
	spin_unlock_irqrestore(&t->sigmask_lock, flags);
189
190
	return send_sig_info(sig, (void *) 1L, t);
191
}
192
193
void
194
gr_handle_crash(struct task_struct *task, const int sig)
195
{
196
	struct acl_subject_label *curr;
197
	struct acl_subject_label *curr2;
198
	struct task_struct *tsk;
199
200
	if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
201
		return;
202
203
	if (unlikely(!gr_acl_is_enabled()))
204
		return;
205
206
	curr = task->acl;
207
208
	if (!(curr->resmask & (1 << GR_CRASH_RES)))
209
		return;
210
211
	if (time_before_eq(curr->expires, jiffies)) {
212
		curr->expires = 0;
213
		curr->crashes = 0;
214
	}
215
216
	curr->crashes++;
217
218
	if (!curr->expires)
219
		curr->expires = jiffies + curr->res[GR_CRASH_RES].rlim_max;
220
221
	if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
222
	    time_after(curr->expires, jiffies)) {
223
		if (task->uid && proc_is_setxid(task)) {
224
			security_alert(GR_SEGVSTART_ACL_MSG,
225
				       gr_task_fullpath(task), task->comm,
226
				       task->pid, task->uid, task->euid,
227
				       task->gid, task->egid,
228
				       gr_parent_task_fullpath(task),
229
				       task->p_pptr->comm, task->p_pptr->pid,
230
				       task->p_pptr->uid, task->p_pptr->euid,
231
				       task->p_pptr->gid, task->p_pptr->egid,
232
				       task->uid,
233
				       curr->res[GR_CRASH_RES].rlim_max / HZ);
234
			write_lock(&gr_uid_lock);
235
			gr_insert_uid(task->uid, curr->expires);
236
			write_unlock(&gr_uid_lock);
237
			curr->expires = 0;
238
			curr->crashes = 0;
239
			read_lock(&tasklist_lock);
240
			for_each_task(tsk) {
241
				if (tsk != task && tsk->uid == task->uid)
242
					gr_fake_force_sig(SIGKILL, tsk);
243
			}
244
			read_unlock(&tasklist_lock);
245
		} else {
246
			security_alert(GR_SEGVNOSUID_ACL_MSG,
247
				       gr_task_fullpath(task), task->comm,
248
				       task->pid, task->uid, task->euid,
249
				       task->gid, task->egid,
250
				       gr_parent_task_fullpath(task),
251
				       task->p_pptr->comm, task->p_pptr->pid,
252
				       task->p_pptr->uid, task->p_pptr->euid,
253
				       task->p_pptr->gid, task->p_pptr->egid,
254
				       kdevname(curr->device), curr->inode,
255
				       curr->res[GR_CRASH_RES].rlim_max / HZ);
256
			read_lock(&tasklist_lock);
257
			for_each_task(tsk) {
258
				if (likely(tsk != task)) {
259
					curr2 = tsk->acl;
260
261
					if (curr2->device == curr->device &&
262
					    curr2->inode == curr->inode)
263
						gr_fake_force_sig(SIGKILL, tsk);
264
				}
265
			}
266
			read_unlock(&tasklist_lock);
267
		}
268
	}
269
270
	return;
271
}
272
273
int
274
gr_check_crash_exec(const struct file *filp)
275
{
276
	struct acl_subject_label *curr;
277
278
	if (unlikely(!gr_acl_is_enabled()))
279
		return 0;
280
281
	read_lock(&gr_inode_lock);
282
	curr = lookup_acl_subj_label(filp->f_dentry->d_inode->i_ino,
283
				     filp->f_dentry->d_inode->i_dev,
284
				     current->role);
285
	read_unlock(&gr_inode_lock);
286
287
	if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
288
	    (!curr->crashes && !curr->expires))
289
		return 0;
290
291
	if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
292
	    time_after(curr->expires, jiffies))
293
		return 1;
294
	else if (time_before_eq(curr->expires, jiffies)) {
295
		curr->crashes = 0;
296
		curr->expires = 0;
297
	}
298
299
	return 0;
300
}
301
302
void
303
gr_handle_alertkill(void)
304
{
305
	struct acl_subject_label *curracl;
306
	__u32 curr_ip;
307
	struct task_struct *task;
308
309
	if (unlikely(!gr_acl_is_enabled()))
310
		return;
311
312
	curracl = current->acl;
313
	curr_ip = current->curr_ip;
314
315
	if ((curracl->mode & GR_KILLIPPROC) && curr_ip &&
316
	    (curr_ip != 0xffffffff)) {
317
		read_lock(&tasklist_lock);
318
		for_each_task(task) {
319
			if (task->curr_ip == curr_ip)
320
				gr_fake_force_sig(SIGKILL, task);
321
		}
322
		read_unlock(&tasklist_lock);
323
	} else if (curracl->mode & GR_KILLPROC)
324
		gr_fake_force_sig(SIGKILL, current);
325
326
	return;
327
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/gracl_shm.c (+36 lines)
Line 0 Link Here
1
/* shared memory handling routines, (c) Brad Spengler 2002, 2003 */
2
3
#include <linux/kernel.h>
4
#include <linux/mm.h>
5
#include <linux/sched.h>
6
#include <linux/file.h>
7
#include <linux/ipc.h>
8
#include <linux/gracl.h>
9
#include <linux/grsecurity.h>
10
#include <linux/grinternal.h>
11
12
int
13
gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
14
		const time_t shm_createtime, const uid_t cuid, const int shmid)
15
{
16
	struct task_struct *task;
17
18
	if (!gr_acl_is_enabled())
19
		return 1;
20
21
	task = find_task_by_pid(shm_cprid);
22
23
	if (unlikely(!task))
24
		task = find_task_by_pid(shm_lapid);
25
26
	if (unlikely(task && ((task->start_time < shm_createtime) ||
27
			      (task->pid == shm_lapid)) &&
28
		     (task->acl->mode & GR_PROTSHM) &&
29
		     (task->acl != current->acl))) {
30
		security_alert(GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid,
31
			       DEFAULTSECARGS);
32
		return 0;
33
	}
34
35
	return 1;
36
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_chdir.c (+20 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/fs.h>
4
#include <linux/file.h>
5
#include <linux/grsecurity.h>
6
#include <linux/grinternal.h>
7
8
void
9
gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
10
{
11
#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
12
	if ((grsec_enable_chdir && grsec_enable_group &&
13
	     in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
14
					      !grsec_enable_group)) {
15
		security_audit(GR_CHDIR_AUDIT_MSG, gr_to_filename(dentry, mnt),
16
			       DEFAULTSECARGS);
17
	}
18
#endif
19
	return;
20
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_chroot.c (+333 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/file.h>
4
#include <linux/fs.h>
5
#include <linux/types.h>
6
#include <linux/grinternal.h>
7
8
int
9
gr_handle_chroot_unix(const pid_t pid)
10
{
11
#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
12
	struct task_struct *p, **htable;
13
14
	if (unlikely(!grsec_enable_chroot_unix))
15
		return 1;
16
17
	if (likely(!proc_is_chrooted(current)))
18
		return 1;
19
20
	read_lock(&tasklist_lock);
21
22
	htable = &pidhash[pid_hashfn(pid)];
23
24
	for (p = *htable; p && p->pid != pid; p = p->pidhash_next) ;
25
26
	if (unlikely(p && !have_same_root(current, p))) {
27
		read_unlock(&tasklist_lock);
28
		security_alert(GR_UNIX_CHROOT_MSG, DEFAULTSECARGS);
29
		return 0;
30
	}
31
	read_unlock(&tasklist_lock);
32
#endif
33
	return 1;
34
}
35
36
int
37
gr_handle_chroot_nice(void)
38
{
39
#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
40
	if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
41
		security_alert(GR_NICE_CHROOT_MSG, DEFAULTSECARGS);
42
		return -EPERM;
43
	}
44
#endif
45
	return 0;
46
}
47
48
int
49
gr_handle_chroot_setpriority(const struct task_struct *p, const int niceval)
50
{
51
#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
52
	if (grsec_enable_chroot_nice && (!have_same_root(p, current)
53
					 || (have_same_root(p, current)
54
					     && (niceval < p->nice)
55
					     && proc_is_chrooted(current)))) {
56
		security_alert(GR_PRIORITY_CHROOT_MSG, p->comm, p->pid,
57
			       DEFAULTSECARGS);
58
		return -ESRCH;
59
	}
60
#endif
61
	return 0;
62
}
63
64
int
65
gr_handle_chroot_capset(const struct task_struct *target)
66
{
67
#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68
	if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
69
	    !have_same_root(current, target)) {
70
		security_alert(GR_CAPSET_CHROOT_MSG, target->comm, target->pid,
71
			       DEFAULTSECARGS);
72
		return 1;
73
	}
74
#endif
75
	return 0;
76
}
77
78
int
79
gr_handle_chroot_rawio(const struct inode *inode)
80
{
81
#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
82
	if (grsec_enable_chroot_caps && proc_is_chrooted(current) && 
83
	    inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
84
		return 1;
85
#endif
86
	return 0;
87
}
88
89
int
90
gr_pid_is_chrooted(const struct task_struct *p)
91
{
92
#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
93
	if (!grsec_enable_chroot_findtask || (current->pid <= 1))
94
		return 0;
95
96
	if (p && p->fs && p->fs->root && p->fs->root->d_inode &&
97
	    child_reaper && child_reaper->fs && child_reaper->fs->root &&
98
	    child_reaper->fs->root->d_inode && current && current->fs &&
99
	    current->fs->root && current->fs->root->d_inode) {
100
		if (proc_is_chrooted(current) && !have_same_root(current, p))
101
			return 1;
102
	}
103
#endif
104
	return 0;
105
}
106
107
int
108
gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
109
{
110
#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
111
	if (!grsec_enable_chroot_fchdir)
112
		return 1;
113
114
	if (!proc_is_chrooted(current))
115
		return 1;
116
	else {
117
		struct dentry *dentry = u_dentry;
118
		struct vfsmount *mnt = u_mnt;
119
		struct dentry *realroot;
120
		struct vfsmount *realrootmnt;
121
		struct dentry *currentroot;
122
		struct vfsmount *currentmnt;
123
124
		read_lock(&child_reaper->fs->lock);
125
		realrootmnt = mntget(child_reaper->fs->rootmnt);
126
		realroot = dget(child_reaper->fs->root);
127
		read_unlock(&child_reaper->fs->lock);
128
129
		read_lock(&current->fs->lock);
130
		currentmnt = mntget(current->fs->rootmnt);
131
		currentroot = dget(current->fs->root);
132
		read_unlock(&current->fs->lock);
133
134
		spin_lock(&dcache_lock);
135
		for (;;) {
136
			if (unlikely
137
			    ((dentry == realroot && mnt == realrootmnt)
138
			     || (dentry == currentroot && mnt == currentmnt)))
139
				break;
140
			if (unlikely
141
			    (dentry == mnt->mnt_root || IS_ROOT(dentry))) {
142
				if (mnt->mnt_parent == mnt)
143
					break;
144
				dentry = mnt->mnt_mountpoint;
145
				mnt = mnt->mnt_parent;
146
				continue;
147
			}
148
			dentry = dentry->d_parent;
149
		}
150
		spin_unlock(&dcache_lock);
151
152
		dput(currentroot);
153
		mntput(currentmnt);
154
155
		if (dentry == realroot && mnt == realrootmnt) {
156
			/* ok, they're definitely trying to fchdir outside of the
157
			   chroot. */
158
			dput(realroot);
159
			mntput(realrootmnt);
160
			security_alert(GR_CHROOT_FCHDIR_MSG,
161
				       gr_to_filename(u_dentry, u_mnt),
162
				       DEFAULTSECARGS);
163
			return 0;
164
		} else {
165
			dput(realroot);
166
			mntput(realrootmnt);
167
			return 1;
168
		}
169
	}
170
#endif
171
	return 1;
172
}
173
174
int
175
gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
176
		const time_t shm_createtime)
177
{
178
#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
179
	struct task_struct *p, **htable;
180
181
	if (unlikely(!grsec_enable_chroot_shmat))
182
		return 1;
183
184
	if (likely(!proc_is_chrooted(current)))
185
		return 1;
186
187
	read_lock(&tasklist_lock);
188
189
	htable = &pidhash[pid_hashfn(shm_cprid)];
190
191
	for (p = *htable; p && p->pid != shm_cprid; p = p->pidhash_next) ;
192
193
	if (unlikely(p && !have_same_root(current, p) &&
194
		     (p->start_time < shm_createtime))) {
195
		read_unlock(&tasklist_lock);
196
		security_alert(GR_SHMAT_CHROOT_MSG, DEFAULTSECARGS);
197
		return 0;
198
	}
199
200
	if (unlikely(!p)) {
201
		htable = &pidhash[pid_hashfn(shm_lapid)];
202
		for (p = *htable; p && p->pid != shm_lapid;
203
		     p = p->pidhash_next) ;
204
205
		if (unlikely(p && !have_same_root(current, p))) {
206
			read_unlock(&tasklist_lock);
207
			security_alert(GR_SHMAT_CHROOT_MSG, DEFAULTSECARGS);
208
			return 0;
209
		}
210
	}
211
212
	read_unlock(&tasklist_lock);
213
#endif
214
	return 1;
215
}
216
217
void
218
gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
219
{
220
#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
221
	if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
222
		security_audit(GR_EXEC_CHROOT_MSG, gr_to_filename(dentry, mnt),
223
			       DEFAULTSECARGS);
224
#endif
225
	return;
226
}
227
228
int
229
gr_handle_chroot_mknod(const struct dentry *dentry,
230
		       const struct vfsmount *mnt, const int mode)
231
{
232
#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
233
	if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) &&
234
	    proc_is_chrooted(current)) {
235
		security_alert(GR_MKNOD_CHROOT_MSG,
236
			       gr_to_filename(dentry, mnt), DEFAULTSECARGS);
237
		return -EPERM;
238
	}
239
#endif
240
	return 0;
241
}
242
243
int
244
gr_handle_chroot_mount(const struct dentry *dentry,
245
		       const struct vfsmount *mnt, const char *dev_name)
246
{
247
#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
248
	if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
249
		security_alert(GR_MOUNT_CHROOT_MSG, dev_name,
250
			       gr_to_filename(dentry, mnt), DEFAULTSECARGS);
251
		return -EPERM;
252
	}
253
#endif
254
	return 0;
255
}
256
257
int
258
gr_handle_chroot_pivot(void)
259
{
260
#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
261
	if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
262
		security_alert(GR_PIVOT_CHROOT_MSG, DEFAULTSECARGS);
263
		return -EPERM;
264
	}
265
#endif
266
	return 0;
267
}
268
269
int
270
gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
271
{
272
#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
273
	if (grsec_enable_chroot_double && proc_is_chrooted(current)) {
274
		security_alert(GR_CHROOT_CHROOT_MSG,
275
			       gr_to_filename(dentry, mnt), DEFAULTSECARGS);
276
		return -EPERM;
277
	}
278
#endif
279
	return 0;
280
}
281
282
void
283
gr_handle_chroot_caps(struct task_struct *task)
284
{
285
#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
286
	if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
287
		task->cap_permitted =
288
		    cap_drop(task->cap_permitted, GR_CHROOT_CAPS);
289
		task->cap_inheritable =
290
		    cap_drop(task->cap_inheritable, GR_CHROOT_CAPS);
291
		task->cap_effective =
292
		    cap_drop(task->cap_effective, GR_CHROOT_CAPS);
293
	}
294
#endif
295
	return;
296
}
297
298
int
299
gr_handle_chroot_sysctl(const int op)
300
{
301
#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
302
	if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
303
	    && (op & 002))
304
		return -EACCES;
305
#endif
306
	return 0;
307
}
308
309
void
310
gr_handle_chroot_chdir(struct dentry *dentry, struct vfsmount *mnt)
311
{
312
#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
313
	if (grsec_enable_chroot_chdir)
314
		set_fs_pwd(current->fs, mnt, dentry);
315
#endif
316
	return;
317
}
318
319
int
320
gr_handle_chroot_chmod(const struct dentry *dentry,
321
		       const struct vfsmount *mnt, const int mode)
322
{
323
#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
324
	if (grsec_enable_chroot_chmod &&
325
	    ((mode & S_ISUID) || (mode & S_ISGID)) &&
326
	    proc_is_chrooted(current)) {
327
		security_alert(GR_CHMOD_CHROOT_MSG,
328
			       gr_to_filename(dentry, mnt), DEFAULTSECARGS);
329
		return -EPERM;
330
	}
331
#endif
332
	return 0;
333
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_disabled.c (+380 lines)
Line 0 Link Here
1
/* 
2
 * when grsecurity is disabled, compile all external functions into nothing
3
 */
4
5
#include <linux/kernel.h>
6
#include <linux/config.h>
7
#include <linux/sched.h>
8
#include <linux/file.h>
9
#include <linux/fs.h>
10
#include <linux/kdev_t.h>
11
#include <linux/net.h>
12
#include <linux/in.h>
13
#include <linux/ip.h>
14
#include <linux/skbuff.h>
15
#include <linux/sysctl.h>
16
17
#ifdef CONFIG_SYSCTL
18
__u32
19
gr_handle_sysctl(const struct ctl_table * table, __u32 mode)
20
{
21
	return mode;
22
}
23
#endif
24
25
int
26
gr_acl_is_enabled(void)
27
{
28
	return 0;
29
}
30
31
int
32
gr_handle_rawio(const struct inode *inode)
33
{
34
	return 0;
35
}
36
37
void
38
gr_acl_handle_psacct(struct task_struct *task, const long code)
39
{
40
	return;
41
}
42
43
int
44
gr_handle_ptrace_exec(const struct dentry *dentry, const struct vfsmount *mnt)
45
{
46
	return 0;
47
}
48
49
int
50
gr_handle_mmap(const struct file *filp, const unsigned long prot)
51
{
52
	return 0;
53
}
54
55
int
56
gr_handle_ptrace(struct task_struct *task, const long request)
57
{
58
	return 0;
59
}
60
61
void
62
gr_learn_resource(const struct task_struct *task,
63
		  const int res, const unsigned long wanted)
64
{
65
	return;
66
}
67
68
int
69
gr_set_acls(const int type)
70
{
71
	return 0;
72
}
73
74
int
75
gr_check_hidden_task(const struct task_struct *tsk)
76
{
77
	return 0;
78
}
79
80
int
81
gr_check_protected_task(const struct task_struct *task)
82
{
83
	return 0;
84
}
85
86
__inline__ void
87
gr_copy_label(struct task_struct *tsk)
88
{
89
	return;
90
}
91
92
void
93
gr_set_pax_flags(struct task_struct *task)
94
{
95
	return;
96
}
97
98
void
99
gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt)
100
{
101
	return;
102
}
103
104
void
105
gr_handle_delete(const ino_t ino, const kdev_t dev)
106
{
107
	return;
108
}
109
110
void
111
gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
112
{
113
	return;
114
}
115
116
void
117
gr_handle_crash(struct task_struct *task, const int sig)
118
{
119
	return;
120
}
121
122
int
123
gr_check_crash_exec(const struct file *filp)
124
{
125
	return 0;
126
}
127
128
int
129
gr_check_crash_uid(const uid_t uid)
130
{
131
	return 0;
132
}
133
134
int
135
gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
136
		 struct dentry *old_dentry,
137
		 struct dentry *new_dentry,
138
		 struct vfsmount *mnt, const __u8 replace)
139
{
140
	return 0;
141
}
142
143
int
144
gr_search_socket(const int family, const int type, const int protocol)
145
{
146
	return 1;
147
}
148
149
int
150
gr_search_connectbind(const int mode, const struct socket *sock,
151
		      const struct sockaddr_in *addr)
152
{
153
	return 1;
154
}
155
156
int
157
gr_is_capable(const int cap)
158
{
159
	return 1;
160
}
161
162
void
163
gr_handle_alertkill(void)
164
{
165
	return;
166
}
167
168
__u32
169
gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
170
{
171
	return 1;
172
}
173
174
__u32
175
gr_acl_handle_hidden_file(const struct dentry * dentry,
176
			  const struct vfsmount * mnt)
177
{
178
	return 1;
179
}
180
181
__u32
182
gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
183
		   const int fmode)
184
{
185
	return 1;
186
}
187
188
__u32
189
gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
190
{
191
	return 1;
192
}
193
194
__u32
195
gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
196
{
197
	return 1;
198
}
199
200
int
201
gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
202
		   unsigned int *vm_flags)
203
{
204
	return 1;
205
}
206
207
__u32
208
gr_acl_handle_truncate(const struct dentry * dentry,
209
		       const struct vfsmount * mnt)
210
{
211
	return 1;
212
}
213
214
__u32
215
gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
216
{
217
	return 1;
218
}
219
220
__u32
221
gr_acl_handle_access(const struct dentry * dentry,
222
		     const struct vfsmount * mnt, const int fmode)
223
{
224
	return 1;
225
}
226
227
__u32
228
gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
229
		     mode_t mode)
230
{
231
	return 1;
232
}
233
234
__u32
235
gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
236
		    mode_t mode)
237
{
238
	return 1;
239
}
240
241
__u32
242
gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
243
{
244
	return 1;
245
}
246
247
void
248
grsecurity_init(void)
249
{
250
	return;
251
}
252
253
__u32
254
gr_acl_handle_mknod(const struct dentry * new_dentry,
255
		    const struct dentry * parent_dentry,
256
		    const struct vfsmount * parent_mnt,
257
		    const int mode)
258
{
259
	return 1;
260
}
261
262
__u32
263
gr_acl_handle_mkdir(const struct dentry * new_dentry,
264
		    const struct dentry * parent_dentry,
265
		    const struct vfsmount * parent_mnt)
266
{
267
	return 1;
268
}
269
270
__u32
271
gr_acl_handle_symlink(const struct dentry * new_dentry,
272
		      const struct dentry * parent_dentry,
273
		      const struct vfsmount * parent_mnt, const char *from)
274
{
275
	return 1;
276
}
277
278
__u32
279
gr_acl_handle_link(const struct dentry * new_dentry,
280
		   const struct dentry * parent_dentry,
281
		   const struct vfsmount * parent_mnt,
282
		   const struct dentry * old_dentry,
283
		   const struct vfsmount * old_mnt, const char *to)
284
{
285
	return 1;
286
}
287
288
int
289
gr_acl_handle_rename(const struct dentry *new_dentry,
290
		     const struct dentry *parent_dentry,
291
		     const struct vfsmount *parent_mnt,
292
		     const struct dentry *old_dentry,
293
		     const struct inode *old_parent_inode,
294
		     const struct vfsmount *old_mnt, const char *newname)
295
{
296
	return 1;
297
}
298
299
__u32
300
gr_acl_handle_filldir(const struct dentry * dentry,
301
		      const struct vfsmount * mnt, const ino_t ino)
302
{
303
	return 1;
304
}
305
306
int
307
gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
308
		const time_t shm_createtime, const uid_t cuid, const int shmid)
309
{
310
	return 1;
311
}
312
313
int
314
gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
315
{
316
	return 1;
317
}
318
319
int
320
gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
321
{
322
	return 1;
323
}
324
325
__u32
326
gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
327
{
328
	return 1;
329
}
330
331
__u32
332
gr_acl_handle_creat(const struct dentry * dentry,
333
		    const struct dentry * p_dentry,
334
		    const struct vfsmount * p_mnt, const int fmode,
335
		    const int imode)
336
{
337
	return 1;
338
}
339
340
void
341
gr_acl_handle_exit(void)
342
{
343
	return;
344
}
345
346
int
347
gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
348
{
349
	return 1;
350
}
351
352
void
353
gr_set_role_label(const uid_t uid, const gid_t gid)
354
{
355
	return;
356
}
357
358
int
359
gr_acl_handle_procpidmem(const struct task_struct *task)
360
{
361
	return 0;
362
}
363
364
int
365
gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
366
{
367
	return 1;
368
}
369
370
int
371
gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
372
{
373
	return 1;
374
}
375
376
void
377
gr_set_kernel_label(struct task_struct *task)
378
{
379
	return;
380
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_exec.c (+70 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/file.h>
4
#include <linux/fs.h>
5
#include <linux/types.h>
6
#include <linux/grdefs.h>
7
#include <linux/grinternal.h>
8
#include <linux/capability.h>
9
10
#include <asm/uaccess.h>
11
12
int
13
gr_handle_nproc(void)
14
{
15
#ifdef CONFIG_GRKERNSEC_EXECVE
16
	if (grsec_enable_execve && current->user &&
17
	    (atomic_read(&current->user->processes) >
18
	     current->rlim[RLIMIT_NPROC].rlim_cur) &&
19
	    !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
20
		security_alert(GR_NPROC_MSG, DEFAULTSECARGS);
21
		return -EAGAIN;
22
	}
23
#endif
24
	return 0;
25
}
26
27
void
28
gr_handle_exec_args(struct linux_binprm *bprm, char **argv)
29
{
30
#ifdef CONFIG_GRKERNSEC_EXECLOG
31
	char grarg[64] = { 0 };
32
	__u8 execlen = 0;
33
	unsigned int i;
34
35
	if (!((grsec_enable_execlog && grsec_enable_group &&
36
	       in_group_p(grsec_audit_gid))
37
	      || (grsec_enable_execlog && !grsec_enable_group)))
38
		return;
39
40
	if (unlikely(!argv))
41
		goto log;
42
43
	for (i = 0; i < bprm->argc && execlen < 62; i++) {
44
		char *p;
45
		__u8 len;
46
47
		if (get_user(p, argv + i))
48
			goto log;
49
		if (!p)
50
			goto log;
51
		len = strnlen_user(p, 62 - execlen);
52
		if (len > 62 - execlen)
53
			len = 62 - execlen;
54
		else if (len > 0)
55
			len--;
56
		if (copy_from_user(grarg + execlen, p, len))
57
			goto log;
58
		execlen += len;
59
		*(grarg + execlen) = ' ';
60
		*(grarg + execlen + 1) = '\0';
61
		execlen++;
62
	}
63
64
      log:
65
	security_audit(GR_EXEC_AUDIT_MSG, gr_to_filename(bprm->file->f_dentry,
66
							 bprm->file->f_vfsmnt),
67
		       grarg, DEFAULTSECARGS);
68
#endif
69
	return;
70
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_fifo.c (+24 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/fs.h>
4
#include <linux/file.h>
5
#include <linux/grinternal.h>
6
7
int
8
gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
9
	       const struct dentry *dir, const int flag, const int acc_mode)
10
{
11
#ifdef CONFIG_GRKERNSEC_FIFO
12
	if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
13
	    !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
14
	    (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
15
	    (current->fsuid != dentry->d_inode->i_uid)) {
16
		if (!permission(dentry->d_inode, acc_mode))
17
			security_alert(GR_FIFO_MSG, gr_to_filename(dentry, mnt),
18
				       dentry->d_inode->i_uid,
19
				       dentry->d_inode->i_gid, DEFAULTSECARGS);
20
		return -EACCES;
21
	}
22
#endif
23
	return 0;
24
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_fork.c (+14 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/grsecurity.h>
4
#include <linux/grinternal.h>
5
6
void
7
gr_log_forkfail(const int retval)
8
{
9
#ifdef CONFIG_GRKERNSEC_FORKFAIL
10
	if (grsec_enable_forkfail)
11
		security_alert(GR_FAILFORK_MSG, retval, DEFAULTSECARGS);
12
#endif
13
	return;
14
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_init.c (+210 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/mm.h>
4
#include <linux/smp_lock.h>
5
#include <linux/gracl.h>
6
#include <linux/slab.h>
7
8
int grsec_enable_link;
9
int grsec_enable_dmesg;
10
int grsec_enable_fifo;
11
int grsec_enable_execve;
12
int grsec_enable_execlog;
13
int grsec_enable_signal;
14
int grsec_enable_forkfail;
15
int grsec_enable_time;
16
int grsec_enable_group;
17
int grsec_audit_gid;
18
int grsec_enable_chdir;
19
int grsec_enable_audit_ipc;
20
int grsec_enable_mount;
21
int grsec_enable_chroot_findtask;
22
int grsec_enable_chroot_mount;
23
int grsec_enable_chroot_shmat;
24
int grsec_enable_chroot_fchdir;
25
int grsec_enable_chroot_double;
26
int grsec_enable_chroot_pivot;
27
int grsec_enable_chroot_chdir;
28
int grsec_enable_chroot_chmod;
29
int grsec_enable_chroot_mknod;
30
int grsec_enable_chroot_nice;
31
int grsec_enable_chroot_execlog;
32
int grsec_enable_chroot_caps;
33
int grsec_enable_chroot_sysctl;
34
int grsec_enable_chroot_unix;
35
int grsec_enable_tpe;
36
int grsec_tpe_gid;
37
int grsec_enable_tpe_all;
38
int grsec_enable_randpid;
39
int grsec_enable_randid;
40
int grsec_enable_randisn;
41
int grsec_enable_randsrc;
42
int grsec_enable_randrpc;
43
int grsec_enable_socket_all;
44
int grsec_socket_all_gid;
45
int grsec_enable_socket_client;
46
int grsec_socket_client_gid;
47
int grsec_enable_socket_server;
48
int grsec_socket_server_gid;
49
int grsec_lock;
50
51
spinlock_t grsec_alert_lock = SPIN_LOCK_UNLOCKED;
52
unsigned long grsec_alert_wtime = 0;
53
unsigned long grsec_alert_fyet = 0;
54
55
spinlock_t grsec_alertgood_lock = SPIN_LOCK_UNLOCKED;
56
unsigned long grsec_alertgood_wtime = 0;
57
unsigned long grsec_alertgood_fyet = 0;
58
59
spinlock_t grsec_audit_lock = SPIN_LOCK_UNLOCKED;
60
61
char *gr_shared_page[4][NR_CPUS];
62
extern struct gr_arg *gr_usermode;
63
extern unsigned char *gr_system_salt;
64
extern unsigned char *gr_system_sum;
65
66
void
67
grsecurity_init(void)
68
{
69
	int i, j;
70
	/* create the per-cpu shared pages */
71
72
	for (j = 0; j < 4; j++) {
73
		for (i = 0; i < NR_CPUS; i++) {
74
			gr_shared_page[j][i] = (char *) get_zeroed_page(GFP_KERNEL);
75
			if (!gr_shared_page[j][i]) {
76
				panic("Unable to allocate grsecurity shared page");
77
				return;
78
			}
79
		}
80
	}
81
82
	/* allocate memory for authentication structure */
83
	gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
84
	gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
85
	gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
86
87
	if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
88
		panic("Unable to allocate grsecurity authentication structure");
89
		return;
90
	}
91
92
#ifndef CONFIG_GRKERNSEC_SYSCTL
93
	grsec_lock = 1;
94
#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
95
	grsec_enable_group = 1;
96
	grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
97
#endif
98
#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
99
	grsec_enable_chdir = 1;
100
#endif
101
#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
102
	grsec_enable_audit_ipc = 1;
103
#endif
104
#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
105
	grsec_enable_mount = 1;
106
#endif
107
#ifdef CONFIG_GRKERNSEC_LINK
108
	grsec_enable_link = 1;
109
#endif
110
#ifdef CONFIG_GRKERNSEC_DMESG
111
	grsec_enable_dmesg = 1;
112
#endif
113
#ifdef CONFIG_GRKERNSEC_FIFO
114
	grsec_enable_fifo = 1;
115
#endif
116
#ifdef CONFIG_GRKERNSEC_EXECVE
117
	grsec_enable_execve = 1;
118
#endif
119
#ifdef CONFIG_GRKERNSEC_EXECLOG
120
	grsec_enable_execlog = 1;
121
#endif
122
#ifdef CONFIG_GRKERNSEC_SIGNAL
123
	grsec_enable_signal = 1;
124
#endif
125
#ifdef CONFIG_GRKERNSEC_FORKFAIL
126
	grsec_enable_forkfail = 1;
127
#endif
128
#ifdef CONFIG_GRKERNSEC_TIME
129
	grsec_enable_time = 1;
130
#endif
131
#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
132
	grsec_enable_chroot_findtask = 1;
133
#endif
134
#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
135
	grsec_enable_chroot_unix = 1;
136
#endif
137
#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
138
	grsec_enable_chroot_mount = 1;
139
#endif
140
#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
141
	grsec_enable_chroot_fchdir = 1;
142
#endif
143
#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
144
	grsec_enable_chroot_shmat = 1;
145
#endif
146
#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
147
	grsec_enable_chroot_double = 1;
148
#endif
149
#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
150
	grsec_enable_chroot_pivot = 1;
151
#endif
152
#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
153
	grsec_enable_chroot_chdir = 1;
154
#endif
155
#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
156
	grsec_enable_chroot_chmod = 1;
157
#endif
158
#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
159
	grsec_enable_chroot_mknod = 1;
160
#endif
161
#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
162
	grsec_enable_chroot_nice = 1;
163
#endif
164
#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
165
	grsec_enable_chroot_execlog = 1;
166
#endif
167
#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
168
	grsec_enable_chroot_caps = 1;
169
#endif
170
#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
171
	grsec_enable_chroot_sysctl = 1;
172
#endif
173
#ifdef CONFIG_GRKERNSEC_TPE
174
	grsec_enable_tpe = 1;
175
	grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
176
#ifdef CONFIG_GRKERNSEC_TPE_ALL
177
	grsec_enable_tpe_all = 1;
178
#endif
179
#endif
180
#ifdef CONFIG_GRKERNSEC_RANDPID
181
	grsec_enable_randpid = 1;
182
#endif
183
#ifdef CONFIG_GRKERNSEC_RANDID
184
	grsec_enable_randid = 1;
185
#endif
186
#ifdef CONFIG_GRKERNSEC_RANDISN
187
	grsec_enable_randisn = 1;
188
#endif
189
#ifdef CONFIG_GRKERNSEC_RANDSRC
190
	grsec_enable_randsrc = 1;
191
#endif
192
#ifdef CONFIG_GRKERNSEC_RANDRPC
193
	grsec_enable_randrpc = 1;
194
#endif
195
#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
196
	grsec_enable_socket_all = 1;
197
	grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
198
#endif
199
#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
200
	grsec_enable_socket_client = 1;
201
	grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
202
#endif
203
#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
204
	grsec_enable_socket_server = 1;
205
	grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
206
#endif
207
#endif
208
209
	return;
210
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_ipc.c (+81 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/types.h>
4
#include <linux/ipc.h>
5
#include <linux/grsecurity.h>
6
#include <linux/grinternal.h>
7
8
void
9
gr_log_msgget(const int ret, const int msgflg)
10
{
11
#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
12
	if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
13
	      grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
14
					  !grsec_enable_group)) && (ret >= 0)
15
	    && (msgflg & IPC_CREAT))
16
		security_audit(GR_MSGQ_AUDIT_MSG, DEFAULTSECARGS);
17
#endif
18
	return;
19
}
20
21
void
22
gr_log_msgrm(const uid_t uid, const uid_t cuid)
23
{
24
#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
25
	if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
26
	     grsec_enable_audit_ipc) ||
27
	    (grsec_enable_audit_ipc && !grsec_enable_group))
28
		security_audit(GR_MSGQR_AUDIT_MSG, uid, cuid, DEFAULTSECARGS);
29
#endif
30
	return;
31
}
32
33
void
34
gr_log_semget(const int err, const int semflg)
35
{
36
#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
37
	if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
38
	      grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
39
					  !grsec_enable_group)) && (err >= 0)
40
	    && (semflg & IPC_CREAT))
41
		security_audit(GR_SEM_AUDIT_MSG, DEFAULTSECARGS);
42
#endif
43
	return;
44
}
45
46
void
47
gr_log_semrm(const uid_t uid, const uid_t cuid)
48
{
49
#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
50
	if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
51
	     grsec_enable_audit_ipc) ||
52
	    (grsec_enable_audit_ipc && !grsec_enable_group))
53
		security_audit(GR_SEMR_AUDIT_MSG, uid, cuid, DEFAULTSECARGS);
54
#endif
55
	return;
56
}
57
58
void
59
gr_log_shmget(const int err, const int shmflg, const size_t size)
60
{
61
#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
62
	if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
63
	      grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
64
					  !grsec_enable_group)) && (err >= 0)
65
	    && (shmflg & IPC_CREAT))
66
		security_audit(GR_SHM_AUDIT_MSG, size, DEFAULTSECARGS);
67
#endif
68
	return;
69
}
70
71
void
72
gr_log_shmrm(const uid_t uid, const uid_t cuid)
73
{
74
#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
75
	if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
76
	     grsec_enable_audit_ipc) ||
77
	    (grsec_enable_audit_ipc && !grsec_enable_group))
78
		security_audit(GR_SHMR_AUDIT_MSG, uid, cuid, DEFAULTSECARGS);
79
#endif
80
	return;
81
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_link.c (+41 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/fs.h>
4
#include <linux/file.h>
5
#include <linux/grinternal.h>
6
7
int
8
gr_handle_follow_link(const struct inode *parent,
9
		      const struct inode *inode,
10
		      const struct dentry *dentry, const struct vfsmount *mnt)
11
{
12
#ifdef CONFIG_GRKERNSEC_LINK
13
	if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
14
	    (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
15
	    (parent->i_mode & S_IWOTH) && (current->fsuid != inode->i_uid)) {
16
		security_alert(GR_SYMLINK_MSG, gr_to_filename(dentry, mnt),
17
			       inode->i_uid, inode->i_gid, DEFAULTSECARGS);
18
		return -EACCES;
19
	}
20
#endif
21
	return 0;
22
}
23
24
int
25
gr_handle_hardlink(const struct dentry *dentry,
26
		   const struct vfsmount *mnt,
27
		   struct inode *inode, const int mode, const char *to)
28
{
29
#ifdef CONFIG_GRKERNSEC_LINK
30
	if (grsec_enable_link && current->fsuid != inode->i_uid &&
31
	    (!S_ISREG(mode) || (mode & S_ISUID) ||
32
	     ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
33
	     (permission(inode, MAY_READ | MAY_WRITE))) &&
34
	    !capable(CAP_FOWNER) && current->uid) {
35
		security_alert(GR_HARDLINK_MSG, gr_to_filename(dentry, mnt),
36
			       inode->i_uid, inode->i_gid, to, DEFAULTSECARGS);
37
		return -EPERM;
38
	}
39
#endif
40
	return 0;
41
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_mem.c (+54 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/mm.h>
4
#include <linux/grinternal.h>
5
6
void
7
gr_handle_ioperm(void)
8
{
9
	security_alert(GR_IOPERM_MSG, DEFAULTSECARGS);
10
	return;
11
}
12
13
void
14
gr_handle_iopl(void)
15
{
16
	security_alert(GR_IOPL_MSG, DEFAULTSECARGS);
17
	return;
18
}
19
20
void
21
gr_handle_mem_write(void)
22
{
23
	security_alert(GR_MEM_WRITE_MSG, DEFAULTSECARGS);
24
	return;
25
}
26
27
void
28
gr_handle_kmem_write(void)
29
{
30
	security_alert(GR_KMEM_MSG, DEFAULTSECARGS);
31
	return;
32
}
33
34
void
35
gr_handle_open_port(void)
36
{
37
	security_alert(GR_PORT_OPEN_MSG, DEFAULTSECARGS);
38
	return;
39
}
40
41
int
42
gr_handle_mem_mmap(const unsigned long offset, struct vm_area_struct *vma)
43
{
44
	if (offset < __pa(high_memory) &&
45
	    (pgprot_val(vma->vm_page_prot) & PROT_WRITE) &&
46
	    !(offset == 0xf0000 && ((vma->vm_end - vma->vm_start) <= 0x10000)) &&
47
	    !(offset == 0xa0000 && ((vma->vm_end - vma->vm_start) <= 0x20000))) {
48
		security_alert(GR_MEM_MMAP_MSG, DEFAULTSECARGS);
49
		return -EPERM;
50
	} else if (offset < __pa(high_memory))
51
		vma->vm_flags &= ~VM_MAYWRITE;
52
53
	return 0;
54
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_mount.c (+34 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/grsecurity.h>
4
#include <linux/grinternal.h>
5
6
void
7
gr_log_remount(const char *devname, const int retval)
8
{
9
#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
10
	if (grsec_enable_mount && (retval >= 0))
11
		security_audit(GR_REMOUNT_AUDIT_MSG, devname, DEFAULTSECARGS);
12
#endif
13
	return;
14
}
15
16
void
17
gr_log_unmount(const char *devname, const int retval)
18
{
19
#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
20
	if (grsec_enable_mount && (retval >= 0))
21
		security_audit(GR_UNMOUNT_AUDIT_MSG, devname, DEFAULTSECARGS);
22
#endif
23
	return;
24
}
25
26
void
27
gr_log_mount(const char *from, const char *to, const int retval)
28
{
29
#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
30
	if (grsec_enable_mount && (retval >= 0))
31
		security_audit(GR_MOUNT_AUDIT_MSG, from, to, DEFAULTSECARGS);
32
#endif
33
	return;
34
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_rand.c (+36 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/smp_lock.h>
4
#include <linux/grsecurity.h>
5
#include <linux/grinternal.h>
6
7
extern int last_pid;
8
9
int
10
gr_random_pid(spinlock_t * pid_lock)
11
{
12
#ifdef CONFIG_GRKERNSEC_RANDPID
13
	struct task_struct *p;
14
	int pid;
15
16
	if (grsec_enable_randpid && current->fs->root) {
17
		read_lock(&tasklist_lock);
18
		spin_lock(pid_lock);
19
20
	      repeater:
21
22
		pid = 1 + (get_random_long() % PID_MAX);
23
24
		for_each_task(p) {
25
			if (p->pid == pid || p->pgrp == pid ||
26
			    p->tgid == pid || p->session == pid)
27
				goto repeater;
28
		}
29
		last_pid = pid;
30
		spin_unlock(pid_lock);
31
		read_unlock(&tasklist_lock);
32
		return pid;
33
	}
34
#endif
35
	return 0;
36
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_sig.c (+47 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/grinternal.h>
4
5
void
6
gr_log_signal(const int sig, const struct task_struct *t)
7
{
8
#ifdef CONFIG_GRKERNSEC_SIGNAL
9
	if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
10
				    (sig == SIGABRT) || (sig == SIGBUS))) {
11
		if (t->pid == current->pid) {
12
			security_alert_good(GR_UNISIGLOG_MSG, sig,
13
					    DEFAULTSECARGS);
14
		} else {
15
			security_alert_good(GR_DUALSIGLOG_MSG, sig,
16
					    gr_task_fullpath(t), t->comm,
17
					    t->pid, t->uid, t->euid, t->gid,
18
					    t->egid, gr_parent_task_fullpath(t),
19
					    t->p_pptr->comm,
20
					    t->p_pptr->pid, t->p_pptr->uid,
21
					    t->p_pptr->euid, t->p_pptr->gid,
22
					    t->p_pptr->egid, DEFAULTSECARGS);
23
		}
24
	}
25
#endif
26
	return;
27
}
28
29
int
30
gr_handle_signal(const struct task_struct *p, const int sig)
31
{
32
#ifdef CONFIG_GRKERNSEC
33
	if (current->pid > 1 && gr_check_protected_task(p)) {
34
		security_alert(GR_SIG_ACL_MSG, sig, gr_task_fullpath(p),
35
			       p->comm, p->pid, p->uid,
36
			       p->euid, p->gid, p->egid,
37
			       gr_parent_task_fullpath(p), p->p_pptr->comm,
38
			       p->p_pptr->pid, p->p_pptr->uid,
39
			       p->p_pptr->euid, p->p_pptr->gid,
40
			       p->p_pptr->egid, DEFAULTSECARGS);
41
		return -EPERM;
42
	} else if (gr_pid_is_chrooted(p)) {
43
		return -EPERM;
44
	}
45
#endif
46
	return 0;
47
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_sock.c (+123 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/file.h>
4
#include <linux/net.h>
5
#include <net/sock.h>
6
#include <linux/grsecurity.h>
7
#include <linux/grinternal.h>
8
#include <linux/gracl.h>
9
10
void
11
gr_attach_curr_ip(const struct sock *sk)
12
{
13
#ifdef CONFIG_GRKERNSEC
14
	struct task_struct *p;
15
	unsigned int i;
16
	struct inode *inode;
17
	struct file *filp;
18
	struct socket *connect_sock;
19
20
	if (unlikely(sk->protocol != IPPROTO_TCP))
21
		return;
22
23
	read_lock(&tasklist_lock);
24
	for_each_task(p) {
25
		if (!p->used_connect)
26
			continue;
27
		task_lock(p);
28
		if (unlikely(!p->files)) {
29
			task_unlock(p);
30
			continue;
31
		}
32
		read_lock(&p->files->file_lock);
33
		for (i = 0; i < p->files->max_fds; i++) {
34
			filp = fcheck_files(p->files, i);
35
			if (likely(!filp))
36
				continue;
37
			inode = filp->f_dentry->d_inode;
38
			if (likely(!inode || !inode->i_sock))
39
				continue;
40
			connect_sock = &inode->u.socket_i;
41
			if (unlikely(!connect_sock ||
42
				     connect_sock->sk->protocol != IPPROTO_TCP))
43
				continue;
44
			if (unlikely(sk->rcv_saddr == connect_sock->sk->daddr &&
45
				     sk->daddr == connect_sock->sk->rcv_saddr &&
46
				     ntohs(sk->sport) ==
47
				     ntohs(connect_sock->sk->dport)
48
				     && ntohs(sk->dport) ==
49
				     ntohs(connect_sock->sk->sport))) {
50
				current->curr_ip = p->curr_ip;
51
				current->used_accept = 1;
52
				read_unlock(&p->files->file_lock);
53
				task_unlock(p);
54
				read_unlock(&tasklist_lock);
55
				return;
56
			}
57
		}
58
		read_unlock(&p->files->file_lock);
59
		task_unlock(p);
60
	}
61
	read_unlock(&tasklist_lock);
62
63
	current->curr_ip = sk->daddr;
64
	current->used_accept = 1;
65
#endif
66
	return;
67
}
68
69
int
70
gr_handle_sock_all(const int family, const int type, const int protocol)
71
{
72
#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
73
	if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
74
	    (family != AF_UNIX) && (family != AF_LOCAL)) {
75
		security_alert(GR_SOCK_MSG, family, type, protocol,
76
			       DEFAULTSECARGS);
77
		return -EACCES;
78
	}
79
#endif
80
	return 0;
81
}
82
83
int
84
gr_handle_sock_server(const struct sockaddr *sck)
85
{
86
#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
87
	if (grsec_enable_socket_server &&
88
	    in_group_p(grsec_socket_server_gid) &&
89
	    sck && (sck->sa_family != AF_UNIX) &&
90
	    (sck->sa_family != AF_LOCAL)) {
91
		security_alert(GR_BIND_MSG, DEFAULTSECARGS);
92
		return -EACCES;
93
	}
94
#endif
95
	return 0;
96
}
97
98
int
99
gr_handle_sock_client(const struct sockaddr *sck)
100
{
101
#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
102
	if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
103
	    sck && (sck->sa_family != AF_UNIX) &&
104
	    (sck->sa_family != AF_LOCAL)) {
105
		security_alert(GR_CONNECT_MSG, DEFAULTSECARGS);
106
		return -EACCES;
107
	}
108
#endif
109
	return 0;
110
}
111
112
__u32
113
gr_cap_rtnetlink(void)
114
{
115
#ifdef CONFIG_GRKERNSEC
116
	if (!gr_acl_is_enabled())
117
		return current->cap_effective;
118
	else
119
		return (current->cap_effective & ~(current->acl->cap_lower));
120
#else
121
	return current->cap_effective;
122
#endif
123
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_sysctl.c (+16 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/sysctl.h>
4
#include <linux/grinternal.h>
5
6
int
7
gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
8
{
9
#ifdef CONFIG_GRKERNSEC_SYSCTL
10
	if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & 002)) {
11
		security_alert(GR_SYSCTL_MSG, name, DEFAULTSECARGS);
12
		return -EACCES;
13
	}
14
#endif
15
	return 0;
16
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_time.c (+13 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/grinternal.h>
4
5
void
6
gr_log_timechange(void)
7
{
8
#ifdef CONFIG_GRKERNSEC_TIME
9
	if (grsec_enable_time)
10
		security_alert_good(GR_TIME_MSG, DEFAULTSECARGS);
11
#endif
12
	return;
13
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsec_tpe.c (+35 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/file.h>
4
#include <linux/fs.h>
5
#include <linux/grinternal.h>
6
7
extern int gr_acl_tpe_check(void);
8
9
int
10
gr_tpe_allow(const struct file *file)
11
{
12
#ifdef CONFIG_GRKERNSEC
13
	struct inode *inode = file->f_dentry->d_parent->d_inode;
14
15
	if (current->uid && ((grsec_enable_tpe && in_group_p(grsec_tpe_gid)) || gr_acl_tpe_check()) &&
16
	    (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
17
						(inode->i_mode & S_IWOTH))))) {
18
		security_alert(GR_EXEC_TPE_MSG,
19
			       gr_to_filename(file->f_dentry, file->f_vfsmnt),
20
			       DEFAULTSECARGS);
21
		return 0;
22
	}
23
#ifdef CONFIG_GRKERNSEC_TPE_ALL
24
	if (current->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
25
	    ((inode->i_uid && (inode->i_uid != current->uid)) ||
26
	     (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
27
		security_alert(GR_EXEC_TPE_MSG,
28
			       gr_to_filename(file->f_dentry, file->f_vfsmnt),
29
			       DEFAULTSECARGS);
30
		return 0;
31
	}
32
#endif
33
#endif
34
	return 1;
35
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/grsum.c (+59 lines)
Line 0 Link Here
1
#include <linux/kernel.h>
2
#include <linux/sched.h>
3
#include <linux/mm.h>
4
#include <asm/scatterlist.h>
5
#include <linux/crypto.h>
6
#include <linux/gracl.h>
7
8
9
#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
10
#error "crypto and sha256 must be built into the kernel"
11
#endif
12
13
int
14
chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
15
{
16
	char *p;
17
	struct crypto_tfm *tfm;
18
	unsigned char temp_sum[GR_SHA_LEN];
19
	struct scatterlist sg[2];
20
	volatile int retval = 0;
21
	volatile int dummy = 0;
22
	unsigned int i;
23
24
	tfm = crypto_alloc_tfm("sha256", 0);
25
	if (tfm == NULL) {
26
		/* should never happen, since sha256 should be built in */
27
		return 1;
28
	}
29
30
	crypto_digest_init(tfm);
31
32
	p = salt;
33
	sg[0].page = virt_to_page(p);
34
	sg[0].offset = ((long) p & ~PAGE_MASK);
35
	sg[0].length = GR_SALT_LEN;
36
	
37
	crypto_digest_update(tfm, sg, 1);
38
39
	p = entry->pw;
40
	sg[0].page = virt_to_page(p);
41
	sg[0].offset = ((long) p & ~PAGE_MASK);
42
	sg[0].length = strlen(entry->pw);
43
44
	crypto_digest_update(tfm, sg, 1);
45
46
	crypto_digest_final(tfm, temp_sum);
47
48
	memset(entry->pw, 0, GR_PW_LEN);
49
50
	for (i = 0; i < GR_SHA_LEN; i++)
51
		if (sum[i] != temp_sum[i])
52
			retval = 1;
53
		else
54
			dummy = 1;	// waste a cycle
55
56
	crypto_free_tfm(tfm);
57
58
	return retval;
59
}
(-)linux-2.4.22-ppc-dev.orig/grsecurity/obsd_rand.c (+195 lines)
Line 0 Link Here
1
2
/*
3
 * Copyright (c) 1996, 1997, 2000-2002 Michael Shalayeff.
4
 * 
5
 * Version 1.89, last modified 19-Sep-99
6
 *    
7
 * Copyright Theodore Ts'o, 1994, 1995, 1996, 1997, 1998, 1999.
8
 * All rights reserved.
9
 *
10
 * Copyright 1998 Niels Provos <provos@citi.umich.edu>
11
 * All rights reserved.
12
 * Theo de Raadt <deraadt@openbsd.org> came up with the idea of using
13
 * such a mathematical system to generate more random (yet non-repeating)
14
 * ids to solve the resolver/named problem.  But Niels designed the
15
 * actual system based on the constraints.
16
 *
17
 * Redistribution and use in source and binary forms, with or without
18
 * modification, are permitted provided that the following conditions
19
 * are met:
20
 * 1. Redistributions of source code must retain the above copyright
21
 *    notice, this list of conditions and the following disclaimer,
22
 * 2. Redistributions in binary form must reproduce the above copyright
23
 *    notice, this list of conditions and the following disclaimer in the
24
 *    documentation and/or other materials provided with the distribution.
25
 * 3. All advertising materials mentioning features or use of this software
26
 *    must display the following acknowledgement:
27
 *    This product includes software developed by Niels Provos.
28
 * 4. The name of the author may not be used to endorse or promote products
29
 *    derived from this software without specific prior written permission.
30
 *
31
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
32
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
33
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
35
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
40
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41
 */
42
43
#include <linux/kernel.h>
44
#include <linux/sched.h>
45
#include <linux/timer.h>
46
#include <linux/smp_lock.h>
47
#include <linux/random.h>
48
#include <linux/grsecurity.h>
49
50
#define RU_OUT 180
51
#define RU_MAX 30000
52
#define RU_GEN 2
53
#define RU_N 32749
54
#define RU_AGEN 7
55
#define RU_M 31104
56
#define PFAC_N 3
57
const static __u16 pfacts[PFAC_N] = { 2, 3, 2729 };
58
59
static __u16 ru_x;
60
static __u16 ru_seed, ru_seed2;
61
static __u16 ru_a, ru_b;
62
static __u16 ru_g;
63
static __u16 ru_counter = 0;
64
static __u16 ru_msb = 0;
65
static unsigned long ru_reseed = 0;
66
static __u32 tmp;
67
68
#define TCP_RNDISS_ROUNDS	15
69
#define TCP_RNDISS_OUT		7200
70
#define TCP_RNDISS_MAX		30000
71
72
static __u8 tcp_rndiss_sbox[NR_CPUS][128];
73
static __u16 tcp_rndiss_msb[NR_CPUS];
74
static __u16 tcp_rndiss_cnt[NR_CPUS];
75
static unsigned long tcp_rndiss_reseed[NR_CPUS];
76
77
static __u16 pmod(__u16, __u16, __u16);
78
static void ip_initid(void);
79
__u16 ip_randomid(void);
80
81
static __u16
82
pmod(__u16 gen, __u16 exp, __u16 mod)
83
{
84
	__u16 s, t, u;
85
86
	s = 1;
87
	t = gen;
88
	u = exp;
89
90
	while (u) {
91
		if (u & 1)
92
			s = (s * t) % mod;
93
		u >>= 1;
94
		t = (t * t) % mod;
95
	}
96
	return (s);
97
}
98
99
static void
100
ip_initid(void)
101
{
102
	__u16 j, i;
103
	int noprime = 1;
104
105
	ru_x = ((tmp = get_random_long()) & 0xFFFF) % RU_M;
106
107
	ru_seed = (tmp >> 16) & 0x7FFF;
108
	ru_seed2 = get_random_long() & 0x7FFF;
109
110
	ru_b = ((tmp = get_random_long()) & 0xfffe) | 1;
111
	ru_a = pmod(RU_AGEN, (tmp >> 16) & 0xfffe, RU_M);
112
	while (ru_b % 3 == 0)
113
		ru_b += 2;
114
115
	j = (tmp = get_random_long()) % RU_N;
116
	tmp = tmp >> 16;
117
118
	while (noprime) {
119
		for (i = 0; i < PFAC_N; i++)
120
			if (j % pfacts[i] == 0)
121
				break;
122
123
		if (i >= PFAC_N)
124
			noprime = 0;
125
		else
126
			j = (j + 1) % RU_N;
127
	}
128
129
	ru_g = pmod(RU_GEN, j, RU_N);
130
	ru_counter = 0;
131
132
	ru_reseed = xtime.tv_sec + RU_OUT;
133
	ru_msb = ru_msb == 0x8000 ? 0 : 0x8000;
134
}
135
136
__u16
137
ip_randomid(void)
138
{
139
	int i, n;
140
141
	if (ru_counter >= RU_MAX || time_after(xtime.tv_sec, ru_reseed))
142
		ip_initid();
143
144
	if (!tmp)
145
		tmp = get_random_long();
146
147
	n = tmp & 0x3;
148
	tmp = tmp >> 2;
149
	if (ru_counter + n >= RU_MAX)
150
		ip_initid();
151
	for (i = 0; i <= n; i++)
152
		ru_x = (ru_a * ru_x + ru_b) % RU_M;
153
	ru_counter += i;
154
155
	return ((ru_seed ^ pmod(ru_g, ru_seed2 ^ ru_x, RU_N)) | ru_msb);
156
}
157
158
__u16
159
tcp_rndiss_encrypt(__u16 val)
160
{
161
	__u16 sum = 0, i;
162
	int cpu = smp_processor_id();
163
164
	for (i = 0; i < TCP_RNDISS_ROUNDS; i++) {
165
		sum += 0x79b9;
166
		val ^= ((__u16) tcp_rndiss_sbox[cpu][(val ^ sum) ^ 0x7f]) << 7;
167
		val = ((val & 0xff) << 7) | (val >> 8);
168
	}
169
170
	return val;
171
}
172
173
static void
174
tcp_rndiss_init(void)
175
{
176
	int cpu = smp_processor_id();
177
178
	get_random_bytes(tcp_rndiss_sbox[cpu], sizeof (tcp_rndiss_sbox));
179
	tcp_rndiss_reseed[cpu] = xtime.tv_sec + TCP_RNDISS_OUT;
180
	tcp_rndiss_msb[cpu] = tcp_rndiss_msb[cpu] == 0x8000 ? 0 : 0x8000;
181
	tcp_rndiss_cnt[cpu] = 0;
182
}
183
184
__u32
185
ip_randomisn(void)
186
{
187
	int cpu = smp_processor_id();
188
189
	if (tcp_rndiss_cnt[cpu] >= TCP_RNDISS_MAX ||
190
	    time_after(xtime.tv_sec, tcp_rndiss_reseed[cpu]))
191
		tcp_rndiss_init();
192
193
	return (((tcp_rndiss_encrypt(tcp_rndiss_cnt[cpu]++) |
194
		  tcp_rndiss_msb[cpu]) << 16) | (get_random_long() & 0x7fff));
195
}
(-)linux-2.4.22-ppc-dev.orig/include/asm-alpha/a.out.h (-1 / +1 lines)
Lines 98-104 Link Here
98
	set_personality (((BFPM->sh_bang || EX.ah.entry < 0x100000000 \
98
	set_personality (((BFPM->sh_bang || EX.ah.entry < 0x100000000 \
99
			   ? ADDR_LIMIT_32BIT : 0) | PER_OSF4))
99
			   ? ADDR_LIMIT_32BIT : 0) | PER_OSF4))
100
100
101
#define STACK_TOP \
101
#define __STACK_TOP \
102
  (current->personality & ADDR_LIMIT_32BIT ? 0x80000000 : 0x00120000000UL)
102
  (current->personality & ADDR_LIMIT_32BIT ? 0x80000000 : 0x00120000000UL)
103
103
104
#endif
104
#endif
(-)linux-2.4.22-ppc-dev.orig/include/asm-alpha/elf.h (+12 lines)
Lines 41-46 Link Here
41
41
42
#define ELF_ET_DYN_BASE		(TASK_UNMAPPED_BASE + 0x1000000)
42
#define ELF_ET_DYN_BASE		(TASK_UNMAPPED_BASE + 0x1000000)
43
43
44
#ifdef CONFIG_GRKERNSEC_PAX_ASLR
45
#define PAX_ELF_ET_DYN_BASE(tsk)        ((tsk)->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
46
47
#define PAX_DELTA_MMAP_LSB(tsk)         PAGE_SHIFT
48
#define PAX_DELTA_MMAP_LEN(tsk)         ((tsk)->personality & ADDR_LIMIT_32BIT ? 14 : 28)
49
#define PAX_DELTA_EXEC_LSB(tsk)         PAGE_SHIFT
50
#define PAX_DELTA_EXEC_LEN(tsk)         ((tsk)->personality & ADDR_LIMIT_32BIT ? 14 : 28)
51
#define PAX_DELTA_STACK_LSB(tsk)        PAGE_SHIFT
52
#define PAX_DELTA_STACK_LEN(tsk)        ((tsk)->personality & ADDR_LIMIT_32BIT ? 14 : 19)
53
#endif
54
55
44
/* $0 is set by ld.so to a pointer to a function which might be 
56
/* $0 is set by ld.so to a pointer to a function which might be 
45
   registered using atexit.  This provides a mean for the dynamic
57
   registered using atexit.  This provides a mean for the dynamic
46
   linker to call DT_FINI functions for shared libraries that have
58
   linker to call DT_FINI functions for shared libraries that have
(-)linux-2.4.22-ppc-dev.orig/include/asm-alpha/mman.h (+4 lines)
Lines 24-29 Link Here
24
#define MAP_LOCKED	0x8000		/* lock the mapping */
24
#define MAP_LOCKED	0x8000		/* lock the mapping */
25
#define MAP_NORESERVE	0x10000		/* don't check for reservations */
25
#define MAP_NORESERVE	0x10000		/* don't check for reservations */
26
26
27
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
28
#define MAP_MIRROR	0x20000
29
#endif
30
27
#define MS_ASYNC	1		/* sync memory asynchronously */
31
#define MS_ASYNC	1		/* sync memory asynchronously */
28
#define MS_SYNC		2		/* synchronous memory sync */
32
#define MS_SYNC		2		/* synchronous memory sync */
29
#define MS_INVALIDATE	4		/* invalidate the caches */
33
#define MS_INVALIDATE	4		/* invalidate the caches */
(-)linux-2.4.22-ppc-dev.orig/include/asm-alpha/pgtable.h (+11 lines)
Lines 96-101 Link Here
96
#define PAGE_SHARED	__pgprot(_PAGE_VALID | __ACCESS_BITS)
96
#define PAGE_SHARED	__pgprot(_PAGE_VALID | __ACCESS_BITS)
97
#define PAGE_COPY	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
97
#define PAGE_COPY	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
98
#define PAGE_READONLY	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
98
#define PAGE_READONLY	__pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
99
100
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
101
#define PAGE_SHARED_NOEXEC    __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
102
#define PAGE_COPY_NOEXEC      __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
103
#define PAGE_READONLY_NOEXEC  __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
104
#else
105
#define PAGE_SHARED_NOEXEC    PAGE_SHARED
106
#define PAGE_COPY_NOEXEC      PAGE_COPY
107
#define PAGE_READONLY_NOEXEC  PAGE_READONLY
108
#endif
109
99
#define PAGE_KERNEL	__pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
110
#define PAGE_KERNEL	__pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
100
111
101
#define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
112
#define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
(-)linux-2.4.22-ppc-dev.orig/include/asm-i386/a.out.h (-1 / +5 lines)
Lines 19-25 Link Here
19
19
20
#ifdef __KERNEL__
20
#ifdef __KERNEL__
21
21
22
#define STACK_TOP	TASK_SIZE
22
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
23
#define __STACK_TOP ((current->flags & PF_PAX_SEGMEXEC)?TASK_SIZE/2:TASK_SIZE)
24
#else
25
#define __STACK_TOP	TASK_SIZE
26
#endif
23
27
24
#endif
28
#endif
25
29
(-)linux-2.4.22-ppc-dev.orig/include/asm-i386/desc.h (-1 / +19 lines)
Lines 46-52 Link Here
46
};
46
};
47
47
48
extern struct desc_struct gdt_table[];
48
extern struct desc_struct gdt_table[];
49
extern struct desc_struct *idt, *gdt;
49
extern struct desc_struct gdt_table2[];
50
extern struct desc_struct *idt, *gdt, *gdt2;
50
51
51
struct Xgt_desc_struct {
52
struct Xgt_desc_struct {
52
	unsigned short size;
53
	unsigned short size;
Lines 55-60 Link Here
55
56
56
#define idt_descr (*(struct Xgt_desc_struct *)((char *)&idt - 2))
57
#define idt_descr (*(struct Xgt_desc_struct *)((char *)&idt - 2))
57
#define gdt_descr (*(struct Xgt_desc_struct *)((char *)&gdt - 2))
58
#define gdt_descr (*(struct Xgt_desc_struct *)((char *)&gdt - 2))
59
#define gdt_descr2 (*(struct Xgt_desc_struct *)((char *)&gdt2 - 2))
58
60
59
#define load_TR(n) __asm__ __volatile__("ltr %%ax"::"a" (__TSS(n)<<3))
61
#define load_TR(n) __asm__ __volatile__("ltr %%ax"::"a" (__TSS(n)<<3))
60
62
Lines 67-72 Link Here
67
extern struct desc_struct default_ldt[];
69
extern struct desc_struct default_ldt[];
68
extern void set_intr_gate(unsigned int irq, void * addr);
70
extern void set_intr_gate(unsigned int irq, void * addr);
69
extern void set_ldt_desc(unsigned int n, void *addr, unsigned int size);
71
extern void set_ldt_desc(unsigned int n, void *addr, unsigned int size);
72
extern void __set_ldt_desc(unsigned int n, void *addr, unsigned int size);
70
extern void set_tss_desc(unsigned int n, void *addr);
73
extern void set_tss_desc(unsigned int n, void *addr);
71
74
72
static inline void clear_LDT(void)
75
static inline void clear_LDT(void)
Lines 94-99 Link Here
94
	__load_LDT(cpu);
97
	__load_LDT(cpu);
95
}
98
}
96
99
100
static inline void _load_LDT (struct mm_struct *mm)
101
{
102
	int cpu = smp_processor_id();
103
	void *segments = mm->context.segments;
104
	int count = LDT_ENTRIES;
105
106
	if (!segments) {
107
		segments = &default_ldt[0];
108
		count = 5;
109
	}
110
		
111
	__set_ldt_desc(cpu, segments, count);
112
	__load_LDT(cpu);
113
}
114
97
#endif /* !__ASSEMBLY__ */
115
#endif /* !__ASSEMBLY__ */
98
116
99
#endif
117
#endif
(-)linux-2.4.22-ppc-dev.orig/include/asm-i386/elf.h (+15 lines)
Lines 55-61 Link Here
55
   the loader.  We need to make sure that it is out of the way of the program
55
   the loader.  We need to make sure that it is out of the way of the program
56
   that it will "exec", and that there is sufficient room for the brk.  */
56
   that it will "exec", and that there is sufficient room for the brk.  */
57
57
58
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
59
#define ELF_ET_DYN_BASE		((current->flags & PF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE/3*2:TASK_SIZE/3*2)
60
#else
58
#define ELF_ET_DYN_BASE         (TASK_SIZE / 3 * 2)
61
#define ELF_ET_DYN_BASE         (TASK_SIZE / 3 * 2)
62
#endif
63
64
#ifdef CONFIG_GRKERNSEC_PAX_ASLR
65
#define PAX_ELF_ET_DYN_BASE(tsk)	0x08048000UL
66
67
#define PAX_DELTA_MMAP_LSB(tsk)		PAGE_SHIFT
68
#define PAX_DELTA_MMAP_LEN(tsk)		16
69
#define PAX_DELTA_EXEC_LSB(tsk)		PAGE_SHIFT
70
#define PAX_DELTA_EXEC_LEN(tsk)		16
71
#define PAX_DELTA_STACK_LSB(tsk)	PAGE_SHIFT  
72
#define PAX_DELTA_STACK_LEN(tsk)	((tsk)->flags & PF_PAX_SEGMEXEC ? 15 : 16)
73
#endif
59
74
60
/* Wow, the "main" arch needs arch dependent functions too.. :) */
75
/* Wow, the "main" arch needs arch dependent functions too.. :) */
61
76
(-)linux-2.4.22-ppc-dev.orig/include/asm-i386/hw_irq.h (+4 lines)
Lines 128-133 Link Here
128
asmlinkage void x(void); \
128
asmlinkage void x(void); \
129
asmlinkage void call_##x(void); \
129
asmlinkage void call_##x(void); \
130
__asm__( \
130
__asm__( \
131
"\n .text" \
131
"\n"__ALIGN_STR"\n" \
132
"\n"__ALIGN_STR"\n" \
132
SYMBOL_NAME_STR(x) ":\n\t" \
133
SYMBOL_NAME_STR(x) ":\n\t" \
133
	"pushl $"#v"-256\n\t" \
134
	"pushl $"#v"-256\n\t" \
Lines 141-146 Link Here
141
asmlinkage void x(struct pt_regs * regs); \
142
asmlinkage void x(struct pt_regs * regs); \
142
asmlinkage void call_##x(void); \
143
asmlinkage void call_##x(void); \
143
__asm__( \
144
__asm__( \
145
"\n .text" \
144
"\n"__ALIGN_STR"\n" \
146
"\n"__ALIGN_STR"\n" \
145
SYMBOL_NAME_STR(x) ":\n\t" \
147
SYMBOL_NAME_STR(x) ":\n\t" \
146
	"pushl $"#v"-256\n\t" \
148
	"pushl $"#v"-256\n\t" \
Lines 155-160 Link Here
155
#define BUILD_COMMON_IRQ() \
157
#define BUILD_COMMON_IRQ() \
156
asmlinkage void call_do_IRQ(void); \
158
asmlinkage void call_do_IRQ(void); \
157
__asm__( \
159
__asm__( \
160
	"\n .text" \
158
	"\n" __ALIGN_STR"\n" \
161
	"\n" __ALIGN_STR"\n" \
159
	"common_interrupt:\n\t" \
162
	"common_interrupt:\n\t" \
160
	SAVE_ALL \
163
	SAVE_ALL \
Lines 175-180 Link Here
175
#define BUILD_IRQ(nr) \
178
#define BUILD_IRQ(nr) \
176
asmlinkage void IRQ_NAME(nr); \
179
asmlinkage void IRQ_NAME(nr); \
177
__asm__( \
180
__asm__( \
181
"\n .text" \
178
"\n"__ALIGN_STR"\n" \
182
"\n"__ALIGN_STR"\n" \
179
SYMBOL_NAME_STR(IRQ) #nr "_interrupt:\n\t" \
183
SYMBOL_NAME_STR(IRQ) #nr "_interrupt:\n\t" \
180
	"pushl $"#nr"-256\n\t" \
184
	"pushl $"#nr"-256\n\t" \
(-)linux-2.4.22-ppc-dev.orig/include/asm-i386/mman.h (+4 lines)
Lines 18-23 Link Here
18
#define MAP_LOCKED	0x2000		/* pages are locked */
18
#define MAP_LOCKED	0x2000		/* pages are locked */
19
#define MAP_NORESERVE	0x4000		/* don't check for reservations */
19
#define MAP_NORESERVE	0x4000		/* don't check for reservations */
20
20
21
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
22
#define MAP_MIRROR	0x8000
23
#endif
24
21
#define MS_ASYNC	1		/* sync memory asynchronously */
25
#define MS_ASYNC	1		/* sync memory asynchronously */
22
#define MS_INVALIDATE	2		/* invalidate the caches */
26
#define MS_INVALIDATE	2		/* invalidate the caches */
23
#define MS_SYNC		4		/* synchronous memory sync */
27
#define MS_SYNC		4		/* synchronous memory sync */
(-)linux-2.4.22-ppc-dev.orig/include/asm-i386/page.h (-1 / +1 lines)
Lines 78-84 Link Here
78
 * and CONFIG_HIGHMEM64G options in the kernel configuration.
78
 * and CONFIG_HIGHMEM64G options in the kernel configuration.
79
 */
79
 */
80
80
81
#define __PAGE_OFFSET		(0xC0000000)
81
#include <asm/page_offset.h>
82
82
83
/*
83
/*
84
 * This much address space is reserved for vmalloc() and iomap()
84
 * This much address space is reserved for vmalloc() and iomap()
(-)linux-2.4.22-ppc-dev.orig/include/asm-i386/page_offset.h (+2 lines)
Line 0 Link Here
1
#define __KERNEL_TEXT_OFFSET	(0xC0400000)
2
#define __PAGE_OFFSET		(0xC0000000)
(-)linux-2.4.22-ppc-dev.orig/include/asm-i386/pgtable.h (-7 / +17 lines)
Lines 205-210 Link Here
205
#define PAGE_COPY	__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
205
#define PAGE_COPY	__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
206
#define PAGE_READONLY	__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
206
#define PAGE_READONLY	__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
207
207
208
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
209
#define PAGE_SHARED_NOEXEC  __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED)
210
#define PAGE_COPY_NOEXEC  __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
211
#define PAGE_READONLY_NOEXEC  __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED) 
212
#else
213
#define PAGE_SHARED_NOEXEC    PAGE_SHARED
214
#define PAGE_COPY_NOEXEC      PAGE_COPY
215
#define PAGE_READONLY_NOEXEC  PAGE_READONLY
216
#endif
217
208
#define __PAGE_KERNEL \
218
#define __PAGE_KERNEL \
209
	(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
219
	(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
210
#define __PAGE_KERNEL_NOCACHE \
220
#define __PAGE_KERNEL_NOCACHE \
Lines 237-254 Link Here
237
 * This is the closest we can get..
247
 * This is the closest we can get..
238
 */
248
 */
239
#define __P000	PAGE_NONE
249
#define __P000	PAGE_NONE
240
#define __P001	PAGE_READONLY
250
#define __P001  PAGE_READONLY_NOEXEC
241
#define __P010	PAGE_COPY
251
#define __P010  PAGE_COPY_NOEXEC
242
#define __P011	PAGE_COPY
252
#define __P011  PAGE_COPY_NOEXEC
243
#define __P100	PAGE_READONLY
253
#define __P100	PAGE_READONLY
244
#define __P101	PAGE_READONLY
254
#define __P101	PAGE_READONLY
245
#define __P110	PAGE_COPY
255
#define __P110	PAGE_COPY
246
#define __P111	PAGE_COPY
256
#define __P111	PAGE_COPY
247
257
248
#define __S000	PAGE_NONE
258
#define __S000	PAGE_NONE
249
#define __S001	PAGE_READONLY
259
#define __S001  PAGE_READONLY_NOEXEC
250
#define __S010	PAGE_SHARED
260
#define __S010  PAGE_SHARED_NOEXEC
251
#define __S011	PAGE_SHARED
261
#define __S011  PAGE_SHARED_NOEXEC
252
#define __S100	PAGE_READONLY
262
#define __S100	PAGE_READONLY
253
#define __S101	PAGE_READONLY
263
#define __S101	PAGE_READONLY
254
#define __S110	PAGE_SHARED
264
#define __S110	PAGE_SHARED
Lines 324-330 Link Here
324
((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
334
((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
325
335
326
/* to find an entry in a page-table-directory. */
336
/* to find an entry in a page-table-directory. */
327
#define pgd_index(address) ((address >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
337
#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
328
338
329
#define __pgd_offset(address) pgd_index(address)
339
#define __pgd_offset(address) pgd_index(address)
330
340
(-)linux-2.4.22-ppc-dev.orig/include/asm-i386/processor.h (+9 lines)
Lines 261-270 Link Here
261
 */
261
 */
262
#define TASK_SIZE	(PAGE_OFFSET)
262
#define TASK_SIZE	(PAGE_OFFSET)
263
263
264
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
265
#define SEGMEXEC_TASK_SIZE	((PAGE_OFFSET) / 2)
266
#endif
267
264
/* This decides where the kernel will search for a free chunk of vm
268
/* This decides where the kernel will search for a free chunk of vm
265
 * space during mmap's.
269
 * space during mmap's.
266
 */
270
 */
271
272
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
273
#define TASK_UNMAPPED_BASE	((current->flags & PF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE/3:TASK_SIZE/3)
274
#else
267
#define TASK_UNMAPPED_BASE	(TASK_SIZE / 3)
275
#define TASK_UNMAPPED_BASE	(TASK_SIZE / 3)
276
#endif
268
277
269
/*
278
/*
270
 * Size of io_bitmap in longwords: 32 is ports 0-0x3ff.
279
 * Size of io_bitmap in longwords: 32 is ports 0-0x3ff.
(-)linux-2.4.22-ppc-dev.orig/include/asm-i386/system.h (+2 lines)
Lines 12-17 Link Here
12
struct task_struct;	/* one of the stranger aspects of C forward declarations.. */
12
struct task_struct;	/* one of the stranger aspects of C forward declarations.. */
13
extern void FASTCALL(__switch_to(struct task_struct *prev, struct task_struct *next));
13
extern void FASTCALL(__switch_to(struct task_struct *prev, struct task_struct *next));
14
14
15
void pax_switch_segments(struct task_struct *);
16
15
#define prepare_to_switch()	do { } while(0)
17
#define prepare_to_switch()	do { } while(0)
16
#define switch_to(prev,next,last) do {					\
18
#define switch_to(prev,next,last) do {					\
17
	asm volatile("pushl %%esi\n\t"					\
19
	asm volatile("pushl %%esi\n\t"					\
(-)linux-2.4.22-ppc-dev.orig/include/asm-parisc/a.out.h (-1 / +1 lines)
Lines 22-28 Link Here
22
/* XXX: STACK_TOP actually should be STACK_BOTTOM for parisc.
22
/* XXX: STACK_TOP actually should be STACK_BOTTOM for parisc.
23
 * prumpf */
23
 * prumpf */
24
24
25
#define STACK_TOP	TASK_SIZE
25
#define __STACK_TOP	TASK_SIZE
26
26
27
#endif
27
#endif
28
28
(-)linux-2.4.22-ppc-dev.orig/include/asm-parisc/elf.h (+11 lines)
Lines 135-140 Link Here
135
135
136
#define ELF_ET_DYN_BASE         (TASK_UNMAPPED_BASE + 0x01000000)
136
#define ELF_ET_DYN_BASE         (TASK_UNMAPPED_BASE + 0x01000000)
137
137
138
#ifdef CONFIG_GRKERNSEC_PAX_ASLR
139
#define PAX_ELF_ET_DYN_BASE(tsk)        0x10000UL
140
141
#define PAX_DELTA_MMAP_LSB(tsk)         PAGE_SHIFT
142
#define PAX_DELTA_MMAP_LEN(tsk)         16
143
#define PAX_DELTA_EXEC_LSB(tsk)         PAGE_SHIFT
144
#define PAX_DELTA_EXEC_LEN(tsk)         16
145
#define PAX_DELTA_STACK_LSB(tsk)        PAGE_SHIFT
146
#define PAX_DELTA_STACK_LEN(tsk)        16
147
#endif
148
138
/* This yields a mask that user programs can use to figure out what
149
/* This yields a mask that user programs can use to figure out what
139
   instruction set this CPU supports.  This could be done in user space,
150
   instruction set this CPU supports.  This could be done in user space,
140
   but it's not easy, and we've already done it here.  */
151
   but it's not easy, and we've already done it here.  */
(-)linux-2.4.22-ppc-dev.orig/include/asm-parisc/mman.h (+4 lines)
Lines 18-23 Link Here
18
#define MAP_NORESERVE	0x4000		/* don't check for reservations */
18
#define MAP_NORESERVE	0x4000		/* don't check for reservations */
19
#define MAP_GROWSDOWN	0x8000		/* stack-like segment */
19
#define MAP_GROWSDOWN	0x8000		/* stack-like segment */
20
20
21
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
22
#define MAP_MIRROR	0x0400
23
#endif
24
21
#define MS_SYNC		1		/* synchronous memory sync */
25
#define MS_SYNC		1		/* synchronous memory sync */
22
#define MS_ASYNC	2		/* sync memory asynchronously */
26
#define MS_ASYNC	2		/* sync memory asynchronously */
23
#define MS_INVALIDATE	4		/* invalidate the caches */
27
#define MS_INVALIDATE	4		/* invalidate the caches */
(-)linux-2.4.22-ppc-dev.orig/include/asm-parisc/pgtable.h (+11 lines)
Lines 167-172 Link Here
167
#define PAGE_EXECREAD   __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
167
#define PAGE_EXECREAD   __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
168
#define PAGE_COPY       PAGE_EXECREAD
168
#define PAGE_COPY       PAGE_EXECREAD
169
#define PAGE_RWX        __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
169
#define PAGE_RWX        __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
170
171
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
172
#define PAGE_SHARED_NOEXEC    __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
173
#define PAGE_COPY_NOEXEC      __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
174
#define PAGE_READONLY_NOEXEC  __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
175
#else
176
#define PAGE_SHARED_NOEXEC    PAGE_SHARED
177
#define PAGE_COPY_NOEXEC      PAGE_COPY
178
#define PAGE_READONLY_NOEXEC  PAGE_READONLY
179
#endif
180
170
#define PAGE_KERNEL	__pgprot(_PAGE_KERNEL)
181
#define PAGE_KERNEL	__pgprot(_PAGE_KERNEL)
171
#define PAGE_KERNEL_RO	__pgprot(_PAGE_PRESENT | _PAGE_EXEC | _PAGE_READ | _PAGE_DIRTY | _PAGE_ACCESSED)
182
#define PAGE_KERNEL_RO	__pgprot(_PAGE_PRESENT | _PAGE_EXEC | _PAGE_READ | _PAGE_DIRTY | _PAGE_ACCESSED)
172
#define PAGE_KERNEL_UNC	__pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
183
#define PAGE_KERNEL_UNC	__pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
(-)linux-2.4.22-ppc-dev.orig/include/asm-ppc/a.out.h (-1 / +1 lines)
Lines 2-8 Link Here
2
#define __PPC_A_OUT_H__
2
#define __PPC_A_OUT_H__
3
3
4
/* grabbed from the intel stuff  */
4
/* grabbed from the intel stuff  */
5
#define STACK_TOP TASK_SIZE
5
#define __STACK_TOP TASK_SIZE
6
6
7
7
8
struct exec
8
struct exec
(-)linux-2.4.22-ppc-dev.orig/include/asm-ppc/elf.h (+11 lines)
Lines 46-51 Link Here
46
46
47
#define ELF_ET_DYN_BASE         (0x08000000)
47
#define ELF_ET_DYN_BASE         (0x08000000)
48
48
49
#ifdef CONFIG_GRKERNSEC_PAX_ASLR
50
#define PAX_ELF_ET_DYN_BASE(tsk)	0x10000000UL
51
52
#define PAX_DELTA_MMAP_LSB(tsk)		PAGE_SHIFT
53
#define PAX_DELTA_MMAP_LEN(tsk)		15
54
#define PAX_DELTA_EXEC_LSB(tsk)		PAGE_SHIFT
55
#define PAX_DELTA_EXEC_LEN(tsk)		15
56
#define PAX_DELTA_STACK_LSB(tsk)	PAGE_SHIFT
57
#define PAX_DELTA_STACK_LEN(tsk)	15
58
#endif
59
49
#define USE_ELF_CORE_DUMP
60
#define USE_ELF_CORE_DUMP
50
#define ELF_EXEC_PAGESIZE	4096
61
#define ELF_EXEC_PAGESIZE	4096
51
62
(-)linux-2.4.22-ppc-dev.orig/include/asm-ppc/mman.h (+4 lines)
Lines 19-24 Link Here
19
#define MAP_DENYWRITE	0x0800		/* ETXTBSY */
19
#define MAP_DENYWRITE	0x0800		/* ETXTBSY */
20
#define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
20
#define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
21
21
22
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
23
#define MAP_MIRROR	0x0200
24
#endif
25
22
#define MS_ASYNC	1		/* sync memory asynchronously */
26
#define MS_ASYNC	1		/* sync memory asynchronously */
23
#define MS_INVALIDATE	2		/* invalidate the caches */
27
#define MS_INVALIDATE	2		/* invalidate the caches */
24
#define MS_SYNC		4		/* synchronous memory sync */
28
#define MS_SYNC		4		/* synchronous memory sync */
(-)linux-2.4.22-ppc-dev.orig/include/asm-ppc/pgtable.h (-10 / +20 lines)
Lines 335-340 Link Here
335
#define PAGE_COPY	__pgprot(_PAGE_BASE | _PAGE_USER)
335
#define PAGE_COPY	__pgprot(_PAGE_BASE | _PAGE_USER)
336
#define PAGE_COPY_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
336
#define PAGE_COPY_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
337
337
338
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
339
# define PAGE_SHARED_NOEXEC	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_GUARDED)
340
# define PAGE_COPY_NOEXEC	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_GUARDED)
341
# define PAGE_READONLY_NOEXEC	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_GUARDED)
342
#else
343
# define PAGE_SHARED_NOEXEC	PAGE_SHARED
344
# define PAGE_COPY_NOEXEC	PAGE_COPY
345
# define PAGE_READONLY_NOEXEC	PAGE_READONLY
346
#endif
347
338
#define PAGE_KERNEL	__pgprot(_PAGE_KERNEL)
348
#define PAGE_KERNEL	__pgprot(_PAGE_KERNEL)
339
#define PAGE_KERNEL_RO	__pgprot(_PAGE_BASE | _PAGE_SHARED)
349
#define PAGE_KERNEL_RO	__pgprot(_PAGE_BASE | _PAGE_SHARED)
340
#define PAGE_KERNEL_CI	__pgprot(_PAGE_IO)
350
#define PAGE_KERNEL_CI	__pgprot(_PAGE_IO)
Lines 346-366 Link Here
346
 * This is the closest we can get..
356
 * This is the closest we can get..
347
 */
357
 */
348
#define __P000	PAGE_NONE
358
#define __P000	PAGE_NONE
349
#define __P001	PAGE_READONLY_X
359
#define __P001	PAGE_READONLY_NOEXEC
350
#define __P010	PAGE_COPY
360
#define __P010	PAGE_COPY_NOEXEC
351
#define __P011	PAGE_COPY_X
361
#define __P011	PAGE_COPY_NOEXEC
352
#define __P100	PAGE_READONLY
362
#define __P100	PAGE_READONLY_X
353
#define __P101	PAGE_READONLY_X
363
#define __P101	PAGE_READONLY_X
354
#define __P110	PAGE_COPY
364
#define __P110	PAGE_COPY_X
355
#define __P111	PAGE_COPY_X
365
#define __P111	PAGE_COPY_X
356
366
357
#define __S000	PAGE_NONE
367
#define __S000	PAGE_NONE
358
#define __S001	PAGE_READONLY_X
368
#define __S001	PAGE_READONLY_NOEXEC
359
#define __S010	PAGE_SHARED
369
#define __S010	PAGE_SHARED_NOEXEC
360
#define __S011	PAGE_SHARED_X
370
#define __S011	PAGE_SHARED_NOEXEC
361
#define __S100	PAGE_READONLY
371
#define __S100	PAGE_READONLY_X
362
#define __S101	PAGE_READONLY_X
372
#define __S101	PAGE_READONLY_X
363
#define __S110	PAGE_SHARED
373
#define __S110	PAGE_SHARED_X
364
#define __S111	PAGE_SHARED_X
374
#define __S111	PAGE_SHARED_X
365
375
366
#ifndef __ASSEMBLY__
376
#ifndef __ASSEMBLY__
(-)linux-2.4.22-ppc-dev.orig/include/asm-sparc/a.out.h (-1 / +1 lines)
Lines 91-97 Link Here
91
91
92
#include <asm/page.h>
92
#include <asm/page.h>
93
93
94
#define STACK_TOP	(PAGE_OFFSET - PAGE_SIZE)
94
#define __STACK_TOP	(PAGE_OFFSET - PAGE_SIZE)
95
95
96
#endif /* __KERNEL__ */
96
#endif /* __KERNEL__ */
97
97
(-)linux-2.4.22-ppc-dev.orig/include/asm-sparc/elf.h (+12 lines)
Lines 83-88 Link Here
83
83
84
#define ELF_ET_DYN_BASE         (0x08000000)
84
#define ELF_ET_DYN_BASE         (0x08000000)
85
85
86
#ifdef CONFIG_GRKERNSEC_PAX_ASLR
87
#define PAX_ELF_ET_DYN_BASE(tsk)	0x10000UL
88
89
#define PAX_DELTA_MMAP_LSB(tsk)		PAGE_SHIFT
90
#define PAX_DELTA_MMAP_LEN(tsk)		16
91
#define PAX_DELTA_EXEC_LSB(tsk)		PAGE_SHIFT
92
#define PAX_DELTA_EXEC_LEN(tsk)		16
93
#define PAX_DELTA_STACK_LSB(tsk)	PAGE_SHIFT
94
#define PAX_DELTA_STACK_LEN(tsk)	16
95
#endif
96
97
86
/* This yields a mask that user programs can use to figure out what
98
/* This yields a mask that user programs can use to figure out what
87
   instruction set this cpu supports.  This can NOT be done in userspace
99
   instruction set this cpu supports.  This can NOT be done in userspace
88
   on Sparc.  */
100
   on Sparc.  */
(-)linux-2.4.22-ppc-dev.orig/include/asm-sparc/mman.h (+4 lines)
Lines 24-29 Link Here
24
#define MAP_DENYWRITE	0x0800		/* ETXTBSY */
24
#define MAP_DENYWRITE	0x0800		/* ETXTBSY */
25
#define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
25
#define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
26
26
27
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
28
#define MAP_MIRROR	0x0400
29
#endif
30
27
#define MS_ASYNC	1		/* sync memory asynchronously */
31
#define MS_ASYNC	1		/* sync memory asynchronously */
28
#define MS_INVALIDATE	2		/* invalidate the caches */
32
#define MS_INVALIDATE	2		/* invalidate the caches */
29
#define MS_SYNC		4		/* synchronous memory sync */
33
#define MS_SYNC		4		/* synchronous memory sync */
(-)linux-2.4.22-ppc-dev.orig/include/asm-sparc/pgtable.h (+17 lines)
Lines 97-102 Link Here
97
BTFIXUPDEF_INT(page_shared)
97
BTFIXUPDEF_INT(page_shared)
98
BTFIXUPDEF_INT(page_copy)
98
BTFIXUPDEF_INT(page_copy)
99
BTFIXUPDEF_INT(page_readonly)
99
BTFIXUPDEF_INT(page_readonly)
100
101
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
102
BTFIXUPDEF_INT(page_shared_noexec)
103
BTFIXUPDEF_INT(page_copy_noexec)
104
BTFIXUPDEF_INT(page_readonly_noexec)
105
#endif
106
100
BTFIXUPDEF_INT(page_kernel)
107
BTFIXUPDEF_INT(page_kernel)
101
108
102
#define PMD_SHIFT       	BTFIXUP_SIMM13(pmd_shift)
109
#define PMD_SHIFT       	BTFIXUP_SIMM13(pmd_shift)
Lines 118-123 Link Here
118
#define PAGE_COPY      __pgprot(BTFIXUP_INT(page_copy))
125
#define PAGE_COPY      __pgprot(BTFIXUP_INT(page_copy))
119
#define PAGE_READONLY  __pgprot(BTFIXUP_INT(page_readonly))
126
#define PAGE_READONLY  __pgprot(BTFIXUP_INT(page_readonly))
120
127
128
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
129
#define PAGE_SHARED_NOEXEC    __pgprot(BTFIXUP_INT(page_shared_noexec))
130
#define PAGE_COPY_NOEXEC      __pgprot(BTFIXUP_INT(page_copy_noexec))
131
#define PAGE_READONLY_NOEXEC  __pgprot(BTFIXUP_INT(page_readonly_noexec))
132
#else
133
#define PAGE_SHARED_NOEXEC    PAGE_SHARED
134
#define PAGE_COPY_NOEXEC      PAGE_COPY
135
#define PAGE_READONLY_NOEXEC  PAGE_READONLY
136
#endif
137
121
extern unsigned long page_kernel;
138
extern unsigned long page_kernel;
122
139
123
#ifdef MODULE
140
#ifdef MODULE
(-)linux-2.4.22-ppc-dev.orig/include/asm-sparc/pgtsrmmu.h (+9 lines)
Lines 73-78 Link Here
73
				    SRMMU_EXEC | SRMMU_REF)
73
				    SRMMU_EXEC | SRMMU_REF)
74
#define SRMMU_PAGE_RDONLY  __pgprot(SRMMU_VALID | SRMMU_CACHE | \
74
#define SRMMU_PAGE_RDONLY  __pgprot(SRMMU_VALID | SRMMU_CACHE | \
75
				    SRMMU_EXEC | SRMMU_REF)
75
				    SRMMU_EXEC | SRMMU_REF)
76
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
77
#define SRMMU_PAGE_SHARED_NOEXEC  __pgprot(SRMMU_VALID | SRMMU_CACHE | \
78
					   SRMMU_WRITE | SRMMU_REF)
79
#define SRMMU_PAGE_COPY_NOEXEC    __pgprot(SRMMU_VALID | SRMMU_CACHE | \
80
					   SRMMU_REF)
81
#define SRMMU_PAGE_RDONLY_NOEXEC  __pgprot(SRMMU_VALID | SRMMU_CACHE | \
82
					   SRMMU_REF)
83
#endif
84
76
#define SRMMU_PAGE_KERNEL  __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
85
#define SRMMU_PAGE_KERNEL  __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
77
				    SRMMU_DIRTY | SRMMU_REF)
86
				    SRMMU_DIRTY | SRMMU_REF)
78
87
(-)linux-2.4.22-ppc-dev.orig/include/asm-sparc/uaccess.h (-1 / +1 lines)
Lines 39-45 Link Here
39
 * No one can read/write anything from userland in the kernel space by setting
39
 * No one can read/write anything from userland in the kernel space by setting
40
 * large size and address near to PAGE_OFFSET - a fault will break his intentions.
40
 * large size and address near to PAGE_OFFSET - a fault will break his intentions.
41
 */
41
 */
42
#define __user_ok(addr,size) ((addr) < STACK_TOP)
42
#define __user_ok(addr,size) ((addr) < __STACK_TOP)
43
#define __kernel_ok (segment_eq(get_fs(), KERNEL_DS))
43
#define __kernel_ok (segment_eq(get_fs(), KERNEL_DS))
44
#define __access_ok(addr,size) (__user_ok((addr) & get_fs().seg,(size)))
44
#define __access_ok(addr,size) (__user_ok((addr) & get_fs().seg,(size)))
45
#define access_ok(type,addr,size) __access_ok((unsigned long)(addr),(size))
45
#define access_ok(type,addr,size) __access_ok((unsigned long)(addr),(size))
(-)linux-2.4.22-ppc-dev.orig/include/asm-sparc64/a.out.h (-1 / +1 lines)
Lines 95-101 Link Here
95
95
96
#ifdef __KERNEL__
96
#ifdef __KERNEL__
97
97
98
#define STACK_TOP (current->thread.flags & SPARC_FLAG_32BIT ? 0xf0000000 : 0x80000000000L)
98
#define __STACK_TOP (current->thread.flags & SPARC_FLAG_32BIT ? 0xf0000000 : 0x80000000000L)
99
99
100
#endif
100
#endif
101
101
(-)linux-2.4.22-ppc-dev.orig/include/asm-sparc64/elf.h (+11 lines)
Lines 82-87 Link Here
82
#define ELF_ET_DYN_BASE         0x0000010000000000UL
82
#define ELF_ET_DYN_BASE         0x0000010000000000UL
83
#endif
83
#endif
84
84
85
#ifdef CONFIG_GRKERNSEC_PAX_ASLR
86
#define PAX_ELF_ET_DYN_BASE(tsk)       ((tsk)->thread.flags & SPARC_FLAG_32BIT ? 0x10000UL : 0x100000UL)
87
88
#define PAX_DELTA_MMAP_LSB(tsk)         (PAGE_SHIFT + 1)
89
#define PAX_DELTA_MMAP_LEN(tsk)         ((tsk)->thread.flags & SPARC_FLAG_32BIT ? 14 : 28 )
90
#define PAX_DELTA_EXEC_LSB(tsk)         (PAGE_SHIFT + 1)
91
#define PAX_DELTA_EXEC_LEN(tsk)         ((tsk)->thread.flags & SPARC_FLAG_32BIT ? 14 : 28 )
92
#define PAX_DELTA_STACK_LSB(tsk)        PAGE_SHIFT
93
#define PAX_DELTA_STACK_LEN(tsk)        ((tsk)->thread.flags & SPARC_FLAG_32BIT ? 15 : 29 )
94
#endif
95
85
96
86
/* This yields a mask that user programs can use to figure out what
97
/* This yields a mask that user programs can use to figure out what
87
   instruction set this cpu supports.  */
98
   instruction set this cpu supports.  */
(-)linux-2.4.22-ppc-dev.orig/include/asm-sparc64/mman.h (+4 lines)
Lines 24-29 Link Here
24
#define MAP_DENYWRITE	0x0800		/* ETXTBSY */
24
#define MAP_DENYWRITE	0x0800		/* ETXTBSY */
25
#define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
25
#define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
26
26
27
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
28
#define MAP_MIRROR	0x0400
29
#endif
30
27
#define MS_ASYNC	1		/* sync memory asynchronously */
31
#define MS_ASYNC	1		/* sync memory asynchronously */
28
#define MS_INVALIDATE	2		/* invalidate the caches */
32
#define MS_INVALIDATE	2		/* invalidate the caches */
29
#define MS_SYNC		4		/* synchronous memory sync */
33
#define MS_SYNC		4		/* synchronous memory sync */
(-)linux-2.4.22-ppc-dev.orig/include/asm-sparc64/pgtable.h (-11 / +26 lines)
Lines 122-128 Link Here
122
#define _PAGE_G		0x0000000000000001	/* Global                             */
122
#define _PAGE_G		0x0000000000000001	/* Global                             */
123
123
124
/* Here are the SpitFire software bits we use in the TTE's. */
124
/* Here are the SpitFire software bits we use in the TTE's. */
125
#define _PAGE_MODIFIED	0x0000000000000800	/* Modified Page (ie. dirty)          */
125
#define _PAGE_MODIFIED	0x0000000000001000	/* Modified Page (ie. dirty)          */
126
#define _PAGE_EXEC	0x0000000000000800	/* Executable SW bit		      */
126
#define _PAGE_ACCESSED	0x0000000000000400	/* Accessed Page (ie. referenced)     */
127
#define _PAGE_ACCESSED	0x0000000000000400	/* Accessed Page (ie. referenced)     */
127
#define _PAGE_READ	0x0000000000000200	/* Readable SW Bit                    */
128
#define _PAGE_READ	0x0000000000000200	/* Readable SW Bit                    */
128
#define _PAGE_WRITE	0x0000000000000100	/* Writable SW Bit                    */
129
#define _PAGE_WRITE	0x0000000000000100	/* Writable SW Bit                    */
Lines 150-165 Link Here
150
151
151
/* Don't set the TTE _PAGE_W bit here, else the dirty bit never gets set. */
152
/* Don't set the TTE _PAGE_W bit here, else the dirty bit never gets set. */
152
#define PAGE_SHARED	__pgprot (_PAGE_PRESENT | _PAGE_VALID | _PAGE_CACHE | \
153
#define PAGE_SHARED	__pgprot (_PAGE_PRESENT | _PAGE_VALID | _PAGE_CACHE | \
153
				  __ACCESS_BITS | _PAGE_WRITE)
154
				  __ACCESS_BITS | _PAGE_WRITE | _PAGE_EXEC)
154
155
155
#define PAGE_COPY	__pgprot (_PAGE_PRESENT | _PAGE_VALID | _PAGE_CACHE | \
156
#define PAGE_COPY	__pgprot (_PAGE_PRESENT | _PAGE_VALID | _PAGE_CACHE | \
156
				  __ACCESS_BITS)
157
				  __ACCESS_BITS | _PAGE_EXEC)
157
158
158
#define PAGE_READONLY	__pgprot (_PAGE_PRESENT | _PAGE_VALID | _PAGE_CACHE | \
159
#define PAGE_READONLY	__pgprot (_PAGE_PRESENT | _PAGE_VALID | _PAGE_CACHE | \
159
				  __ACCESS_BITS)
160
				  __ACCESS_BITS | _PAGE_EXEC)
160
161
161
#define PAGE_KERNEL	__pgprot (_PAGE_PRESENT | _PAGE_VALID | _PAGE_CACHE | \
162
#define PAGE_KERNEL	__pgprot (_PAGE_PRESENT | _PAGE_VALID | _PAGE_CACHE | \
162
				  __PRIV_BITS | __ACCESS_BITS | __DIRTY_BITS)
163
				  __PRIV_BITS | __ACCESS_BITS | __DIRTY_BITS | \
164
				  _PAGE_EXEC)
165
166
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
167
#define PAGE_SHARED_NOEXEC    __pgprot (_PAGE_PRESENT | _PAGE_VALID | _PAGE_CACHE | \
168
					__ACCESS_BITS | _PAGE_WRITE)
169
#define PAGE_COPY_NOEXEC      __pgprot (_PAGE_PRESENT | _PAGE_VALID | _PAGE_CACHE | \
170
					__ACCESS_BITS)
171
#define PAGE_READONLY_NOEXEC  __pgprot (_PAGE_PRESENT | _PAGE_VALID | _PAGE_CACHE | \
172
					__ACCESS_BITS)
173
#else
174
#define PAGE_SHARED_NOEXEC     PAGE_SHARED
175
#define PAGE_COPY_NOEXEC       PAGE_COPY
176
#define PAGE_READONLY_NOEXEC   PAGE_READONLY
177
#endif
163
178
164
#define PAGE_INVALID	__pgprot (0)
179
#define PAGE_INVALID	__pgprot (0)
165
180
Lines 170-187 Link Here
170
#define pg_iobits (_PAGE_VALID | _PAGE_PRESENT | __DIRTY_BITS | __ACCESS_BITS | _PAGE_E)
185
#define pg_iobits (_PAGE_VALID | _PAGE_PRESENT | __DIRTY_BITS | __ACCESS_BITS | _PAGE_E)
171
186
172
#define __P000	PAGE_NONE
187
#define __P000	PAGE_NONE
173
#define __P001	PAGE_READONLY
188
#define __P001	PAGE_READONLY_NOEXEC
174
#define __P010	PAGE_COPY
189
#define __P010	PAGE_COPY_NOEXEC
175
#define __P011	PAGE_COPY
190
#define __P011	PAGE_COPY_NOEXEC
176
#define __P100	PAGE_READONLY
191
#define __P100	PAGE_READONLY
177
#define __P101	PAGE_READONLY
192
#define __P101	PAGE_READONLY
178
#define __P110	PAGE_COPY
193
#define __P110	PAGE_COPY
179
#define __P111	PAGE_COPY
194
#define __P111	PAGE_COPY
180
195
181
#define __S000	PAGE_NONE
196
#define __S000	PAGE_NONE
182
#define __S001	PAGE_READONLY
197
#define __S001	PAGE_READONLY_NOEXEC
183
#define __S010	PAGE_SHARED
198
#define __S010	PAGE_SHARED_NOEXEC
184
#define __S011	PAGE_SHARED
199
#define __S011	PAGE_SHARED_NOEXEC
185
#define __S100	PAGE_READONLY
200
#define __S100	PAGE_READONLY
186
#define __S101	PAGE_READONLY
201
#define __S101	PAGE_READONLY
187
#define __S110	PAGE_SHARED
202
#define __S110	PAGE_SHARED
(-)linux-2.4.22-ppc-dev.orig/include/linux/a.out.h (+18 lines)
Lines 7-12 Link Here
7
7
8
#include <asm/a.out.h>
8
#include <asm/a.out.h>
9
9
10
#ifdef CONFIG_GRKERNSEC_PAX_RANDUSTACK
11
#define __DELTA_STACK (current->mm->delta_stack)
12
#else
13
#define __DELTA_STACK 0UL
14
#endif
15
16
#ifndef STACK_TOP
17
#define STACK_TOP	(__STACK_TOP - __DELTA_STACK)
18
#endif
19
10
#endif /* __STRUCT_EXEC_OVERRIDE__ */
20
#endif /* __STRUCT_EXEC_OVERRIDE__ */
11
21
12
/* these go in the N_MACHTYPE field */
22
/* these go in the N_MACHTYPE field */
Lines 37-42 Link Here
37
  M_MIPS2 = 152		/* MIPS R6000/R4000 binary */
47
  M_MIPS2 = 152		/* MIPS R6000/R4000 binary */
38
};
48
};
39
49
50
/* Constants for the N_FLAGS field */
51
#define F_PAX_PAGEEXEC 1	/* Paging based non-executable pages */
52
#define F_PAX_EMUTRAMP 2	/* Emulate trampolines */
53
#define F_PAX_MPROTECT 4	/* Restrict mprotect() */
54
#define F_PAX_RANDMMAP 8	/* Randomize mmap() base */   
55
#define F_PAX_RANDEXEC 16	/* Randomize ET_EXEC base */
56
#define F_PAX_SEGMEXEC 32	/* Segmentation based non-executable pages */
57
40
#if !defined (N_MAGIC)
58
#if !defined (N_MAGIC)
41
#define N_MAGIC(exec) ((exec).a_info & 0xffff)
59
#define N_MAGIC(exec) ((exec).a_info & 0xffff)
42
#endif
60
#endif
(-)linux-2.4.22-ppc-dev.orig/include/linux/binfmts.h (+2 lines)
Lines 59-64 Link Here
59
extern int do_coredump(long signr, struct pt_regs * regs);
59
extern int do_coredump(long signr, struct pt_regs * regs);
60
extern void set_binfmt(struct linux_binfmt *new);
60
extern void set_binfmt(struct linux_binfmt *new);
61
61
62
void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63
void pax_report_insns(void *pc);
62
64
63
#if 0
65
#if 0
64
/* this went away now */
66
/* this went away now */
(-)linux-2.4.22-ppc-dev.orig/include/linux/elf.h (+13 lines)
Lines 117-122 Link Here
117
#define DT_DEBUG	21
117
#define DT_DEBUG	21
118
#define DT_TEXTREL	22
118
#define DT_TEXTREL	22
119
#define DT_JMPREL	23
119
#define DT_JMPREL	23
120
#define DT_FLAGS	30
121
#define DF_TEXTREL	0x00000004
120
#define DT_LOPROC	0x70000000
122
#define DT_LOPROC	0x70000000
121
#define DT_HIPROC	0x7fffffff
123
#define DT_HIPROC	0x7fffffff
122
#define DT_MIPS_RLD_VERSION	0x70000001
124
#define DT_MIPS_RLD_VERSION	0x70000001
Lines 255-260 Link Here
255
#define R_MIPS_LOVENDOR		100
257
#define R_MIPS_LOVENDOR		100
256
#define R_MIPS_HIVENDOR		127
258
#define R_MIPS_HIVENDOR		127
257
259
260
/* Constants for the e_flags field */
261
#define EF_PAX_PAGEEXEC               1       /* Paging based non-executable pages */
262
#define EF_PAX_EMUTRAMP               2       /* Emulate trampolines */
263
#define EF_PAX_MPROTECT               4       /* Restrict mprotect() */
264
#define EF_PAX_RANDMMAP               8       /* Randomize mmap() base */ 
265
#define EF_PAX_RANDEXEC		      16      /* Randomize ET_EXEC base */
266
#define EF_PAX_SEGMEXEC		      32      /* Segmentation based non-executable pages */
258
267
259
/*
268
/*
260
 * Sparc ELF relocation types
269
 * Sparc ELF relocation types
Lines 550-555 Link Here
550
#define	EI_VERSION	6
559
#define	EI_VERSION	6
551
#define	EI_PAD		7
560
#define	EI_PAD		7
552
561
562
#define EI_PAX		14
563
553
#define	ELFMAG0		0x7f		/* EI_MAG */
564
#define	ELFMAG0		0x7f		/* EI_MAG */
554
#define	ELFMAG1		'E'
565
#define	ELFMAG1		'E'
555
#define	ELFMAG2		'L'
566
#define	ELFMAG2		'L'
Lines 597-602 Link Here
597
#define elfhdr		elf32_hdr
608
#define elfhdr		elf32_hdr
598
#define elf_phdr	elf32_phdr
609
#define elf_phdr	elf32_phdr
599
#define elf_note	elf32_note
610
#define elf_note	elf32_note
611
#define elf_dyn		Elf32_Dyn
600
612
601
#else
613
#else
602
614
Lines 604-609 Link Here
604
#define elfhdr		elf64_hdr
616
#define elfhdr		elf64_hdr
605
#define elf_phdr	elf64_phdr
617
#define elf_phdr	elf64_phdr
606
#define elf_note	elf64_note
618
#define elf_note	elf64_note
619
#define elf_dyn		Elf64_Dyn
607
620
608
#endif
621
#endif
609
622
(-)linux-2.4.22-ppc-dev.orig/include/linux/fs.h (-1 / +1 lines)
Lines 1091-1097 Link Here
1091
1091
1092
asmlinkage long sys_open(const char *, int, int);
1092
asmlinkage long sys_open(const char *, int, int);
1093
asmlinkage long sys_close(unsigned int);	/* yes, it's really unsigned */
1093
asmlinkage long sys_close(unsigned int);	/* yes, it's really unsigned */
1094
extern int do_truncate(struct dentry *, loff_t start);
1094
extern int do_truncate(struct dentry *, loff_t start, struct vfsmount *);
1095
1095
1096
extern struct file *filp_open(const char *, int, int);
1096
extern struct file *filp_open(const char *, int, int);
1097
extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
1097
extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
(-)linux-2.4.22-ppc-dev.orig/include/linux/gracl.h (+212 lines)
Line 0 Link Here
1
#ifndef GR_ACL_H
2
#define GR_ACL_H
3
#endif
4
#include <linux/grdefs.h>
5
#include <linux/resource.h>
6
7
#include <asm/resource.h>
8
9
/* * * * * * * * * * * * * * * * * * * * *
10
 * grsecurity ACL System
11
 * Main header file
12
 * Purpose: define most gracl data structures 
13
 * * * * * * * * * * * * * * * * * * * * */
14
15
/* Major status information */
16
17
#define GR_VERSION  "grsecurity 2.0"
18
19
enum {
20
21
	SHUTDOWN = 0,
22
	ENABLE = 1,
23
	SPROLE = 2,
24
	RELOAD = 3,
25
	SEGVMOD = 4,
26
	STATUS = 5,
27
	UNSPROLE = 6
28
};
29
30
/* Password setup definitions
31
 * kernel/grhash.c */
32
enum {
33
	GR_PW_LEN = 128,
34
	GR_SALT_LEN = 16,
35
	GR_SHA_LEN = 32,
36
};
37
38
enum {
39
	GR_SPROLE_LEN = 64,
40
};
41
42
/* Begin Data Structures */
43
44
struct sprole_pw {
45
	unsigned char *rolename;
46
	unsigned char salt[GR_SALT_LEN];
47
	unsigned char sum[GR_SHA_LEN];	/* 256-bit SHA hash of the password */
48
};
49
50
struct name_entry {
51
	ino_t inode;
52
	kdev_t device;
53
	char *name;
54
	__u16 len;
55
};
56
57
struct acl_role_db {
58
	struct acl_role_label **r_hash;
59
	__u32 r_size;
60
};
61
62
struct name_db {
63
	struct name_entry **n_hash;
64
	__u32 n_size;
65
};
66
67
struct crash_uid {
68
	uid_t uid;
69
	unsigned long expires;
70
};
71
72
/* Userspace Grsecurity ACL data structures */
73
struct acl_subject_label {
74
	char *filename;
75
	ino_t inode;
76
	kdev_t device;
77
	__u32 mode;
78
	__u32 cap_raise;
79
	__u32 cap_lower;
80
81
	struct rlimit res[RLIM_NLIMITS + 1];
82
	__u16 resmask;
83
84
	__u32 ip_proto[8];
85
	__u32 ip_type;
86
	struct acl_ip_label **ips;
87
	__u32 ip_num;
88
89
	__u32 crashes;
90
	unsigned long expires;
91
92
	struct acl_subject_label *parent_subject;
93
	struct acl_object_label *proc_object;
94
	struct acl_ip_label *ip_object;
95
	struct acl_subject_label *prev;
96
	struct acl_subject_label *next;
97
98
	struct acl_object_label **obj_hash;
99
	__u32 obj_hash_size;
100
};
101
102
struct role_allowed_ip {
103
	__u32 addr;
104
	__u32 netmask;
105
106
	struct role_allowed_ip *prev;
107
	struct role_allowed_ip *next;
108
};
109
110
struct role_transition {
111
	char *rolename;
112
113
	struct role_transition *prev;
114
	struct role_transition *next;
115
};
116
117
struct acl_role_label {
118
	char *rolename;
119
	uid_t uidgid;
120
	__u16 roletype;
121
122
	__u16 auth_attempts;
123
	unsigned long expires;
124
125
	struct acl_subject_label *root_label;
126
	struct acl_subject_label *proc_subject;
127
128
	struct acl_role_label *prev;
129
	struct acl_role_label *next;
130
131
	struct role_transition *transitions;
132
	struct role_allowed_ip *allowed_ips;
133
	struct acl_subject_label **subj_hash;
134
	__u32 subj_hash_size;
135
};
136
137
struct user_acl_role_db {
138
	struct acl_role_label **r_table;
139
	__u32 r_entries;	/* number of entries in table */
140
	__u32 s_entries;	/* total number of subject acls */
141
	__u32 i_entries;	/* total number of ip acls */
142
	__u32 o_entries;	/* Total number of object acls */
143
	__u32 a_entries;	/* total number of allowed ips */
144
	__u32 t_entries;	/* total number of transitions */
145
};
146
147
struct acl_object_label {
148
	char *filename;
149
	ino_t inode;
150
	kdev_t device;
151
	__u32 mode;
152
153
	struct acl_subject_label *nested;
154
155
	/* next two structures not used */
156
157
	struct acl_object_label *prev;
158
	struct acl_object_label *next;
159
};
160
161
struct acl_ip_label {
162
	__u32 addr;
163
	__u32 netmask;
164
	__u16 low, high;
165
	__u8 mode;
166
	__u32 type;
167
	__u32 proto[8];
168
169
	/* next two structures not used */
170
171
	struct acl_ip_label *prev;
172
	struct acl_ip_label *next;
173
};
174
175
struct gr_arg {
176
	struct user_acl_role_db role_db;
177
	unsigned char pw[GR_PW_LEN];
178
	unsigned char salt[GR_SALT_LEN];
179
	unsigned char sum[GR_SHA_LEN];
180
	unsigned char sp_role[GR_SPROLE_LEN];
181
	struct sprole_pw *sprole_pws;
182
	__u16 num_sprole_pws;
183
	kdev_t segv_device;
184
	ino_t segv_inode;
185
	uid_t segv_uid;
186
	__u16 mode;
187
};
188
189
/* End Data Structures Section */
190
191
/* Hash functions generated by empirical testing by Brad Spengler
192
   Makes good use of the low bits of the inode.  Generally 0-1 times
193
   in loop for successful match.  0-3 for unsuccessful match.
194
   Shift/add algorithm with modulus of table size and an XOR*/
195
196
static __inline__ unsigned long
197
rhash(const uid_t uid, const __u16 type, const unsigned long sz)
198
{
199
	return (((uid << type) + (uid ^ type)) % sz);
200
}
201
202
static __inline__ unsigned long
203
fhash(const ino_t ino, const kdev_t dev, const unsigned long sz)
204
{
205
	return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
206
}
207
208
static __inline__ unsigned long
209
nhash(const char *name, const __u16 len, const unsigned long sz)
210
{
211
	return full_name_hash(name, len) % sz;
212
}
(-)linux-2.4.22-ppc-dev.orig/include/linux/gralloc.h (+8 lines)
Line 0 Link Here
1
#ifndef __GRALLOC_H
2
#define __GRALLOC_H
3
4
void acl_free_all(void);
5
int acl_alloc_stack_init(unsigned long size);
6
void *acl_alloc(unsigned long len);
7
8
#endif
(-)linux-2.4.22-ppc-dev.orig/include/linux/grdefs.h (+104 lines)
Line 0 Link Here
1
#ifndef GRDEFS_H
2
#define GRDEFS_H
3
4
/* Begin grsecurity status declarations */
5
6
enum {
7
	GR_READY = 0x01,
8
	GR_STATUS_INIT = 0x00	// disabled state
9
};
10
11
/* Begin  ACL declarations */
12
13
/* Role flags */
14
15
enum {
16
	GR_ROLE_USER = 0x0001,
17
	GR_ROLE_GROUP = 0x0002,
18
	GR_ROLE_DEFAULT = 0x0004,
19
	GR_ROLE_SPECIAL = 0x0008,
20
	GR_ROLE_AUTH = 0x0010,
21
	GR_ROLE_NOPW = 0x0020,
22
	GR_ROLE_GOD = 0x0040,
23
	GR_ROLE_LEARN = 0x0080,
24
	GR_ROLE_TPE = 0x0100
25
};
26
27
/* ACL Subject and Object mode flags */
28
enum {
29
	GR_DELETED = 0x00000080
30
};
31
32
/* ACL Object-only mode flags */
33
enum {
34
	GR_READ = 0x00000001,
35
	GR_APPEND = 0x00000002,
36
	GR_WRITE = 0x00000004,
37
	GR_EXEC = 0x00000008,
38
	GR_FIND = 0x00000010,
39
	GR_INHERIT = 0x00000040,
40
	GR_PTRACERD = 0x00000100,
41
	GR_SETID = 0x00000200,
42
	GR_CREATE = 0x00000400,
43
	GR_DELETE = 0x00000800,
44
	GR_AUDIT_READ = 0x00001000,
45
	GR_AUDIT_APPEND = 0x00002000,
46
	GR_AUDIT_WRITE = 0x0004000,
47
	GR_AUDIT_EXEC = 0x00008000,
48
	GR_AUDIT_FIND = 0x00010000,
49
	GR_AUDIT_INHERIT = 0x00020000,
50
	GR_AUDIT_SETID = 0x00400000,
51
	GR_AUDIT_CREATE = 0x00800000,
52
	GR_AUDIT_DELETE = 0x01000000,
53
	GR_SUPPRESS = 0x02000000,
54
	GR_NOLEARN = 0x04000000
55
};
56
57
#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
58
		   GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
59
		   GR_AUDIT_CREATE | GR_AUDIT_DELETE)
60
61
/* ACL subject-only mode flags */
62
enum {
63
	GR_KILL = 0x00000001,
64
	GR_VIEW = 0x00000002,
65
	GR_PROTECTED = 0x00000100,
66
	GR_LEARN = 0x00000200,
67
	GR_OVERRIDE = 0x00000400,
68
	/* just a placeholder, this mode is only used in userspace */
69
	GR_DUMMY = 0x00000800,
70
71
	GR_PAXPAGE = 0x00001000,
72
	GR_PAXSEGM = 0x00002000,
73
	GR_PAXGCC = 0x00004000,
74
	GR_PAXRANDMMAP = 0x00008000,
75
	GR_PAXRANDEXEC = 0x00010000,
76
	GR_PAXMPROTECT = 0x00020000,
77
	GR_PROTSHM = 0x00040000,
78
	GR_KILLPROC = 0x00080000,
79
	GR_KILLIPPROC = 0x00100000,
80
	/* just a placeholder, this mode is only used in userspace */
81
	GR_NOTROJAN = 0x00200000,
82
	GR_PROTPROCFD = 0x00400000,
83
	GR_PROCACCT = 0x00800000
84
};
85
86
#define GR_CRASH_RES	11
87
#define GR_UIDTABLE_MAX 500
88
89
/* begin resource learning section */
90
enum {
91
	GR_RLIM_CPU_BUMP = 60,
92
	GR_RLIM_FSIZE_BUMP = 50000,
93
	GR_RLIM_DATA_BUMP = 10000,
94
	GR_RLIM_STACK_BUMP = 1000,
95
	GR_RLIM_CORE_BUMP = 10000,
96
	GR_RLIM_RSS_BUMP = 500000,
97
	GR_RLIM_NPROC_BUMP = 1,
98
	GR_RLIM_NOFILE_BUMP = 5,
99
	GR_RLIM_MEMLOCK_BUMP = 50000,
100
	GR_RLIM_AS_BUMP = 500000,
101
	GR_RLIM_LOCKS_BUMP = 2
102
};
103
104
#endif
(-)linux-2.4.22-ppc-dev.orig/include/linux/grinternal.h (+193 lines)
Line 0 Link Here
1
#ifndef __GRINTERNAL_H
2
#define __GRINTERNAL_H
3
4
#ifdef CONFIG_GRKERNSEC
5
6
#include <linux/grdefs.h>
7
#include <linux/grmsg.h>
8
9
extern void gr_add_learn_entry(const char *fmt, ...);
10
extern __u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
11
			    const struct vfsmount *mnt);
12
extern __u32 gr_check_create(const struct dentry *new_dentry,
13
			     const struct dentry *parent,
14
			     const struct vfsmount *mnt, const __u32 mode);
15
extern int gr_check_protected_task(const struct task_struct *task);
16
extern __inline__ __u32 to_gr_audit(const __u32 reqmode);
17
extern int gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
18
			    struct dentry *old_dentry,
19
			    struct dentry *new_dentry,
20
			    struct vfsmount *mnt, const __u8 replace);
21
extern int gr_set_acls(const int type);
22
23
extern void gr_handle_alertkill(void);
24
extern char *gr_to_filename(const struct dentry *dentry,
25
			    const struct vfsmount *mnt);
26
extern char *gr_to_filename1(const struct dentry *dentry,
27
			    const struct vfsmount *mnt);
28
extern char *gr_to_filename2(const struct dentry *dentry,
29
			    const struct vfsmount *mnt);
30
extern char *gr_to_filename3(const struct dentry *dentry,
31
			    const struct vfsmount *mnt);
32
33
extern int grsec_enable_link;
34
extern int grsec_enable_fifo;
35
extern int grsec_enable_execve;
36
extern int grsec_enable_forkbomb;
37
extern int grsec_forkbomb_gid;
38
extern int grsec_forkbomb_sec;
39
extern int grsec_forkbomb_max;
40
extern int grsec_enable_execlog;
41
extern int grsec_enable_signal;
42
extern int grsec_enable_forkfail;
43
extern int grsec_enable_time;
44
extern int grsec_enable_chroot_shmat;
45
extern int grsec_enable_chroot_findtask;
46
extern int grsec_enable_chroot_mount;
47
extern int grsec_enable_chroot_double;
48
extern int grsec_enable_chroot_pivot;
49
extern int grsec_enable_chroot_chdir;
50
extern int grsec_enable_chroot_chmod;
51
extern int grsec_enable_chroot_mknod;
52
extern int grsec_enable_chroot_fchdir;
53
extern int grsec_enable_chroot_nice;
54
extern int grsec_enable_chroot_execlog;
55
extern int grsec_enable_chroot_caps;
56
extern int grsec_enable_chroot_sysctl;
57
extern int grsec_enable_chroot_unix;
58
extern int grsec_enable_tpe;
59
extern int grsec_tpe_gid;
60
extern int grsec_enable_tpe_all;
61
extern int grsec_enable_sidcaps;
62
extern int grsec_enable_randpid;
63
extern int grsec_enable_socket_all;
64
extern int grsec_socket_all_gid;
65
extern int grsec_enable_socket_client;
66
extern int grsec_socket_client_gid;
67
extern int grsec_enable_socket_server;
68
extern int grsec_socket_server_gid;
69
extern int grsec_audit_gid;
70
extern int grsec_enable_group;
71
extern int grsec_enable_audit_ipc;
72
extern int grsec_enable_mount;
73
extern int grsec_enable_chdir;
74
extern int grsec_lock;
75
76
extern struct task_struct *child_reaper;
77
78
extern spinlock_t grsec_alert_lock;
79
extern unsigned long grsec_alert_wtime;
80
extern unsigned long grsec_alert_fyet;
81
82
extern spinlock_t grsec_alertgood_lock;
83
extern unsigned long grsec_alertgood_wtime;
84
extern unsigned long grsec_alertgood_fyet;
85
86
extern spinlock_t grsec_audit_lock;
87
88
#define gr_task_fullpath(tsk) (tsk->exec_file ? \
89
			gr_to_filename2(tsk->exec_file->f_dentry, \
90
			tsk->exec_file->f_vfsmnt) : "/")
91
92
#define gr_parent_task_fullpath(tsk) (tsk->p_pptr->exec_file ? \
93
			gr_to_filename3(tsk->p_pptr->exec_file->f_dentry, \
94
			tsk->p_pptr->exec_file->f_vfsmnt) : "/")
95
96
#define proc_is_chrooted(tsk_a)  ((tsk_a->pid > 1) && \
97
			  ((tsk_a->fs->root->d_inode->i_dev != \
98
			  child_reaper->fs->root->d_inode->i_dev) || \
99
			  (tsk_a->fs->root->d_inode->i_ino != \
100
			  child_reaper->fs->root->d_inode->i_ino)))
101
102
#define have_same_root(tsk_a,tsk_b) ((tsk_a->fs->root->d_inode->i_dev == \
103
			  tsk_b->fs->root->d_inode->i_dev) && \
104
			  (tsk_a->fs->root->d_inode->i_ino == \
105
			  tsk_b->fs->root->d_inode->i_ino))
106
107
#define DEFAULTSECARGS gr_task_fullpath(current), current->comm, \
108
		       current->pid, current->uid, \
109
		       current->euid, current->gid, current->egid, \
110
		       gr_parent_task_fullpath(current), \
111
		       current->p_pptr->comm, current->p_pptr->pid, \
112
		       current->p_pptr->uid, current->p_pptr->euid, \
113
		       current->p_pptr->gid, current->p_pptr->egid
114
115
#define GR_CHROOT_CAPS ( \
116
	CAP_TO_MASK(CAP_FOWNER) | \
117
	CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
118
	CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
119
	CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
120
	CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
121
	CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
122
	CAP_TO_MASK(CAP_IPC_OWNER))
123
124
#define security_alert_good(normal_msg,args...) \
125
({ \
126
	spin_lock(&grsec_alertgood_lock); \
127
	\
128
	if (!grsec_alertgood_wtime || jiffies - grsec_alertgood_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) { \
129
	    grsec_alertgood_wtime = jiffies; grsec_alertgood_fyet = 0; \
130
	    if (current->curr_ip) \
131
		printk(KERN_ALERT "grsec: From %u.%u.%u.%u: " normal_msg "\n", NIPQUAD(current->curr_ip) , ## args); \
132
	    else \
133
	    	printk(KERN_ALERT "grsec: " normal_msg "\n" , ## args); \
134
	} else if((jiffies - grsec_alertgood_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alertgood_fyet < CONFIG_GRKERNSEC_FLOODBURST)) { \
135
	    grsec_alertgood_fyet++; \
136
	    if (current->curr_ip) \
137
		printk(KERN_ALERT "grsec: From %u.%u.%u.%u: " normal_msg "\n", NIPQUAD(current->curr_ip) , ## args); \
138
	    else \
139
	    	printk(KERN_ALERT "grsec: " normal_msg "\n" , ## args); \
140
	} else if (grsec_alertgood_fyet == CONFIG_GRKERNSEC_FLOODBURST) { \
141
	    grsec_alertgood_wtime = jiffies; grsec_alertgood_fyet++; \
142
	    printk(KERN_ALERT "grsec: more alerts, logging disabled for " \
143
		    "%d seconds\n", CONFIG_GRKERNSEC_FLOODTIME); \
144
	} \
145
	\
146
	spin_unlock(&grsec_alertgood_lock); \
147
})
148
149
#define security_alert(normal_msg,args...) \
150
({ \
151
	spin_lock(&grsec_alert_lock); \
152
	\
153
	if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) { \
154
	    grsec_alert_wtime = jiffies; grsec_alert_fyet = 0; \
155
	    if (current->curr_ip) \
156
		printk(KERN_ALERT "grsec: From %u.%u.%u.%u: " normal_msg "\n", NIPQUAD(current->curr_ip) , ## args); \
157
	    else \
158
	    	printk(KERN_ALERT "grsec: " normal_msg "\n" , ## args); \
159
	} else if((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) { \
160
	    grsec_alert_fyet++; \
161
	    if (current->curr_ip) \
162
		printk(KERN_ALERT "grsec: From %u.%u.%u.%u: " normal_msg "\n", NIPQUAD(current->curr_ip) , ## args); \
163
	    else \
164
	    	printk(KERN_ALERT "grsec: " normal_msg "\n" , ## args); \
165
	} else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) { \
166
	    grsec_alert_wtime = jiffies; grsec_alert_fyet++; \
167
	    printk(KERN_ALERT "grsec: more alerts, logging disabled for " \
168
		    "%d seconds\n", CONFIG_GRKERNSEC_FLOODTIME); \
169
	} \
170
	\
171
	gr_handle_alertkill(); \
172
	spin_unlock(&grsec_alert_lock); \
173
})
174
175
#define security_audit(normal_msg,args...) \
176
({ \
177
	spin_lock(&grsec_audit_lock); \
178
	if (current->curr_ip) \
179
		printk(KERN_INFO "grsec: From %u.%u.%u.%u: " normal_msg "\n", \
180
		       NIPQUAD(current->curr_ip) , ## args); \
181
	else \
182
		printk(KERN_INFO "grsec: " normal_msg "\n", ## args); \
183
	spin_unlock(&grsec_audit_lock); \
184
})
185
186
#define security_learn(normal_msg,args...) \
187
({ \
188
	gr_add_learn_entry(normal_msg "\n", ## args); \
189
})
190
191
#endif
192
193
#endif
(-)linux-2.4.22-ppc-dev.orig/include/linux/grmsg.h (+104 lines)
Line 0 Link Here
1
#define DEFAULTSECMSG "%.256s[%.16s:%d] uid/euid:%d/%d gid/egid:%d/%d, parent %.256s[%.16s:%d] uid/euid:%d/%d gid/egid:%d/%d"
2
#define GR_ACL_PROCACCT_MSG "%.256s[%.16s:%d] IP:%u.%u.%u.%u TTY:%.64s uid/euid:%d/%d gid/egid:%d/%d run time:[%ud %uh %um %us] cpu time:[%ud %uh %um %us] %s with exit code %ld, parent %.256s[%.16s:%d] IP:%u.%u.%u.%u TTY:%.64s uid/euid:%d/%d gid/egid:%d/%d"
3
#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by " DEFAULTSECMSG
4
#define GR_IOPERM_MSG "denied use of ioperm() by " DEFAULTSECMSG
5
#define GR_IOPL_MSG "denied use of iopl() by " DEFAULTSECMSG
6
#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by " DEFAULTSECMSG
7
#define GR_UNIX_CHROOT_MSG "denied connect to abstract AF_UNIX socket outside of chroot by " DEFAULTSECMSG
8
#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by " DEFAULTSECMSG
9
#define GR_KMEM_MSG "attempted write to /dev/kmem by " DEFAULTSECMSG
10
#define GR_PORT_OPEN_MSG "attempted open of /dev/port by " DEFAULTSECMSG
11
#define GR_MEM_WRITE_MSG "attempted write of /dev/mem by " DEFAULTSECMSG
12
#define GR_MEM_MMAP_MSG "attempted mmap write of /dev/[k]mem by " DEFAULTSECMSG
13
#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by " DEFAULTSECMSG
14
#define GR_LEARN_AUDIT_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%lu\t%lu\t%.4095s\t%lu\t%u.%u.%u.%u"
15
#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by " DEFAULTSECMSG
16
#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by " DEFAULTSECMSG
17
#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by " DEFAULTSECMSG
18
#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by " DEFAULTSECMSG
19
#define GR_MKNOD_CHROOT_MSG "refused attempt to mknod %.950s from chroot by " DEFAULTSECMSG
20
#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by " DEFAULTSECMSG
21
#define GR_UNIXCONNECT_ACL_MSG "%s connect to the unix domain socket %.950s by " DEFAULTSECMSG
22
#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by " DEFAULTSECMSG
23
#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by " DEFAULTSECMSG
24
#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by " DEFAULTSECMSG
25
#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by " DEFAULTSECMSG
26
#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for " DEFAULTSECMSG
27
#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by " DEFAULTSECMSG
28
#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by " DEFAULTSECMSG
29
#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by " DEFAULTSECMSG
30
#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by " DEFAULTSECMSG
31
#define GR_NPROC_MSG "attempt to overstep process limit by " DEFAULTSECMSG
32
#define GR_EXEC_ACL_MSG "%s execution of %.950s by " DEFAULTSECMSG
33
#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by " DEFAULTSECMSG
34
#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " Banning uid %u from login for %lu seconds"
35
#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " Banning execution of [%.16s:%lu] for %lu seconds"
36
#define GR_MOUNT_CHROOT_MSG "denied attempt to mount %.30s as %.930s from chroot by " DEFAULTSECMSG
37
#define GR_PIVOT_CHROOT_MSG "denied attempt to pivot_root from chroot by " DEFAULTSECMSG
38
#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by " DEFAULTSECMSG
39
#define GR_ATIME_ACL_MSG "%s access time change of %.950s by " DEFAULTSECMSG
40
#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by " DEFAULTSECMSG
41
#define GR_CHROOT_CHROOT_MSG "denied attempt to double chroot to %.950s by " DEFAULTSECMSG
42
#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by " DEFAULTSECMSG
43
#define GR_CHMOD_CHROOT_MSG "denied attempt to chmod +s %.950s by " DEFAULTSECMSG
44
#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by " DEFAULTSECMSG
45
#define GR_CHROOT_FCHDIR_MSG "attempted fchdir outside of chroot to %.950s by " DEFAULTSECMSG
46
#define GR_CHOWN_ACL_MSG "%s chown of %.950s by " DEFAULTSECMSG
47
#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by " DEFAULTSECMSG
48
#define GR_INITF_ACL_MSG "init_variables() failed %s"
49
#define GR_DISABLED_ACL_MSG "Error loading %s, trying to run kernel with acls disabled. To disable acls at startup use <kernel image name> gracl=off from your boot loader"
50
#define GR_DEV_ACL_MSG "/dev/grsec: being fed garbage %d bytes sent %d required"
51
#define GR_SHUTS_ACL_MSG "shutdown auth success for " DEFAULTSECMSG
52
#define GR_SHUTF_ACL_MSG "shutdown auth failure for " DEFAULTSECMSG
53
#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for " DEFAULTSECMSG
54
#define GR_SEGVMODS_ACL_MSG "segvmod auth success for " DEFAULTSECMSG
55
#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for " DEFAULTSECMSG
56
#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for " DEFAULTSECMSG
57
#define GR_ENABLE_ACL_MSG "Loaded %s"
58
#define GR_ENABLEF_ACL_MSG "Unable to load %s for " DEFAULTSECMSG " RBAC system may already be enabled."
59
#define GR_RELOADI_ACL_MSG "Ignoring reload request for disabled RBAC system"
60
#define GR_RELOAD_ACL_MSG "Reloaded %s"
61
#define GR_RELOADF_ACL_MSG "Failed reload of %s for " DEFAULTSECMSG
62
#define GR_SPROLEI_ACL_MSG "Ignoring change to special role for disabled RBAC system for " DEFAULTSECMSG
63
#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by " DEFAULTSECMSG
64
#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by " DEFAULTSECMSG
65
#define GR_SPROLEF_ACL_MSG "special role %s failure for " DEFAULTSECMSG
66
#define GR_UNSPROLEI_ACL_MSG "Ignoring unauth of special role for disabled RBAC system for " DEFAULTSECMSG
67
#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by " DEFAULTSECMSG
68
#define GR_UNSPROLEF_ACL_MSG "special role unauth of %s failure for " DEFAULTSECMSG
69
#define GR_INVMODE_ACL_MSG "Invalid mode %d by " DEFAULTSECMSG
70
#define GR_MAXPW_ACL_MSG "Maximum pw attempts reached (%d), locking password authentication"
71
#define GR_MAXROLEPW_ACL_MSG "Maximum pw attempts reached (%d) trying to auth to special role %s, locking auth for role of " DEFAULTSECMSG
72
#define GR_PRIORITY_CHROOT_MSG "attempted priority change of process (%.16s:%d) by " DEFAULTSECMSG
73
#define GR_CAPSET_CHROOT_MSG "denied capset of (%.16s:%d) within chroot by " DEFAULTSECMSG
74
#define GR_FAILFORK_MSG "failed fork with errno %d by " DEFAULTSECMSG
75
#define GR_NICE_CHROOT_MSG "attempted priority change by " DEFAULTSECMSG
76
#define GR_UNISIGLOG_MSG "signal %d sent to " DEFAULTSECMSG
77
#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by " DEFAULTSECMSG
78
#define GR_SIG_ACL_MSG "Attempted send of signal %d to protected task " DEFAULTSECMSG " by " DEFAULTSECMSG
79
#define GR_SYSCTL_MSG "attempt to modify grsecurity sysctl value : %.32s by " DEFAULTSECMSG
80
#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by " DEFAULTSECMSG
81
#define GR_TIME_MSG "time set by " DEFAULTSECMSG
82
#define GR_DEFACL_MSG "Fatal: Unable to find ACL for (%.16s:%d)"
83
#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by " DEFAULTSECMSG
84
#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by " DEFAULTSECMSG
85
#define GR_SOCK_MSG "attempted socket(%.16s,%.16s,%.16s) by " DEFAULTSECMSG
86
#define GR_BIND_MSG "attempted bind() by " DEFAULTSECMSG
87
#define GR_CONNECT_MSG "attempted connect by " DEFAULTSECMSG
88
#define GR_BIND_ACL_MSG "attempted bind to %u.%u.%u.%u port %u sock type %.16s protocol %.16s by " DEFAULTSECMSG
89
#define GR_CONNECT_ACL_MSG "attempted connect to %u.%u.%u.%u port %u sock type %.16s protocol %.16s by " DEFAULTSECMSG
90
#define GR_IP_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%u.%u.%u.%u\t%u\t%u\t%u\t%u\t%u.%u.%u.%u"
91
#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process " DEFAULTSECMSG
92
#define GR_CAP_ACL_MSG "use of %s denied for " DEFAULTSECMSG
93
#define GR_REMOUNT_AUDIT_MSG "remount of %.30s by " DEFAULTSECMSG
94
#define GR_UNMOUNT_AUDIT_MSG "unmount of %.30s by " DEFAULTSECMSG
95
#define GR_MOUNT_AUDIT_MSG "mount %.30s to %.64s by " DEFAULTSECMSG
96
#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by " DEFAULTSECMSG
97
#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.63s) by " DEFAULTSECMSG
98
#define GR_MSGQ_AUDIT_MSG "message queue created by " DEFAULTSECMSG
99
#define GR_MSGQR_AUDIT_MSG "message queue of uid:%d euid:%d removed by " DEFAULTSECMSG
100
#define GR_SEM_AUDIT_MSG "semaphore created by " DEFAULTSECMSG
101
#define GR_SEMR_AUDIT_MSG "semaphore of uid:%d euid:%d removed by " DEFAULTSECMSG
102
#define GR_SHM_AUDIT_MSG "shared memory of size %d created by " DEFAULTSECMSG
103
#define GR_SHMR_AUDIT_MSG "shared memory of uid:%d euid:%d removed by " DEFAULTSECMSG
104
#define GR_RESOURCE_MSG "attempted resource overstep by requesting %lu for %.16s against limit %lu by " DEFAULTSECMSG
(-)linux-2.4.22-ppc-dev.orig/include/linux/grsecurity.h (+174 lines)
Line 0 Link Here
1
#ifndef GR_SECURITY_H
2
#define GR_SECURITY_H
3
4
extern int gr_pid_is_chrooted(const struct task_struct *p);
5
extern int gr_handle_chroot_nice(void);
6
extern int gr_handle_chroot_sysctl(const int op);
7
extern int gr_handle_chroot_capset(const struct task_struct *target);
8
extern int gr_handle_chroot_setpriority(const struct task_struct *p,
9
					const int niceval);
10
extern int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
11
extern int gr_handle_chroot_chroot(const struct dentry *dentry,
12
				   const struct vfsmount *mnt);
13
extern void gr_handle_chroot_caps(struct task_struct *task);
14
extern void gr_handle_chroot_chdir(struct dentry *dentry, struct vfsmount *mnt);
15
extern int gr_handle_chroot_chmod(const struct dentry *dentry,
16
				  const struct vfsmount *mnt, const int mode);
17
extern int gr_handle_chroot_mknod(const struct dentry *dentry,
18
				  const struct vfsmount *mnt, const int mode);
19
extern int gr_handle_chroot_mount(const struct dentry *dentry,
20
				  const struct vfsmount *mnt,
21
				  const char *dev_name);
22
extern int gr_handle_chroot_pivot(void);
23
extern int gr_handle_chroot_unix(const pid_t pid);
24
25
extern int gr_handle_rawio(const struct inode *inode);
26
extern int gr_handle_nproc(void);
27
28
extern void gr_handle_ioperm(void);
29
extern void gr_handle_iopl(void);
30
31
extern int gr_tpe_allow(const struct file *file);
32
33
extern int gr_random_pid(spinlock_t * pid_lock);
34
35
extern void gr_log_forkfail(const int retval);
36
extern void gr_log_timechange(void);
37
extern void gr_log_signal(const int sig, const struct task_struct *t);
38
extern void gr_log_chdir(const struct dentry *dentry,
39
			 const struct vfsmount *mnt);
40
extern void gr_log_chroot_exec(const struct dentry *dentry,
41
			       const struct vfsmount *mnt);
42
extern void gr_handle_exec_args(struct linux_binprm *bprm, char **argv);
43
extern void gr_log_remount(const char *devname, const int retval);
44
extern void gr_log_unmount(const char *devname, const int retval);
45
extern void gr_log_mount(const char *from, const char *to, const int retval);
46
extern void gr_log_msgget(const int ret, const int msgflg);
47
extern void gr_log_msgrm(const uid_t uid, const uid_t cuid);
48
extern void gr_log_semget(const int err, const int semflg);
49
extern void gr_log_semrm(const uid_t uid, const uid_t cuid);
50
extern void gr_log_shmget(const int err, const int shmflg, const size_t size);
51
extern void gr_log_shmrm(const uid_t uid, const uid_t cuid);
52
53
extern int gr_handle_follow_link(const struct inode *parent,
54
				 const struct inode *inode,
55
				 const struct dentry *dentry,
56
				 const struct vfsmount *mnt);
57
extern int gr_handle_fifo(const struct dentry *dentry,
58
			  const struct vfsmount *mnt,
59
			  const struct dentry *dir, const int flag,
60
			  const int acc_mode);
61
extern int gr_handle_hardlink(const struct dentry *dentry,
62
			      const struct vfsmount *mnt,
63
			      struct inode *inode,
64
			      const int mode, const char *to);
65
66
extern int gr_is_capable(const int cap);
67
extern void gr_learn_resource(const struct task_struct *task, const int limit,
68
			      const unsigned long wanted);
69
extern void gr_copy_label(struct task_struct *tsk);
70
extern void gr_handle_crash(struct task_struct *task, const int sig);
71
extern int gr_handle_signal(const struct task_struct *p, const int sig);
72
extern int gr_check_crash_uid(const uid_t uid);
73
extern int gr_check_protected_task(const struct task_struct *task);
74
extern int gr_acl_handle_mmap(const struct file *file,
75
			      const unsigned long prot);
76
extern int gr_acl_handle_mprotect(const struct file *file,
77
				  const unsigned long prot);
78
extern int gr_check_hidden_task(const struct task_struct *tsk);
79
extern __u32 gr_acl_handle_truncate(const struct dentry *dentry,
80
				    const struct vfsmount *mnt);
81
extern __u32 gr_acl_handle_utime(const struct dentry *dentry,
82
				 const struct vfsmount *mnt);
83
extern __u32 gr_acl_handle_access(const struct dentry *dentry,
84
				  const struct vfsmount *mnt, const int fmode);
85
extern __u32 gr_acl_handle_fchmod(const struct dentry *dentry,
86
				  const struct vfsmount *mnt, mode_t mode);
87
extern __u32 gr_acl_handle_chmod(const struct dentry *dentry,
88
				 const struct vfsmount *mnt, mode_t mode);
89
extern __u32 gr_acl_handle_chown(const struct dentry *dentry,
90
				 const struct vfsmount *mnt);
91
extern int gr_handle_ptrace_exec(const struct dentry *dentry,
92
				 const struct vfsmount *mnt);
93
extern int gr_handle_ptrace(struct task_struct *task, const long request);
94
extern int gr_handle_mmap(const struct file *filp, const unsigned long prot);
95
extern __u32 gr_acl_handle_execve(const struct dentry *dentry,
96
				  const struct vfsmount *mnt);
97
extern int gr_check_crash_exec(const struct file *filp);
98
extern int gr_acl_is_enabled(void);
99
extern void gr_set_kernel_label(struct task_struct *task);
100
extern void gr_set_role_label(struct task_struct *task, const uid_t uid,
101
			      const gid_t gid);
102
extern void gr_set_proc_label(const struct dentry *dentry,
103
			      const struct vfsmount *mnt);
104
extern __u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
105
				       const struct vfsmount *mnt);
106
extern __u32 gr_acl_handle_open(const struct dentry *dentry,
107
				const struct vfsmount *mnt, const int fmode);
108
extern __u32 gr_acl_handle_creat(const struct dentry *dentry,
109
				 const struct dentry *p_dentry,
110
				 const struct vfsmount *p_mnt, const int fmode,
111
				 const int imode);
112
extern void gr_handle_create(const struct dentry *dentry,
113
			     const struct vfsmount *mnt);
114
extern __u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
115
				 const struct dentry *parent_dentry,
116
				 const struct vfsmount *parent_mnt,
117
				 const int mode);
118
extern __u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
119
				 const struct dentry *parent_dentry,
120
				 const struct vfsmount *parent_mnt);
121
extern __u32 gr_acl_handle_rmdir(const struct dentry *dentry,
122
				 const struct vfsmount *mnt);
123
extern void gr_handle_delete(const ino_t ino, const kdev_t dev);
124
extern __u32 gr_acl_handle_unlink(const struct dentry *dentry,
125
				  const struct vfsmount *mnt);
126
extern __u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
127
				   const struct dentry *parent_dentry,
128
				   const struct vfsmount *parent_mnt,
129
				   const char *from);
130
extern __u32 gr_acl_handle_link(const struct dentry *new_dentry,
131
				const struct dentry *parent_dentry,
132
				const struct vfsmount *parent_mnt,
133
				const struct dentry *old_dentry,
134
				const struct vfsmount *old_mnt, const char *to);
135
extern int gr_acl_handle_rename(struct dentry *new_dentry,
136
				struct dentry *parent_dentry,
137
				const struct vfsmount *parent_mnt,
138
				struct dentry *old_dentry,
139
				struct inode *old_parent_inode,
140
				struct vfsmount *old_mnt, const char *newname);
141
extern __u32 gr_check_link(const struct dentry *new_dentry,
142
			   const struct dentry *parent_dentry,
143
			   const struct vfsmount *parent_mnt,
144
			   const struct dentry *old_dentry,
145
			   const struct vfsmount *old_mnt);
146
extern __u32 gr_acl_handle_filldir(const struct dentry *dentry,
147
				   const struct vfsmount *mnt, const ino_t ino);
148
extern __u32 gr_acl_handle_unix(const struct dentry *dentry,
149
				const struct vfsmount *mnt);
150
extern void gr_set_pax_flags(struct task_struct *task);
151
extern void gr_acl_handle_exit(void);
152
extern void gr_acl_handle_psacct(struct task_struct *task, const long code);
153
extern int gr_acl_handle_procpidmem(const struct task_struct *task);
154
extern __u32 gr_cap_rtnetlink(void);
155
156
#ifdef CONFIG_GRKERNSEC
157
extern void gr_handle_mem_write(void);
158
extern void gr_handle_kmem_write(void);
159
extern void gr_handle_open_port(void);
160
extern int gr_handle_mem_mmap(const unsigned long offset,
161
			      struct vm_area_struct *vma);
162
163
extern __u16 ip_randomid(void);
164
extern __u32 ip_randomisn(void);
165
extern unsigned long get_random_long(void);
166
167
extern int grsec_enable_dmesg;
168
extern int grsec_enable_randid;
169
extern int grsec_enable_randisn;
170
extern int grsec_enable_randsrc;
171
extern int grsec_enable_randrpc;
172
#endif
173
174
#endif
(-)linux-2.4.22-ppc-dev.orig/include/linux/kernel.h (-3 / +6 lines)
Lines 71-84 Link Here
71
extern long long simple_strtoll(const char *,char **,unsigned int);
71
extern long long simple_strtoll(const char *,char **,unsigned int);
72
extern int sprintf(char * buf, const char * fmt, ...)
72
extern int sprintf(char * buf, const char * fmt, ...)
73
	__attribute__ ((format (printf, 2, 3)));
73
	__attribute__ ((format (printf, 2, 3)));
74
extern int vsprintf(char *buf, const char *, va_list);
74
extern int vsprintf(char *buf, const char *, va_list)
75
	__attribute__ ((format (printf, 2, 0)));
75
extern int snprintf(char * buf, size_t size, const char * fmt, ...)
76
extern int snprintf(char * buf, size_t size, const char * fmt, ...)
76
	__attribute__ ((format (printf, 3, 4)));
77
	__attribute__ ((format (printf, 3, 4)));
77
extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
78
extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
79
	__attribute__ ((format (printf, 3, 0)));
78
80
79
extern int sscanf(const char *, const char *, ...)
81
extern int sscanf(const char *, const char *, ...)
80
	__attribute__ ((format (scanf,2,3)));
82
	__attribute__ ((format (scanf,2,3)));
81
extern int vsscanf(const char *, const char *, va_list);
83
extern int vsscanf(const char *, const char *, va_list)
84
	__attribute__ ((format (scanf, 2, 0)));
82
85
83
extern int get_option(char **str, int *pint);
86
extern int get_option(char **str, int *pint);
84
extern char *get_options(char *str, int nints, int *ints);
87
extern char *get_options(char *str, int nints, int *ints);
(-)linux-2.4.22-ppc-dev.orig/include/linux/mm.h (-8 / +115 lines)
Lines 22-30 Link Here
22
extern struct list_head active_list;
22
extern struct list_head active_list;
23
extern struct list_head inactive_list;
23
extern struct list_head inactive_list;
24
24
25
extern void gr_learn_resource(const struct task_struct * task, const int limit,
26
			      const unsigned long wanted);
27
25
#include <asm/page.h>
28
#include <asm/page.h>
26
#include <asm/pgtable.h>
29
#include <asm/pgtable.h>
27
#include <asm/atomic.h>
30
#include <asm/atomic.h>
31
#include <asm/mman.h>
28
32
29
/*
33
/*
30
 * Linux kernel virtual memory manager primitives.
34
 * Linux kernel virtual memory manager primitives.
Lines 104-109 Link Here
104
#define VM_DONTEXPAND	0x00040000	/* Cannot expand with mremap() */
108
#define VM_DONTEXPAND	0x00040000	/* Cannot expand with mremap() */
105
#define VM_RESERVED	0x00080000	/* Don't unmap it from swap_out */
109
#define VM_RESERVED	0x00080000	/* Don't unmap it from swap_out */
106
110
111
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
112
#define VM_MIRROR	0x00100000	/* vma is mirroring another */
113
#endif
114
115
#ifdef CONFIG_GRKERNSEC_PAX_MPROTECT
116
#define VM_MAYNOTWRITE	0x00200000	/* vma cannot be granted VM_WRITE any more */
117
#endif
118
119
#ifdef ARCH_STACK_GROWSUP
120
#define __VM_STACK_FLAGS	0x00000233
121
#else
122
#define __VM_STACK_FLAGS	0x00000133
123
#endif
124
125
#if defined(CONFIG_GRKERNSEC_PAX_PAGEEXEC) || defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC)
126
#ifdef CONFIG_GRKERNSEC_PAX_MPROTECT
127
#define VM_STACK_FLAGS	(__VM_STACK_FLAGS | \
128
			((current->flags & PF_PAX_MPROTECT)?0:VM_MAYEXEC) | \
129
			((current->flags & (PF_PAX_PAGEEXEC|PF_PAX_SEGMEXEC))?0:VM_EXEC))
130
#else
131
#define VM_STACK_FLAGS	(__VM_STACK_FLAGS | VM_MAYEXEC | \
132
			((current->flags & (PF_PAX_PAGEEXEC|PF_PAX_SEGMEXEC))?0:VM_EXEC))
133
#endif
134
#else
135
#define VM_STACK_FLAGS (__VM_STACK_FLAGS | VM_EXEC | VM_MAYEXEC)
136
#endif
137
107
#ifndef VM_STACK_FLAGS
138
#ifndef VM_STACK_FLAGS
108
#define VM_STACK_FLAGS	0x00000177
139
#define VM_STACK_FLAGS	0x00000177
109
#endif
140
#endif
Lines 554-574 Link Here
554
	unsigned long len, unsigned long prot,
585
	unsigned long len, unsigned long prot,
555
	unsigned long flag, unsigned long pgoff);
586
	unsigned long flag, unsigned long pgoff);
556
587
588
extern int do_munmap(struct mm_struct *, unsigned long, size_t);
589
557
static inline unsigned long do_mmap(struct file *file, unsigned long addr,
590
static inline unsigned long do_mmap(struct file *file, unsigned long addr,
558
	unsigned long len, unsigned long prot,
591
	unsigned long len, unsigned long prot,
559
	unsigned long flag, unsigned long offset)
592
	unsigned long flag, unsigned long offset)
560
{
593
{
561
	unsigned long ret = -EINVAL;
594
	unsigned long ret = -EINVAL;
595
596
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
597
	if ((current->flags & PF_PAX_SEGMEXEC) &&
598
	   (len > SEGMEXEC_TASK_SIZE || (addr && addr > SEGMEXEC_TASK_SIZE-len)))
599
		goto out;
600
#endif
601
562
	if ((offset + PAGE_ALIGN(len)) < offset)
602
	if ((offset + PAGE_ALIGN(len)) < offset)
563
		goto out;
603
		goto out;
564
	if (!(offset & ~PAGE_MASK))
604
	if (!(offset & ~PAGE_MASK))
565
		ret = do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
605
		ret = do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
606
607
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
608
#define BAD_ADDR(x)	((unsigned long)(x) > TASK_SIZE)
609
	if ((current->flags & PF_PAX_SEGMEXEC) && !BAD_ADDR(ret) &&
610
	    (prot & PROT_EXEC) && ((flag & MAP_TYPE) == MAP_PRIVATE)
611
612
#ifdef CONFIG_GRKERNSEC_PAX_MPROTECT
613
	    && (!(current->flags & PF_PAX_MPROTECT) || (file && !(prot & PROT_WRITE)))
614
#endif
615
	   )
616
	{
617
		unsigned long ret_m;
618
		ret_m = do_mmap_pgoff(NULL, ret + SEGMEXEC_TASK_SIZE, 0UL, prot, flag | MAP_MIRROR | MAP_FIXED, ret);
619
		if (BAD_ADDR(ret_m)) {
620
			do_munmap(current->mm, ret, len);
621
			ret = ret_m;
622
		}
623
	}
624
#undef BAD_ADDR
625
#endif
626
566
out:
627
out:
567
	return ret;
628
	return ret;
568
}
629
}
569
630
570
extern int do_munmap(struct mm_struct *, unsigned long, size_t);
571
572
extern unsigned long do_brk(unsigned long, unsigned long);
631
extern unsigned long do_brk(unsigned long, unsigned long);
573
632
574
static inline void __vma_unlink(struct mm_struct * mm, struct vm_area_struct * vma, struct vm_area_struct * prev)
633
static inline void __vma_unlink(struct mm_struct * mm, struct vm_area_struct * vma, struct vm_area_struct * prev)
Lines 581-586 Link Here
581
640
582
static inline int can_vma_merge(struct vm_area_struct * vma, unsigned long vm_flags)
641
static inline int can_vma_merge(struct vm_area_struct * vma, unsigned long vm_flags)
583
{
642
{
643
644
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
645
	if ((vma->vm_flags | vm_flags) & VM_MIRROR)
646
		return 0;
647
#endif
648
584
	if (!vma->vm_file && vma->vm_flags == vm_flags)
649
	if (!vma->vm_file && vma->vm_flags == vm_flags)
585
		return 1;
650
		return 1;
586
	else
651
	else
Lines 635-640 Link Here
635
	return gfp_mask;
700
	return gfp_mask;
636
}
701
}
637
702
703
/* Look up the first VMA which satisfies  addr < vm_end,  NULL if none. */
704
extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr);
705
extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
706
					     struct vm_area_struct **pprev);
707
708
638
extern int heap_stack_gap;
709
extern int heap_stack_gap;
639
710
640
/*
711
/*
Lines 665-673 Link Here
665
		goto out;
736
		goto out;
666
	spin_lock(&vma->vm_mm->page_table_lock);
737
	spin_lock(&vma->vm_mm->page_table_lock);
667
	grow = (vma->vm_start - address) >> PAGE_SHIFT;
738
	grow = (vma->vm_start - address) >> PAGE_SHIFT;
739
740
	gr_learn_resource(current, RLIMIT_STACK, vma->vm_end - address);
741
	gr_learn_resource(current, RLIMIT_AS, (vma->vm_mm->total_vm + grow) << PAGE_SHIFT);
742
	gr_learn_resource(current, RLIMIT_MEMLOCK, (vma->vm_mm->locked_vm + grow) << PAGE_SHIFT);
743
744
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
745
	if (vma->vm_flags & VM_MIRROR) {
746
		struct vm_area_struct * vma_m;
747
		unsigned long address_m;
748
749
		address_m = vma->vm_start + (unsigned long)vma->vm_private_data;
750
		vma_m = find_vma(vma->vm_mm, address_m);
751
		if (!vma_m || vma_m->vm_start != address_m || !(vma_m->vm_flags & VM_MIRROR) ||
752
		    vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start) {
753
			spin_unlock(&vma->vm_mm->page_table_lock);
754
			printk(KERN_ERR "PAX: VMMIRROR: expand bug, %08lx, %08lx, %08lx, %08lx, %08lx\n",
755
			       address, vma->vm_start, vma_m->vm_start, vma->vm_end, vma_m->vm_end);
756
			return -ENOMEM;
757
		}
758
759
		address_m = address + (unsigned long)vma->vm_private_data;
760
		if (vma_m->vm_end - address_m > current->rlim[RLIMIT_STACK].rlim_cur ||
761
		    ((vma_m->vm_mm->total_vm + 2*grow) << PAGE_SHIFT) > current->rlim[RLIMIT_AS].rlim_cur ||
762
		    ((vma_m->vm_flags & VM_LOCKED) && ((vma_m->vm_mm->locked_vm + 2*grow) << PAGE_SHIFT) >
763
		     current->rlim[RLIMIT_MEMLOCK].rlim_cur)) {
764
			spin_unlock(&vma->vm_mm->page_table_lock);
765
			return -ENOMEM;
766
		}
767
768
		vma_m->vm_start = address_m;
769
		vma_m->vm_pgoff -= grow;
770
		vma_m->vm_mm->total_vm += grow;
771
		if (vma_m->vm_flags & VM_LOCKED)
772
			vma_m->vm_mm->locked_vm += grow;
773
	} else
774
#endif
775
668
	if (vma->vm_end - address > current->rlim[RLIMIT_STACK].rlim_cur ||
776
	if (vma->vm_end - address > current->rlim[RLIMIT_STACK].rlim_cur ||
669
	    ((vma->vm_mm->total_vm + grow) << PAGE_SHIFT) > current->rlim[RLIMIT_AS].rlim_cur)
777
	    ((vma->vm_mm->total_vm + grow) << PAGE_SHIFT) > current->rlim[RLIMIT_AS].rlim_cur ||
778
	    ((vma->vm_flags & VM_LOCKED) && ((vma->vm_mm->locked_vm + grow) << PAGE_SHIFT) >
779
	     current->rlim[RLIMIT_MEMLOCK].rlim_cur)) {
670
		goto out_unlock;
780
		goto out_unlock;
781
	}
782
671
	vma->vm_start = address;
783
	vma->vm_start = address;
672
	vma->vm_pgoff -= grow;
784
	vma->vm_pgoff -= grow;
673
	vma->vm_mm->total_vm += grow;
785
	vma->vm_mm->total_vm += grow;
Lines 680-690 Link Here
680
	return err;
792
	return err;
681
}
793
}
682
794
683
/* Look up the first VMA which satisfies  addr < vm_end,  NULL if none. */
684
extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr);
685
extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
686
					     struct vm_area_struct **pprev);
687
688
/* Look up the first VMA which intersects the interval start_addr..end_addr-1,
795
/* Look up the first VMA which intersects the interval start_addr..end_addr-1,
689
   NULL if none.  Assume start_addr < end_addr. */
796
   NULL if none.  Assume start_addr < end_addr. */
690
static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
797
static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
(-)linux-2.4.22-ppc-dev.orig/include/linux/proc_fs.h (+3 lines)
Lines 143-148 Link Here
143
extern struct proc_dir_entry *proc_mknod(const char *,mode_t,
143
extern struct proc_dir_entry *proc_mknod(const char *,mode_t,
144
		struct proc_dir_entry *,kdev_t);
144
		struct proc_dir_entry *,kdev_t);
145
extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
145
extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
146
#ifdef CONFIG_GRKERNSEC_PROC
147
extern struct proc_dir_entry *proc_priv_mkdir(const char *, struct proc_dir_entry *);
148
#endif
146
149
147
static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
150
static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
148
	mode_t mode, struct proc_dir_entry *base, 
151
	mode_t mode, struct proc_dir_entry *base, 
(-)linux-2.4.22-ppc-dev.orig/include/linux/sched.h (-4 / +43 lines)
Lines 27-32 Link Here
27
#include <linux/securebits.h>
27
#include <linux/securebits.h>
28
#include <linux/fs_struct.h>
28
#include <linux/fs_struct.h>
29
29
30
extern int gr_is_capable(const int cap);
31
extern int gr_pid_is_chrooted(const struct task_struct *p);
32
30
struct exec_domain;
33
struct exec_domain;
31
34
32
/*
35
/*
Lines 227-232 Link Here
227
	unsigned long cpu_vm_mask;
230
	unsigned long cpu_vm_mask;
228
	unsigned long swap_address;
231
	unsigned long swap_address;
229
232
233
#ifdef CONFIG_GRKERNSEC_PAX_DLRESOLVE
234
	unsigned long call_dl_resolve;
235
#endif
236
237
#if defined(CONFIG_PPC32) && defined(CONFIG_GRKERNSEC_PAX_EMUSIGRT)
238
	unsigned long call_syscall;
239
#endif
240
241
#ifdef CONFIG_GRKERNSEC_PAX_ASLR
242
	unsigned long delta_mmap;		/* PaX: randomized offset */
243
	unsigned long delta_exec;		/* PaX: randomized offset */
244
	unsigned long delta_stack;		/* PaX: randomized offset */
245
#endif
246
 
230
	unsigned dumpable:1;
247
	unsigned dumpable:1;
231
248
232
	/* Architecture-specific MM context */
249
	/* Architecture-specific MM context */
Lines 406-412 Link Here
406
	int (*notifier)(void *priv);
423
	int (*notifier)(void *priv);
407
	void *notifier_data;
424
	void *notifier_data;
408
	sigset_t *notifier_mask;
425
	sigset_t *notifier_mask;
409
	
426
410
/* Thread group tracking */
427
/* Thread group tracking */
411
   	u32 parent_exec_id;
428
   	u32 parent_exec_id;
412
   	u32 self_exec_id;
429
   	u32 self_exec_id;
Lines 415-420 Link Here
415
432
416
/* journalling filesystem info */
433
/* journalling filesystem info */
417
	void *journal_info;
434
	void *journal_info;
435
436
#ifdef CONFIG_GRKERNSEC
437
/* added by grsecurity's ACL system */	
438
	struct acl_subject_label *acl;
439
	struct acl_role_label *role;
440
	struct file *exec_file;
441
	u32 curr_ip;
442
	u16 acl_role_id;	
443
	u8 acl_sp_role:1;	
444
	u8 used_accept:1;	
445
	u8 used_connect:1;	
446
	u8 is_writable:1;
447
#endif
418
};
448
};
419
449
420
/*
450
/*
Lines 435-440 Link Here
435
465
436
#define PF_USEDFPU	0x00100000	/* task used FPU this quantum (SMP) */
466
#define PF_USEDFPU	0x00100000	/* task used FPU this quantum (SMP) */
437
467
468
#define PF_PAX_PAGEEXEC       0x01000000      /* Paging based non-executable pages */
469
#define PF_PAX_EMUTRAMP       0x02000000      /* Emulate trampolines */
470
#define PF_PAX_MPROTECT       0x04000000      /* Restrict mprotect() */
471
#define PF_PAX_RANDMMAP       0x08000000      /* Randomize mmap() base */
472
#define PF_PAX_RANDEXEC	      0x10000000      /* Randomize ET_EXEC base */
473
#define PF_PAX_SEGMEXEC	      0x20000000      /* Segmentation based non-executable pages */
474
438
/*
475
/*
439
 * Ptrace flags
476
 * Ptrace flags
440
 */
477
 */
Lines 549-554 Link Here
549
	*p->pidhash_pprev = p->pidhash_next;
586
	*p->pidhash_pprev = p->pidhash_next;
550
}
587
}
551
588
589
#include <asm/current.h>
590
552
static inline struct task_struct *find_task_by_pid(int pid)
591
static inline struct task_struct *find_task_by_pid(int pid)
553
{
592
{
554
	struct task_struct *p, **htable = &pidhash[pid_hashfn(pid)];
593
	struct task_struct *p, **htable = &pidhash[pid_hashfn(pid)];
Lines 556-561 Link Here
556
	for(p = *htable; p && p->pid != pid; p = p->pidhash_next)
595
	for(p = *htable; p && p->pid != pid; p = p->pidhash_next)
557
		;
596
		;
558
597
598
	if(gr_pid_is_chrooted(p)) p = NULL;
599
559
	return p;
600
	return p;
560
}
601
}
561
602
Lines 576-583 Link Here
576
extern struct user_struct * alloc_uid(uid_t);
617
extern struct user_struct * alloc_uid(uid_t);
577
extern void free_uid(struct user_struct *);
618
extern void free_uid(struct user_struct *);
578
619
579
#include <asm/current.h>
580
581
extern unsigned long volatile jiffies;
620
extern unsigned long volatile jiffies;
582
extern unsigned long itimer_ticks;
621
extern unsigned long itimer_ticks;
583
extern unsigned long itimer_next;
622
extern unsigned long itimer_next;
Lines 741-747 Link Here
741
static inline int capable(int cap)
780
static inline int capable(int cap)
742
{
781
{
743
#if 1 /* ok now */
782
#if 1 /* ok now */
744
	if (cap_raised(current->cap_effective, cap))
783
	if (cap_raised(current->cap_effective, cap) && gr_is_capable(cap))
745
#else
784
#else
746
	if (cap_is_fs_cap(cap) ? current->fsuid == 0 : current->euid == 0)
785
	if (cap_is_fs_cap(cap) ? current->fsuid == 0 : current->euid == 0)
747
#endif
786
#endif
(-)linux-2.4.22-ppc-dev.orig/include/linux/sysctl.h (+1 lines)
Lines 127-132 Link Here
127
 	KERN_CORE_PATTERN=56,	/* string: pattern for core-files */
127
 	KERN_CORE_PATTERN=56,	/* string: pattern for core-files */
128
	KERN_PPC_L3CR=57,       /* l3cr register on PPC */
128
	KERN_PPC_L3CR=57,       /* l3cr register on PPC */
129
	KERN_EXCEPTION_TRACE=58, /* boolean: exception trace */
129
	KERN_EXCEPTION_TRACE=58, /* boolean: exception trace */
130
	KERN_GRSECURITY=68,	/* grsecurity */
130
};
131
};
131
132
132
133
(-)linux-2.4.22-ppc-dev.orig/include/net/inetpeer.h (-1 / +14 lines)
Lines 13-18 Link Here
13
#include <linux/init.h>
13
#include <linux/init.h>
14
#include <linux/sched.h>
14
#include <linux/sched.h>
15
#include <linux/spinlock.h>
15
#include <linux/spinlock.h>
16
16
#include <asm/atomic.h>
17
#include <asm/atomic.h>
17
18
18
struct inet_peer
19
struct inet_peer
Lines 34-39 Link Here
34
/* can be called with or without local BH being disabled */
35
/* can be called with or without local BH being disabled */
35
struct inet_peer	*inet_getpeer(__u32 daddr, int create);
36
struct inet_peer	*inet_getpeer(__u32 daddr, int create);
36
37
38
#ifdef CONFIG_GRKERNSEC_RANDID
39
extern int grsec_enable_randid;
40
extern __u16 ip_randomid(void);
41
#endif
42
37
extern spinlock_t inet_peer_unused_lock;
43
extern spinlock_t inet_peer_unused_lock;
38
extern struct inet_peer *inet_peer_unused_head;
44
extern struct inet_peer *inet_peer_unused_head;
39
extern struct inet_peer **inet_peer_unused_tailp;
45
extern struct inet_peer **inet_peer_unused_tailp;
Lines 58-64 Link Here
58
	__u16 id;
64
	__u16 id;
59
65
60
	spin_lock_bh(&inet_peer_idlock);
66
	spin_lock_bh(&inet_peer_idlock);
61
	id = p->ip_id_count++;
67
68
#ifdef CONFIG_GRKERNSEC_RANDID
69
	if(grsec_enable_randid)
70
		id = htons(ip_randomid());
71
	else
72
#endif
73
		id = p->ip_id_count++;
74
62
	spin_unlock_bh(&inet_peer_idlock);
75
	spin_unlock_bh(&inet_peer_idlock);
63
	return id;
76
	return id;
64
}
77
}
(-)linux-2.4.22-ppc-dev.orig/include/net/ip.h (-1 / +12 lines)
Lines 64-69 Link Here
64
	void			(*destructor)(struct sock *);
64
	void			(*destructor)(struct sock *);
65
};
65
};
66
66
67
#ifdef CONFIG_GRKERNSEC_RANDID
68
extern int grsec_enable_randid;
69
extern __u16 ip_randomid(void);
70
#endif
71
67
extern struct ip_ra_chain *ip_ra_chain;
72
extern struct ip_ra_chain *ip_ra_chain;
68
extern rwlock_t ip_ra_lock;
73
extern rwlock_t ip_ra_lock;
69
74
Lines 197-203 Link Here
197
		 * does not change, they drop every other packet in
202
		 * does not change, they drop every other packet in
198
		 * a TCP stream using header compression.
203
		 * a TCP stream using header compression.
199
		 */
204
		 */
200
		iph->id = ((sk && sk->daddr) ? htons(sk->protinfo.af_inet.id++) : 0);
205
206
#ifdef CONFIG_GRKERNSEC_RANDID
207
		if(grsec_enable_randid)
208
			iph->id = htons(ip_randomid());
209
		else
210
#endif
211
			iph->id = ((sk && sk->daddr) ? htons(sk->protinfo.af_inet.id++) : 0);
201
	} else
212
	} else
202
		__ip_select_ident(iph, dst);
213
		__ip_select_ident(iph, dst);
203
}
214
}
(-)linux-2.4.22-ppc-dev.orig/init/main.c (+4 lines)
Lines 27-32 Link Here
27
#include <linux/iobuf.h>
27
#include <linux/iobuf.h>
28
#include <linux/bootmem.h>
28
#include <linux/bootmem.h>
29
#include <linux/tty.h>
29
#include <linux/tty.h>
30
#include <linux/grsecurity.h>
30
31
31
#include <asm/io.h>
32
#include <asm/io.h>
32
#include <asm/bugs.h>
33
#include <asm/bugs.h>
Lines 111-116 Link Here
111
extern void ipc_init(void);
112
extern void ipc_init(void);
112
#endif
113
#endif
113
114
115
extern void grsecurity_init(void);
116
114
/*
117
/*
115
 * Boot command-line arguments
118
 * Boot command-line arguments
116
 */
119
 */
Lines 552-557 Link Here
552
	do_basic_setup();
555
	do_basic_setup();
553
556
554
	prepare_namespace();
557
	prepare_namespace();
558
	grsecurity_init();
555
559
556
	/*
560
	/*
557
	 * Ok, we have completed the initial bootup, and
561
	 * Ok, we have completed the initial bootup, and
(-)linux-2.4.22-ppc-dev.orig/ipc/msg.c (+6 lines)
Lines 22-27 Link Here
22
#include <linux/init.h>
22
#include <linux/init.h>
23
#include <linux/proc_fs.h>
23
#include <linux/proc_fs.h>
24
#include <linux/list.h>
24
#include <linux/list.h>
25
#include <linux/grsecurity.h>
25
#include <asm/uaccess.h>
26
#include <asm/uaccess.h>
26
#include "util.h"
27
#include "util.h"
27
28
Lines 326-331 Link Here
326
		msg_unlock(id);
327
		msg_unlock(id);
327
	}
328
	}
328
	up(&msg_ids.sem);
329
	up(&msg_ids.sem);
330
331
	gr_log_msgget(ret, msgflg);
332
329
	return ret;
333
	return ret;
330
}
334
}
331
335
Lines 560-565 Link Here
560
		break;
564
		break;
561
	}
565
	}
562
	case IPC_RMID:
566
	case IPC_RMID:
567
		gr_log_msgrm(ipcp->uid, ipcp->cuid);
568
563
		freeque (msqid); 
569
		freeque (msqid); 
564
		break;
570
		break;
565
	}
571
	}
(-)linux-2.4.22-ppc-dev.orig/ipc/sem.c (+6 lines)
Lines 63-68 Link Here
63
#include <linux/init.h>
63
#include <linux/init.h>
64
#include <linux/proc_fs.h>
64
#include <linux/proc_fs.h>
65
#include <linux/time.h>
65
#include <linux/time.h>
66
#include <linux/grsecurity.h>
66
#include <asm/uaccess.h>
67
#include <asm/uaccess.h>
67
#include "util.h"
68
#include "util.h"
68
69
Lines 182-187 Link Here
182
	}
183
	}
183
184
184
	up(&sem_ids.sem);
185
	up(&sem_ids.sem);
186
187
	gr_log_semget(err, semflg);
188
185
	return err;
189
	return err;
186
}
190
}
187
191
Lines 724-729 Link Here
724
728
725
	switch(cmd){
729
	switch(cmd){
726
	case IPC_RMID:
730
	case IPC_RMID:
731
		gr_log_semrm(ipcp->uid, ipcp->cuid);
732
727
		freeary(semid);
733
		freeary(semid);
728
		err = 0;
734
		err = 0;
729
		break;
735
		break;
(-)linux-2.4.22-ppc-dev.orig/ipc/shm.c (+42 lines)
Lines 23-28 Link Here
23
#include <linux/mman.h>
23
#include <linux/mman.h>
24
#include <linux/proc_fs.h>
24
#include <linux/proc_fs.h>
25
#include <asm/uaccess.h>
25
#include <asm/uaccess.h>
26
#include <linux/grsecurity.h>
26
27
27
#include "util.h"
28
#include "util.h"
28
29
Lines 38-45 Link Here
38
	time_t			shm_ctim;
39
	time_t			shm_ctim;
39
	pid_t			shm_cprid;
40
	pid_t			shm_cprid;
40
	pid_t			shm_lprid;
41
	pid_t			shm_lprid;
42
43
#ifdef CONFIG_GRKERNSEC
44
	time_t			shm_createtime;
45
	pid_t			shm_lapid;
46
#endif
41
};
47
};
42
48
49
#ifdef CONFIG_GRKERNSEC
50
extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
51
        	            const time_t shm_createtime, const uid_t cuid,
52
                	    const int shmid);
53
extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
54
                    const time_t shm_createtime);
55
#endif
56
43
#define shm_flags	shm_perm.mode
57
#define shm_flags	shm_perm.mode
44
58
45
static struct file_operations shm_file_operations;
59
static struct file_operations shm_file_operations;
Lines 209-214 Link Here
209
	shp->shm_lprid = 0;
223
	shp->shm_lprid = 0;
210
	shp->shm_atim = shp->shm_dtim = 0;
224
	shp->shm_atim = shp->shm_dtim = 0;
211
	shp->shm_ctim = CURRENT_TIME;
225
	shp->shm_ctim = CURRENT_TIME;
226
#ifdef CONFIG_GRKERNSEC
227
	shp->shm_createtime = CURRENT_TIME;
228
#endif
212
	shp->shm_segsz = size;
229
	shp->shm_segsz = size;
213
	shp->shm_nattch = 0;
230
	shp->shm_nattch = 0;
214
	shp->id = shm_buildid(id,shp->shm_perm.seq);
231
	shp->id = shm_buildid(id,shp->shm_perm.seq);
Lines 254-259 Link Here
254
		shm_unlock(id);
271
		shm_unlock(id);
255
	}
272
	}
256
	up(&shm_ids.sem);
273
	up(&shm_ids.sem);
274
275
	gr_log_shmget(err, shmflg, size);
276
257
	return err;
277
	return err;
258
}
278
}
259
279
Lines 509-514 Link Here
509
			err=-EPERM;
529
			err=-EPERM;
510
			goto out_unlock_up;
530
			goto out_unlock_up;
511
		}
531
		}
532
533
		gr_log_shmrm(shp->shm_perm.uid, shp->shm_perm.cuid);
534
512
		if (shp->shm_nattch){
535
		if (shp->shm_nattch){
513
			shp->shm_flags |= SHM_DEST;
536
			shp->shm_flags |= SHM_DEST;
514
			/* Do not find it any more */
537
			/* Do not find it any more */
Lines 622-630 Link Here
622
		shm_unlock(shmid);
645
		shm_unlock(shmid);
623
		return -EACCES;
646
		return -EACCES;
624
	}
647
	}
648
649
#ifdef CONFIG_GRKERNSEC
650
	if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
651
			     shp->shm_perm.cuid, shmid)) {
652
		shm_unlock(shmid);
653
		return -EACCES;
654
	}
655
656
	if (!gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
657
		shm_unlock(shmid);
658
		return -EACCES;
659
	}
660
#endif
661
625
	file = shp->shm_file;
662
	file = shp->shm_file;
626
	size = file->f_dentry->d_inode->i_size;
663
	size = file->f_dentry->d_inode->i_size;
627
	shp->shm_nattch++;
664
	shp->shm_nattch++;
665
666
#ifdef CONFIG_GRKERNSEC
667
	shp->shm_lapid = current->pid;
668
#endif
669
628
	shm_unlock(shmid);
670
	shm_unlock(shmid);
629
671
630
	down_write(&current->mm->mmap_sem);
672
	down_write(&current->mm->mmap_sem);
(-)linux-2.4.22-ppc-dev.orig/kernel/capability.c (+5 lines)
Lines 7-12 Link Here
7
7
8
#include <linux/mm.h>
8
#include <linux/mm.h>
9
#include <asm/uaccess.h>
9
#include <asm/uaccess.h>
10
#include <linux/grsecurity.h>
10
11
11
kernel_cap_t cap_bset = CAP_INIT_EFF_SET;
12
kernel_cap_t cap_bset = CAP_INIT_EFF_SET;
12
13
Lines 168-173 Link Here
168
             target = current;
169
             target = current;
169
     }
170
     }
170
171
172
     if (gr_handle_chroot_capset(target)) {
173
	     error = -ESRCH;
174
	     goto out;
175
     }
171
176
172
     /* verify restrictions on target's new Inheritable set */
177
     /* verify restrictions on target's new Inheritable set */
173
     if (!cap_issubset(inheritable,
178
     if (!cap_issubset(inheritable,
(-)linux-2.4.22-ppc-dev.orig/kernel/exit.c (+5 lines)
Lines 16-21 Link Here
16
#ifdef CONFIG_BSD_PROCESS_ACCT
16
#ifdef CONFIG_BSD_PROCESS_ACCT
17
#include <linux/acct.h>
17
#include <linux/acct.h>
18
#endif
18
#endif
19
#include <linux/grsecurity.h>
19
20
20
#include <asm/uaccess.h>
21
#include <asm/uaccess.h>
21
#include <asm/pgtable.h>
22
#include <asm/pgtable.h>
Lines 439-444 Link Here
439
#ifdef CONFIG_BSD_PROCESS_ACCT
440
#ifdef CONFIG_BSD_PROCESS_ACCT
440
	acct_process(code);
441
	acct_process(code);
441
#endif
442
#endif
443
444
	gr_acl_handle_psacct(tsk, code);
445
	gr_acl_handle_exit();
446
442
	__exit_mm(tsk);
447
	__exit_mm(tsk);
443
448
444
	lock_kernel();
449
	lock_kernel();
(-)linux-2.4.22-ppc-dev.orig/kernel/fork.c (+12 lines)
Lines 22-27 Link Here
22
#include <linux/namespace.h>
22
#include <linux/namespace.h>
23
#include <linux/personality.h>
23
#include <linux/personality.h>
24
#include <linux/compiler.h>
24
#include <linux/compiler.h>
25
#include <linux/grsecurity.h>
25
26
26
#include <asm/pgtable.h>
27
#include <asm/pgtable.h>
27
#include <asm/pgalloc.h>
28
#include <asm/pgalloc.h>
Lines 93-98 Link Here
93
	if (flags & CLONE_PID)
94
	if (flags & CLONE_PID)
94
		return current->pid;
95
		return current->pid;
95
96
97
	pid = gr_random_pid(&lastpid_lock);
98
	if (pid)
99
		return pid;
100
96
	spin_lock(&lastpid_lock);
101
	spin_lock(&lastpid_lock);
97
	beginpid = last_pid;
102
	beginpid = last_pid;
98
	if((++last_pid) & 0xffff8000) {
103
	if((++last_pid) & 0xffff8000) {
Lines 667-672 Link Here
667
	 * friends to set the per-user process limit to something lower
672
	 * friends to set the per-user process limit to something lower
668
	 * than the amount of processes root is running. -- Rik
673
	 * than the amount of processes root is running. -- Rik
669
	 */
674
	 */
675
676
	gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->user->processes));
677
670
	if (atomic_read(&p->user->processes) >= p->rlim[RLIMIT_NPROC].rlim_cur
678
	if (atomic_read(&p->user->processes) >= p->rlim[RLIMIT_NPROC].rlim_cur
671
	              && !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE))
679
	              && !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE))
672
		goto bad_fork_free;
680
		goto bad_fork_free;
Lines 751-756 Link Here
751
	retval = copy_thread(0, clone_flags, stack_start, stack_size, p, regs);
759
	retval = copy_thread(0, clone_flags, stack_start, stack_size, p, regs);
752
	if (retval)
760
	if (retval)
753
		goto bad_fork_cleanup_namespace;
761
		goto bad_fork_cleanup_namespace;
762
	gr_copy_label(p);
754
	p->semundo = NULL;
763
	p->semundo = NULL;
755
	
764
	
756
	/* Our parent execution domain becomes current domain
765
	/* Our parent execution domain becomes current domain
Lines 836-841 Link Here
836
	free_uid(p->user);
845
	free_uid(p->user);
837
bad_fork_free:
846
bad_fork_free:
838
	free_task_struct(p);
847
	free_task_struct(p);
848
849
	gr_log_forkfail(retval);
850
839
	goto fork_out;
851
	goto fork_out;
840
}
852
}
841
853
(-)linux-2.4.22-ppc-dev.orig/kernel/ksyms.c (+7 lines)
Lines 49-54 Link Here
49
#include <linux/seq_file.h>
49
#include <linux/seq_file.h>
50
#include <linux/dnotify.h>
50
#include <linux/dnotify.h>
51
#include <linux/crc32.h>
51
#include <linux/crc32.h>
52
#include <linux/grsecurity.h>
52
#include <asm/checksum.h>
53
#include <asm/checksum.h>
53
54
54
#if defined(CONFIG_PROC_FS)
55
#if defined(CONFIG_PROC_FS)
Lines 600-602 Link Here
600
/* To match ksyms with System.map */
601
/* To match ksyms with System.map */
601
extern const char _end[];
602
extern const char _end[];
602
EXPORT_SYMBOL(_end);
603
EXPORT_SYMBOL(_end);
604
605
/* grsecurity */
606
EXPORT_SYMBOL(gr_is_capable);
607
EXPORT_SYMBOL(gr_pid_is_chrooted);
608
EXPORT_SYMBOL(gr_learn_resource);
609
EXPORT_SYMBOL(gr_set_kernel_label);
(-)linux-2.4.22-ppc-dev.orig/kernel/module.c (+10 lines)
Lines 900-905 Link Here
900
	struct module *mod;
900
	struct module *mod;
901
	int err;
901
	int err;
902
902
903
#ifdef CONFIG_GRKERNSEC_HIDESYM
904
	if (!capable(CAP_SYS_MODULE))
905
		return -EPERM;
906
#endif
907
903
	lock_kernel();
908
	lock_kernel();
904
	if (name_user == NULL)
909
	if (name_user == NULL)
905
		mod = &kernel_module;
910
		mod = &kernel_module;
Lines 969-974 Link Here
969
	int i;
974
	int i;
970
	struct kernel_sym ksym;
975
	struct kernel_sym ksym;
971
976
977
#ifdef CONFIG_GRKERNSEC_HIDESYM
978
	if (!capable(CAP_SYS_MODULE))
979
		return 0;
980
#endif
981
972
	lock_kernel();
982
	lock_kernel();
973
	for (mod = module_list, i = 0; mod; mod = mod->next) {
983
	for (mod = module_list, i = 0; mod; mod = mod->next) {
974
		/* include the count for the module name! */
984
		/* include the count for the module name! */
(-)linux-2.4.22-ppc-dev.orig/kernel/printk.c (+6 lines)
Lines 26-31 Link Here
26
#include <linux/module.h>
26
#include <linux/module.h>
27
#include <linux/interrupt.h>			/* For in_interrupt() */
27
#include <linux/interrupt.h>			/* For in_interrupt() */
28
#include <linux/config.h>
28
#include <linux/config.h>
29
#include <linux/grsecurity.h>
29
#ifdef CONFIG_BOOTX_TEXT
30
#ifdef CONFIG_BOOTX_TEXT
30
#include <asm/btext.h>
31
#include <asm/btext.h>
31
#endif
32
#endif
Lines 296-301 Link Here
296
297
297
asmlinkage long sys_syslog(int type, char * buf, int len)
298
asmlinkage long sys_syslog(int type, char * buf, int len)
298
{
299
{
300
#ifdef CONFIG_GRKERNSEC_DMESG
301
	if (!capable(CAP_SYS_ADMIN) && grsec_enable_dmesg)
302
		return -EPERM;
303
	else
304
#endif
299
	if ((type != 3) && !capable(CAP_SYS_ADMIN))
305
	if ((type != 3) && !capable(CAP_SYS_ADMIN))
300
		return -EPERM;
306
		return -EPERM;
301
	return do_syslog(type, buf, len);
307
	return do_syslog(type, buf, len);
(-)linux-2.4.22-ppc-dev.orig/kernel/sched.c (+14 lines)
Lines 22-27 Link Here
22
#include <linux/config.h>
22
#include <linux/config.h>
23
#include <linux/mm.h>
23
#include <linux/mm.h>
24
#include <linux/init.h>
24
#include <linux/init.h>
25
#include <linux/file.h>
25
#include <linux/smp_lock.h>
26
#include <linux/smp_lock.h>
26
#include <linux/nmi.h>
27
#include <linux/nmi.h>
27
#include <linux/interrupt.h>
28
#include <linux/interrupt.h>
Lines 29-34 Link Here
29
#include <linux/completion.h>
30
#include <linux/completion.h>
30
#include <linux/prefetch.h>
31
#include <linux/prefetch.h>
31
#include <linux/compiler.h>
32
#include <linux/compiler.h>
33
#include <linux/grsecurity.h>
32
34
33
#include <asm/uaccess.h>
35
#include <asm/uaccess.h>
34
#include <asm/mmu_context.h>
36
#include <asm/mmu_context.h>
Lines 910-915 Link Here
910
			return -EPERM;
912
			return -EPERM;
911
		if (increment < -40)
913
		if (increment < -40)
912
			increment = -40;
914
			increment = -40;
915
916
		if (gr_handle_chroot_nice())
917
			return -EPERM;
913
	}
918
	}
914
	if (increment > 40)
919
	if (increment > 40)
915
		increment = 40;
920
		increment = 40;
Lines 1288-1299 Link Here
1288
1293
1289
	write_lock_irq(&tasklist_lock);
1294
	write_lock_irq(&tasklist_lock);
1290
1295
1296
#ifdef CONFIG_GRKERNSEC
1297
	if (this_task->exec_file) {
1298
		fput(this_task->exec_file);
1299
		this_task->exec_file = NULL;
1300
	}
1301
#endif
1302
1291
	/* Reparent to init */
1303
	/* Reparent to init */
1292
	REMOVE_LINKS(this_task);
1304
	REMOVE_LINKS(this_task);
1293
	this_task->p_pptr = child_reaper;
1305
	this_task->p_pptr = child_reaper;
1294
	this_task->p_opptr = child_reaper;
1306
	this_task->p_opptr = child_reaper;
1295
	SET_LINKS(this_task);
1307
	SET_LINKS(this_task);
1296
1308
1309
	gr_set_kernel_label(this_task);
1310
1297
	/* Set the exit signal to SIGCHLD so we signal init on exit */
1311
	/* Set the exit signal to SIGCHLD so we signal init on exit */
1298
	this_task->exit_signal = SIGCHLD;
1312
	this_task->exit_signal = SIGCHLD;
1299
1313
(-)linux-2.4.22-ppc-dev.orig/kernel/signal.c (-8 / +25 lines)
Lines 13-18 Link Here
13
#include <linux/smp_lock.h>
13
#include <linux/smp_lock.h>
14
#include <linux/init.h>
14
#include <linux/init.h>
15
#include <linux/sched.h>
15
#include <linux/sched.h>
16
#include <linux/fs.h>
17
#include <linux/grsecurity.h>
16
18
17
#include <asm/uaccess.h>
19
#include <asm/uaccess.h>
18
20
Lines 554-559 Link Here
554
	if (!sig || !t->sig)
556
	if (!sig || !t->sig)
555
		goto out_nolock;
557
		goto out_nolock;
556
558
559
	gr_log_signal(sig, t);
560
557
	spin_lock_irqsave(&t->sigmask_lock, flags);
561
	spin_lock_irqsave(&t->sigmask_lock, flags);
558
	handle_stop_signal(sig, t);
562
	handle_stop_signal(sig, t);
559
563
Lines 603-608 Link Here
603
	recalc_sigpending(t);
607
	recalc_sigpending(t);
604
	spin_unlock_irqrestore(&t->sigmask_lock, flags);
608
	spin_unlock_irqrestore(&t->sigmask_lock, flags);
605
609
610
	gr_handle_crash(t, sig);
611
606
	return send_sig_info(sig, info, t);
612
	return send_sig_info(sig, info, t);
607
}
613
}
608
614
Lines 622-630 Link Here
622
		read_lock(&tasklist_lock);
628
		read_lock(&tasklist_lock);
623
		for_each_task(p) {
629
		for_each_task(p) {
624
			if (p->pgrp == pgrp && thread_group_leader(p)) {
630
			if (p->pgrp == pgrp && thread_group_leader(p)) {
625
				int err = send_sig_info(sig, info, p);
631
				if (gr_handle_signal(p, sig))
626
				if (retval)
632
					retval = -EPERM;
627
					retval = err;
633
				else {
634
					int err = send_sig_info(sig, info, p);
635
					if (retval)
636
						retval = err;
637
				}
628
			}
638
			}
629
		}
639
		}
630
		read_unlock(&tasklist_lock);
640
		read_unlock(&tasklist_lock);
Lines 675-681 Link Here
675
                       if (tg)
685
                       if (tg)
676
                               p = tg;
686
                               p = tg;
677
                }
687
                }
678
		error = send_sig_info(sig, info, p);
688
		if (gr_handle_signal(p, sig))
689
			error = -EPERM;
690
		else
691
			error = send_sig_info(sig, info, p);
679
	}
692
	}
680
	read_unlock(&tasklist_lock);
693
	read_unlock(&tasklist_lock);
681
	return error;
694
	return error;
Lines 700-709 Link Here
700
		read_lock(&tasklist_lock);
713
		read_lock(&tasklist_lock);
701
		for_each_task(p) {
714
		for_each_task(p) {
702
			if (p->pid > 1 && p != current && thread_group_leader(p)) {
715
			if (p->pid > 1 && p != current && thread_group_leader(p)) {
703
				int err = send_sig_info(sig, info, p);
716
				if (gr_handle_signal(p, sig))
704
				++count;
717
					retval = -EPERM;
705
				if (err != -EPERM)
718
				else {
706
					retval = err;
719
					int err = send_sig_info(sig, info, p);
720
					++count;
721
					if (err != -EPERM)
722
						retval = err;
723
				}
707
			}
724
			}
708
		}
725
		}
709
		read_unlock(&tasklist_lock);
726
		read_unlock(&tasklist_lock);
(-)linux-2.4.22-ppc-dev.orig/kernel/sys.c (-1 / +27 lines)
Lines 4-9 Link Here
4
 *  Copyright (C) 1991, 1992  Linus Torvalds
4
 *  Copyright (C) 1991, 1992  Linus Torvalds
5
 */
5
 */
6
6
7
#include <linux/config.h>
7
#include <linux/module.h>
8
#include <linux/module.h>
8
#include <linux/mm.h>
9
#include <linux/mm.h>
9
#include <linux/utsname.h>
10
#include <linux/utsname.h>
Lines 14-19 Link Here
14
#include <linux/prctl.h>
15
#include <linux/prctl.h>
15
#include <linux/init.h>
16
#include <linux/init.h>
16
#include <linux/highuid.h>
17
#include <linux/highuid.h>
18
#include <linux/grsecurity.h>
17
19
18
#include <asm/uaccess.h>
20
#include <asm/uaccess.h>
19
#include <asm/io.h>
21
#include <asm/io.h>
Lines 239-244 Link Here
239
		}
241
		}
240
		if (error == -ESRCH)
242
		if (error == -ESRCH)
241
			error = 0;
243
			error = 0;
244
245
		if (gr_handle_chroot_setpriority(p, niceval)) {
246
			read_unlock(&tasklist_lock);
247
			return -ESRCH;
248
		}
249
242
		if (niceval < p->nice && !capable(CAP_SYS_NICE))
250
		if (niceval < p->nice && !capable(CAP_SYS_NICE))
243
			error = -EACCES;
251
			error = -EACCES;
244
		else
252
		else
Lines 425-430 Link Here
425
	if (rgid != (gid_t) -1 ||
433
	if (rgid != (gid_t) -1 ||
426
	    (egid != (gid_t) -1 && egid != old_rgid))
434
	    (egid != (gid_t) -1 && egid != old_rgid))
427
		current->sgid = new_egid;
435
		current->sgid = new_egid;
436
437
	gr_set_role_label(current, current->uid, new_rgid);
438
428
	current->fsgid = new_egid;
439
	current->fsgid = new_egid;
429
	current->egid = new_egid;
440
	current->egid = new_egid;
430
	current->gid = new_rgid;
441
	current->gid = new_rgid;
Lines 447-452 Link Here
447
			current->mm->dumpable=0;
458
			current->mm->dumpable=0;
448
			wmb();
459
			wmb();
449
		}
460
		}
461
462
		gr_set_role_label(current, current->uid, gid);
463
450
		current->gid = current->egid = current->sgid = current->fsgid = gid;
464
		current->gid = current->egid = current->sgid = current->fsgid = gid;
451
	}
465
	}
452
	else if ((gid == current->gid) || (gid == current->sgid))
466
	else if ((gid == current->gid) || (gid == current->sgid))
Lines 530-535 Link Here
530
		current->mm->dumpable = 0;
544
		current->mm->dumpable = 0;
531
		wmb();
545
		wmb();
532
	}
546
	}
547
548
	gr_set_role_label(current, new_ruid, current->gid);
549
533
	current->uid = new_ruid;
550
	current->uid = new_ruid;
534
	current->user = new_user;
551
	current->user = new_user;
535
	free_uid(old_user);
552
	free_uid(old_user);
Lines 626-631 Link Here
626
	} else if ((uid != current->uid) && (uid != new_suid))
643
	} else if ((uid != current->uid) && (uid != new_suid))
627
		return -EPERM;
644
		return -EPERM;
628
645
646
	if (gr_check_crash_uid(uid))
647
		return -EPERM;
648
629
	if (old_euid != uid)
649
	if (old_euid != uid)
630
	{
650
	{
631
		current->mm->dumpable = 0;
651
		current->mm->dumpable = 0;
Lines 722-729 Link Here
722
		current->egid = egid;
742
		current->egid = egid;
723
	}
743
	}
724
	current->fsgid = current->egid;
744
	current->fsgid = current->egid;
725
	if (rgid != (gid_t) -1)
745
	if (rgid != (gid_t) -1) {
746
		gr_set_role_label(current, current->uid, rgid);
726
		current->gid = rgid;
747
		current->gid = rgid;
748
	}
727
	if (sgid != (gid_t) -1)
749
	if (sgid != (gid_t) -1)
728
		current->sgid = sgid;
750
		current->sgid = sgid;
729
	return 0;
751
	return 0;
Lines 1146-1151 Link Here
1146
       if (new_rlim.rlim_cur > new_rlim.rlim_max)
1168
       if (new_rlim.rlim_cur > new_rlim.rlim_max)
1147
               return -EINVAL;
1169
               return -EINVAL;
1148
	old_rlim = current->rlim + resource;
1170
	old_rlim = current->rlim + resource;
1171
1172
	if (old_rlim->rlim_max < old_rlim->rlim_cur)
1173
		return -EINVAL;
1174
1149
	if (((new_rlim.rlim_cur > old_rlim->rlim_max) ||
1175
	if (((new_rlim.rlim_cur > old_rlim->rlim_max) ||
1150
	     (new_rlim.rlim_max > old_rlim->rlim_max)) &&
1176
	     (new_rlim.rlim_max > old_rlim->rlim_max)) &&
1151
	    !capable(CAP_SYS_RESOURCE))
1177
	    !capable(CAP_SYS_RESOURCE))
(-)linux-2.4.22-ppc-dev.orig/kernel/sysctl.c (+203 lines)
Lines 38-43 Link Here
38
#endif
38
#endif
39
39
40
#if defined(CONFIG_SYSCTL)
40
#if defined(CONFIG_SYSCTL)
41
#include <linux/grsecurity.h>
42
#include <linux/grinternal.h>
43
44
extern int gr_proc_handler(ctl_table * table, int write, struct file * filp,
45
			   void * buffer, size_t * lenp);
46
extern __u32 gr_handle_sysctl(const ctl_table * table, const void *oldval,
47
			      const void *newval);
48
extern int gr_handle_sysctl_mod(const char *dirname, const char *name, const int op);
49
extern int gr_handle_chroot_sysctl(const int op);
41
50
42
/* External variables not in a header file. */
51
/* External variables not in a header file. */
43
extern int panic_timeout;
52
extern int panic_timeout;
Lines 125-130 Link Here
125
static ctl_table dev_table[];
134
static ctl_table dev_table[];
126
extern ctl_table random_table[];
135
extern ctl_table random_table[];
127
136
137
static ctl_table grsecurity_table[];
138
128
/* /proc declarations: */
139
/* /proc declarations: */
129
140
130
#ifdef CONFIG_PROC_FS
141
#ifdef CONFIG_PROC_FS
Lines 271-278 Link Here
271
	{KERN_EXCEPTION_TRACE,"exception-trace",
282
	{KERN_EXCEPTION_TRACE,"exception-trace",
272
	 &exception_trace,sizeof(int),0644,NULL,&proc_dointvec},
283
	 &exception_trace,sizeof(int),0644,NULL,&proc_dointvec},
273
#endif	
284
#endif	
285
#ifdef CONFIG_GRKERNSEC_SYSCTL
286
	{KERN_GRSECURITY, "grsecurity", NULL, 0, 0500, grsecurity_table},
287
#endif
288
	{0}
289
};
290
291
#ifdef CONFIG_GRKERNSEC_SYSCTL
292
enum {GS_LINK=1, GS_FIFO, GS_EXECVE, GS_EXECLOG, GS_SIGNAL, 
293
GS_FORKFAIL, GS_TIME, GS_CHROOT_SHMAT, GS_CHROOT_UNIX, GS_CHROOT_MNT,
294
GS_CHROOT_FCHDIR, GS_CHROOT_DBL, GS_CHROOT_PVT, GS_CHROOT_CD, GS_CHROOT_CM,
295
GS_CHROOT_MK, GS_CHROOT_NI, GS_CHROOT_EXECLOG, GS_CHROOT_CAPS, 
296
GS_CHROOT_SYSCTL, GS_TPE, GS_TPE_GID, GS_TPE_ALL, GS_SIDCAPS, 
297
GS_RANDPID, GS_RANDID, GS_RANDSRC, GS_RANDISN,
298
GS_SOCKET_ALL, GS_SOCKET_ALL_GID, GS_SOCKET_CLIENT,
299
GS_SOCKET_CLIENT_GID, GS_SOCKET_SERVER, GS_SOCKET_SERVER_GID, GS_TTY, GS_TTYS,
300
GS_PTY, GS_GROUP, GS_GID, GS_ACHDIR, GS_AMOUNT, GS_AIPC, GS_DMSG, GS_RANDRPC,
301
GS_FINDTASK, GS_LOCK};
302
303
static ctl_table grsecurity_table[] = {
304
#ifdef CONFIG_GRKERNSEC_LINK
305
	{GS_LINK, "linking_restrictions", &grsec_enable_link, sizeof (int),
306
	 0600, NULL, &proc_dointvec}, 
307
#endif
308
#ifdef CONFIG_GRKERNSEC_FIFO
309
	{GS_FIFO, "fifo_restrictions", &grsec_enable_fifo, sizeof (int),
310
	 0600, NULL, &proc_dointvec},
311
#endif
312
#ifdef CONFIG_GRKERNSEC_EXECVE
313
	{GS_EXECVE, "execve_limiting", &grsec_enable_execve, sizeof (int),
314
	 0600, NULL, &proc_dointvec},
315
#endif
316
#ifdef CONFIG_GRKERNSEC_EXECLOG
317
	{GS_EXECLOG, "exec_logging", &grsec_enable_execlog, sizeof (int),
318
	 0600, NULL, &proc_dointvec},
319
#endif
320
#ifdef CONFIG_GRKERNSEC_SIGNAL
321
	{GS_SIGNAL, "signal_logging", &grsec_enable_signal, sizeof (int),
322
	 0600, NULL, &proc_dointvec},
323
#endif
324
#ifdef CONFIG_GRKERNSEC_FORKFAIL
325
	{GS_FORKFAIL, "forkfail_logging", &grsec_enable_forkfail, sizeof (int),
326
	 0600, NULL, &proc_dointvec},
327
#endif
328
#ifdef CONFIG_GRKERNSEC_TIME
329
	{GS_TIME, "timechange_logging", &grsec_enable_time, sizeof (int),
330
	 0600, NULL, &proc_dointvec},
331
#endif
332
#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
333
	{GS_CHROOT_SHMAT, "chroot_deny_shmat", &grsec_enable_chroot_shmat, sizeof (int),
334
	 0600, NULL, &proc_dointvec},
335
#endif
336
#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
337
	{GS_CHROOT_UNIX, "chroot_deny_unix", &grsec_enable_chroot_unix, sizeof(int),
338
	 0600, NULL, &proc_dointvec},
339
#endif
340
#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
341
	{GS_CHROOT_MNT, "chroot_deny_mount", &grsec_enable_chroot_mount, sizeof (int),
342
	 0600, NULL, &proc_dointvec},
343
#endif
344
#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
345
	{GS_CHROOT_FCHDIR, "chroot_deny_fchdir", &grsec_enable_chroot_fchdir, sizeof (int),
346
	 0600, NULL, &proc_dointvec},
347
#endif
348
#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
349
	{GS_CHROOT_DBL, "chroot_deny_chroot", &grsec_enable_chroot_double, sizeof (int),
350
	 0600, NULL, &proc_dointvec},
351
#endif
352
#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
353
	{GS_CHROOT_PVT, "chroot_deny_pivot", &grsec_enable_chroot_pivot, sizeof (int),
354
	 0600, NULL, &proc_dointvec},
355
#endif
356
#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
357
	{GS_CHROOT_CD, "chroot_enforce_chdir", &grsec_enable_chroot_chdir, sizeof (int),
358
	 0600, NULL, &proc_dointvec},
359
#endif
360
#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
361
	{GS_CHROOT_CM, "chroot_deny_chmod", &grsec_enable_chroot_chmod, sizeof (int),
362
	 0600, NULL, &proc_dointvec},
363
#endif
364
#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
365
	{GS_CHROOT_MK, "chroot_deny_mknod", &grsec_enable_chroot_mknod, sizeof (int),
366
	 0600, NULL, &proc_dointvec},
367
#endif
368
#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
369
	{GS_CHROOT_NI, "chroot_restrict_nice", &grsec_enable_chroot_nice, sizeof (int),
370
	 0600, NULL, &proc_dointvec},
371
#endif
372
#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
373
	{GS_CHROOT_EXECLOG, "chroot_execlog",
374
	 &grsec_enable_chroot_execlog, sizeof (int),
375
         0600, NULL, &proc_dointvec},
376
#endif
377
#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
378
	{GS_CHROOT_CAPS, "chroot_caps", &grsec_enable_chroot_caps, sizeof (int),
379
	 0600, NULL, &proc_dointvec},
380
#endif
381
#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
382
	{GS_CHROOT_SYSCTL, "chroot_deny_sysctl", &grsec_enable_chroot_sysctl, sizeof (int),
383
	 0600, NULL, &proc_dointvec},
384
#endif
385
#ifdef CONFIG_GRKERNSEC_TPE
386
	{GS_TPE, "tpe", &grsec_enable_tpe, sizeof (int),
387
	 0600, NULL, &proc_dointvec},
388
	{GS_TPE_GID, "tpe_gid", &grsec_tpe_gid, sizeof (int),
389
	 0600, NULL, &proc_dointvec},
390
#endif
391
#ifdef CONFIG_GRKERNSEC_TPE_ALL
392
	{GS_TPE_ALL, "tpe_restrict_all", &grsec_enable_tpe_all, sizeof (int),
393
	 0600, NULL, &proc_dointvec},
394
#endif
395
#ifdef CONFIG_GRKERNSEC_RANDPID
396
	{GS_RANDPID, "rand_pids", &grsec_enable_randpid, sizeof (int),
397
	 0600, NULL, &proc_dointvec},
398
#endif
399
#ifdef CONFIG_GRKERNSEC_RANDID
400
	{GS_RANDID, "rand_ip_ids", &grsec_enable_randid, sizeof (int),
401
	 0600, NULL, &proc_dointvec},
402
#endif
403
#ifdef CONFIG_GRKERNSEC_RANDSRC
404
	{GS_RANDSRC, "rand_tcp_src_ports", &grsec_enable_randsrc, sizeof (int),
405
	 0600, NULL, &proc_dointvec},
406
#endif
407
#ifdef CONFIG_GRKERNSEC_RANDISN
408
	{GS_RANDISN, "rand_isns", &grsec_enable_randisn, sizeof (int),
409
	 0600, NULL, &proc_dointvec},
410
#endif
411
#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
412
	{GS_SOCKET_ALL, "socket_all", &grsec_enable_socket_all, sizeof (int),
413
	 0600, NULL, &proc_dointvec},
414
	{GS_SOCKET_ALL_GID, "socket_all_gid",
415
	 &grsec_socket_all_gid, sizeof (int),
416
	 0600, NULL, &proc_dointvec},
417
#endif
418
#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
419
	{GS_SOCKET_CLIENT, "socket_client", 
420
	 &grsec_enable_socket_client, sizeof (int),
421
	 0600, NULL, &proc_dointvec},
422
	{GS_SOCKET_CLIENT_GID, "socket_client_gid", 
423
	 &grsec_socket_client_gid, sizeof (int),
424
	 0600, NULL, &proc_dointvec},
425
#endif
426
#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
427
	{GS_SOCKET_SERVER, "socket_server", 
428
	 &grsec_enable_socket_server, sizeof (int),
429
	 0600, NULL, &proc_dointvec},
430
	{GS_SOCKET_SERVER_GID, "socket_server_gid",
431
	 &grsec_socket_server_gid, sizeof (int),
432
	 0600, NULL, &proc_dointvec},
433
#endif
434
#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
435
	{GS_GROUP, "audit_group", &grsec_enable_group, sizeof (int),
436
	 0600, NULL, &proc_dointvec},
437
	{GS_GID, "audit_gid",
438
	 &grsec_audit_gid, sizeof (int),
439
	 0600, NULL, &proc_dointvec},
440
#endif
441
#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
442
	{GS_ACHDIR, "audit_chdir", &grsec_enable_chdir, sizeof (int),
443
	 0600, NULL, &proc_dointvec},
444
#endif
445
#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
446
	{GS_AMOUNT, "audit_mount", &grsec_enable_mount, sizeof (int),
447
	 0600, NULL, &proc_dointvec},
448
#endif
449
#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
450
	{GS_AIPC, "audit_ipc", &grsec_enable_audit_ipc, sizeof (int),
451
	 0600, NULL, &proc_dointvec},
452
#endif
453
#ifdef CONFIG_GRKERNSEC_DMESG
454
	{GS_AIPC, "dmesg", &grsec_enable_dmesg, sizeof (int),
455
	 0600, NULL, &proc_dointvec},
456
#endif
457
#ifdef CONFIG_GRKERNSEC_RANDRPC
458
	{GS_RANDRPC, "rand_rpc", &grsec_enable_randrpc, sizeof (int),
459
	 0600, NULL, &proc_dointvec},
460
#endif
461
#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
462
	{GS_FINDTASK, "chroot_findtask", &grsec_enable_chroot_findtask, 
463
	 sizeof (int), 0600, NULL, &proc_dointvec},
464
#endif
465
	{GS_LOCK, "grsec_lock", &grsec_lock, sizeof (int), 0600, NULL,
466
	 &proc_dointvec},
274
	{0}
467
	{0}
275
};
468
};
469
#endif
276
470
277
static ctl_table vm_table[] = {
471
static ctl_table vm_table[] = {
278
	{VM_BDFLUSH, "bdflush", &bdf_prm, 9*sizeof(int), 0644, NULL,
472
	{VM_BDFLUSH, "bdflush", &bdf_prm, 9*sizeof(int), 0644, NULL,
Lines 411-416 Link Here
411
605
412
static inline int ctl_perm(ctl_table *table, int op)
606
static inline int ctl_perm(ctl_table *table, int op)
413
{
607
{
608
	if (gr_handle_sysctl_mod(table->de->parent->name, table->de->name, op))
609
		return -EACCES;
610
	if (gr_handle_chroot_sysctl(op))
611
		return -EACCES;
612
414
	return test_perm(table->mode, op);
613
	return test_perm(table->mode, op);
415
}
614
}
416
615
Lines 444-449 Link Here
444
				table = table->child;
643
				table = table->child;
445
				goto repeat;
644
				goto repeat;
446
			}
645
			}
646
647
			if (!gr_handle_sysctl(table, oldval, newval))
648
				return -EACCES;
649
447
			error = do_sysctl_strategy(table, name, nlen,
650
			error = do_sysctl_strategy(table, name, nlen,
448
						   oldval, oldlenp,
651
						   oldval, oldlenp,
449
						   newval, newlen, context);
652
						   newval, newlen, context);
(-)linux-2.4.22-ppc-dev.orig/kernel/time.c (+6 lines)
Lines 27-32 Link Here
27
#include <linux/mm.h>
27
#include <linux/mm.h>
28
#include <linux/timex.h>
28
#include <linux/timex.h>
29
#include <linux/smp_lock.h>
29
#include <linux/smp_lock.h>
30
#include <linux/grsecurity.h>
30
31
31
#include <asm/uaccess.h>
32
#include <asm/uaccess.h>
32
33
Lines 89-94 Link Here
89
	time_maxerror = NTP_PHASE_LIMIT;
90
	time_maxerror = NTP_PHASE_LIMIT;
90
	time_esterror = NTP_PHASE_LIMIT;
91
	time_esterror = NTP_PHASE_LIMIT;
91
	write_unlock_irq(&xtime_lock);
92
	write_unlock_irq(&xtime_lock);
93
94
	gr_log_timechange();
95
92
	return 0;
96
	return 0;
93
}
97
}
94
98
Lines 167-172 Link Here
167
		 * globally block out interrupts when it runs.
171
		 * globally block out interrupts when it runs.
168
		 */
172
		 */
169
		do_settimeofday(tv);
173
		do_settimeofday(tv);
174
175
		gr_log_timechange();
170
	}
176
	}
171
	return 0;
177
	return 0;
172
}
178
}
(-)linux-2.4.22-ppc-dev.orig/kernel/timer.c (+3 lines)
Lines 541-546 Link Here
541
541
542
	psecs = (p->times.tms_utime += user);
542
	psecs = (p->times.tms_utime += user);
543
	psecs += (p->times.tms_stime += system);
543
	psecs += (p->times.tms_stime += system);
544
545
	gr_learn_resource(p, RLIMIT_CPU, psecs / HZ);
546
544
	if (psecs / HZ > p->rlim[RLIMIT_CPU].rlim_cur) {
547
	if (psecs / HZ > p->rlim[RLIMIT_CPU].rlim_cur) {
545
		/* Send SIGXCPU every second.. */
548
		/* Send SIGXCPU every second.. */
546
		if (!(psecs % HZ))
549
		if (!(psecs % HZ))
(-)linux-2.4.22-ppc-dev.orig/mm/filemap.c (+9 lines)
Lines 2345-2350 Link Here
2345
	}
2345
	}
2346
	if (!mapping->a_ops->readpage)
2346
	if (!mapping->a_ops->readpage)
2347
		return -ENOEXEC;
2347
		return -ENOEXEC;
2348
2349
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
2350
	if (current->flags & PF_PAX_PAGEEXEC)
2351
		vma->vm_page_prot = protection_map[vma->vm_flags & 0x0f];
2352
#endif
2353
2348
	UPDATE_ATIME(inode);
2354
	UPDATE_ATIME(inode);
2349
	vma->vm_ops = &generic_file_vm_ops;
2355
	vma->vm_ops = &generic_file_vm_ops;
2350
	return 0;
2356
	return 0;
Lines 2629-2634 Link Here
2629
	error = -EIO;
2635
	error = -EIO;
2630
	rlim_rss = current->rlim ?  current->rlim[RLIMIT_RSS].rlim_cur :
2636
	rlim_rss = current->rlim ?  current->rlim[RLIMIT_RSS].rlim_cur :
2631
				LONG_MAX; /* default: see resource.h */
2637
				LONG_MAX; /* default: see resource.h */
2638
	gr_learn_resource(current, RLIMIT_RSS, vma->vm_mm->rss + (end - start));
2632
	if ((vma->vm_mm->rss + (end - start)) > rlim_rss)
2639
	if ((vma->vm_mm->rss + (end - start)) > rlim_rss)
2633
		return error;
2640
		return error;
2634
2641
Lines 3104-3109 Link Here
3104
	err = -EFBIG;
3111
	err = -EFBIG;
3105
	
3112
	
3106
	if (!S_ISBLK(inode->i_mode) && limit != RLIM_INFINITY) {
3113
	if (!S_ISBLK(inode->i_mode) && limit != RLIM_INFINITY) {
3114
		gr_learn_resource(current, RLIMIT_FSIZE, pos);
3107
		if (pos >= limit) {
3115
		if (pos >= limit) {
3108
			send_sig(SIGXFSZ, current, 0);
3116
			send_sig(SIGXFSZ, current, 0);
3109
			goto out;
3117
			goto out;
Lines 3139-3144 Link Here
3139
	 */
3147
	 */
3140
	 
3148
	 
3141
	if (!S_ISBLK(inode->i_mode)) {
3149
	if (!S_ISBLK(inode->i_mode)) {
3150
		gr_learn_resource(current, RLIMIT_FSIZE, *count + (u32)pos);
3142
		if (pos >= inode->i_sb->s_maxbytes)
3151
		if (pos >= inode->i_sb->s_maxbytes)
3143
		{
3152
		{
3144
			if (*count || pos > inode->i_sb->s_maxbytes) {
3153
			if (*count || pos > inode->i_sb->s_maxbytes) {
(-)linux-2.4.22-ppc-dev.orig/mm/memory.c (+126 lines)
Lines 925-930 Link Here
925
	establish_pte(vma, address, page_table, pte_mkwrite(pte_mkdirty(mk_pte(new_page, vma->vm_page_prot))));
925
	establish_pte(vma, address, page_table, pte_mkwrite(pte_mkdirty(mk_pte(new_page, vma->vm_page_prot))));
926
}
926
}
927
927
928
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
929
/* PaX: if vma is mirrored, synchronize the mirror's PTE
930
 *
931
 * mm->page_table_lock is held on entry and is not released on exit or inside
932
 * to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
933
 */
934
static void pax_mirror_fault(struct mm_struct *mm, struct vm_area_struct * vma,
935
       unsigned long address, pte_t *pte)
936
{
937
	unsigned long address_m;
938
	struct vm_area_struct * vma_m = NULL;
939
	pte_t * pte_m, entry_m;
940
	struct page * page_m;
941
942
	if (!(vma->vm_flags & VM_MIRROR))
943
		return;
944
945
	address_m = vma->vm_start + (unsigned long)vma->vm_private_data;
946
	vma_m = find_vma(mm, address_m);
947
	if (!vma_m || vma_m->vm_start != address_m)
948
		return;
949
950
	address_m = address + (unsigned long)vma->vm_private_data;
951
952
	{
953
		pgd_t *pgd_m;
954
		pmd_t *pmd_m;
955
956
		pgd_m = pgd_offset(mm, address_m);
957
		pmd_m = pmd_offset(pgd_m, address_m);
958
		pte_m = pte_offset(pmd_m, address_m);
959
	}
960
961
	if (pte_present(*pte_m)) {
962
		flush_cache_page(vma_m, address_m);
963
		flush_icache_page(vma_m, pte_page(*pte_m));
964
	}
965
	entry_m = ptep_get_and_clear(pte_m);
966
	if (pte_present(entry_m))
967
		flush_tlb_page(vma_m, address_m);  
968
969
	if (pte_none(entry_m)) {
970
		++mm->rss;
971
	} else if (pte_present(entry_m)) {
972
		page_cache_release(pte_page(entry_m));
973
	} else {
974
		free_swap_and_cache(pte_to_swp_entry(entry_m));
975
		++mm->rss;
976
	}
977
978
	page_m = pte_page(*pte);
979
	page_cache_get(page_m);
980
	entry_m = mk_pte(page_m, vma_m->vm_page_prot);
981
	if (pte_write(*pte))
982
		entry_m = pte_mkdirty(pte_mkwrite(entry_m));
983
	establish_pte(vma_m, address_m, pte_m, entry_m);  
984
}                      
985
#endif
986
928
/*
987
/*
929
 * This routine handles present pages, when users try to write
988
 * This routine handles present pages, when users try to write
930
 * to a shared page. It is done by copying the page to a new address
989
 * to a shared page. It is done by copying the page to a new address
Lines 988-993 Link Here
988
1047
989
		/* Free the old page.. */
1048
		/* Free the old page.. */
990
		new_page = old_page;
1049
		new_page = old_page;
1050
1051
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
1052
		pax_mirror_fault(mm, vma, address, page_table);
1053
#endif
1054
991
	}
1055
	}
992
	spin_unlock(&mm->page_table_lock);
1056
	spin_unlock(&mm->page_table_lock);
993
	page_cache_release(new_page);
1057
	page_cache_release(new_page);
Lines 1065-1070 Link Here
1065
1129
1066
do_expand:
1130
do_expand:
1067
	limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
1131
	limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
1132
	gr_learn_resource(current, RLIMIT_FSIZE, offset);
1068
	if (limit != RLIM_INFINITY && offset > limit)
1133
	if (limit != RLIM_INFINITY && offset > limit)
1069
		goto out_sig;
1134
		goto out_sig;
1070
	if (offset > inode->i_sb->s_maxbytes)
1135
	if (offset > inode->i_sb->s_maxbytes)
Lines 1178-1183 Link Here
1178
1243
1179
	/* No need to invalidate - it was non-present before */
1244
	/* No need to invalidate - it was non-present before */
1180
	update_mmu_cache(vma, address, pte);
1245
	update_mmu_cache(vma, address, pte);
1246
1247
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
1248
	pax_mirror_fault(mm, vma, address, page_table);
1249
#endif
1250
1181
	spin_unlock(&mm->page_table_lock);
1251
	spin_unlock(&mm->page_table_lock);
1182
	return ret;
1252
	return ret;
1183
}
1253
}
Lines 1223-1228 Link Here
1223
1293
1224
	/* No need to invalidate - it was non-present before */
1294
	/* No need to invalidate - it was non-present before */
1225
	update_mmu_cache(vma, addr, entry);
1295
	update_mmu_cache(vma, addr, entry);
1296
1297
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
1298
	pax_mirror_fault(mm, vma, addr, page_table);
1299
#endif
1300
1226
	spin_unlock(&mm->page_table_lock);
1301
	spin_unlock(&mm->page_table_lock);
1227
	return 1;	/* Minor fault */
1302
	return 1;	/* Minor fault */
1228
1303
Lines 1303-1308 Link Here
1303
1378
1304
	/* no need to invalidate: a not-present page shouldn't be cached */
1379
	/* no need to invalidate: a not-present page shouldn't be cached */
1305
	update_mmu_cache(vma, address, entry);
1380
	update_mmu_cache(vma, address, entry);
1381
1382
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
1383
	pax_mirror_fault(mm, vma, address, page_table);
1384
#endif
1385
1306
	spin_unlock(&mm->page_table_lock);
1386
	spin_unlock(&mm->page_table_lock);
1307
	return 2;	/* Major fault */
1387
	return 2;	/* Major fault */
1308
}
1388
}
Lines 1367-1372 Link Here
1367
	pgd_t *pgd;
1447
	pgd_t *pgd;
1368
	pmd_t *pmd;
1448
	pmd_t *pmd;
1369
1449
1450
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
1451
	unsigned long address_m = 0UL;
1452
	struct vm_area_struct * vma_m = NULL;
1453
#endif
1454
1370
	current->state = TASK_RUNNING;
1455
	current->state = TASK_RUNNING;
1371
	pgd = pgd_offset(mm, address);
1456
	pgd = pgd_offset(mm, address);
1372
1457
Lines 1375-1380 Link Here
1375
	 * and the SMP-safe atomic PTE updates.
1460
	 * and the SMP-safe atomic PTE updates.
1376
	 */
1461
	 */
1377
	spin_lock(&mm->page_table_lock);
1462
	spin_lock(&mm->page_table_lock);
1463
1464
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
1465
	if (vma->vm_flags & VM_MIRROR) {
1466
		pgd_t *pgd_m;
1467
		pmd_t *pmd_m;
1468
		pte_t *pte_m;
1469
1470
		address_m = vma->vm_start + (unsigned long)vma->vm_private_data;
1471
		vma_m = find_vma(mm, address_m);
1472
1473
		/* PaX: sanity checks */
1474
		if (!vma_m) {
1475
			spin_unlock(&mm->page_table_lock);
1476
			printk(KERN_ERR "PAX: VMMIRROR: fault bug, %08lx, %p, %08lx, %p\n",
1477
			       address, vma, address_m, vma_m);
1478
			return 0;
1479
		} else if (!(vma_m->vm_flags & VM_MIRROR) ||
1480
			   vma_m->vm_start != address_m ||
1481
			   vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start)
1482
		{
1483
			spin_unlock(&mm->page_table_lock);
1484
			printk(KERN_ERR "PAX: VMMIRROR: fault bug2, %08lx, %08lx, %08lx, %08lx, %08lx\n",
1485
				address, vma->vm_start, vma_m->vm_start, vma->vm_end, vma_m->vm_end);
1486
			return 0;
1487
		}
1488
1489
		address_m = address + (unsigned long)vma->vm_private_data;
1490
		pgd_m = pgd_offset(mm, address_m);
1491
		pmd_m = pmd_alloc(mm, pgd_m, address_m);
1492
		if (!pmd_m) {
1493
			spin_unlock(&mm->page_table_lock);
1494
			return -1;
1495
		}
1496
		pte_m = pte_alloc(mm, pmd_m, address_m);
1497
		if (!pte_m) {
1498
			spin_unlock(&mm->page_table_lock);
1499
			return -1;
1500
		}
1501
	}			
1502
#endif
1503
1378
	pmd = pmd_alloc(mm, pgd, address);
1504
	pmd = pmd_alloc(mm, pgd, address);
1379
1505
1380
	if (pmd) {
1506
	if (pmd) {
(-)linux-2.4.22-ppc-dev.orig/mm/mlock.c (+28 lines)
Lines 114-122 Link Here
114
	return 0;
114
	return 0;
115
}
115
}
116
116
117
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
118
static int __mlock_fixup(struct vm_area_struct * vma,
119
	unsigned long start, unsigned long end, unsigned int newflags);
117
static int mlock_fixup(struct vm_area_struct * vma, 
120
static int mlock_fixup(struct vm_area_struct * vma, 
118
	unsigned long start, unsigned long end, unsigned int newflags)
121
	unsigned long start, unsigned long end, unsigned int newflags)
119
{
122
{
123
	if (vma->vm_flags & VM_MIRROR) {
124
		struct vm_area_struct * vma_m;
125
		unsigned long start_m, end_m;
126
127
		start_m = vma->vm_start + (unsigned long)vma->vm_private_data;
128
		vma_m = find_vma(vma->vm_mm, start_m);
129
		if (vma_m && vma_m->vm_start == start_m && (vma_m->vm_flags & VM_MIRROR)) {
130
			start_m = start + (unsigned long)vma->vm_private_data;
131
			end_m = end + (unsigned long)vma->vm_private_data;
132
			__mlock_fixup(vma_m, start_m, end_m, newflags);
133
		} else
134
			printk("PAX: VMMIRROR: mlock bug in %s, %08lx\n", current->comm, vma->vm_start);
135
	}
136
	return __mlock_fixup(vma, start, end, newflags);
137
}
138
139
static int __mlock_fixup(struct vm_area_struct * vma,
140
	unsigned long start, unsigned long end, unsigned int newflags)
141
#else
142
static int mlock_fixup(struct vm_area_struct * vma,
143
	unsigned long start, unsigned long end, unsigned int newflags)
144
#endif
145
{
120
	int pages, retval;
146
	int pages, retval;
121
147
122
	if (newflags == vma->vm_flags)
148
	if (newflags == vma->vm_flags)
Lines 209-214 Link Here
209
	lock_limit >>= PAGE_SHIFT;
235
	lock_limit >>= PAGE_SHIFT;
210
236
211
	/* check against resource limits */
237
	/* check against resource limits */
238
	gr_learn_resource(current, RLIMIT_MEMLOCK, locked);
212
	if (locked > lock_limit)
239
	if (locked > lock_limit)
213
		goto out;
240
		goto out;
214
241
Lines 276-281 Link Here
276
	lock_limit >>= PAGE_SHIFT;
303
	lock_limit >>= PAGE_SHIFT;
277
304
278
	ret = -ENOMEM;
305
	ret = -ENOMEM;
306
	gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm);
279
	if (current->mm->total_vm > lock_limit)
307
	if (current->mm->total_vm > lock_limit)
280
		goto out;
308
		goto out;
281
309
(-)linux-2.4.22-ppc-dev.orig/mm/mmap.c (-35 / +262 lines)
Lines 14-19 Link Here
14
#include <linux/file.h>
14
#include <linux/file.h>
15
#include <linux/fs.h>
15
#include <linux/fs.h>
16
#include <linux/personality.h>
16
#include <linux/personality.h>
17
#include <linux/random.h>
18
#include <linux/grsecurity.h>
17
19
18
#include <asm/uaccess.h>
20
#include <asm/uaccess.h>
19
#include <asm/pgalloc.h>
21
#include <asm/pgalloc.h>
Lines 169-174 Link Here
169
171
170
	/* Check against rlimit.. */
172
	/* Check against rlimit.. */
171
	rlim = current->rlim[RLIMIT_DATA].rlim_cur;
173
	rlim = current->rlim[RLIMIT_DATA].rlim_cur;
174
	gr_learn_resource(current, RLIMIT_DATA, brk - mm->start_data);
172
	if (rlim < RLIM_INFINITY && brk - mm->start_data > rlim)
175
	if (rlim < RLIM_INFINITY && brk - mm->start_data > rlim)
173
		goto out;
176
		goto out;
174
177
Lines 206-211 Link Here
206
		_trans(prot, PROT_WRITE, VM_WRITE) |
209
		_trans(prot, PROT_WRITE, VM_WRITE) |
207
		_trans(prot, PROT_EXEC, VM_EXEC);
210
		_trans(prot, PROT_EXEC, VM_EXEC);
208
	flag_bits =
211
	flag_bits =
212
213
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
214
		_trans(flags, MAP_MIRROR, VM_MIRROR) |
215
#endif
216
209
		_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN) |
217
		_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN) |
210
		_trans(flags, MAP_DENYWRITE, VM_DENYWRITE) |
218
		_trans(flags, MAP_DENYWRITE, VM_DENYWRITE) |
211
		_trans(flags, MAP_EXECUTABLE, VM_EXECUTABLE);
219
		_trans(flags, MAP_EXECUTABLE, VM_EXECUTABLE);
Lines 401-406 Link Here
401
	int error;
409
	int error;
402
	rb_node_t ** rb_link, * rb_parent;
410
	rb_node_t ** rb_link, * rb_parent;
403
411
412
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
413
	struct vm_area_struct * vma_m = NULL;
414
	
415
	if (flags & MAP_MIRROR) {
416
		/* PaX: sanity checks, to be removed when proved to be stable */
417
		if (file || len || ((flags & MAP_TYPE) != MAP_PRIVATE))
418
			return -EINVAL;
419
420
		vma_m = find_vma(mm, pgoff);
421
422
		if (!vma_m ||
423
		    vma_m->vm_start != pgoff ||
424
		    (vma_m->vm_flags & VM_MIRROR) ||
425
		    (!(vma_m->vm_flags & VM_WRITE) && (prot & PROT_WRITE)))
426
			return -EINVAL;
427
428
		file = vma_m->vm_file;
429
		pgoff = vma_m->vm_pgoff;
430
		len = vma_m->vm_end - vma_m->vm_start;
431
	}
432
#endif
433
404
	if (file && (!file->f_op || !file->f_op->mmap))
434
	if (file && (!file->f_op || !file->f_op->mmap))
405
		return -ENODEV;
435
		return -ENODEV;
406
436
Lines 433-442 Link Here
433
	 */
463
	 */
434
	vm_flags = calc_vm_flags(prot,flags) | mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
464
	vm_flags = calc_vm_flags(prot,flags) | mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
435
465
466
#if defined(CONFIG_GRKERNSEC_PAX_PAGEEXEC) || defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC)
467
	if (current->flags & (PF_PAX_PAGEEXEC | PF_PAX_SEGMEXEC)) {
468
469
#ifdef CONFIG_GRKERNSEC_PAX_MPROTECT
470
		if (current->flags & PF_PAX_MPROTECT) {
471
			if (!file || (prot & PROT_WRITE))
472
				vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
473
			else
474
				vm_flags &= ~VM_MAYWRITE;
475
476
#ifdef CONFIG_GRKERNSEC_PAX_RANDEXEC
477
			if (file && (flags & MAP_MIRROR) && (vm_flags & VM_EXEC))
478
				vma_m->vm_flags &= ~VM_MAYWRITE;
479
#endif
480
481
		}
482
#endif
483
484
	}
485
#endif
486
436
	/* mlock MCL_FUTURE? */
487
	/* mlock MCL_FUTURE? */
437
	if (vm_flags & VM_LOCKED) {
488
	if (vm_flags & VM_LOCKED) {
438
		unsigned long locked = mm->locked_vm << PAGE_SHIFT;
489
		unsigned long locked = mm->locked_vm << PAGE_SHIFT;
439
		locked += len;
490
		locked += len;
491
		gr_learn_resource(current, RLIMIT_MEMLOCK, locked);
440
		if (locked > current->rlim[RLIMIT_MEMLOCK].rlim_cur)
492
		if (locked > current->rlim[RLIMIT_MEMLOCK].rlim_cur)
441
			return -EAGAIN;
493
			return -EAGAIN;
442
	}
494
	}
Lines 481-486 Link Here
481
		}
533
		}
482
	}
534
	}
483
535
536
	if (!gr_acl_handle_mmap(file, prot))
537
		return -EACCES;
538
484
	/* Clear old maps */
539
	/* Clear old maps */
485
munmap_back:
540
munmap_back:
486
	vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
541
	vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
Lines 491-500 Link Here
491
	}
546
	}
492
547
493
	/* Check against address space limit. */
548
	/* Check against address space limit. */
549
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
550
	if (!(vm_flags & VM_MIRROR)) {
551
#endif
552
	gr_learn_resource(current, RLIMIT_AS, (mm->total_vm << PAGE_SHIFT) + len);
494
	if ((mm->total_vm << PAGE_SHIFT) + len
553
	if ((mm->total_vm << PAGE_SHIFT) + len
495
	    > current->rlim[RLIMIT_AS].rlim_cur)
554
	    > current->rlim[RLIMIT_AS].rlim_cur)
496
		return -ENOMEM;
555
		return -ENOMEM;
497
556
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
557
	}
558
#endif
498
	/* Private writable mapping? Check memory availability.. */
559
	/* Private writable mapping? Check memory availability.. */
499
	if ((vm_flags & (VM_SHARED | VM_WRITE)) == VM_WRITE &&
560
	if ((vm_flags & (VM_SHARED | VM_WRITE)) == VM_WRITE &&
500
	    !(flags & MAP_NORESERVE)				 &&
561
	    !(flags & MAP_NORESERVE)				 &&
Lines 518-523 Link Here
518
	vma->vm_start = addr;
579
	vma->vm_start = addr;
519
	vma->vm_end = addr + len;
580
	vma->vm_end = addr + len;
520
	vma->vm_flags = vm_flags;
581
	vma->vm_flags = vm_flags;
582
583
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
584
	if ((file || !(current->flags & PF_PAX_PAGEEXEC)) && (vm_flags & (VM_READ|VM_WRITE)))
585
		vma->vm_page_prot = protection_map[(vm_flags | VM_EXEC) & 0x0f];
586
	else
587
#endif
588
521
	vma->vm_page_prot = protection_map[vm_flags & 0x0f];
589
	vma->vm_page_prot = protection_map[vm_flags & 0x0f];
522
	vma->vm_ops = NULL;
590
	vma->vm_ops = NULL;
523
	vma->vm_pgoff = pgoff;
591
	vma->vm_pgoff = pgoff;
Lines 546-551 Link Here
546
			goto free_vma;
614
			goto free_vma;
547
	}
615
	}
548
616
617
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
618
	if (flags & MAP_MIRROR) {
619
		vma_m->vm_flags |= VM_MIRROR;
620
		vma_m->vm_private_data = (void *)(vma->vm_start - vma_m->vm_start);
621
		vma->vm_private_data = (void *)(vma_m->vm_start - vma->vm_start);
622
	}
623
#endif
624
549
	/* Can addr have changed??
625
	/* Can addr have changed??
550
	 *
626
	 *
551
	 * Answer: Yes, several device drivers can do it in their
627
	 * Answer: Yes, several device drivers can do it in their
Lines 581-586 Link Here
581
		atomic_inc(&file->f_dentry->d_inode->i_writecount);
657
		atomic_inc(&file->f_dentry->d_inode->i_writecount);
582
658
583
out:	
659
out:	
660
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
661
	if (!(flags & MAP_MIRROR))
662
#endif
584
	mm->total_vm += len >> PAGE_SHIFT;
663
	mm->total_vm += len >> PAGE_SHIFT;
585
	if (vm_flags & VM_LOCKED) {
664
	if (vm_flags & VM_LOCKED) {
586
		mm->locked_vm += len >> PAGE_SHIFT;
665
		mm->locked_vm += len >> PAGE_SHIFT;
Lines 617-636 Link Here
617
{
696
{
618
	struct vm_area_struct *vma;
697
	struct vm_area_struct *vma;
619
698
699
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
700
	if ((current->flags & PF_PAX_SEGMEXEC) && len > SEGMEXEC_TASK_SIZE)
701
		return -ENOMEM;
702
	else
703
#endif
704
620
	if (len > TASK_SIZE)
705
	if (len > TASK_SIZE)
621
		return -ENOMEM;
706
		return -ENOMEM;
622
707
708
#ifdef CONFIG_GRKERNSEC_PAX_RANDMMAP
709
	if (!(current->flags & PF_PAX_RANDMMAP) || !filp)
710
#endif
711
623
	if (addr) {
712
	if (addr) {
624
		addr = PAGE_ALIGN(addr);
713
		addr = PAGE_ALIGN(addr);
625
		vma = find_vma(current->mm, addr);
714
		vma = find_vma(current->mm, addr);
715
716
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
717
		if ((current->flags & PF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE-len < addr)		
718
			return -ENOMEM;
719
#endif
720
626
		if (TASK_SIZE - len >= addr &&
721
		if (TASK_SIZE - len >= addr &&
627
		    (!vma || addr + len <= vma->vm_start))
722
		    (!vma || addr + len <= vma->vm_start))
628
			return addr;
723
			return addr;
629
	}
724
	}
630
	addr = PAGE_ALIGN(TASK_UNMAPPED_BASE);
725
	addr = PAGE_ALIGN(TASK_UNMAPPED_BASE);
631
726
727
#ifdef CONFIG_GRKERNSEC_PAX_RANDMMAP
728
	/* PaX: randomize base address if requested */
729
	if (current->flags & PF_PAX_RANDMMAP)
730
		addr += current->mm->delta_mmap;
731
#endif
732
632
	for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
733
	for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
633
		/* At this point:  (!vma || addr < vma->vm_end). */
734
		/* At this point:  (!vma || addr < vma->vm_end). */
735
736
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
737
		if ((current->flags & PF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE-len < addr)
738
			return -ENOMEM;
739
		else
740
#endif
741
634
		unsigned long __heap_stack_gap;
742
		unsigned long __heap_stack_gap;
635
		if (TASK_SIZE - len < addr)
743
		if (TASK_SIZE - len < addr)
636
			return -ENOMEM;
744
			return -ENOMEM;
Lines 799-804 Link Here
799
	struct vm_area_struct *mpnt;
907
	struct vm_area_struct *mpnt;
800
	unsigned long end = addr + len;
908
	unsigned long end = addr + len;
801
909
910
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
911
	if (!(area->vm_flags & VM_MIRROR))
912
#endif
802
	area->vm_mm->total_vm -= len >> PAGE_SHIFT;
913
	area->vm_mm->total_vm -= len >> PAGE_SHIFT;
803
	if (area->vm_flags & VM_LOCKED)
914
	if (area->vm_flags & VM_LOCKED)
804
		area->vm_mm->locked_vm -= len >> PAGE_SHIFT;
915
		area->vm_mm->locked_vm -= len >> PAGE_SHIFT;
Lines 924-929 Link Here
924
	}
1035
	}
925
}
1036
}
926
1037
1038
static inline struct vm_area_struct *unmap_vma(struct mm_struct *mm,
1039
	unsigned long addr, size_t len, struct vm_area_struct *mpnt,
1040
	struct vm_area_struct *extra)
1041
{
1042
	unsigned long st, end, size;
1043
	struct file *file = NULL;
1044
1045
	st = addr < mpnt->vm_start ? mpnt->vm_start : addr;
1046
	end = addr+len;
1047
	end = end > mpnt->vm_end ? mpnt->vm_end : end;
1048
	size = end - st;
1049
1050
	if (mpnt->vm_flags & VM_DENYWRITE &&
1051
	    (st != mpnt->vm_start || end != mpnt->vm_end) &&
1052
	    (file = mpnt->vm_file) != NULL) {
1053
		atomic_dec(&file->f_dentry->d_inode->i_writecount);
1054
	}
1055
	remove_shared_vm_struct(mpnt);
1056
	zap_page_range(mm, st, size);
1057
1058
	/*
1059
	 * Fix the mapping, and free the old area if it wasn't reused.
1060
	 */
1061
	extra = unmap_fixup(mm, mpnt, st, size, extra);
1062
	if (file)
1063
		atomic_inc(&file->f_dentry->d_inode->i_writecount);
1064
	return extra;
1065
}
1066
       
1067
static struct vm_area_struct *unmap_vma_list(struct mm_struct *mm,
1068
	unsigned long addr, size_t len, struct vm_area_struct *free,
1069
	struct vm_area_struct *extra, struct vm_area_struct *prev)
1070
{
1071
	struct vm_area_struct *mpnt;
1072
1073
	/* Ok - we have the memory areas we should free on the 'free' list,
1074
	 * so release them, and unmap the page range..
1075
	 * If the one of the segments is only being partially unmapped,
1076
	 * it will put new vm_area_struct(s) into the address space.
1077
	 * In that case we have to be careful with VM_DENYWRITE.
1078
	 */
1079
	while ((mpnt = free) != NULL) {
1080
		free = free->vm_next;
1081
		extra = unmap_vma(mm, addr, len, mpnt, extra);
1082
	}
1083
1084
	free_pgtables(mm, prev, addr, addr+len);
1085
1086
	return extra;
1087
}
1088
1089
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
1090
static struct vm_area_struct *unmap_vma_mirror_list(struct mm_struct *mm,
1091
	unsigned long addr, size_t len, struct vm_area_struct *free_m,
1092
	struct vm_area_struct *extra_m)
1093
{
1094
	struct vm_area_struct *mpnt, *prev;
1095
1096
	while ((mpnt = free_m) != NULL) {
1097
		unsigned long addr_m, start, end;
1098
1099
		free_m = free_m->vm_next;
1100
1101
		addr_m = addr - (unsigned long)mpnt->vm_private_data;
1102
		start = addr_m < mpnt->vm_start ? mpnt->vm_start : addr_m;
1103
		end = addr_m+len;
1104
		end = end > mpnt->vm_end ? mpnt->vm_end : end;
1105
		find_vma_prev(mm, mpnt->vm_start, &prev);
1106
		extra_m = unmap_vma(mm, addr_m, len, mpnt, extra_m);
1107
1108
		free_pgtables(mm, prev, start, end);
1109
	}               
1110
1111
	return extra_m;
1112
}
1113
#endif
1114
927
/* Munmap is split into 2 main parts -- this part which finds
1115
/* Munmap is split into 2 main parts -- this part which finds
928
 * what needs doing, and the areas themselves, which do the
1116
 * what needs doing, and the areas themselves, which do the
929
 * work.  This now handles partial unmappings.
1117
 * work.  This now handles partial unmappings.
Lines 933-938 Link Here
933
{
1121
{
934
	struct vm_area_struct *mpnt, *prev, **npp, *free, *extra;
1122
	struct vm_area_struct *mpnt, *prev, **npp, *free, *extra;
935
1123
1124
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
1125
	struct vm_area_struct *free_m, *extra_m;
1126
#endif
1127
936
	if ((addr & ~PAGE_MASK) || addr > TASK_SIZE || len > TASK_SIZE-addr)
1128
	if ((addr & ~PAGE_MASK) || addr > TASK_SIZE || len > TASK_SIZE-addr)
937
		return -EINVAL;
1129
		return -EINVAL;
938
1130
Lines 965-1024 Link Here
965
	if (!extra)
1157
	if (!extra)
966
		return -ENOMEM;
1158
		return -ENOMEM;
967
1159
1160
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
1161
	if (current->flags & (PF_PAX_SEGMEXEC | PF_PAX_RANDEXEC)) { 
1162
		extra_m = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
1163
		if (!extra_m) {
1164
			kmem_cache_free(vm_area_cachep, extra);
1165
			return -ENOMEM;
1166
		}
1167
	} else
1168
		extra_m = NULL;
1169
1170
	free_m = NULL;
1171
#endif
1172
968
	npp = (prev ? &prev->vm_next : &mm->mmap);
1173
	npp = (prev ? &prev->vm_next : &mm->mmap);
969
	free = NULL;
1174
	free = NULL;
970
	spin_lock(&mm->page_table_lock);
1175
	spin_lock(&mm->page_table_lock);
971
	for ( ; mpnt && mpnt->vm_start < addr+len; mpnt = *npp) {
1176
	for ( ; mpnt && mpnt->vm_start < addr+len; mpnt = *npp) {
1177
		mm->map_count--;
972
		*npp = mpnt->vm_next;
1178
		*npp = mpnt->vm_next;
973
		mpnt->vm_next = free;
1179
		mpnt->vm_next = free;
974
		free = mpnt;
1180
		free = mpnt;
975
		rb_erase(&mpnt->vm_rb, &mm->mm_rb);
1181
		rb_erase(&mpnt->vm_rb, &mm->mm_rb);
1182
1183
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
1184
		if (free->vm_flags & VM_MIRROR) {
1185
			struct vm_area_struct *mpnt_m, *prev_m, **npp_m;
1186
			unsigned long addr_m = free->vm_start + (unsigned long)free->vm_private_data;
1187
1188
			mm->mmap_cache = NULL;  /* Kill the cache. */
1189
			mpnt_m = find_vma_prev(mm, addr_m, &prev_m);
1190
			if (mpnt_m && mpnt_m->vm_start == addr_m && (mpnt_m->vm_flags & VM_MIRROR)) {
1191
				mm->map_count--;
1192
				npp_m = (prev_m ? &prev_m->vm_next : &mm->mmap);
1193
				*npp_m = mpnt_m->vm_next;
1194
				mpnt_m->vm_next = free_m;
1195
				free_m = mpnt_m;
1196
				rb_erase(&mpnt_m->vm_rb, &mm->mm_rb);
1197
			} else
1198
				printk("PAX: VMMIRROR: munmap bug in %s, %08lx\n", current->comm, free->vm_start);
1199
		}
1200
#endif
1201
976
	}
1202
	}
977
	mm->mmap_cache = NULL;	/* Kill the cache. */
1203
	mm->mmap_cache = NULL;	/* Kill the cache. */
978
	spin_unlock(&mm->page_table_lock);
1204
	spin_unlock(&mm->page_table_lock);
979
1205
980
	/* Ok - we have the memory areas we should free on the 'free' list,
1206
	extra = unmap_vma_list(mm, addr, len, free, extra, prev);
981
	 * so release them, and unmap the page range..
982
	 * If the one of the segments is only being partially unmapped,
983
	 * it will put new vm_area_struct(s) into the address space.
984
	 * In that case we have to be careful with VM_DENYWRITE.
985
	 */
986
	while ((mpnt = free) != NULL) {
987
		unsigned long st, end, size;
988
		struct file *file = NULL;
989
990
		free = free->vm_next;
991
1207
992
		st = addr < mpnt->vm_start ? mpnt->vm_start : addr;
1208
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
993
		end = addr+len;
1209
	extra_m = unmap_vma_mirror_list(mm, addr, len, free_m, extra_m);
994
		end = end > mpnt->vm_end ? mpnt->vm_end : end;
1210
#endif
995
		size = end - st;
996
997
		if (mpnt->vm_flags & VM_DENYWRITE &&
998
		    (st != mpnt->vm_start || end != mpnt->vm_end) &&
999
		    (file = mpnt->vm_file) != NULL) {
1000
			atomic_dec(&file->f_dentry->d_inode->i_writecount);
1001
		}
1002
		remove_shared_vm_struct(mpnt);
1003
		mm->map_count--;
1004
1005
		zap_page_range(mm, st, size);
1006
1211
1007
		/*
1008
		 * Fix the mapping, and free the old area if it wasn't reused.
1009
		 */
1010
		extra = unmap_fixup(mm, mpnt, st, size, extra);
1011
		if (file)
1012
			atomic_inc(&file->f_dentry->d_inode->i_writecount);
1013
	}
1014
	validate_mm(mm);
1212
	validate_mm(mm);
1015
1213
1214
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
1215
	if (extra_m)
1216
		kmem_cache_free(vm_area_cachep, extra_m);
1217
#endif
1218
1016
	/* Release the extra vma struct if it wasn't used */
1219
	/* Release the extra vma struct if it wasn't used */
1017
	if (extra)
1220
	if (extra)
1018
		kmem_cache_free(vm_area_cachep, extra);
1221
		kmem_cache_free(vm_area_cachep, extra);
1019
1222
1020
	free_pgtables(mm, prev, addr, addr+len);
1021
1022
	return 0;
1223
	return 0;
1023
}
1224
}
1024
1225
Lines 1027-1034 Link Here
1027
	int ret;
1228
	int ret;
1028
	struct mm_struct *mm = current->mm;
1229
	struct mm_struct *mm = current->mm;
1029
1230
1231
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
1232
	if ((current->flags & PF_PAX_SEGMEXEC) &&
1233
	    (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
1234
		return -EINVAL;
1235
#endif
1236
1030
	down_write(&mm->mmap_sem);
1237
	down_write(&mm->mmap_sem);
1031
	ret = do_munmap(mm, addr, len);
1238
	ret = do_munmap(mm, addr, len);
1239
1032
	up_write(&mm->mmap_sem);
1240
	up_write(&mm->mmap_sem);
1033
	return ret;
1241
	return ret;
1034
}
1242
}
Lines 1055-1060 Link Here
1055
	if (mm->def_flags & VM_LOCKED) {
1263
	if (mm->def_flags & VM_LOCKED) {
1056
		unsigned long locked = mm->locked_vm << PAGE_SHIFT;
1264
		unsigned long locked = mm->locked_vm << PAGE_SHIFT;
1057
		locked += len;
1265
		locked += len;
1266
		gr_learn_resource(current, RLIMIT_MEMLOCK, locked);
1058
		if (locked > current->rlim[RLIMIT_MEMLOCK].rlim_cur)
1267
		if (locked > current->rlim[RLIMIT_MEMLOCK].rlim_cur)
1059
			return -EAGAIN;
1268
			return -EAGAIN;
1060
	}
1269
	}
Lines 1071-1076 Link Here
1071
	}
1280
	}
1072
1281
1073
	/* Check against address space limits *after* clearing old maps... */
1282
	/* Check against address space limits *after* clearing old maps... */
1283
	gr_learn_resource(current, RLIMIT_AS, (mm->total_vm << PAGE_SHIFT) + len);
1074
	if ((mm->total_vm << PAGE_SHIFT) + len
1284
	if ((mm->total_vm << PAGE_SHIFT) + len
1075
	    > current->rlim[RLIMIT_AS].rlim_cur)
1285
	    > current->rlim[RLIMIT_AS].rlim_cur)
1076
		return -ENOMEM;
1286
		return -ENOMEM;
Lines 1083-1088 Link Here
1083
1293
1084
	flags = VM_DATA_DEFAULT_FLAGS | mm->def_flags;
1294
	flags = VM_DATA_DEFAULT_FLAGS | mm->def_flags;
1085
1295
1296
#if defined(CONFIG_GRKERNSEC_PAX_PAGEEXEC) || defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC)
1297
	if (current->flags & (PF_PAX_PAGEEXEC | PF_PAX_SEGMEXEC)) {
1298
		flags &= ~VM_EXEC;
1299
1300
#ifdef CONFIG_GRKERNSEC_PAX_MPROTECT
1301
		if (current->flags & PF_PAX_MPROTECT)
1302
			flags &= ~VM_MAYEXEC;
1303
#endif
1304
1305
	}
1306
#endif
1086
	/* Can we just expand an old anonymous mapping? */
1307
	/* Can we just expand an old anonymous mapping? */
1087
	if (rb_parent && vma_merge(mm, prev, rb_parent, addr, addr + len, flags))
1308
	if (rb_parent && vma_merge(mm, prev, rb_parent, addr, addr + len, flags))
1088
		goto out;
1309
		goto out;
Lines 1098-1103 Link Here
1098
	vma->vm_start = addr;
1319
	vma->vm_start = addr;
1099
	vma->vm_end = addr + len;
1320
	vma->vm_end = addr + len;
1100
	vma->vm_flags = flags;
1321
	vma->vm_flags = flags;
1322
1323
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
1324
	if (!(current->flags & PF_PAX_PAGEEXEC) && (flags & (VM_READ|VM_WRITE)))
1325
		vma->vm_page_prot = protection_map[(flags | VM_EXEC) & 0x0f];
1326
	else
1327
#endif
1101
	vma->vm_page_prot = protection_map[flags & 0x0f];
1328
	vma->vm_page_prot = protection_map[flags & 0x0f];
1102
	vma->vm_ops = NULL;
1329
	vma->vm_ops = NULL;
1103
	vma->vm_pgoff = 0;
1330
	vma->vm_pgoff = 0;
(-)linux-2.4.22-ppc-dev.orig/mm/mprotect.c (+122 lines)
Lines 7-12 Link Here
7
#include <linux/smp_lock.h>
7
#include <linux/smp_lock.h>
8
#include <linux/shm.h>
8
#include <linux/shm.h>
9
#include <linux/mman.h>
9
#include <linux/mman.h>
10
#include <linux/grsecurity.h>
11
12
#ifdef CONFIG_GRKERNSEC_PAX_MPROTECT
13
#include <linux/elf.h>
14
#include <linux/fs.h>
15
#endif
10
16
11
#include <asm/uaccess.h>
17
#include <asm/uaccess.h>
12
#include <asm/pgalloc.h>
18
#include <asm/pgalloc.h>
Lines 236-244 Link Here
236
	return 0;
242
	return 0;
237
}
243
}
238
244
245
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
246
static int __mprotect_fixup(struct vm_area_struct * vma, struct vm_area_struct ** pprev,
247
	unsigned long start, unsigned long end, unsigned int newflags);
248
239
static int mprotect_fixup(struct vm_area_struct * vma, struct vm_area_struct ** pprev,
249
static int mprotect_fixup(struct vm_area_struct * vma, struct vm_area_struct ** pprev,
240
	unsigned long start, unsigned long end, unsigned int newflags)
250
	unsigned long start, unsigned long end, unsigned int newflags)
241
{
251
{
252
	if (vma->vm_flags & VM_MIRROR) {
253
		struct vm_area_struct * vma_m, * prev_m;
254
		unsigned long start_m, end_m;
255
256
		start_m = vma->vm_start + (unsigned long)vma->vm_private_data;
257
		vma_m = find_vma_prev(vma->vm_mm, start_m, &prev_m);
258
		if (vma_m && vma_m->vm_start == start_m && (vma_m->vm_flags & VM_MIRROR)) {
259
			start_m = start + (unsigned long)vma->vm_private_data;
260
			end_m = end + (unsigned long)vma->vm_private_data;
261
			if ((current->flags & PF_PAX_SEGMEXEC) && !(newflags & VM_EXEC))
262
				__mprotect_fixup(vma_m, &prev_m, start_m, end_m, vma_m->vm_flags & ~(PROT_READ | PROT_WRITE | PROT_EXEC));
263
			else
264
				__mprotect_fixup(vma_m, &prev_m, start_m, end_m, newflags);
265
		} else
266
			printk("PAX: VMMIRROR: mprotect bug in %s, %08lx\n", current->comm, vma->vm_start);
267
	}
268
269
	return __mprotect_fixup(vma, pprev, start, end, newflags);
270
}
271
272
static int __mprotect_fixup(struct vm_area_struct * vma, struct vm_area_struct ** pprev,
273
	unsigned long start, unsigned long end, unsigned int newflags)
274
#else
275
static int mprotect_fixup(struct vm_area_struct * vma, struct vm_area_struct ** pprev,
276
	unsigned long start, unsigned long end, unsigned int newflags)
277
#endif
278
{
242
	pgprot_t newprot;
279
	pgprot_t newprot;
243
	int error;
280
	int error;
244
281
Lines 246-251 Link Here
246
		*pprev = vma;
283
		*pprev = vma;
247
		return 0;
284
		return 0;
248
	}
285
	}
286
287
#ifdef CONFIG_GRKERNSEC_PAX_PAGEEXEC
288
	if (!(current->flags & PF_PAX_PAGEEXEC) && (newflags & (VM_READ|VM_WRITE)))
289
		newprot = protection_map[(newflags | VM_EXEC) & 0xf];
290
	else
291
#endif
249
	newprot = protection_map[newflags & 0xf];
292
	newprot = protection_map[newflags & 0xf];
250
	if (start == vma->vm_start) {
293
	if (start == vma->vm_start) {
251
		if (end == vma->vm_end)
294
		if (end == vma->vm_end)
Lines 264-269 Link Here
264
	return 0;
307
	return 0;
265
}
308
}
266
309
310
#ifdef CONFIG_GRKERNSEC_PAX_MPROTECT
311
/* PaX: non-PIC ELF libraries need relocations on their executable segments
312
 * therefore we'll grant them VM_MAYWRITE once during their life.
313
 *
314
 * The checks favor ld-linux.so behaviour which operates on a per ELF segment
315
 * basis because we want to allow the common case and not the special ones.
316
 */
317
static inline void pax_handle_maywrite(struct vm_area_struct * vma, unsigned long start)
318
{
319
	struct elfhdr elf_h;
320
	struct elf_phdr elf_p, p_dyn;
321
	elf_dyn dyn;
322
	unsigned long i, j = 65536UL / sizeof(struct elf_phdr);
323
324
#ifndef CONFIG_GRKERNSEC_PAX_NOELFRELOCS
325
	if ((vma->vm_start != start) ||
326
	    !vma->vm_file ||
327
	    !(vma->vm_flags & VM_MAYEXEC) ||
328
	    (vma->vm_flags & VM_MAYNOTWRITE))
329
#endif
330
331
		return;
332
333
	if (0 > kernel_read(vma->vm_file, 0UL, (char*)&elf_h, sizeof(elf_h)) ||
334
	    memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
335
336
#ifdef CONFIG_GRKERNSEC_PAX_ETEXECRELOCS
337
	    (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) ||
338
#else
339
	    elf_h.e_type != ET_DYN ||
340
#endif
341
342
	    !elf_check_arch(&elf_h) ||
343
	    elf_h.e_phentsize != sizeof(struct elf_phdr) ||
344
	    elf_h.e_phnum > j)
345
		return;
346
347
	for (i = 0UL; i < elf_h.e_phnum; i++) {
348
		if (0 > kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char*)&elf_p, sizeof(elf_p)))
349
			return;
350
		if (elf_p.p_type == PT_DYNAMIC) {
351
			p_dyn = elf_p;
352
			j = i;
353
		}
354
	}
355
	if (elf_h.e_phnum <= j)
356
		return;
357
358
	i = 0UL;
359
	do {
360
		if (0 > kernel_read(vma->vm_file, p_dyn.p_offset + i*sizeof(dyn), (char*)&dyn, sizeof(dyn)))
361
			return;
362
		if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
363
			vma->vm_flags |= VM_MAYWRITE | VM_MAYNOTWRITE;
364
			return;
365
		}
366
		i++;
367
	} while (dyn.d_tag != DT_NULL);
368
	return;
369
}
370
#endif
371
267
asmlinkage long sys_mprotect(unsigned long start, size_t len, unsigned long prot)
372
asmlinkage long sys_mprotect(unsigned long start, size_t len, unsigned long prot)
268
{
373
{
269
	unsigned long nstart, end, tmp;
374
	unsigned long nstart, end, tmp;
Lines 288-293 Link Here
288
	if (!vma || vma->vm_start > start)
393
	if (!vma || vma->vm_start > start)
289
		goto out;
394
		goto out;
290
395
396
	if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
397
		error = -EACCES;
398
		goto out;
399
	}
400
401
#ifdef CONFIG_GRKERNSEC_PAX_MPROTECT
402
	if ((current->flags & PF_PAX_MPROTECT) && (prot & PROT_WRITE))
403
		pax_handle_maywrite(vma, start);
404
#endif
405
291
	for (nstart = start ; ; ) {
406
	for (nstart = start ; ; ) {
292
		unsigned int newflags;
407
		unsigned int newflags;
293
		int last = 0;
408
		int last = 0;
Lines 300-305 Link Here
300
			goto out;
415
			goto out;
301
		}
416
		}
302
417
418
#ifdef CONFIG_GRKERNSEC_PAX_MPROTECT
419
		/* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
420
		if ((current->flags & PF_PAX_MPROTECT) && (prot & PROT_WRITE) && (vma->vm_flags & VM_MAYNOTWRITE))
421
			newflags &= ~VM_MAYWRITE;
422
#endif
423
303
		if (vma->vm_end > end) {
424
		if (vma->vm_end > end) {
304
			error = mprotect_fixup(vma, &prev, nstart, end, newflags);
425
			error = mprotect_fixup(vma, &prev, nstart, end, newflags);
305
			goto out;
426
			goto out;
Lines 332-337 Link Here
332
		prev->vm_mm->map_count--;
453
		prev->vm_mm->map_count--;
333
	}
454
	}
334
out:
455
out:
456
335
	up_write(&current->mm->mmap_sem);
457
	up_write(&current->mm->mmap_sem);
336
	return error;
458
	return error;
337
}
459
}
(-)linux-2.4.22-ppc-dev.orig/mm/mremap.c (-1 / +35 lines)
Lines 193-199 Link Here
193
		}
193
		}
194
194
195
		do_munmap(current->mm, addr, old_len);
195
		do_munmap(current->mm, addr, old_len);
196
196
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
197
		if (!(new_vma->vm_flags & VM_MIRROR))
198
#endif
197
		current->mm->total_vm += new_len >> PAGE_SHIFT;
199
		current->mm->total_vm += new_len >> PAGE_SHIFT;
198
		if (vm_locked) {
200
		if (vm_locked) {
199
			current->mm->locked_vm += new_len >> PAGE_SHIFT;
201
			current->mm->locked_vm += new_len >> PAGE_SHIFT;
Lines 232-237 Link Here
232
	old_len = PAGE_ALIGN(old_len);
234
	old_len = PAGE_ALIGN(old_len);
233
	new_len = PAGE_ALIGN(new_len);
235
	new_len = PAGE_ALIGN(new_len);
234
236
237
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
238
	if ((current->flags & PF_PAX_SEGMEXEC) &&
239
	    (new_len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-new_len ||
240
	     old_len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-old_len))
241
		goto out;
242
#endif
243
235
	/* new_addr is only valid if MREMAP_FIXED is specified */
244
	/* new_addr is only valid if MREMAP_FIXED is specified */
236
	if (flags & MREMAP_FIXED) {
245
	if (flags & MREMAP_FIXED) {
237
		if (new_addr & ~PAGE_MASK)
246
		if (new_addr & ~PAGE_MASK)
Lines 242-247 Link Here
242
		if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
251
		if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
243
			goto out;
252
			goto out;
244
253
254
#ifdef CONFIG_GRKERNSEC_PAX_SEGMEXEC
255
		if ((current->flags & PF_PAX_SEGMEXEC) &&
256
		    (new_len > SEGMEXEC_TASK_SIZE || new_addr > SEGMEXEC_TASK_SIZE-new_len))
257
			goto out;
258
#endif
259
245
		/* Check if the location we're moving into overlaps the
260
		/* Check if the location we're moving into overlaps the
246
		 * old location at all, and fail if it does.
261
		 * old location at all, and fail if it does.
247
		 */
262
		 */
Lines 272-277 Link Here
272
	vma = find_vma(current->mm, addr);
287
	vma = find_vma(current->mm, addr);
273
	if (!vma || vma->vm_start > addr)
288
	if (!vma || vma->vm_start > addr)
274
		goto out;
289
		goto out;
290
291
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
292
	if ((current->flags & (PF_PAX_SEGMEXEC | PF_PAX_RANDEXEC)) &&
293
	    (vma->vm_flags & VM_MIRROR))
294
		return -EINVAL;
295
#endif
296
275
	/* We can't remap across vm area boundaries */
297
	/* We can't remap across vm area boundaries */
276
	if (old_len > vma->vm_end - addr)
298
	if (old_len > vma->vm_end - addr)
277
		goto out;
299
		goto out;
Lines 283-295 Link Here
283
		unsigned long locked = current->mm->locked_vm << PAGE_SHIFT;
305
		unsigned long locked = current->mm->locked_vm << PAGE_SHIFT;
284
		locked += new_len - old_len;
306
		locked += new_len - old_len;
285
		ret = -EAGAIN;
307
		ret = -EAGAIN;
308
		gr_learn_resource(current, RLIMIT_MEMLOCK, locked);
286
		if (locked > current->rlim[RLIMIT_MEMLOCK].rlim_cur)
309
		if (locked > current->rlim[RLIMIT_MEMLOCK].rlim_cur)
287
			goto out;
310
			goto out;
288
	}
311
	}
289
	ret = -ENOMEM;
312
	ret = -ENOMEM;
313
314
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
315
	if (!(vma->vm_flags & VM_MIRROR)) {
316
#endif   
317
	gr_learn_resource(current, RLIMIT_AS, (current->mm->total_vm << PAGE_SHIFT) + (new_len - old_len));
290
	if ((current->mm->total_vm << PAGE_SHIFT) + (new_len - old_len)
318
	if ((current->mm->total_vm << PAGE_SHIFT) + (new_len - old_len)
291
	    > current->rlim[RLIMIT_AS].rlim_cur)
319
	    > current->rlim[RLIMIT_AS].rlim_cur)
292
		goto out;
320
		goto out;
321
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
322
	}
323
#endif
293
	/* Private writable mapping? Check memory availability.. */
324
	/* Private writable mapping? Check memory availability.. */
294
	if ((vma->vm_flags & (VM_SHARED | VM_WRITE)) == VM_WRITE &&
325
	if ((vma->vm_flags & (VM_SHARED | VM_WRITE)) == VM_WRITE &&
295
	    !(flags & MAP_NORESERVE)				 &&
326
	    !(flags & MAP_NORESERVE)				 &&
Lines 311-316 Link Here
311
			spin_lock(&vma->vm_mm->page_table_lock);
342
			spin_lock(&vma->vm_mm->page_table_lock);
312
			vma->vm_end = addr + new_len;
343
			vma->vm_end = addr + new_len;
313
			spin_unlock(&vma->vm_mm->page_table_lock);
344
			spin_unlock(&vma->vm_mm->page_table_lock);
345
#if defined(CONFIG_GRKERNSEC_PAX_SEGMEXEC) || defined(CONFIG_GRKERNSEC_PAX_RANDEXEC)
346
			if (!(vma->vm_flags & VM_MIRROR))
347
#endif   
314
			current->mm->total_vm += pages;
348
			current->mm->total_vm += pages;
315
			if (vma->vm_flags & VM_LOCKED) {
349
			if (vma->vm_flags & VM_LOCKED) {
316
				current->mm->locked_vm += pages;
350
				current->mm->locked_vm += pages;
(-)linux-2.4.22-ppc-dev.orig/net/ipv4/af_inet.c (-1 / +7 lines)
Lines 83-88 Link Here
83
#include <linux/init.h>
83
#include <linux/init.h>
84
#include <linux/poll.h>
84
#include <linux/poll.h>
85
#include <linux/netfilter_ipv4.h>
85
#include <linux/netfilter_ipv4.h>
86
#include <linux/grsecurity.h>
86
87
87
#include <asm/uaccess.h>
88
#include <asm/uaccess.h>
88
#include <asm/system.h>
89
#include <asm/system.h>
Lines 374-380 Link Here
374
	else
375
	else
375
		sk->protinfo.af_inet.pmtudisc = IP_PMTUDISC_WANT;
376
		sk->protinfo.af_inet.pmtudisc = IP_PMTUDISC_WANT;
376
377
377
	sk->protinfo.af_inet.id = 0;
378
#ifdef CONFIG_GRKERNSEC_RANDID
379
	if(grsec_enable_randid)
380
		sk->protinfo.af_inet.id = htons(ip_randomid());
381
	else
382
#endif
383
		sk->protinfo.af_inet.id = 0;
378
384
379
	sock_init_data(sock,sk);
385
	sock_init_data(sock,sk);
380
386
(-)linux-2.4.22-ppc-dev.orig/net/ipv4/icmp.c (+3 lines)
Lines 87-92 Link Here
87
#include <linux/errno.h>
87
#include <linux/errno.h>
88
#include <linux/timer.h>
88
#include <linux/timer.h>
89
#include <linux/init.h>
89
#include <linux/init.h>
90
#include <linux/grsecurity.h>
91
90
#include <asm/system.h>
92
#include <asm/system.h>
91
#include <asm/uaccess.h>
93
#include <asm/uaccess.h>
92
#include <net/checksum.h>
94
#include <net/checksum.h>
Lines 715-720 Link Here
715
717
716
		icmp_param.data.icmph=*skb->h.icmph;
718
		icmp_param.data.icmph=*skb->h.icmph;
717
		icmp_param.data.icmph.type=ICMP_ECHOREPLY;
719
		icmp_param.data.icmph.type=ICMP_ECHOREPLY;
720
718
		icmp_param.skb=skb;
721
		icmp_param.skb=skb;
719
		icmp_param.offset=0;
722
		icmp_param.offset=0;
720
		icmp_param.data_len=skb->len;
723
		icmp_param.data_len=skb->len;
(-)linux-2.4.22-ppc-dev.orig/net/ipv4/ip_output.c (-1 / +8 lines)
Lines 77-82 Link Here
77
#include <linux/netfilter_ipv4.h>
77
#include <linux/netfilter_ipv4.h>
78
#include <linux/mroute.h>
78
#include <linux/mroute.h>
79
#include <linux/netlink.h>
79
#include <linux/netlink.h>
80
#include <linux/grsecurity.h>
80
81
81
/*
82
/*
82
 *      Shall we try to damage output packets if routing dev changes?
83
 *      Shall we try to damage output packets if routing dev changes?
Lines 514-520 Link Here
514
	 *	Begin outputting the bytes.
515
	 *	Begin outputting the bytes.
515
	 */
516
	 */
516
517
517
	id = sk->protinfo.af_inet.id++;
518
#ifdef CONFIG_GRKERNSEC_RANDID
519
	if(grsec_enable_randid) { 
520
		id = htons(ip_randomid());	
521
		sk->protinfo.af_inet.id = htons(ip_randomid());
522
	} else
523
#endif
524
		id = sk->protinfo.af_inet.id++;
518
525
519
	do {
526
	do {
520
		char *data;
527
		char *data;
(-)linux-2.4.22-ppc-dev.orig/net/ipv4/netfilter/Config.in (+1 lines)
Lines 33-38 Link Here
33
  dep_tristate '  LENGTH match support' CONFIG_IP_NF_MATCH_LENGTH $CONFIG_IP_NF_IPTABLES
33
  dep_tristate '  LENGTH match support' CONFIG_IP_NF_MATCH_LENGTH $CONFIG_IP_NF_IPTABLES
34
  dep_tristate '  TTL match support' CONFIG_IP_NF_MATCH_TTL $CONFIG_IP_NF_IPTABLES
34
  dep_tristate '  TTL match support' CONFIG_IP_NF_MATCH_TTL $CONFIG_IP_NF_IPTABLES
35
  dep_tristate '  tcpmss match support' CONFIG_IP_NF_MATCH_TCPMSS $CONFIG_IP_NF_IPTABLES
35
  dep_tristate '  tcpmss match support' CONFIG_IP_NF_MATCH_TCPMSS $CONFIG_IP_NF_IPTABLES
36
  dep_tristate '  stealth match support' CONFIG_IP_NF_MATCH_STEALTH $CONFIG_IP_NF_IPTABLES
36
  if [ "$CONFIG_IP_NF_CONNTRACK" != "n" ]; then
37
  if [ "$CONFIG_IP_NF_CONNTRACK" != "n" ]; then
37
    dep_tristate '  Helper match support' CONFIG_IP_NF_MATCH_HELPER $CONFIG_IP_NF_IPTABLES
38
    dep_tristate '  Helper match support' CONFIG_IP_NF_MATCH_HELPER $CONFIG_IP_NF_IPTABLES
38
  fi
39
  fi
(-)linux-2.4.22-ppc-dev.orig/net/ipv4/netfilter/Makefile (+1 lines)
Lines 86-91 Link Here
86
obj-$(CONFIG_IP_NF_MATCH_CONNTRACK) += ipt_conntrack.o
86
obj-$(CONFIG_IP_NF_MATCH_CONNTRACK) += ipt_conntrack.o
87
obj-$(CONFIG_IP_NF_MATCH_UNCLEAN) += ipt_unclean.o
87
obj-$(CONFIG_IP_NF_MATCH_UNCLEAN) += ipt_unclean.o
88
obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o
88
obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o
89
obj-$(CONFIG_IP_NF_MATCH_STEALTH) += ipt_stealth.o
89
90
90
# targets
91
# targets
91
obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
92
obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
(-)linux-2.4.22-ppc-dev.orig/net/ipv4/netfilter/ipt_stealth.c (+109 lines)
Line 0 Link Here
1
/* Kernel module to add stealth support.
2
 *
3
 * Copyright (C) 2002 Brad Spengler  <spender@grsecurity.net>
4
 *
5
 */
6
7
#include <linux/kernel.h>
8
#include <linux/module.h>
9
#include <linux/skbuff.h>
10
#include <linux/net.h>
11
#include <linux/sched.h>
12
#include <linux/inet.h>
13
#include <linux/stddef.h>
14
15
#include <net/ip.h>
16
#include <net/sock.h>
17
#include <net/tcp.h>
18
#include <net/udp.h>
19
#include <net/route.h>
20
#include <net/inet_common.h>
21
22
#include <linux/netfilter_ipv4/ip_tables.h>
23
24
MODULE_LICENSE("GPL");
25
26
extern struct sock *udp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
27
28
static int
29
match(const struct sk_buff *skb,
30
      const struct net_device *in,
31
      const struct net_device *out,
32
      const void *matchinfo,
33
      int offset,
34
      const void *hdr,
35
      u_int16_t datalen,
36
      int *hotdrop)
37
{
38
	struct iphdr *ip = skb->nh.iph;
39
	struct tcphdr *th = (struct tcphdr *) hdr;
40
	struct udphdr *uh = (struct udphdr *) hdr;
41
	struct sock *sk = NULL;
42
43
	if (!ip || !hdr || offset) return 0;
44
45
	switch(ip->protocol) {
46
	case IPPROTO_TCP:
47
		if (datalen < sizeof(struct tcphdr)) {
48
			*hotdrop = 1;
49
			return 0;
50
		}
51
		if (!(th->syn && !th->ack)) return 0;
52
		sk = tcp_v4_lookup_listener(ip->daddr, ntohs(th->dest), ((struct rtable*)skb->dst)->rt_iif);	
53
		break;
54
	case IPPROTO_UDP:
55
		if (datalen < sizeof(struct udphdr)) {
56
			*hotdrop = 1;
57
			return 0;
58
		}
59
		sk = udp_v4_lookup(ip->saddr, uh->source, ip->daddr, uh->dest, skb->dev->ifindex);
60
		break;
61
	default:
62
		return 0;
63
	}
64
65
	if(!sk) // port is being listened on, match this
66
		return 1;
67
	else {
68
		sock_put(sk);
69
		return 0;
70
	}
71
}
72
73
/* Called when user tries to insert an entry of this type. */
74
static int
75
checkentry(const char *tablename,
76
           const struct ipt_ip *ip,
77
           void *matchinfo,
78
           unsigned int matchsize,
79
           unsigned int hook_mask)
80
{
81
        if (matchsize != IPT_ALIGN(0))
82
                return 0;
83
84
	if(((ip->proto == IPPROTO_TCP && !(ip->invflags & IPT_INV_PROTO)) ||
85
		((ip->proto == IPPROTO_UDP) && !(ip->invflags & IPT_INV_PROTO)))
86
		&& (hook_mask & (1 << NF_IP_LOCAL_IN)))
87
			return 1;
88
89
	printk("stealth: Only works on TCP and UDP for the INPUT chain.\n");
90
91
        return 0;
92
}
93
94
95
static struct ipt_match stealth_match
96
= { { NULL, NULL }, "stealth", &match, &checkentry, NULL, THIS_MODULE };
97
98
static int __init init(void)
99
{
100
	return ipt_register_match(&stealth_match);
101
}
102
103
static void __exit fini(void)
104
{
105
	ipt_unregister_match(&stealth_match);
106
}
107
108
module_init(init);
109
module_exit(fini);
(-)linux-2.4.22-ppc-dev.orig/net/ipv4/tcp_ipv4.c (-9 / +48 lines)
Lines 67-72 Link Here
67
#include <linux/inet.h>
67
#include <linux/inet.h>
68
#include <linux/stddef.h>
68
#include <linux/stddef.h>
69
#include <linux/ipsec.h>
69
#include <linux/ipsec.h>
70
#include <linux/grsecurity.h>
70
71
71
extern int sysctl_ip_dynaddr;
72
extern int sysctl_ip_dynaddr;
72
extern int sysctl_ip_default_ttl;
73
extern int sysctl_ip_default_ttl;
Lines 221-229 Link Here
221
222
222
		spin_lock(&tcp_portalloc_lock);
223
		spin_lock(&tcp_portalloc_lock);
223
		rover = tcp_port_rover;
224
		rover = tcp_port_rover;
224
		do {	rover++;
225
                do {
225
			if ((rover < low) || (rover > high))
226
#ifdef CONFIG_GRKERNSEC_RANDSRC
226
				rover = low;
227
			if (grsec_enable_randsrc && (high > low)) {
228
				rover = low + (get_random_long() % (high - low));
229
			} else
230
#endif
231
			{
232
				rover++;
233
				if ((rover < low) || (rover > high))
234
					rover = low;
235
			}
236
227
			head = &tcp_bhash[tcp_bhashfn(rover)];
237
			head = &tcp_bhash[tcp_bhashfn(rover)];
228
			spin_lock(&head->lock);
238
			spin_lock(&head->lock);
229
			for (tb = head->chain; tb; tb = tb->next)
239
			for (tb = head->chain; tb; tb = tb->next)
Lines 546-551 Link Here
546
556
547
static inline __u32 tcp_v4_init_sequence(struct sock *sk, struct sk_buff *skb)
557
static inline __u32 tcp_v4_init_sequence(struct sock *sk, struct sk_buff *skb)
548
{
558
{
559
#ifdef CONFIG_GRKERNSEC_RANDISN
560
	if (likely(grsec_enable_randisn))
561
		return ip_randomisn();
562
	else
563
#endif
549
	return secure_tcp_sequence_number(skb->nh.iph->daddr,
564
	return secure_tcp_sequence_number(skb->nh.iph->daddr,
550
					  skb->nh.iph->saddr,
565
					  skb->nh.iph->saddr,
551
					  skb->h.th->dest,
566
					  skb->h.th->dest,
Lines 681-689 Link Here
681
		rover = tcp_port_rover;
696
		rover = tcp_port_rover;
682
697
683
		do {
698
		do {
684
			rover++;
699
#ifdef CONFIG_GRKERNSEC_RANDSRC
685
			if ((rover < low) || (rover > high))
700
			if(grsec_enable_randsrc && (high > low)) {
686
				rover = low;
701
				rover = low + (get_random_long() % (high - low));
702
			} else
703
#endif
704
			{
705
				rover++;
706
				if ((rover < low) || (rover > high))
707
					rover = low;
708
			}
687
			head = &tcp_bhash[tcp_bhashfn(rover)];
709
			head = &tcp_bhash[tcp_bhashfn(rover)];
688
			spin_lock(&head->lock);		
710
			spin_lock(&head->lock);		
689
711
Lines 844-854 Link Here
844
	if (err)
866
	if (err)
845
		goto failure;
867
		goto failure;
846
868
847
	if (!tp->write_seq)
869
	if (!tp->write_seq) {
870
#ifdef CONFIG_GRKERNSEC_RANDISN
871
		if (likely(grsec_enable_randisn))
872
			tp->write_seq = ip_randomisn();
873
		else
874
#endif
848
		tp->write_seq = secure_tcp_sequence_number(sk->saddr, sk->daddr,
875
		tp->write_seq = secure_tcp_sequence_number(sk->saddr, sk->daddr,
849
							   sk->sport, usin->sin_port);
876
							   sk->sport, usin->sin_port);
877
	}
850
878
851
	sk->protinfo.af_inet.id = tp->write_seq^jiffies;
879
#ifdef CONFIG_GRKERNSEC_RANDID
880
	if(grsec_enable_randid)
881
		sk->protinfo.af_inet.id = htons(ip_randomid());
882
	else
883
#endif
884
		sk->protinfo.af_inet.id = tp->write_seq^jiffies;
852
885
853
	err = tcp_connect(sk);
886
	err = tcp_connect(sk);
854
	if (err)
887
	if (err)
Lines 1570-1576 Link Here
1570
	newtp->ext_header_len = 0;
1603
	newtp->ext_header_len = 0;
1571
	if (newsk->protinfo.af_inet.opt)
1604
	if (newsk->protinfo.af_inet.opt)
1572
		newtp->ext_header_len = newsk->protinfo.af_inet.opt->optlen;
1605
		newtp->ext_header_len = newsk->protinfo.af_inet.opt->optlen;
1573
	newsk->protinfo.af_inet.id = newtp->write_seq^jiffies;
1606
1607
#ifdef CONFIG_GRKERNSEC_RANDID
1608
	if(grsec_enable_randid)
1609
		newsk->protinfo.af_inet.id = htons(ip_randomid());
1610
	else
1611
#endif
1612
		newsk->protinfo.af_inet.id = newtp->write_seq^jiffies;
1574
1613
1575
	tcp_sync_mss(newsk, dst->pmtu);
1614
	tcp_sync_mss(newsk, dst->pmtu);
1576
	newtp->advmss = dst->advmss;
1615
	newtp->advmss = dst->advmss;
(-)linux-2.4.22-ppc-dev.orig/net/ipv4/udp.c (-1 / +26 lines)
Lines 91-96 Link Here
91
#include <net/ipv6.h>
91
#include <net/ipv6.h>
92
#include <net/protocol.h>
92
#include <net/protocol.h>
93
#include <linux/skbuff.h>
93
#include <linux/skbuff.h>
94
#include <linux/grsecurity.h>
94
#include <net/sock.h>
95
#include <net/sock.h>
95
#include <net/udp.h>
96
#include <net/udp.h>
96
#include <net/icmp.h>
97
#include <net/icmp.h>
Lines 98-103 Link Here
98
#include <net/inet_common.h>
99
#include <net/inet_common.h>
99
#include <net/checksum.h>
100
#include <net/checksum.h>
100
101
102
extern int gr_search_udp_recvmsg(const struct sock *sk,
103
					const struct sk_buff *skb);
104
extern int gr_search_udp_sendmsg(const struct sock *sk,
105
					const struct sockaddr_in *addr);
106
101
/*
107
/*
102
 *	Snmp MIB for the UDP layer
108
 *	Snmp MIB for the UDP layer
103
 */
109
 */
Lines 478-486 Link Here
478
		ufh.uh.dest = usin->sin_port;
484
		ufh.uh.dest = usin->sin_port;
479
		if (ufh.uh.dest == 0)
485
		if (ufh.uh.dest == 0)
480
			return -EINVAL;
486
			return -EINVAL;
487
488
		if (!gr_search_udp_sendmsg(sk, usin))
489
			return -EPERM;
481
	} else {
490
	} else {
482
		if (sk->state != TCP_ESTABLISHED)
491
		if (sk->state != TCP_ESTABLISHED)
483
			return -EDESTADDRREQ;
492
			return -EDESTADDRREQ;
493
494
		if (!gr_search_udp_sendmsg(sk, NULL))
495
			return -EPERM;
496
484
		ufh.daddr = sk->daddr;
497
		ufh.daddr = sk->daddr;
485
		ufh.uh.dest = sk->dport;
498
		ufh.uh.dest = sk->dport;
486
		/* Open fast path for connected socket.
499
		/* Open fast path for connected socket.
Lines 488-493 Link Here
488
		 */
501
		 */
489
		connected = 1;
502
		connected = 1;
490
  	}
503
  	}
504
491
	ipc.addr = sk->saddr;
505
	ipc.addr = sk->saddr;
492
	ufh.uh.source = sk->sport;
506
	ufh.uh.source = sk->sport;
493
507
Lines 659-664 Link Here
659
	if (!skb)
673
	if (!skb)
660
		goto out;
674
		goto out;
661
  
675
  
676
	if (!gr_search_udp_recvmsg(sk, skb)) {
677
		err = -EPERM;
678
		goto out_free;
679
	}
680
662
  	copied = skb->len - sizeof(struct udphdr);
681
  	copied = skb->len - sizeof(struct udphdr);
663
	if (copied > len) {
682
	if (copied > len) {
664
		copied = len;
683
		copied = len;
Lines 763-769 Link Here
763
	sk->daddr = rt->rt_dst;
782
	sk->daddr = rt->rt_dst;
764
	sk->dport = usin->sin_port;
783
	sk->dport = usin->sin_port;
765
	sk->state = TCP_ESTABLISHED;
784
	sk->state = TCP_ESTABLISHED;
766
	sk->protinfo.af_inet.id = jiffies;
785
786
#ifdef CONFIG_GRKERNSEC_RANDID
787
	if(grsec_enable_randid)
788
		sk->protinfo.af_inet.id = htons(ip_randomid());
789
	else
790
#endif
791
		sk->protinfo.af_inet.id = jiffies;
767
792
768
	sk_dst_set(sk, &rt->u.dst);
793
	sk_dst_set(sk, &rt->u.dst);
769
	return(0);
794
	return(0);
(-)linux-2.4.22-ppc-dev.orig/net/netlink/af_netlink.c (-1 / +3 lines)
Lines 40-45 Link Here
40
#include <linux/proc_fs.h>
40
#include <linux/proc_fs.h>
41
#include <linux/smp_lock.h>
41
#include <linux/smp_lock.h>
42
#include <linux/notifier.h>
42
#include <linux/notifier.h>
43
#include <linux/grsecurity.h>
43
#include <net/sock.h>
44
#include <net/sock.h>
44
#include <net/scm.h>
45
#include <net/scm.h>
45
46
Lines 625-631 Link Here
625
	   check them, when this message will be delivered
626
	   check them, when this message will be delivered
626
	   to corresponding kernel module.   --ANK (980802)
627
	   to corresponding kernel module.   --ANK (980802)
627
	 */
628
	 */
628
	NETLINK_CB(skb).eff_cap = current->cap_effective;
629
630
	NETLINK_CB(skb).eff_cap = gr_cap_rtnetlink();
629
631
630
	err = -EFAULT;
632
	err = -EFAULT;
631
	if (memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len)) {
633
	if (memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len)) {
(-)linux-2.4.22-ppc-dev.orig/net/netsyms.c (+44 lines)
Lines 24-29 Link Here
24
#include <net/checksum.h>
24
#include <net/checksum.h>
25
#include <linux/etherdevice.h>
25
#include <linux/etherdevice.h>
26
#include <net/route.h>
26
#include <net/route.h>
27
#include <linux/grsecurity.h>
27
#ifdef CONFIG_HIPPI
28
#ifdef CONFIG_HIPPI
28
#include <linux/hippidevice.h>
29
#include <linux/hippidevice.h>
29
#endif
30
#endif
Lines 606-611 Link Here
606
607
607
EXPORT_SYMBOL(softnet_data);
608
EXPORT_SYMBOL(softnet_data);
608
609
610
#if defined(CONFIG_IP_NF_MATCH_STEALTH_MODULE)
611
#if !defined (CONFIG_IPV6_MODULE) && !defined (CONFIG_KHTTPD) && !defined (CONFIG_KHTTPD_MODULE)
612
EXPORT_SYMBOL(tcp_v4_lookup_listener);
613
#endif
614
extern struct sock *udp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
615
EXPORT_SYMBOL(udp_v4_lookup);
616
#endif
617
618
#if defined(CONFIG_GRKERNSEC_RANDID)
619
EXPORT_SYMBOL(ip_randomid);
620
#endif
621
#if defined(CONFIG_GRKERNSEC_RANDSRC) || defined(CONFIG_GRKERNSEC_RANDRPC)
622
EXPORT_SYMBOL(get_random_long);
623
#endif
624
#ifdef CONFIG_GRKERNSEC_RANDISN
625
EXPORT_SYMBOL(ip_randomisn);
626
EXPORT_SYMBOL(grsec_enable_randisn);
627
#endif
628
#ifdef CONFIG_GRKERNSEC_RANDID
629
EXPORT_SYMBOL(grsec_enable_randid);
630
#endif
631
#ifdef CONFIG_GRKERNSEC_RANDSRC
632
EXPORT_SYMBOL(grsec_enable_randsrc);
633
#endif
634
#ifdef CONFIG_GRKERNSEC_RANDRPC
635
EXPORT_SYMBOL(grsec_enable_randrpc);
636
#endif
637
638
EXPORT_SYMBOL(gr_cap_rtnetlink);
639
640
extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
641
extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
642
643
EXPORT_SYMBOL(gr_search_udp_recvmsg);
644
EXPORT_SYMBOL(gr_search_udp_sendmsg);
645
646
#ifdef CONFIG_UNIX_MODULE
647
EXPORT_SYMBOL(gr_acl_handle_unix);
648
EXPORT_SYMBOL(gr_acl_handle_mknod);
649
EXPORT_SYMBOL(gr_handle_chroot_unix);
650
EXPORT_SYMBOL(gr_handle_create);
651
#endif
652
609
#if defined(CONFIG_NET_RADIO) || defined(CONFIG_NET_PCMCIA_RADIO)
653
#if defined(CONFIG_NET_RADIO) || defined(CONFIG_NET_PCMCIA_RADIO)
610
#include <net/iw_handler.h>
654
#include <net/iw_handler.h>
611
EXPORT_SYMBOL(wireless_send_event);
655
EXPORT_SYMBOL(wireless_send_event);
(-)linux-2.4.22-ppc-dev.orig/net/socket.c (-1 / +80 lines)
Lines 85-90 Link Here
85
#include <net/scm.h>
85
#include <net/scm.h>
86
#include <linux/netfilter.h>
86
#include <linux/netfilter.h>
87
87
88
extern void gr_attach_curr_ip(const struct sock *sk);
89
extern int gr_handle_sock_all(const int family, const int type,
90
			      const int protocol);
91
extern int gr_handle_sock_server(const struct sockaddr *sck);  
92
extern int gr_handle_sock_client(const struct sockaddr *sck);
93
extern int gr_search_connect(const struct socket * sock,
94
			     const struct sockaddr_in * addr);  
95
extern int gr_search_bind(const struct socket * sock,
96
			  const struct sockaddr_in * addr);
97
extern int gr_search_socket(const int domain, const int type,
98
			    const int protocol);
99
88
static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
100
static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
89
static ssize_t sock_read(struct file *file, char *buf,
101
static ssize_t sock_read(struct file *file, char *buf,
90
			 size_t size, loff_t *ppos);
102
			 size_t size, loff_t *ppos);
Lines 699-704 Link Here
699
711
700
int sock_close(struct inode *inode, struct file *filp)
712
int sock_close(struct inode *inode, struct file *filp)
701
{
713
{
714
	struct socket *sock;
702
	/*
715
	/*
703
	 *	It was possible the inode is NULL we were 
716
	 *	It was possible the inode is NULL we were 
704
	 *	closing an unfinished socket. 
717
	 *	closing an unfinished socket. 
Lines 709-716 Link Here
709
		printk(KERN_DEBUG "sock_close: NULL inode\n");
722
		printk(KERN_DEBUG "sock_close: NULL inode\n");
710
		return 0;
723
		return 0;
711
	}
724
	}
725
	sock = socki_lookup(inode);
726
712
	sock_fasync(-1, filp, 0);
727
	sock_fasync(-1, filp, 0);
728
729
#ifdef CONFIG_GRKERNSEC
730
	if (unlikely(current->used_accept && sock->sk &&
731
		     (sock->sk->protocol == IPPROTO_TCP) &&
732
	    	     (sock->sk->daddr == current->curr_ip))) {
733
		current->used_accept = 0;
734
		current->curr_ip = 0;
735
	}
736
#endif
737
713
	sock_release(socki_lookup(inode));
738
	sock_release(socki_lookup(inode));
739
714
	return 0;
740
	return 0;
715
}
741
}
716
742
Lines 903-908 Link Here
903
	int retval;
929
	int retval;
904
	struct socket *sock;
930
	struct socket *sock;
905
931
932
	if(!gr_search_socket(family, type, protocol)) {
933
		retval = -EACCES;
934
		goto out;
935
	}
936
937
	if (gr_handle_sock_all(family, type, protocol)) {
938
		retval = -EACCES;
939
		goto out;
940
	}
941
906
	retval = sock_create(family, type, protocol, &sock);
942
	retval = sock_create(family, type, protocol, &sock);
907
	if (retval < 0)
943
	if (retval < 0)
908
		goto out;
944
		goto out;
Lines 998-1009 Link Here
998
{
1034
{
999
	struct socket *sock;
1035
	struct socket *sock;
1000
	char address[MAX_SOCK_ADDR];
1036
	char address[MAX_SOCK_ADDR];
1037
	struct sockaddr * sck;
1001
	int err;
1038
	int err;
1002
1039
1003
	if((sock = sockfd_lookup(fd,&err))!=NULL)
1040
	if((sock = sockfd_lookup(fd,&err))!=NULL)
1004
	{
1041
	{
1005
		if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0)
1042
		if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0) {
1043
			sck = (struct sockaddr *) address;
1044
1045
			if(!gr_search_bind(sock, (struct sockaddr_in *) sck)) {
1046
				sockfd_put(sock);
1047
				return -EACCES;
1048
			}
1049
1050
			if (gr_handle_sock_server(sck)) {
1051
				sockfd_put(sock);
1052
				return -EACCES;
1053
			}
1054
1006
			err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);
1055
			err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);
1056
		}
1007
		sockfd_put(sock);
1057
		sockfd_put(sock);
1008
	}			
1058
	}			
1009
	return err;
1059
	return err;
Lines 1079-1084 Link Here
1079
	if ((err = sock_map_fd(newsock)) < 0)
1129
	if ((err = sock_map_fd(newsock)) < 0)
1080
		goto out_release;
1130
		goto out_release;
1081
1131
1132
	gr_attach_curr_ip(newsock->sk);
1133
1082
out_put:
1134
out_put:
1083
	sockfd_put(sock);
1135
	sockfd_put(sock);
1084
out:
1136
out:
Lines 1106-1111 Link Here
1106
{
1158
{
1107
	struct socket *sock;
1159
	struct socket *sock;
1108
	char address[MAX_SOCK_ADDR];
1160
	char address[MAX_SOCK_ADDR];
1161
	struct sockaddr * sck;
1109
	int err;
1162
	int err;
1110
1163
1111
	sock = sockfd_lookup(fd, &err);
1164
	sock = sockfd_lookup(fd, &err);
Lines 1114-1119 Link Here
1114
	err = move_addr_to_kernel(uservaddr, addrlen, address);
1167
	err = move_addr_to_kernel(uservaddr, addrlen, address);
1115
	if (err < 0)
1168
	if (err < 0)
1116
		goto out_put;
1169
		goto out_put;
1170
1171
	sck = (struct sockaddr *) address;
1172
1173
	if (!gr_search_connect(sock, (struct sockaddr_in *) sck)) {
1174
		err = -EACCES;
1175
		goto out_put;
1176
	}
1177
1178
	if (gr_handle_sock_client(sck)) {
1179
		err = -EACCES;
1180
		goto out_put;
1181
	}
1182
1183
#ifdef CONFIG_GRKERNSEC
1184
	if (sock->sk->protocol == IPPROTO_TCP)
1185
		current->used_connect = 1;
1186
#endif
1187
1117
	err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,
1188
	err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,
1118
				 sock->file->f_flags);
1189
				 sock->file->f_flags);
1119
out_put:
1190
out_put:
Lines 1333-1338 Link Here
1333
		err=sock->ops->shutdown(sock, how);
1404
		err=sock->ops->shutdown(sock, how);
1334
		sockfd_put(sock);
1405
		sockfd_put(sock);
1335
	}
1406
	}
1407
1408
#ifdef CONFIG_GRKERNSEC
1409
	if (likely(!err && current->used_accept)) {
1410
		current->used_accept = 0;
1411
		current->curr_ip = 0;
1412
	}
1413
#endif
1414
1336
	return err;
1415
	return err;
1337
}
1416
}
1338
1417
(-)linux-2.4.22-ppc-dev.orig/net/sunrpc/xprt.c (+7 lines)
Lines 59-64 Link Here
59
#include <linux/unistd.h>
59
#include <linux/unistd.h>
60
#include <linux/sunrpc/clnt.h>
60
#include <linux/sunrpc/clnt.h>
61
#include <linux/file.h>
61
#include <linux/file.h>
62
#include <linux/grsecurity.h>
62
63
63
#include <net/sock.h>
64
#include <net/sock.h>
64
#include <net/checksum.h>
65
#include <net/checksum.h>
Lines 1290-1295 Link Here
1290
	}
1291
	}
1291
	ret = xid++;
1292
	ret = xid++;
1292
	spin_unlock(&xid_lock);
1293
	spin_unlock(&xid_lock);
1294
1295
#ifdef CONFIG_GRKERNSEC_RANDRPC
1296
	if (grsec_enable_randrpc)
1297
		ret = (u32) get_random_long();
1298
#endif
1299
1293
	return ret;
1300
	return ret;
1294
}
1301
}
1295
1302
(-)linux-2.4.22-ppc-dev.orig/net/unix/af_unix.c (+41 lines)
Lines 109-114 Link Here
109
#include <linux/poll.h>
109
#include <linux/poll.h>
110
#include <linux/smp_lock.h>
110
#include <linux/smp_lock.h>
111
#include <linux/rtnetlink.h>
111
#include <linux/rtnetlink.h>
112
#include <linux/grsecurity.h>
112
113
113
#include <asm/checksum.h>
114
#include <asm/checksum.h>
114
115
Lines 599-604 Link Here
599
		if (err)
600
		if (err)
600
			goto put_fail;
601
			goto put_fail;
601
602
603
		if (!gr_acl_handle_unix(nd.dentry, nd.mnt)) {
604
			err = -EACCES;
605
			goto put_fail;
606
		}
607
		
602
		err = -ECONNREFUSED;
608
		err = -ECONNREFUSED;
603
		if (!S_ISSOCK(nd.dentry->d_inode->i_mode))
609
		if (!S_ISSOCK(nd.dentry->d_inode->i_mode))
604
			goto put_fail;
610
			goto put_fail;
Lines 622-627 Link Here
622
		if (u) {
628
		if (u) {
623
			struct dentry *dentry;
629
			struct dentry *dentry;
624
			dentry = u->protinfo.af_unix.dentry;
630
			dentry = u->protinfo.af_unix.dentry;
631
632
			if (!gr_handle_chroot_unix(u->peercred.pid)) {
633
				err = -EPERM;
634
				sock_put(u);
635
				goto fail;
636
			}
637
625
			if (dentry)
638
			if (dentry)
626
				UPDATE_ATIME(dentry->d_inode);
639
				UPDATE_ATIME(dentry->d_inode);
627
		} else
640
		} else
Lines 720-728 Link Here
720
		 * All right, let's create it.
733
		 * All right, let's create it.
721
		 */
734
		 */
722
		mode = S_IFSOCK | (sock->inode->i_mode & ~current->fs->umask);
735
		mode = S_IFSOCK | (sock->inode->i_mode & ~current->fs->umask);
736
	
737
		if (!gr_acl_handle_mknod(dentry, nd.dentry, nd.mnt, mode)) {
738
			err = -EACCES;
739
			goto out_mknod_dput;
740
		}	
741
723
		err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
742
		err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
743
724
		if (err)
744
		if (err)
725
			goto out_mknod_dput;
745
			goto out_mknod_dput;
746
747
		gr_handle_create(dentry, nd.mnt);
748
726
		up(&nd.dentry->d_inode->i_sem);
749
		up(&nd.dentry->d_inode->i_sem);
727
		dput(nd.dentry);
750
		dput(nd.dentry);
728
		nd.dentry = dentry;
751
		nd.dentry = dentry;
Lines 740-745 Link Here
740
			goto out_unlock;
763
			goto out_unlock;
741
		}
764
		}
742
765
766
#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
767
		sk->peercred.pid = current->pid;
768
#endif
769
743
		list = &unix_socket_table[addr->hash];
770
		list = &unix_socket_table[addr->hash];
744
	} else {
771
	} else {
745
		list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
772
		list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
Lines 866-871 Link Here
866
	int st;
893
	int st;
867
	int err;
894
	int err;
868
	long timeo;
895
	long timeo;
896
#ifdef CONFIG_GRKERNSEC
897
	struct task_struct *p, **htable;
898
#endif
869
899
870
	err = unix_mkname(sunaddr, addr_len, &hash);
900
	err = unix_mkname(sunaddr, addr_len, &hash);
871
	if (err < 0)
901
	if (err < 0)
Lines 989-994 Link Here
989
	/* Set credentials */
1019
	/* Set credentials */
990
	sk->peercred = other->peercred;
1020
	sk->peercred = other->peercred;
991
1021
1022
#ifdef CONFIG_GRKERNSEC
1023
	read_lock(&tasklist_lock);
1024
	htable = &pidhash[pid_hashfn(other->peercred.pid)];
1025
	for (p = *htable; p && p->pid != other->peercred.pid; p = p->pidhash_next);
1026
	if (p) {
1027
		p->curr_ip = current->curr_ip;
1028
		p->used_accept = 1;
1029
	}
1030
	read_unlock(&tasklist_lock);
1031
#endif
1032
992
	sock_hold(newsk);
1033
	sock_hold(newsk);
993
	unix_peer(sk)=newsk;
1034
	unix_peer(sk)=newsk;
994
	sock->state=SS_CONNECTED;
1035
	sock->state=SS_CONNECTED;

Return to bug 35819