0001.patch 105 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122
  1. diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
  2. index 51f845419b9c..be23caf4af4d 100644
  3. --- a/Documentation/admin-guide/kernel-parameters.txt
  4. +++ b/Documentation/admin-guide/kernel-parameters.txt
  5. @@ -509,16 +509,6 @@
  6. nosocket -- Disable socket memory accounting.
  7. nokmem -- Disable kernel memory accounting.
  8. - checkreqprot [SELINUX] Set initial checkreqprot flag value.
  9. - Format: { "0" | "1" }
  10. - See security/selinux/Kconfig help text.
  11. - 0 -- check protection applied by kernel (includes
  12. - any implied execute protection).
  13. - 1 -- check protection requested by application.
  14. - Default value is set via a kernel config option.
  15. - Value can be changed at runtime via
  16. - /selinux/checkreqprot.
  17. -
  18. cio_ignore= [S390]
  19. See Documentation/s390/common_io.rst for details.
  20. clk_ignore_unused
  21. @@ -3454,6 +3444,11 @@
  22. the specified number of seconds. This is to be used if
  23. your oopses keep scrolling off the screen.
  24. + extra_latent_entropy
  25. + Enable a very simple form of latent entropy extraction
  26. + from the first 4GB of memory as the bootmem allocator
  27. + passes the memory pages to the buddy allocator.
  28. +
  29. pcbit= [HW,ISDN]
  30. pcd. [PARIDE]
  31. diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
  32. index 568c24ff00a7..5e3e2749d842 100644
  33. --- a/Documentation/admin-guide/sysctl/kernel.rst
  34. +++ b/Documentation/admin-guide/sysctl/kernel.rst
  35. @@ -102,6 +102,7 @@ show up in /proc/sys/kernel:
  36. - sysctl_writes_strict
  37. - tainted ==> Documentation/admin-guide/tainted-kernels.rst
  38. - threads-max
  39. +- tiocsti_restrict
  40. - unknown_nmi_panic
  41. - watchdog
  42. - watchdog_thresh
  43. @@ -743,6 +744,8 @@ users (without CAP_SYS_ADMIN). The default value is 2.
  44. >=1 Disallow CPU event access by users without CAP_SYS_ADMIN
  45. >=2 Disallow kernel profiling by users without CAP_SYS_ADMIN
  46. +
  47. +>=3 Disallow use of any event by users without CAP_SYS_ADMIN
  48. === ==================================================================
  49. @@ -1154,6 +1157,25 @@ thread structures would occupy too much (more than 1/8th) of the
  50. available RAM pages threads-max is reduced accordingly.
  51. +tiocsti_restrict:
  52. +=================
  53. +
  54. +This toggle indicates whether unprivileged users are prevented from using the
  55. +TIOCSTI ioctl to inject commands into other processes which share a tty
  56. +session.
  57. +
  58. +When tiocsti_restrict is set to (0) there are no restrictions(accept the
  59. +default restriction of only being able to injection commands into one's own
  60. +tty). When tiocsti_restrict is set to (1), users must have CAP_SYS_ADMIN to
  61. +use the TIOCSTI ioctl.
  62. +
  63. +When user namespaces are in use, the check for the capability CAP_SYS_ADMIN is
  64. +done against the user namespace that originally opened the tty.
  65. +
  66. +The kernel config option CONFIG_SECURITY_TIOCSTI_RESTRICT sets the default
  67. +value of tiocsti_restrict.
  68. +
  69. +
  70. unknown_nmi_panic:
  71. ==================
  72. diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt
  73. index 5cf601c94e35..1fd8046af9f3 100644
  74. --- a/Documentation/networking/ip-sysctl.txt
  75. +++ b/Documentation/networking/ip-sysctl.txt
  76. @@ -583,6 +583,23 @@ tcp_comp_sack_nr - INTEGER
  77. Default : 44
  78. +tcp_simult_connect - BOOLEAN
  79. + Enable TCP simultaneous connect that adds a weakness in Linux's strict
  80. + implementation of TCP that allows two clients to connect to each other
  81. + without either entering a listening state. The weakness allows an attacker
  82. + to easily prevent a client from connecting to a known server provided the
  83. + source port for the connection is guessed correctly.
  84. +
  85. + As the weakness could be used to prevent an antivirus or IPS from fetching
  86. + updates, or prevent an SSL gateway from fetching a CRL, it should be
  87. + eliminated by disabling this option. Though Linux is one of few operating
  88. + systems supporting simultaneous connect, it has no legitimate use in
  89. + practice and is rarely supported by firewalls.
  90. +
  91. + Disabling this may break TCP STUNT which is used by some applications for
  92. + NAT traversal.
  93. + Default: Value of CONFIG_TCP_SIMULT_CONNECT_DEFAULT_ON
  94. +
  95. tcp_slow_start_after_idle - BOOLEAN
  96. If set, provide RFC2861 behavior and time out the congestion
  97. window after an idle period. An idle period is defined at
  98. diff --git a/arch/Kconfig b/arch/Kconfig
  99. index 4d03616bf597..138d1925abf6 100644
  100. --- a/arch/Kconfig
  101. +++ b/arch/Kconfig
  102. @@ -679,7 +679,7 @@ config ARCH_MMAP_RND_BITS
  103. int "Number of bits to use for ASLR of mmap base address" if EXPERT
  104. range ARCH_MMAP_RND_BITS_MIN ARCH_MMAP_RND_BITS_MAX
  105. default ARCH_MMAP_RND_BITS_DEFAULT if ARCH_MMAP_RND_BITS_DEFAULT
  106. - default ARCH_MMAP_RND_BITS_MIN
  107. + default ARCH_MMAP_RND_BITS_MAX
  108. depends on HAVE_ARCH_MMAP_RND_BITS
  109. help
  110. This value can be used to select the number of bits to use to
  111. @@ -713,7 +713,7 @@ config ARCH_MMAP_RND_COMPAT_BITS
  112. int "Number of bits to use for ASLR of mmap base address for compatible applications" if EXPERT
  113. range ARCH_MMAP_RND_COMPAT_BITS_MIN ARCH_MMAP_RND_COMPAT_BITS_MAX
  114. default ARCH_MMAP_RND_COMPAT_BITS_DEFAULT if ARCH_MMAP_RND_COMPAT_BITS_DEFAULT
  115. - default ARCH_MMAP_RND_COMPAT_BITS_MIN
  116. + default ARCH_MMAP_RND_COMPAT_BITS_MAX
  117. depends on HAVE_ARCH_MMAP_RND_COMPAT_BITS
  118. help
  119. This value can be used to select the number of bits to use to
  120. diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
  121. index 384b1bf56667..ccb53d76c68c 100644
  122. --- a/arch/arm64/Kconfig
  123. +++ b/arch/arm64/Kconfig
  124. @@ -1179,6 +1179,7 @@ config RODATA_FULL_DEFAULT_ENABLED
  125. config ARM64_SW_TTBR0_PAN
  126. bool "Emulate Privileged Access Never using TTBR0_EL1 switching"
  127. + default y
  128. help
  129. Enabling this option prevents the kernel from accessing
  130. user-space memory directly by pointing TTBR0_EL1 to a reserved
  131. @@ -1578,6 +1579,7 @@ config RANDOMIZE_BASE
  132. bool "Randomize the address of the kernel image"
  133. select ARM64_MODULE_PLTS if MODULES
  134. select RELOCATABLE
  135. + default y
  136. help
  137. Randomizes the virtual address at which the kernel image is
  138. loaded, as a security feature that deters exploit attempts
  139. diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
  140. index cf09010d825f..dc4083ceff57 100644
  141. --- a/arch/arm64/Kconfig.debug
  142. +++ b/arch/arm64/Kconfig.debug
  143. @@ -43,6 +43,7 @@ config ARM64_RANDOMIZE_TEXT_OFFSET
  144. config DEBUG_WX
  145. bool "Warn on W+X mappings at boot"
  146. select ARM64_PTDUMP_CORE
  147. + default y
  148. ---help---
  149. Generate a warning if any W+X mappings are found at boot.
  150. diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
  151. index c9a867ac32d4..5c4d264f6a6e 100644
  152. --- a/arch/arm64/configs/defconfig
  153. +++ b/arch/arm64/configs/defconfig
  154. @@ -1,4 +1,3 @@
  155. -CONFIG_SYSVIPC=y
  156. CONFIG_POSIX_MQUEUE=y
  157. CONFIG_AUDIT=y
  158. CONFIG_NO_HZ_IDLE=y
  159. diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
  160. index b618017205a3..0a228dbcad65 100644
  161. --- a/arch/arm64/include/asm/elf.h
  162. +++ b/arch/arm64/include/asm/elf.h
  163. @@ -103,14 +103,10 @@
  164. /*
  165. * This is the base location for PIE (ET_DYN with INTERP) loads. On
  166. - * 64-bit, this is above 4GB to leave the entire 32-bit address
  167. + * 64-bit, this is raised to 4GB to leave the entire 32-bit address
  168. * space open for things that want to use the area for 32-bit pointers.
  169. */
  170. -#ifdef CONFIG_ARM64_FORCE_52BIT
  171. -#define ELF_ET_DYN_BASE (2 * TASK_SIZE_64 / 3)
  172. -#else
  173. -#define ELF_ET_DYN_BASE (2 * DEFAULT_MAP_WINDOW_64 / 3)
  174. -#endif /* CONFIG_ARM64_FORCE_52BIT */
  175. +#define ELF_ET_DYN_BASE 0x100000000UL
  176. #ifndef __ASSEMBLY__
  177. @@ -164,10 +160,10 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
  178. /* 1GB of VA */
  179. #ifdef CONFIG_COMPAT
  180. #define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
  181. - 0x7ff >> (PAGE_SHIFT - 12) : \
  182. - 0x3ffff >> (PAGE_SHIFT - 12))
  183. + ((1UL << mmap_rnd_compat_bits) - 1) >> (PAGE_SHIFT - 12) : \
  184. + ((1UL << mmap_rnd_bits) - 1) >> (PAGE_SHIFT - 12))
  185. #else
  186. -#define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12))
  187. +#define STACK_RND_MASK (((1UL << mmap_rnd_bits) - 1) >> (PAGE_SHIFT - 12))
  188. #endif
  189. #ifdef __AARCH64EB__
  190. diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
  191. index df0a3a1b08ae..8c4d25460460 100644
  192. --- a/arch/x86/Kconfig
  193. +++ b/arch/x86/Kconfig
  194. @@ -1220,8 +1220,7 @@ config VM86
  195. default X86_LEGACY_VM86
  196. config X86_16BIT
  197. - bool "Enable support for 16-bit segments" if EXPERT
  198. - default y
  199. + bool "Enable support for 16-bit segments"
  200. depends on MODIFY_LDT_SYSCALL
  201. ---help---
  202. This option is required by programs like Wine to run 16-bit
  203. @@ -2366,7 +2365,7 @@ config COMPAT_VDSO
  204. choice
  205. prompt "vsyscall table for legacy applications"
  206. depends on X86_64
  207. - default LEGACY_VSYSCALL_XONLY
  208. + default LEGACY_VSYSCALL_NONE
  209. help
  210. Legacy user code that does not know how to find the vDSO expects
  211. to be able to issue three syscalls by calling fixed addresses in
  212. @@ -2462,8 +2461,7 @@ config CMDLINE_OVERRIDE
  213. be set to 'N' under normal conditions.
  214. config MODIFY_LDT_SYSCALL
  215. - bool "Enable the LDT (local descriptor table)" if EXPERT
  216. - default y
  217. + bool "Enable the LDT (local descriptor table)"
  218. ---help---
  219. Linux can allow user programs to install a per-process x86
  220. Local Descriptor Table (LDT) using the modify_ldt(2) system
  221. diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
  222. index bf9cd83de777..13ef90f3de52 100644
  223. --- a/arch/x86/Kconfig.debug
  224. +++ b/arch/x86/Kconfig.debug
  225. @@ -91,6 +91,7 @@ config EFI_PGT_DUMP
  226. config DEBUG_WX
  227. bool "Warn on W+X mappings at boot"
  228. select X86_PTDUMP_CORE
  229. + default y
  230. ---help---
  231. Generate a warning if any W+X mappings are found at boot.
  232. diff --git a/arch/x86/configs/x86_64_defconfig b/arch/x86/configs/x86_64_defconfig
  233. index 8092d7baf8b5..6cdf055c7a79 100644
  234. --- a/arch/x86/configs/x86_64_defconfig
  235. +++ b/arch/x86/configs/x86_64_defconfig
  236. @@ -1,5 +1,4 @@
  237. # CONFIG_LOCALVERSION_AUTO is not set
  238. -CONFIG_SYSVIPC=y
  239. CONFIG_POSIX_MQUEUE=y
  240. CONFIG_BSD_PROCESS_ACCT=y
  241. CONFIG_TASKSTATS=y
  242. diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
  243. index 8d7a4a2caf55..ca6e37881893 100644
  244. --- a/arch/x86/entry/vdso/vma.c
  245. +++ b/arch/x86/entry/vdso/vma.c
  246. @@ -198,55 +198,9 @@ static int map_vdso(const struct vdso_image *image, unsigned long addr)
  247. }
  248. #ifdef CONFIG_X86_64
  249. -/*
  250. - * Put the vdso above the (randomized) stack with another randomized
  251. - * offset. This way there is no hole in the middle of address space.
  252. - * To save memory make sure it is still in the same PTE as the stack
  253. - * top. This doesn't give that many random bits.
  254. - *
  255. - * Note that this algorithm is imperfect: the distribution of the vdso
  256. - * start address within a PMD is biased toward the end.
  257. - *
  258. - * Only used for the 64-bit and x32 vdsos.
  259. - */
  260. -static unsigned long vdso_addr(unsigned long start, unsigned len)
  261. -{
  262. - unsigned long addr, end;
  263. - unsigned offset;
  264. -
  265. - /*
  266. - * Round up the start address. It can start out unaligned as a result
  267. - * of stack start randomization.
  268. - */
  269. - start = PAGE_ALIGN(start);
  270. -
  271. - /* Round the lowest possible end address up to a PMD boundary. */
  272. - end = (start + len + PMD_SIZE - 1) & PMD_MASK;
  273. - if (end >= DEFAULT_MAP_WINDOW)
  274. - end = DEFAULT_MAP_WINDOW;
  275. - end -= len;
  276. -
  277. - if (end > start) {
  278. - offset = get_random_int() % (((end - start) >> PAGE_SHIFT) + 1);
  279. - addr = start + (offset << PAGE_SHIFT);
  280. - } else {
  281. - addr = start;
  282. - }
  283. -
  284. - /*
  285. - * Forcibly align the final address in case we have a hardware
  286. - * issue that requires alignment for performance reasons.
  287. - */
  288. - addr = align_vdso_addr(addr);
  289. -
  290. - return addr;
  291. -}
  292. -
  293. static int map_vdso_randomized(const struct vdso_image *image)
  294. {
  295. - unsigned long addr = vdso_addr(current->mm->start_stack, image->size-image->sym_vvar_start);
  296. -
  297. - return map_vdso(image, addr);
  298. + return map_vdso(image, 0);
  299. }
  300. #endif
  301. diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
  302. index 69c0f892e310..f9f7a85bb71e 100644
  303. --- a/arch/x86/include/asm/elf.h
  304. +++ b/arch/x86/include/asm/elf.h
  305. @@ -248,11 +248,11 @@ extern int force_personality32;
  306. /*
  307. * This is the base location for PIE (ET_DYN with INTERP) loads. On
  308. - * 64-bit, this is above 4GB to leave the entire 32-bit address
  309. + * 64-bit, this is raised to 4GB to leave the entire 32-bit address
  310. * space open for things that want to use the area for 32-bit pointers.
  311. */
  312. #define ELF_ET_DYN_BASE (mmap_is_ia32() ? 0x000400000UL : \
  313. - (DEFAULT_MAP_WINDOW / 3 * 2))
  314. + 0x100000000UL)
  315. /* This yields a mask that user programs can use to figure out what
  316. instruction set this CPU supports. This could be done in user space,
  317. @@ -312,8 +312,8 @@ extern bool mmap_address_hint_valid(unsigned long addr, unsigned long len);
  318. #ifdef CONFIG_X86_32
  319. -#define __STACK_RND_MASK(is32bit) (0x7ff)
  320. -#define STACK_RND_MASK (0x7ff)
  321. +#define __STACK_RND_MASK(is32bit) ((1UL << mmap_rnd_bits) - 1)
  322. +#define STACK_RND_MASK ((1UL << mmap_rnd_bits) - 1)
  323. #define ARCH_DLINFO ARCH_DLINFO_IA32
  324. @@ -322,7 +322,11 @@ extern bool mmap_address_hint_valid(unsigned long addr, unsigned long len);
  325. #else /* CONFIG_X86_32 */
  326. /* 1GB for 64bit, 8MB for 32bit */
  327. -#define __STACK_RND_MASK(is32bit) ((is32bit) ? 0x7ff : 0x3fffff)
  328. +#ifdef CONFIG_COMPAT
  329. +#define __STACK_RND_MASK(is32bit) ((is32bit) ? (1UL << mmap_rnd_compat_bits) - 1 : (1UL << mmap_rnd_bits) - 1)
  330. +#else
  331. +#define __STACK_RND_MASK(is32bit) ((1UL << mmap_rnd_bits) - 1)
  332. +#endif
  333. #define STACK_RND_MASK __STACK_RND_MASK(mmap_is_ia32())
  334. #define ARCH_DLINFO \
  335. @@ -380,5 +384,4 @@ struct va_alignment {
  336. } ____cacheline_aligned;
  337. extern struct va_alignment va_align;
  338. -extern unsigned long align_vdso_addr(unsigned long);
  339. #endif /* _ASM_X86_ELF_H */
  340. diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
  341. index 6f66d841262d..6914640316dc 100644
  342. --- a/arch/x86/include/asm/tlbflush.h
  343. +++ b/arch/x86/include/asm/tlbflush.h
  344. @@ -295,6 +295,7 @@ static inline void cr4_set_bits_irqsoff(unsigned long mask)
  345. unsigned long cr4;
  346. cr4 = this_cpu_read(cpu_tlbstate.cr4);
  347. + BUG_ON(cr4 != __read_cr4());
  348. if ((cr4 | mask) != cr4)
  349. __cr4_set(cr4 | mask);
  350. }
  351. @@ -305,6 +306,7 @@ static inline void cr4_clear_bits_irqsoff(unsigned long mask)
  352. unsigned long cr4;
  353. cr4 = this_cpu_read(cpu_tlbstate.cr4);
  354. + BUG_ON(cr4 != __read_cr4());
  355. if ((cr4 & ~mask) != cr4)
  356. __cr4_set(cr4 & ~mask);
  357. }
  358. @@ -334,6 +336,7 @@ static inline void cr4_toggle_bits_irqsoff(unsigned long mask)
  359. unsigned long cr4;
  360. cr4 = this_cpu_read(cpu_tlbstate.cr4);
  361. + BUG_ON(cr4 != __read_cr4());
  362. __cr4_set(cr4 ^ mask);
  363. }
  364. @@ -440,6 +443,7 @@ static inline void __native_flush_tlb_global(void)
  365. raw_local_irq_save(flags);
  366. cr4 = this_cpu_read(cpu_tlbstate.cr4);
  367. + BUG_ON(cr4 != __read_cr4());
  368. /* toggle PGE */
  369. native_write_cr4(cr4 ^ X86_CR4_PGE);
  370. /* write old PGE again and flush TLBs */
  371. diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
  372. index 1592f309c3c1..136a272ceb09 100644
  373. --- a/arch/x86/kernel/cpu/common.c
  374. +++ b/arch/x86/kernel/cpu/common.c
  375. @@ -2033,7 +2033,6 @@ void cpu_init(void)
  376. wrmsrl(MSR_KERNEL_GS_BASE, 0);
  377. barrier();
  378. - x86_configure_nx();
  379. x2apic_setup();
  380. /*
  381. diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
  382. index b8de27bb6e09..4149f330076f 100644
  383. --- a/arch/x86/kernel/process.c
  384. +++ b/arch/x86/kernel/process.c
  385. @@ -42,6 +42,8 @@
  386. #include <asm/prctl.h>
  387. #include <asm/spec-ctrl.h>
  388. #include <asm/proto.h>
  389. +#include <asm/elf.h>
  390. +#include <linux/sizes.h>
  391. #include "process.h"
  392. @@ -793,7 +795,10 @@ unsigned long arch_align_stack(unsigned long sp)
  393. unsigned long arch_randomize_brk(struct mm_struct *mm)
  394. {
  395. - return randomize_page(mm->brk, 0x02000000);
  396. + if (mmap_is_ia32())
  397. + return mm->brk + get_random_long() % SZ_32M + PAGE_SIZE;
  398. + else
  399. + return mm->brk + get_random_long() % SZ_1G + PAGE_SIZE;
  400. }
  401. /*
  402. diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
  403. index 42e31358a9d3..e13f2166f922 100644
  404. --- a/arch/x86/kernel/sys_x86_64.c
  405. +++ b/arch/x86/kernel/sys_x86_64.c
  406. @@ -54,13 +54,6 @@ static unsigned long get_align_bits(void)
  407. return va_align.bits & get_align_mask();
  408. }
  409. -unsigned long align_vdso_addr(unsigned long addr)
  410. -{
  411. - unsigned long align_mask = get_align_mask();
  412. - addr = (addr + align_mask) & ~align_mask;
  413. - return addr | get_align_bits();
  414. -}
  415. -
  416. static int __init control_va_addr_alignment(char *str)
  417. {
  418. /* guard against enabling this on other CPU families */
  419. diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
  420. index 0a74407ef92e..5ceff405c81c 100644
  421. --- a/arch/x86/mm/init_32.c
  422. +++ b/arch/x86/mm/init_32.c
  423. @@ -560,9 +560,9 @@ static void __init pagetable_init(void)
  424. #define DEFAULT_PTE_MASK ~(_PAGE_NX | _PAGE_GLOBAL)
  425. /* Bits supported by the hardware: */
  426. -pteval_t __supported_pte_mask __read_mostly = DEFAULT_PTE_MASK;
  427. +pteval_t __supported_pte_mask __ro_after_init = DEFAULT_PTE_MASK;
  428. /* Bits allowed in normal kernel mappings: */
  429. -pteval_t __default_kernel_pte_mask __read_mostly = DEFAULT_PTE_MASK;
  430. +pteval_t __default_kernel_pte_mask __ro_after_init = DEFAULT_PTE_MASK;
  431. EXPORT_SYMBOL_GPL(__supported_pte_mask);
  432. /* Used in PAGE_KERNEL_* macros which are reasonably used out-of-tree: */
  433. EXPORT_SYMBOL(__default_kernel_pte_mask);
  434. diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
  435. index a37ccafe065b..64df9614e105 100644
  436. --- a/arch/x86/mm/init_64.c
  437. +++ b/arch/x86/mm/init_64.c
  438. @@ -97,9 +97,9 @@ DEFINE_ENTRY(pte, pte, init)
  439. */
  440. /* Bits supported by the hardware: */
  441. -pteval_t __supported_pte_mask __read_mostly = ~0;
  442. +pteval_t __supported_pte_mask __ro_after_init = ~0;
  443. /* Bits allowed in normal kernel mappings: */
  444. -pteval_t __default_kernel_pte_mask __read_mostly = ~0;
  445. +pteval_t __default_kernel_pte_mask __ro_after_init = ~0;
  446. EXPORT_SYMBOL_GPL(__supported_pte_mask);
  447. /* Used in PAGE_KERNEL_* macros which are reasonably used out-of-tree: */
  448. EXPORT_SYMBOL(__default_kernel_pte_mask);
  449. diff --git a/block/blk-softirq.c b/block/blk-softirq.c
  450. index 457d9ba3eb20..5f987fc1c0a0 100644
  451. --- a/block/blk-softirq.c
  452. +++ b/block/blk-softirq.c
  453. @@ -20,7 +20,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
  454. * Softirq action handler - move entries to local list and loop over them
  455. * while passing them to the queue registered handler.
  456. */
  457. -static __latent_entropy void blk_done_softirq(struct softirq_action *h)
  458. +static __latent_entropy void blk_done_softirq(void)
  459. {
  460. struct list_head *cpu_list, local_list;
  461. diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
  462. index e2cf9859c67b..9b7ec4e053bd 100644
  463. --- a/drivers/ata/libata-core.c
  464. +++ b/drivers/ata/libata-core.c
  465. @@ -5199,7 +5199,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
  466. struct ata_port *ap;
  467. unsigned int tag;
  468. - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
  469. + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
  470. ap = qc->ap;
  471. qc->flags = 0;
  472. @@ -5216,7 +5216,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
  473. struct ata_port *ap;
  474. struct ata_link *link;
  475. - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
  476. + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
  477. WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
  478. ap = qc->ap;
  479. link = qc->dev->link;
  480. diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
  481. index 85e97550a9a6..1cfd2c7bd1bf 100644
  482. --- a/drivers/char/Kconfig
  483. +++ b/drivers/char/Kconfig
  484. @@ -9,7 +9,6 @@ source "drivers/tty/Kconfig"
  485. config DEVMEM
  486. bool "/dev/mem virtual device support"
  487. - default y
  488. help
  489. Say Y here if you want to support the /dev/mem device.
  490. The /dev/mem device is used to access areas of physical
  491. @@ -514,7 +513,6 @@ config TELCLOCK
  492. config DEVPORT
  493. bool "/dev/port character device"
  494. depends on ISA || PCI
  495. - default y
  496. help
  497. Say Y here if you want to support the /dev/port device. The /dev/port
  498. device is similar to /dev/mem, but for I/O ports.
  499. diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
  500. index c7623f99ac0f..859c2782c8e2 100644
  501. --- a/drivers/tty/Kconfig
  502. +++ b/drivers/tty/Kconfig
  503. @@ -122,7 +122,6 @@ config UNIX98_PTYS
  504. config LEGACY_PTYS
  505. bool "Legacy (BSD) PTY support"
  506. - default y
  507. ---help---
  508. A pseudo terminal (PTY) is a software device consisting of two
  509. halves: a master and a slave. The slave device behaves identical to
  510. diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
  511. index bb14bd4f6e55..340deb0029e2 100644
  512. --- a/drivers/tty/tty_io.c
  513. +++ b/drivers/tty/tty_io.c
  514. @@ -173,6 +173,7 @@ static void free_tty_struct(struct tty_struct *tty)
  515. put_device(tty->dev);
  516. kfree(tty->write_buf);
  517. tty->magic = 0xDEADDEAD;
  518. + put_user_ns(tty->owner_user_ns);
  519. kfree(tty);
  520. }
  521. @@ -2180,11 +2181,19 @@ static int tty_fasync(int fd, struct file *filp, int on)
  522. * current->signal->tty check is safe without locks
  523. */
  524. +int tiocsti_restrict = IS_ENABLED(CONFIG_SECURITY_TIOCSTI_RESTRICT);
  525. +
  526. static int tiocsti(struct tty_struct *tty, char __user *p)
  527. {
  528. char ch, mbz = 0;
  529. struct tty_ldisc *ld;
  530. + if (tiocsti_restrict &&
  531. + !ns_capable(tty->owner_user_ns, CAP_SYS_ADMIN)) {
  532. + dev_warn_ratelimited(tty->dev,
  533. + "Denied TIOCSTI ioctl for non-privileged process\n");
  534. + return -EPERM;
  535. + }
  536. if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
  537. return -EPERM;
  538. if (get_user(ch, p))
  539. @@ -3013,6 +3022,7 @@ struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx)
  540. tty->index = idx;
  541. tty_line_name(driver, idx, tty->name);
  542. tty->dev = tty_get_device(tty);
  543. + tty->owner_user_ns = get_user_ns(current_user_ns());
  544. return tty;
  545. }
  546. diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
  547. index 18e874b0441e..a010a4a5830e 100644
  548. --- a/drivers/usb/core/Makefile
  549. +++ b/drivers/usb/core/Makefile
  550. @@ -11,6 +11,7 @@ usbcore-y += phy.o port.o
  551. usbcore-$(CONFIG_OF) += of.o
  552. usbcore-$(CONFIG_USB_PCI) += hcd-pci.o
  553. usbcore-$(CONFIG_ACPI) += usb-acpi.o
  554. +usbcore-$(CONFIG_SYSCTL) += sysctl.o
  555. obj-$(CONFIG_USB) += usbcore.o
  556. diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
  557. index 238674fab7ce..289edfcd7f42 100644
  558. --- a/drivers/usb/core/hub.c
  559. +++ b/drivers/usb/core/hub.c
  560. @@ -5095,6 +5095,12 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
  561. goto done;
  562. return;
  563. }
  564. +
  565. + if (deny_new_usb) {
  566. + dev_err(&port_dev->dev, "denied insert of USB device on port %d\n", port1);
  567. + goto done;
  568. + }
  569. +
  570. if (hub_is_superspeed(hub->hdev))
  571. unit_load = 150;
  572. else
  573. diff --git a/drivers/usb/core/sysctl.c b/drivers/usb/core/sysctl.c
  574. new file mode 100644
  575. index 000000000000..2b7b9d778dd2
  576. --- /dev/null
  577. +++ b/drivers/usb/core/sysctl.c
  578. @@ -0,0 +1,46 @@
  579. +#include <linux/errno.h>
  580. +#include <linux/printk.h>
  581. +#include <linux/init.h>
  582. +#include <linux/sysctl.h>
  583. +#include <linux/usb.h>
  584. +
  585. +static int zero = 0;
  586. +static int one = 1;
  587. +
  588. +static struct ctl_table usb_table[] = {
  589. + {
  590. + .procname = "deny_new_usb",
  591. + .data = &deny_new_usb,
  592. + .maxlen = sizeof(int),
  593. + .mode = 0644,
  594. + .proc_handler = proc_dointvec_minmax_sysadmin,
  595. + .extra1 = &zero,
  596. + .extra2 = &one,
  597. + },
  598. + { }
  599. +};
  600. +
  601. +static struct ctl_table usb_root_table[] = {
  602. + { .procname = "kernel",
  603. + .mode = 0555,
  604. + .child = usb_table },
  605. + { }
  606. +};
  607. +
  608. +static struct ctl_table_header *usb_table_header;
  609. +
  610. +int __init usb_init_sysctl(void)
  611. +{
  612. + usb_table_header = register_sysctl_table(usb_root_table);
  613. + if (!usb_table_header) {
  614. + pr_warn("usb: sysctl registration failed\n");
  615. + return -ENOMEM;
  616. + }
  617. +
  618. + return 0;
  619. +}
  620. +
  621. +void usb_exit_sysctl(void)
  622. +{
  623. + unregister_sysctl_table(usb_table_header);
  624. +}
  625. diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
  626. index 502d911f71fa..61f3174cc3d8 100644
  627. --- a/drivers/usb/core/usb.c
  628. +++ b/drivers/usb/core/usb.c
  629. @@ -73,6 +73,9 @@ MODULE_PARM_DESC(autosuspend, "default autosuspend delay");
  630. #define usb_autosuspend_delay 0
  631. #endif
  632. +int deny_new_usb __read_mostly = 0;
  633. +EXPORT_SYMBOL(deny_new_usb);
  634. +
  635. static bool match_endpoint(struct usb_endpoint_descriptor *epd,
  636. struct usb_endpoint_descriptor **bulk_in,
  637. struct usb_endpoint_descriptor **bulk_out,
  638. @@ -1067,6 +1070,9 @@ static int __init usb_init(void)
  639. usb_debugfs_init();
  640. usb_acpi_register();
  641. + retval = usb_init_sysctl();
  642. + if (retval)
  643. + goto sysctl_init_failed;
  644. retval = bus_register(&usb_bus_type);
  645. if (retval)
  646. goto bus_register_failed;
  647. @@ -1101,6 +1107,8 @@ static int __init usb_init(void)
  648. bus_notifier_failed:
  649. bus_unregister(&usb_bus_type);
  650. bus_register_failed:
  651. + usb_exit_sysctl();
  652. +sysctl_init_failed:
  653. usb_acpi_unregister();
  654. usb_debugfs_cleanup();
  655. out:
  656. @@ -1124,6 +1132,7 @@ static void __exit usb_exit(void)
  657. usb_hub_cleanup();
  658. bus_unregister_notifier(&usb_bus_type, &usb_bus_nb);
  659. bus_unregister(&usb_bus_type);
  660. + usb_exit_sysctl();
  661. usb_acpi_unregister();
  662. usb_debugfs_cleanup();
  663. idr_destroy(&usb_bus_idr);
  664. diff --git a/fs/exec.c b/fs/exec.c
  665. index a7d78241082a..58901ced219e 100644
  666. --- a/fs/exec.c
  667. +++ b/fs/exec.c
  668. @@ -63,6 +63,7 @@
  669. #include <linux/oom.h>
  670. #include <linux/compat.h>
  671. #include <linux/vmalloc.h>
  672. +#include <linux/random.h>
  673. #include <linux/uaccess.h>
  674. #include <asm/mmu_context.h>
  675. @@ -276,6 +277,8 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
  676. arch_bprm_mm_init(mm, vma);
  677. up_write(&mm->mmap_sem);
  678. bprm->p = vma->vm_end - sizeof(void *);
  679. + if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
  680. + bprm->p ^= get_random_int() & ~PAGE_MASK;
  681. return 0;
  682. err:
  683. up_write(&mm->mmap_sem);
  684. diff --git a/fs/namei.c b/fs/namei.c
  685. index a4cba6991a4d..ad71a8abbd82 100644
  686. --- a/fs/namei.c
  687. +++ b/fs/namei.c
  688. @@ -877,10 +877,10 @@ static inline void put_link(struct nameidata *nd)
  689. path_put(&last->link);
  690. }
  691. -int sysctl_protected_symlinks __read_mostly = 0;
  692. -int sysctl_protected_hardlinks __read_mostly = 0;
  693. -int sysctl_protected_fifos __read_mostly;
  694. -int sysctl_protected_regular __read_mostly;
  695. +int sysctl_protected_symlinks __read_mostly = 1;
  696. +int sysctl_protected_hardlinks __read_mostly = 1;
  697. +int sysctl_protected_fifos __read_mostly = 2;
  698. +int sysctl_protected_regular __read_mostly = 2;
  699. /**
  700. * may_follow_link - Check symlink following for unsafe situations
  701. diff --git a/fs/nfs/Kconfig b/fs/nfs/Kconfig
  702. index e84c187d942e..fdac5ca7f677 100644
  703. --- a/fs/nfs/Kconfig
  704. +++ b/fs/nfs/Kconfig
  705. @@ -195,4 +195,3 @@ config NFS_DEBUG
  706. bool
  707. depends on NFS_FS && SUNRPC_DEBUG
  708. select CRC32
  709. - default y
  710. diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
  711. index cb5629bd5fff..bc44606fcc48 100644
  712. --- a/fs/proc/Kconfig
  713. +++ b/fs/proc/Kconfig
  714. @@ -41,7 +41,6 @@ config PROC_KCORE
  715. config PROC_VMCORE
  716. bool "/proc/vmcore support"
  717. depends on PROC_FS && CRASH_DUMP
  718. - default y
  719. help
  720. Exports the dump image of crashed kernel in ELF format.
  721. diff --git a/fs/stat.c b/fs/stat.c
  722. index 268c9eb89656..b6ef85222932 100644
  723. --- a/fs/stat.c
  724. +++ b/fs/stat.c
  725. @@ -40,8 +40,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
  726. stat->gid = inode->i_gid;
  727. stat->rdev = inode->i_rdev;
  728. stat->size = i_size_read(inode);
  729. - stat->atime = inode->i_atime;
  730. - stat->mtime = inode->i_mtime;
  731. + if (is_sidechannel_device(inode) && !capable_noaudit(CAP_MKNOD)) {
  732. + stat->atime = inode->i_ctime;
  733. + stat->mtime = inode->i_ctime;
  734. + } else {
  735. + stat->atime = inode->i_atime;
  736. + stat->mtime = inode->i_mtime;
  737. + }
  738. stat->ctime = inode->i_ctime;
  739. stat->blksize = i_blocksize(inode);
  740. stat->blocks = inode->i_blocks;
  741. @@ -77,9 +82,14 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat,
  742. if (IS_AUTOMOUNT(inode))
  743. stat->attributes |= STATX_ATTR_AUTOMOUNT;
  744. - if (inode->i_op->getattr)
  745. - return inode->i_op->getattr(path, stat, request_mask,
  746. - query_flags);
  747. + if (inode->i_op->getattr) {
  748. + int retval = inode->i_op->getattr(path, stat, request_mask, query_flags);
  749. + if (!retval && is_sidechannel_device(inode) && !capable_noaudit(CAP_MKNOD)) {
  750. + stat->atime = stat->ctime;
  751. + stat->mtime = stat->ctime;
  752. + }
  753. + return retval;
  754. + }
  755. generic_fillattr(inode, stat);
  756. return 0;
  757. diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
  758. index 740853465356..56d2e6966980 100644
  759. --- a/fs/userfaultfd.c
  760. +++ b/fs/userfaultfd.c
  761. @@ -28,7 +28,11 @@
  762. #include <linux/security.h>
  763. #include <linux/hugetlb.h>
  764. +#ifdef CONFIG_USERFAULTFD_UNPRIVILEGED
  765. int sysctl_unprivileged_userfaultfd __read_mostly = 1;
  766. +#else
  767. +int sysctl_unprivileged_userfaultfd __read_mostly;
  768. +#endif
  769. static struct kmem_cache *userfaultfd_ctx_cachep __read_mostly;
  770. diff --git a/include/linux/cache.h b/include/linux/cache.h
  771. index 750621e41d1c..e7157c18c62c 100644
  772. --- a/include/linux/cache.h
  773. +++ b/include/linux/cache.h
  774. @@ -31,6 +31,8 @@
  775. #define __ro_after_init __attribute__((__section__(".data..ro_after_init")))
  776. #endif
  777. +#define __read_only __ro_after_init
  778. +
  779. #ifndef ____cacheline_aligned
  780. #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
  781. #endif
  782. diff --git a/include/linux/capability.h b/include/linux/capability.h
  783. index ecce0f43c73a..e46306dd4401 100644
  784. --- a/include/linux/capability.h
  785. +++ b/include/linux/capability.h
  786. @@ -208,6 +208,7 @@ extern bool has_capability_noaudit(struct task_struct *t, int cap);
  787. extern bool has_ns_capability_noaudit(struct task_struct *t,
  788. struct user_namespace *ns, int cap);
  789. extern bool capable(int cap);
  790. +extern bool capable_noaudit(int cap);
  791. extern bool ns_capable(struct user_namespace *ns, int cap);
  792. extern bool ns_capable_noaudit(struct user_namespace *ns, int cap);
  793. extern bool ns_capable_setid(struct user_namespace *ns, int cap);
  794. @@ -234,6 +235,10 @@ static inline bool capable(int cap)
  795. {
  796. return true;
  797. }
  798. +static inline bool capable_noaudit(int cap)
  799. +{
  800. + return true;
  801. +}
  802. static inline bool ns_capable(struct user_namespace *ns, int cap)
  803. {
  804. return true;
  805. diff --git a/include/linux/fs.h b/include/linux/fs.h
  806. index e009b52ab6b0..71e374c77338 100644
  807. --- a/include/linux/fs.h
  808. +++ b/include/linux/fs.h
  809. @@ -3645,4 +3645,15 @@ static inline int inode_drain_writes(struct inode *inode)
  810. return filemap_write_and_wait(inode->i_mapping);
  811. }
  812. +extern int device_sidechannel_restrict;
  813. +
  814. +static inline bool is_sidechannel_device(const struct inode *inode)
  815. +{
  816. + umode_t mode;
  817. + if (!device_sidechannel_restrict)
  818. + return false;
  819. + mode = inode->i_mode;
  820. + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
  821. +}
  822. +
  823. #endif /* _LINUX_FS_H */
  824. diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
  825. index e9d2024473b0..e75cfbcfda56 100644
  826. --- a/include/linux/fsnotify.h
  827. +++ b/include/linux/fsnotify.h
  828. @@ -269,6 +269,9 @@ static inline void fsnotify_access(struct file *file)
  829. struct inode *inode = file_inode(file);
  830. __u32 mask = FS_ACCESS;
  831. + if (is_sidechannel_device(inode))
  832. + return;
  833. +
  834. if (S_ISDIR(inode->i_mode))
  835. mask |= FS_ISDIR;
  836. @@ -285,6 +288,9 @@ static inline void fsnotify_modify(struct file *file)
  837. struct inode *inode = file_inode(file);
  838. __u32 mask = FS_MODIFY;
  839. + if (is_sidechannel_device(inode))
  840. + return;
  841. +
  842. if (S_ISDIR(inode->i_mode))
  843. mask |= FS_ISDIR;
  844. diff --git a/include/linux/gfp.h b/include/linux/gfp.h
  845. index c89f8456f18d..c85e898c2a37 100644
  846. --- a/include/linux/gfp.h
  847. +++ b/include/linux/gfp.h
  848. @@ -553,9 +553,9 @@ extern struct page *alloc_pages_vma(gfp_t gfp_mask, int order,
  849. extern unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order);
  850. extern unsigned long get_zeroed_page(gfp_t gfp_mask);
  851. -void *alloc_pages_exact(size_t size, gfp_t gfp_mask);
  852. +void *alloc_pages_exact(size_t size, gfp_t gfp_mask) __attribute__((alloc_size(1)));
  853. void free_pages_exact(void *virt, size_t size);
  854. -void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask);
  855. +void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask) __attribute__((alloc_size(2)));
  856. #define __get_free_page(gfp_mask) \
  857. __get_free_pages((gfp_mask), 0)
  858. diff --git a/include/linux/highmem.h b/include/linux/highmem.h
  859. index 900f224bb640..97e0135c8268 100644
  860. --- a/include/linux/highmem.h
  861. +++ b/include/linux/highmem.h
  862. @@ -215,6 +215,13 @@ static inline void clear_highpage(struct page *page)
  863. kunmap_atomic(kaddr);
  864. }
  865. +static inline void verify_zero_highpage(struct page *page)
  866. +{
  867. + void *kaddr = kmap_atomic(page);
  868. + BUG_ON(memchr_inv(kaddr, 0, PAGE_SIZE));
  869. + kunmap_atomic(kaddr);
  870. +}
  871. +
  872. static inline void zero_user_segments(struct page *page,
  873. unsigned start1, unsigned end1,
  874. unsigned start2, unsigned end2)
  875. diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
  876. index 01517747214a..8b712abac03f 100644
  877. --- a/include/linux/interrupt.h
  878. +++ b/include/linux/interrupt.h
  879. @@ -544,7 +544,7 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
  880. struct softirq_action
  881. {
  882. - void (*action)(struct softirq_action *);
  883. + void (*action)(void);
  884. };
  885. asmlinkage void do_softirq(void);
  886. @@ -559,7 +559,7 @@ static inline void do_softirq_own_stack(void)
  887. }
  888. #endif
  889. -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
  890. +extern void __init open_softirq(int nr, void (*action)(void));
  891. extern void softirq_init(void);
  892. extern void __raise_softirq_irqoff(unsigned int nr);
  893. diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
  894. index 069aa2ebef90..cb9e3637a620 100644
  895. --- a/include/linux/kobject_ns.h
  896. +++ b/include/linux/kobject_ns.h
  897. @@ -45,7 +45,7 @@ struct kobj_ns_type_operations {
  898. void (*drop_ns)(void *);
  899. };
  900. -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
  901. +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
  902. int kobj_ns_type_registered(enum kobj_ns_type type);
  903. const struct kobj_ns_type_operations *kobj_child_ns_ops(struct kobject *parent);
  904. const struct kobj_ns_type_operations *kobj_ns_ops(struct kobject *kobj);
  905. diff --git a/include/linux/mm.h b/include/linux/mm.h
  906. index d14aba548ff4..2b665745900e 100644
  907. --- a/include/linux/mm.h
  908. +++ b/include/linux/mm.h
  909. @@ -667,7 +667,7 @@ static inline int is_vmalloc_or_module_addr(const void *x)
  910. }
  911. #endif
  912. -extern void *kvmalloc_node(size_t size, gfp_t flags, int node);
  913. +extern void *kvmalloc_node(size_t size, gfp_t flags, int node) __attribute__((alloc_size(1)));
  914. static inline void *kvmalloc(size_t size, gfp_t flags)
  915. {
  916. return kvmalloc_node(size, flags, NUMA_NO_NODE);
  917. diff --git a/include/linux/percpu.h b/include/linux/percpu.h
  918. index 5e76af742c80..9a6c682ec127 100644
  919. --- a/include/linux/percpu.h
  920. +++ b/include/linux/percpu.h
  921. @@ -123,7 +123,7 @@ extern int __init pcpu_page_first_chunk(size_t reserved_size,
  922. pcpu_fc_populate_pte_fn_t populate_pte_fn);
  923. #endif
  924. -extern void __percpu *__alloc_reserved_percpu(size_t size, size_t align);
  925. +extern void __percpu *__alloc_reserved_percpu(size_t size, size_t align) __attribute__((alloc_size(1)));
  926. extern bool __is_kernel_percpu_address(unsigned long addr, unsigned long *can_addr);
  927. extern bool is_kernel_percpu_address(unsigned long addr);
  928. @@ -131,8 +131,8 @@ extern bool is_kernel_percpu_address(unsigned long addr);
  929. extern void __init setup_per_cpu_areas(void);
  930. #endif
  931. -extern void __percpu *__alloc_percpu_gfp(size_t size, size_t align, gfp_t gfp);
  932. -extern void __percpu *__alloc_percpu(size_t size, size_t align);
  933. +extern void __percpu *__alloc_percpu_gfp(size_t size, size_t align, gfp_t gfp) __attribute__((alloc_size(1)));
  934. +extern void __percpu *__alloc_percpu(size_t size, size_t align) __attribute__((alloc_size(1)));
  935. extern void free_percpu(void __percpu *__pdata);
  936. extern phys_addr_t per_cpu_ptr_to_phys(void *addr);
  937. diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
  938. index 9e0e20c11aa3..6830f1831dea 100644
  939. --- a/include/linux/perf_event.h
  940. +++ b/include/linux/perf_event.h
  941. @@ -1271,6 +1271,11 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
  942. int perf_event_max_stack_handler(struct ctl_table *table, int write,
  943. void __user *buffer, size_t *lenp, loff_t *ppos);
  944. +static inline bool perf_paranoid_any(void)
  945. +{
  946. + return sysctl_perf_event_paranoid > 2;
  947. +}
  948. +
  949. static inline bool perf_paranoid_tracepoint_raw(void)
  950. {
  951. return sysctl_perf_event_paranoid > -1;
  952. diff --git a/include/linux/slab.h b/include/linux/slab.h
  953. index 4d2a2fa55ed5..be3a8234edde 100644
  954. --- a/include/linux/slab.h
  955. +++ b/include/linux/slab.h
  956. @@ -184,8 +184,8 @@ void memcg_deactivate_kmem_caches(struct mem_cgroup *, struct mem_cgroup *);
  957. /*
  958. * Common kmalloc functions provided by all allocators
  959. */
  960. -void * __must_check __krealloc(const void *, size_t, gfp_t);
  961. -void * __must_check krealloc(const void *, size_t, gfp_t);
  962. +void * __must_check __krealloc(const void *, size_t, gfp_t) __attribute__((alloc_size(2)));
  963. +void * __must_check krealloc(const void *, size_t, gfp_t) __attribute((alloc_size(2)));
  964. void kfree(const void *);
  965. void kzfree(const void *);
  966. size_t __ksize(const void *);
  967. @@ -390,7 +390,7 @@ static __always_inline unsigned int kmalloc_index(size_t size)
  968. }
  969. #endif /* !CONFIG_SLOB */
  970. -void *__kmalloc(size_t size, gfp_t flags) __assume_kmalloc_alignment __malloc;
  971. +void *__kmalloc(size_t size, gfp_t flags) __assume_kmalloc_alignment __malloc __attribute__((alloc_size(1)));
  972. void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags) __assume_slab_alignment __malloc;
  973. void kmem_cache_free(struct kmem_cache *, void *);
  974. @@ -414,7 +414,7 @@ static __always_inline void kfree_bulk(size_t size, void **p)
  975. }
  976. #ifdef CONFIG_NUMA
  977. -void *__kmalloc_node(size_t size, gfp_t flags, int node) __assume_kmalloc_alignment __malloc;
  978. +void *__kmalloc_node(size_t size, gfp_t flags, int node) __assume_kmalloc_alignment __malloc __attribute__((alloc_size(1)));
  979. void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node) __assume_slab_alignment __malloc;
  980. #else
  981. static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
  982. @@ -539,7 +539,7 @@ static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
  983. * Try really hard to succeed the allocation but fail
  984. * eventually.
  985. */
  986. -static __always_inline void *kmalloc(size_t size, gfp_t flags)
  987. +static __always_inline __attribute__((alloc_size(1))) void *kmalloc(size_t size, gfp_t flags)
  988. {
  989. if (__builtin_constant_p(size)) {
  990. #ifndef CONFIG_SLOB
  991. @@ -581,7 +581,7 @@ static __always_inline unsigned int kmalloc_size(unsigned int n)
  992. return 0;
  993. }
  994. -static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
  995. +static __always_inline __attribute__((alloc_size(1))) void *kmalloc_node(size_t size, gfp_t flags, int node)
  996. {
  997. #ifndef CONFIG_SLOB
  998. if (__builtin_constant_p(size) &&
  999. diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
  1000. index d2153789bd9f..97da977d6060 100644
  1001. --- a/include/linux/slub_def.h
  1002. +++ b/include/linux/slub_def.h
  1003. @@ -121,6 +121,11 @@ struct kmem_cache {
  1004. unsigned long random;
  1005. #endif
  1006. +#ifdef CONFIG_SLAB_CANARY
  1007. + unsigned long random_active;
  1008. + unsigned long random_inactive;
  1009. +#endif
  1010. +
  1011. #ifdef CONFIG_NUMA
  1012. /*
  1013. * Defragmentation by allocating from a remote node.
  1014. diff --git a/include/linux/string.h b/include/linux/string.h
  1015. index b2264355272d..2115131ba73f 100644
  1016. --- a/include/linux/string.h
  1017. +++ b/include/linux/string.h
  1018. @@ -268,6 +268,12 @@ void __read_overflow2(void) __compiletime_error("detected read beyond size of ob
  1019. void __read_overflow3(void) __compiletime_error("detected read beyond size of object passed as 3rd parameter");
  1020. void __write_overflow(void) __compiletime_error("detected write beyond size of object passed as 1st parameter");
  1021. +#ifdef CONFIG_FORTIFY_SOURCE_STRICT_STRING
  1022. +#define __string_size(p) __builtin_object_size(p, 1)
  1023. +#else
  1024. +#define __string_size(p) __builtin_object_size(p, 0)
  1025. +#endif
  1026. +
  1027. #if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE)
  1028. #ifdef CONFIG_KASAN
  1029. @@ -296,7 +302,7 @@ extern char *__underlying_strncpy(char *p, const char *q, __kernel_size_t size)
  1030. __FORTIFY_INLINE char *strncpy(char *p, const char *q, __kernel_size_t size)
  1031. {
  1032. - size_t p_size = __builtin_object_size(p, 0);
  1033. + size_t p_size = __string_size(p);
  1034. if (__builtin_constant_p(size) && p_size < size)
  1035. __write_overflow();
  1036. if (p_size < size)
  1037. @@ -306,7 +312,7 @@ __FORTIFY_INLINE char *strncpy(char *p, const char *q, __kernel_size_t size)
  1038. __FORTIFY_INLINE char *strcat(char *p, const char *q)
  1039. {
  1040. - size_t p_size = __builtin_object_size(p, 0);
  1041. + size_t p_size = __string_size(p);
  1042. if (p_size == (size_t)-1)
  1043. return __underlying_strcat(p, q);
  1044. if (strlcat(p, q, p_size) >= p_size)
  1045. @@ -317,7 +323,7 @@ __FORTIFY_INLINE char *strcat(char *p, const char *q)
  1046. __FORTIFY_INLINE __kernel_size_t strlen(const char *p)
  1047. {
  1048. __kernel_size_t ret;
  1049. - size_t p_size = __builtin_object_size(p, 0);
  1050. + size_t p_size = __string_size(p);
  1051. /* Work around gcc excess stack consumption issue */
  1052. if (p_size == (size_t)-1 ||
  1053. @@ -332,7 +338,7 @@ __FORTIFY_INLINE __kernel_size_t strlen(const char *p)
  1054. extern __kernel_size_t __real_strnlen(const char *, __kernel_size_t) __RENAME(strnlen);
  1055. __FORTIFY_INLINE __kernel_size_t strnlen(const char *p, __kernel_size_t maxlen)
  1056. {
  1057. - size_t p_size = __builtin_object_size(p, 0);
  1058. + size_t p_size = __string_size(p);
  1059. __kernel_size_t ret = __real_strnlen(p, maxlen < p_size ? maxlen : p_size);
  1060. if (p_size <= ret && maxlen != ret)
  1061. fortify_panic(__func__);
  1062. @@ -344,8 +350,8 @@ extern size_t __real_strlcpy(char *, const char *, size_t) __RENAME(strlcpy);
  1063. __FORTIFY_INLINE size_t strlcpy(char *p, const char *q, size_t size)
  1064. {
  1065. size_t ret;
  1066. - size_t p_size = __builtin_object_size(p, 0);
  1067. - size_t q_size = __builtin_object_size(q, 0);
  1068. + size_t p_size = __string_size(p);
  1069. + size_t q_size = __string_size(q);
  1070. if (p_size == (size_t)-1 && q_size == (size_t)-1)
  1071. return __real_strlcpy(p, q, size);
  1072. ret = strlen(q);
  1073. @@ -365,8 +371,8 @@ __FORTIFY_INLINE size_t strlcpy(char *p, const char *q, size_t size)
  1074. __FORTIFY_INLINE char *strncat(char *p, const char *q, __kernel_size_t count)
  1075. {
  1076. size_t p_len, copy_len;
  1077. - size_t p_size = __builtin_object_size(p, 0);
  1078. - size_t q_size = __builtin_object_size(q, 0);
  1079. + size_t p_size = __string_size(p);
  1080. + size_t q_size = __string_size(q);
  1081. if (p_size == (size_t)-1 && q_size == (size_t)-1)
  1082. return __underlying_strncat(p, q, count);
  1083. p_len = strlen(p);
  1084. @@ -479,8 +485,8 @@ __FORTIFY_INLINE void *kmemdup(const void *p, size_t size, gfp_t gfp)
  1085. /* defined after fortified strlen and memcpy to reuse them */
  1086. __FORTIFY_INLINE char *strcpy(char *p, const char *q)
  1087. {
  1088. - size_t p_size = __builtin_object_size(p, 0);
  1089. - size_t q_size = __builtin_object_size(q, 0);
  1090. + size_t p_size = __string_size(p);
  1091. + size_t q_size = __string_size(q);
  1092. if (p_size == (size_t)-1 && q_size == (size_t)-1)
  1093. return __underlying_strcpy(p, q);
  1094. memcpy(p, q, strlen(q) + 1);
  1095. diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
  1096. index aa615a0863f5..56e46e43b1b0 100644
  1097. --- a/include/linux/sysctl.h
  1098. +++ b/include/linux/sysctl.h
  1099. @@ -58,6 +58,8 @@ extern int proc_dointvec_minmax(struct ctl_table *, int,
  1100. extern int proc_douintvec_minmax(struct ctl_table *table, int write,
  1101. void __user *buffer, size_t *lenp,
  1102. loff_t *ppos);
  1103. +extern int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
  1104. + void *buffer, size_t *lenp, loff_t *ppos);
  1105. extern int proc_dointvec_jiffies(struct ctl_table *, int,
  1106. void __user *, size_t *, loff_t *);
  1107. extern int proc_dointvec_userhz_jiffies(struct ctl_table *, int,
  1108. diff --git a/include/linux/tty.h b/include/linux/tty.h
  1109. index 8be25caa97f6..ca9ea36782a3 100644
  1110. --- a/include/linux/tty.h
  1111. +++ b/include/linux/tty.h
  1112. @@ -14,6 +14,7 @@
  1113. #include <uapi/linux/tty.h>
  1114. #include <linux/rwsem.h>
  1115. #include <linux/llist.h>
  1116. +#include <linux/user_namespace.h>
  1117. /*
  1118. @@ -342,6 +343,7 @@ struct tty_struct {
  1119. /* If the tty has a pending do_SAK, queue it here - akpm */
  1120. struct work_struct SAK_work;
  1121. struct tty_port *port;
  1122. + struct user_namespace *owner_user_ns;
  1123. } __randomize_layout;
  1124. /* Each of a tty's open files has private_data pointing to tty_file_private */
  1125. @@ -351,6 +353,8 @@ struct tty_file_private {
  1126. struct list_head list;
  1127. };
  1128. +extern int tiocsti_restrict;
  1129. +
  1130. /* tty magic number */
  1131. #define TTY_MAGIC 0x5401
  1132. diff --git a/include/linux/usb.h b/include/linux/usb.h
  1133. index abcf1ce9bb06..25dfdd22bc7d 100644
  1134. --- a/include/linux/usb.h
  1135. +++ b/include/linux/usb.h
  1136. @@ -2025,6 +2025,16 @@ extern void usb_led_activity(enum usb_led_event ev);
  1137. static inline void usb_led_activity(enum usb_led_event ev) {}
  1138. #endif
  1139. +/* sysctl.c */
  1140. +extern int deny_new_usb;
  1141. +#ifdef CONFIG_SYSCTL
  1142. +extern int usb_init_sysctl(void);
  1143. +extern void usb_exit_sysctl(void);
  1144. +#else
  1145. +static inline int usb_init_sysctl(void) { return 0; }
  1146. +static inline void usb_exit_sysctl(void) { }
  1147. +#endif /* CONFIG_SYSCTL */
  1148. +
  1149. #endif /* __KERNEL__ */
  1150. #endif
  1151. diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
  1152. index 01a1334c5fc5..576e00382884 100644
  1153. --- a/include/linux/vmalloc.h
  1154. +++ b/include/linux/vmalloc.h
  1155. @@ -88,19 +88,19 @@ static inline void vmalloc_init(void)
  1156. static inline unsigned long vmalloc_nr_pages(void) { return 0; }
  1157. #endif
  1158. -extern void *vmalloc(unsigned long size);
  1159. -extern void *vzalloc(unsigned long size);
  1160. -extern void *vmalloc_user(unsigned long size);
  1161. -extern void *vmalloc_node(unsigned long size, int node);
  1162. -extern void *vzalloc_node(unsigned long size, int node);
  1163. -extern void *vmalloc_exec(unsigned long size);
  1164. -extern void *vmalloc_32(unsigned long size);
  1165. -extern void *vmalloc_32_user(unsigned long size);
  1166. -extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
  1167. +extern void *vmalloc(unsigned long size) __attribute__((alloc_size(1)));
  1168. +extern void *vzalloc(unsigned long size) __attribute__((alloc_size(1)));
  1169. +extern void *vmalloc_user(unsigned long size) __attribute__((alloc_size(1)));
  1170. +extern void *vmalloc_node(unsigned long size, int node) __attribute__((alloc_size(1)));
  1171. +extern void *vzalloc_node(unsigned long size, int node) __attribute__((alloc_size(1)));
  1172. +extern void *vmalloc_exec(unsigned long size) __attribute__((alloc_size(1)));
  1173. +extern void *vmalloc_32(unsigned long size) __attribute__((alloc_size(1)));
  1174. +extern void *vmalloc_32_user(unsigned long size) __attribute__((alloc_size(1)));
  1175. +extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot) __attribute__((alloc_size(1)));
  1176. extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
  1177. unsigned long start, unsigned long end, gfp_t gfp_mask,
  1178. pgprot_t prot, unsigned long vm_flags, int node,
  1179. - const void *caller);
  1180. + const void *caller) __attribute__((alloc_size(1)));
  1181. #ifndef CONFIG_MMU
  1182. extern void *__vmalloc_node_flags(unsigned long size, int node, gfp_t flags);
  1183. static inline void *__vmalloc_node_flags_caller(unsigned long size, int node,
  1184. diff --git a/include/net/tcp.h b/include/net/tcp.h
  1185. index 164ba7b77bd9..159339f324a4 100644
  1186. --- a/include/net/tcp.h
  1187. +++ b/include/net/tcp.h
  1188. @@ -246,6 +246,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo);
  1189. /* sysctl variables for tcp */
  1190. extern int sysctl_tcp_max_orphans;
  1191. extern long sysctl_tcp_mem[3];
  1192. +extern int sysctl_tcp_simult_connect;
  1193. #define TCP_RACK_LOSS_DETECTION 0x1 /* Use RACK to detect losses */
  1194. #define TCP_RACK_STATIC_REO_WND 0x2 /* Use static RACK reo wnd */
  1195. diff --git a/init/Kconfig b/init/Kconfig
  1196. index f641518f4ac5..54786890b3e7 100644
  1197. --- a/init/Kconfig
  1198. +++ b/init/Kconfig
  1199. @@ -357,6 +357,7 @@ config USELIB
  1200. config AUDIT
  1201. bool "Auditing support"
  1202. depends on NET
  1203. + default y
  1204. help
  1205. Enable auditing infrastructure that can be used with another
  1206. kernel subsystem, such as SELinux (which requires this for
  1207. @@ -1095,6 +1096,22 @@ config USER_NS
  1208. If unsure, say N.
  1209. +config USER_NS_UNPRIVILEGED
  1210. + bool "Allow unprivileged users to create namespaces"
  1211. + depends on USER_NS
  1212. + default n
  1213. + help
  1214. + When disabled, unprivileged users will not be able to create
  1215. + new namespaces. Allowing users to create their own namespaces
  1216. + has been part of several recent local privilege escalation
  1217. + exploits, so if you need user namespaces but are
  1218. + paranoid^Wsecurity-conscious you want to disable this.
  1219. +
  1220. + This setting can be overridden at runtime via the
  1221. + kernel.unprivileged_userns_clone sysctl.
  1222. +
  1223. + If unsure, say N.
  1224. +
  1225. config PID_NS
  1226. bool "PID Namespaces"
  1227. default y
  1228. @@ -1307,9 +1324,8 @@ menuconfig EXPERT
  1229. Only use this if you really know what you are doing.
  1230. config UID16
  1231. - bool "Enable 16-bit UID system calls" if EXPERT
  1232. + bool "Enable 16-bit UID system calls"
  1233. depends on HAVE_UID16 && MULTIUSER
  1234. - default y
  1235. help
  1236. This enables the legacy 16-bit UID syscall wrappers.
  1237. @@ -1338,14 +1354,13 @@ config SGETMASK_SYSCALL
  1238. If unsure, leave the default option here.
  1239. config SYSFS_SYSCALL
  1240. - bool "Sysfs syscall support" if EXPERT
  1241. - default y
  1242. + bool "Sysfs syscall support"
  1243. ---help---
  1244. sys_sysfs is an obsolete system call no longer supported in libc.
  1245. Note that disabling this option is more secure but might break
  1246. compatibility with some systems.
  1247. - If unsure say Y here.
  1248. + If unsure say N here.
  1249. config SYSCTL_SYSCALL
  1250. bool "Sysctl syscall support" if EXPERT
  1251. @@ -1513,8 +1528,7 @@ config SHMEM
  1252. which may be appropriate on small systems without swap.
  1253. config AIO
  1254. - bool "Enable AIO support" if EXPERT
  1255. - default y
  1256. + bool "Enable AIO support"
  1257. help
  1258. This option enables POSIX asynchronous I/O which may by used
  1259. by some high performance threaded applications. Disabling
  1260. @@ -1621,6 +1635,7 @@ config BPF_JIT_ALWAYS_ON
  1261. config BPF_UNPRIV_DEFAULT_OFF
  1262. bool "Disable unprivileged BPF by default"
  1263. depends on BPF_SYSCALL
  1264. + default y
  1265. help
  1266. Disables unprivileged BPF by default by setting the corresponding
  1267. /proc/sys/kernel/unprivileged_bpf_disabled knob to 2. An admin can
  1268. @@ -1635,6 +1650,23 @@ config USERFAULTFD
  1269. Enable the userfaultfd() system call that allows to intercept and
  1270. handle page faults in userland.
  1271. +config USERFAULTFD_UNPRIVILEGED
  1272. + bool "Allow unprivileged users to use the userfaultfd syscall"
  1273. + depends on USERFAULTFD
  1274. + default n
  1275. + help
  1276. + When disabled, unprivileged users will not be able to use the userfaultfd
  1277. + syscall. Userfaultfd provide attackers with a way to stall a kernel
  1278. + thread in the middle of memory accesses from userspace by initiating an
  1279. + access on an unmapped page. To avoid various heap grooming and heap
  1280. + spraying techniques for exploiting use-after-free flaws this should be
  1281. + disabled by default.
  1282. +
  1283. + This setting can be overridden at runtime via the
  1284. + vm.unprivileged_userfaultfd sysctl.
  1285. +
  1286. + If unsure, say N.
  1287. +
  1288. config ARCH_HAS_MEMBARRIER_CALLBACKS
  1289. bool
  1290. @@ -1747,7 +1779,7 @@ config VM_EVENT_COUNTERS
  1291. config SLUB_DEBUG
  1292. default y
  1293. - bool "Enable SLUB debugging support" if EXPERT
  1294. + bool "Enable SLUB debugging support"
  1295. depends on SLUB && SYSFS
  1296. help
  1297. SLUB has extensive debug support features. Disabling these can
  1298. @@ -1771,7 +1803,6 @@ config SLUB_MEMCG_SYSFS_ON
  1299. config COMPAT_BRK
  1300. bool "Disable heap randomization"
  1301. - default y
  1302. help
  1303. Randomizing heap placement makes heap exploits harder, but it
  1304. also breaks ancient binaries (including anything libc5 based).
  1305. @@ -1818,7 +1849,6 @@ endchoice
  1306. config SLAB_MERGE_DEFAULT
  1307. bool "Allow slab caches to be merged"
  1308. - default y
  1309. help
  1310. For reduced kernel memory fragmentation, slab caches can be
  1311. merged when they share the same size and other characteristics.
  1312. @@ -1831,9 +1861,9 @@ config SLAB_MERGE_DEFAULT
  1313. command line.
  1314. config SLAB_FREELIST_RANDOM
  1315. - default n
  1316. depends on SLAB || SLUB
  1317. bool "SLAB freelist randomization"
  1318. + default y
  1319. help
  1320. Randomizes the freelist order used on creating new pages. This
  1321. security feature reduces the predictability of the kernel slab
  1322. @@ -1842,12 +1872,30 @@ config SLAB_FREELIST_RANDOM
  1323. config SLAB_FREELIST_HARDENED
  1324. bool "Harden slab freelist metadata"
  1325. depends on SLUB
  1326. + default y
  1327. help
  1328. Many kernel heap attacks try to target slab cache metadata and
  1329. other infrastructure. This options makes minor performance
  1330. sacrifices to harden the kernel slab allocator against common
  1331. freelist exploit methods.
  1332. +config SLAB_CANARY
  1333. + depends on SLUB
  1334. + depends on !SLAB_MERGE_DEFAULT
  1335. + bool "SLAB canaries"
  1336. + default y
  1337. + help
  1338. + Place canaries at the end of kernel slab allocations, sacrificing
  1339. + some performance and memory usage for security.
  1340. +
  1341. + Canaries can detect some forms of heap corruption when allocations
  1342. + are freed and as part of the HARDENED_USERCOPY feature. It provides
  1343. + basic use-after-free detection for HARDENED_USERCOPY.
  1344. +
  1345. + Canaries absorb small overflows (rendering them harmless), mitigate
  1346. + non-NUL terminated C string overflows on 64-bit via a guaranteed zero
  1347. + byte and provide basic double-free detection.
  1348. +
  1349. config SHUFFLE_PAGE_ALLOCATOR
  1350. bool "Page allocator randomization"
  1351. default SLAB_FREELIST_RANDOM && ACPI_NUMA
  1352. diff --git a/kernel/audit.c b/kernel/audit.c
  1353. index 39e84d65d253..12b4b3b478c0 100644
  1354. --- a/kernel/audit.c
  1355. +++ b/kernel/audit.c
  1356. @@ -1695,6 +1695,9 @@ static int __init audit_enable(char *str)
  1357. if (audit_default == AUDIT_OFF)
  1358. audit_initialized = AUDIT_DISABLED;
  1359. + else if (!audit_ever_enabled)
  1360. + audit_initialized = AUDIT_UNINITIALIZED;
  1361. +
  1362. if (audit_set_enabled(audit_default))
  1363. pr_err("audit: error setting audit state (%d)\n",
  1364. audit_default);
  1365. diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
  1366. index dde21d23f220..3fce16faf85f 100644
  1367. --- a/kernel/bpf/core.c
  1368. +++ b/kernel/bpf/core.c
  1369. @@ -523,7 +523,7 @@ void bpf_prog_kallsyms_del_all(struct bpf_prog *fp)
  1370. #ifdef CONFIG_BPF_JIT
  1371. /* All BPF JIT sysctl knobs here. */
  1372. int bpf_jit_enable __read_mostly = IS_BUILTIN(CONFIG_BPF_JIT_ALWAYS_ON);
  1373. -int bpf_jit_harden __read_mostly;
  1374. +int bpf_jit_harden __read_mostly = 2;
  1375. int bpf_jit_kallsyms __read_mostly;
  1376. long bpf_jit_limit __read_mostly;
  1377. long bpf_jit_limit_max __read_mostly;
  1378. diff --git a/kernel/capability.c b/kernel/capability.c
  1379. index 1444f3954d75..8cc9dd7992f2 100644
  1380. --- a/kernel/capability.c
  1381. +++ b/kernel/capability.c
  1382. @@ -449,6 +449,12 @@ bool capable(int cap)
  1383. return ns_capable(&init_user_ns, cap);
  1384. }
  1385. EXPORT_SYMBOL(capable);
  1386. +
  1387. +bool capable_noaudit(int cap)
  1388. +{
  1389. + return ns_capable_noaudit(&init_user_ns, cap);
  1390. +}
  1391. +EXPORT_SYMBOL(capable_noaudit);
  1392. #endif /* CONFIG_MULTIUSER */
  1393. /**
  1394. diff --git a/kernel/events/core.c b/kernel/events/core.c
  1395. index f18a5bbc66ef..1ad470ef3fd0 100644
  1396. --- a/kernel/events/core.c
  1397. +++ b/kernel/events/core.c
  1398. @@ -404,8 +404,13 @@ static cpumask_var_t perf_online_mask;
  1399. * 0 - disallow raw tracepoint access for unpriv
  1400. * 1 - disallow cpu events for unpriv
  1401. * 2 - disallow kernel profiling for unpriv
  1402. + * 3 - disallow all unpriv perf event use
  1403. */
  1404. +#ifdef CONFIG_SECURITY_PERF_EVENTS_RESTRICT
  1405. +int sysctl_perf_event_paranoid __read_mostly = 3;
  1406. +#else
  1407. int sysctl_perf_event_paranoid __read_mostly = 2;
  1408. +#endif
  1409. /* Minimum for 512 kiB + 1 user control page */
  1410. int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
  1411. @@ -11041,6 +11046,9 @@ SYSCALL_DEFINE5(perf_event_open,
  1412. if (flags & ~PERF_FLAG_ALL)
  1413. return -EINVAL;
  1414. + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
  1415. + return -EACCES;
  1416. +
  1417. err = perf_copy_attr(attr_uptr, &attr);
  1418. if (err)
  1419. return err;
  1420. diff --git a/kernel/fork.c b/kernel/fork.c
  1421. index 1728aa77861c..9868846c1412 100644
  1422. --- a/kernel/fork.c
  1423. +++ b/kernel/fork.c
  1424. @@ -106,6 +106,11 @@
  1425. #define CREATE_TRACE_POINTS
  1426. #include <trace/events/task.h>
  1427. +#ifdef CONFIG_USER_NS
  1428. +extern int unprivileged_userns_clone;
  1429. +#else
  1430. +#define unprivileged_userns_clone 0
  1431. +#endif
  1432. /*
  1433. * Minimum number of threads to boot the kernel
  1434. @@ -1808,6 +1813,10 @@ static __latent_entropy struct task_struct *copy_process(
  1435. if ((clone_flags & (CLONE_NEWUSER|CLONE_FS)) == (CLONE_NEWUSER|CLONE_FS))
  1436. return ERR_PTR(-EINVAL);
  1437. + if ((clone_flags & CLONE_NEWUSER) && !unprivileged_userns_clone)
  1438. + if (!capable(CAP_SYS_ADMIN))
  1439. + return ERR_PTR(-EPERM);
  1440. +
  1441. /*
  1442. * Thread groups must share signals as well, and detached threads
  1443. * can only be started up within the thread group.
  1444. @@ -2866,6 +2875,12 @@ int ksys_unshare(unsigned long unshare_flags)
  1445. if (unshare_flags & CLONE_NEWNS)
  1446. unshare_flags |= CLONE_FS;
  1447. + if ((unshare_flags & CLONE_NEWUSER) && !unprivileged_userns_clone) {
  1448. + err = -EPERM;
  1449. + if (!capable(CAP_SYS_ADMIN))
  1450. + goto bad_unshare_out;
  1451. + }
  1452. +
  1453. err = check_unshare_flags(unshare_flags);
  1454. if (err)
  1455. goto bad_unshare_out;
  1456. diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
  1457. index 477b4eb44af5..db28cc3fd301 100644
  1458. --- a/kernel/rcu/tiny.c
  1459. +++ b/kernel/rcu/tiny.c
  1460. @@ -74,7 +74,7 @@ void rcu_sched_clock_irq(int user)
  1461. }
  1462. /* Invoke the RCU callbacks whose grace period has elapsed. */
  1463. -static __latent_entropy void rcu_process_callbacks(struct softirq_action *unused)
  1464. +static __latent_entropy void rcu_process_callbacks(void)
  1465. {
  1466. struct rcu_head *next, *list;
  1467. unsigned long flags;
  1468. diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
  1469. index 615283404d9d..0daa6877ea09 100644
  1470. --- a/kernel/rcu/tree.c
  1471. +++ b/kernel/rcu/tree.c
  1472. @@ -2389,7 +2389,7 @@ static __latent_entropy void rcu_core(void)
  1473. trace_rcu_utilization(TPS("End RCU core"));
  1474. }
  1475. -static void rcu_core_si(struct softirq_action *h)
  1476. +static void rcu_core_si(void)
  1477. {
  1478. rcu_core();
  1479. }
  1480. diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
  1481. index 2680216234ff..564c13c727de 100644
  1482. --- a/kernel/sched/fair.c
  1483. +++ b/kernel/sched/fair.c
  1484. @@ -10016,7 +10016,7 @@ int newidle_balance(struct rq *this_rq, struct rq_flags *rf)
  1485. * run_rebalance_domains is triggered when needed from the scheduler tick.
  1486. * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
  1487. */
  1488. -static __latent_entropy void run_rebalance_domains(struct softirq_action *h)
  1489. +static __latent_entropy void run_rebalance_domains(void)
  1490. {
  1491. struct rq *this_rq = this_rq();
  1492. enum cpu_idle_type idle = this_rq->idle_balance ?
  1493. diff --git a/kernel/softirq.c b/kernel/softirq.c
  1494. index 0427a86743a4..5e6a9b4ccb41 100644
  1495. --- a/kernel/softirq.c
  1496. +++ b/kernel/softirq.c
  1497. @@ -52,7 +52,7 @@ DEFINE_PER_CPU_ALIGNED(irq_cpustat_t, irq_stat);
  1498. EXPORT_PER_CPU_SYMBOL(irq_stat);
  1499. #endif
  1500. -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
  1501. +static struct softirq_action softirq_vec[NR_SOFTIRQS] __ro_after_init __aligned(PAGE_SIZE);
  1502. DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
  1503. @@ -289,7 +289,7 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)
  1504. kstat_incr_softirqs_this_cpu(vec_nr);
  1505. trace_softirq_entry(vec_nr);
  1506. - h->action(h);
  1507. + h->action();
  1508. trace_softirq_exit(vec_nr);
  1509. if (unlikely(prev_count != preempt_count())) {
  1510. pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
  1511. @@ -452,7 +452,7 @@ void __raise_softirq_irqoff(unsigned int nr)
  1512. or_softirq_pending(1UL << nr);
  1513. }
  1514. -void open_softirq(int nr, void (*action)(struct softirq_action *))
  1515. +void __init open_softirq(int nr, void (*action)(void))
  1516. {
  1517. softirq_vec[nr].action = action;
  1518. }
  1519. @@ -498,8 +498,7 @@ void __tasklet_hi_schedule(struct tasklet_struct *t)
  1520. }
  1521. EXPORT_SYMBOL(__tasklet_hi_schedule);
  1522. -static void tasklet_action_common(struct softirq_action *a,
  1523. - struct tasklet_head *tl_head,
  1524. +static void tasklet_action_common(struct tasklet_head *tl_head,
  1525. unsigned int softirq_nr)
  1526. {
  1527. struct tasklet_struct *list;
  1528. @@ -536,14 +535,14 @@ static void tasklet_action_common(struct softirq_action *a,
  1529. }
  1530. }
  1531. -static __latent_entropy void tasklet_action(struct softirq_action *a)
  1532. +static __latent_entropy void tasklet_action(void)
  1533. {
  1534. - tasklet_action_common(a, this_cpu_ptr(&tasklet_vec), TASKLET_SOFTIRQ);
  1535. + tasklet_action_common(this_cpu_ptr(&tasklet_vec), TASKLET_SOFTIRQ);
  1536. }
  1537. -static __latent_entropy void tasklet_hi_action(struct softirq_action *a)
  1538. +static __latent_entropy void tasklet_hi_action(void)
  1539. {
  1540. - tasklet_action_common(a, this_cpu_ptr(&tasklet_hi_vec), HI_SOFTIRQ);
  1541. + tasklet_action_common(this_cpu_ptr(&tasklet_hi_vec), HI_SOFTIRQ);
  1542. }
  1543. void tasklet_init(struct tasklet_struct *t,
  1544. diff --git a/kernel/sysctl.c b/kernel/sysctl.c
  1545. index 865e539c7354..6a3032679601 100644
  1546. --- a/kernel/sysctl.c
  1547. +++ b/kernel/sysctl.c
  1548. @@ -100,6 +100,9 @@
  1549. #ifdef CONFIG_LOCKUP_DETECTOR
  1550. #include <linux/nmi.h>
  1551. #endif
  1552. +#if defined CONFIG_TTY
  1553. +#include <linux/tty.h>
  1554. +#endif
  1555. #if defined(CONFIG_SYSCTL)
  1556. @@ -110,6 +113,9 @@ extern int core_uses_pid;
  1557. extern char core_pattern[];
  1558. extern unsigned int core_pipe_limit;
  1559. #endif
  1560. +#ifdef CONFIG_USER_NS
  1561. +extern int unprivileged_userns_clone;
  1562. +#endif
  1563. extern int pid_max;
  1564. extern int pid_max_min, pid_max_max;
  1565. extern int percpu_pagelist_fraction;
  1566. @@ -121,32 +127,32 @@ extern int sysctl_nr_trim_pages;
  1567. /* Constants used for minimum and maximum */
  1568. #ifdef CONFIG_LOCKUP_DETECTOR
  1569. -static int sixty = 60;
  1570. +static int sixty __read_only = 60;
  1571. #endif
  1572. -static int __maybe_unused neg_one = -1;
  1573. -static int __maybe_unused two = 2;
  1574. -static int __maybe_unused four = 4;
  1575. -static unsigned long zero_ul;
  1576. -static unsigned long one_ul = 1;
  1577. -static unsigned long long_max = LONG_MAX;
  1578. -static int one_hundred = 100;
  1579. -static int one_thousand = 1000;
  1580. +static int __maybe_unused neg_one __read_only = -1;
  1581. +static int __maybe_unused two __read_only = 2;
  1582. +static int __maybe_unused four __read_only = 4;
  1583. +static unsigned long zero_ul __read_only;
  1584. +static unsigned long one_ul __read_only = 1;
  1585. +static unsigned long long_max __read_only = LONG_MAX;
  1586. +static int one_hundred __read_only = 100;
  1587. +static int one_thousand __read_only = 1000;
  1588. #ifdef CONFIG_PRINTK
  1589. -static int ten_thousand = 10000;
  1590. +static int ten_thousand __read_only = 10000;
  1591. #endif
  1592. #ifdef CONFIG_PERF_EVENTS
  1593. -static int six_hundred_forty_kb = 640 * 1024;
  1594. +static int six_hundred_forty_kb __read_only = 640 * 1024;
  1595. #endif
  1596. /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
  1597. -static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
  1598. +static unsigned long dirty_bytes_min __read_only = 2 * PAGE_SIZE;
  1599. /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
  1600. -static int maxolduid = 65535;
  1601. -static int minolduid;
  1602. +static int maxolduid __read_only = 65535;
  1603. +static int minolduid __read_only;
  1604. -static int ngroups_max = NGROUPS_MAX;
  1605. +static int ngroups_max __read_only = NGROUPS_MAX;
  1606. static const int cap_last_cap = CAP_LAST_CAP;
  1607. /*
  1608. @@ -154,9 +160,12 @@ static const int cap_last_cap = CAP_LAST_CAP;
  1609. * and hung_task_check_interval_secs
  1610. */
  1611. #ifdef CONFIG_DETECT_HUNG_TASK
  1612. -static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
  1613. +static unsigned long hung_task_timeout_max __read_only = (LONG_MAX/HZ);
  1614. #endif
  1615. +int device_sidechannel_restrict __read_mostly = 1;
  1616. +EXPORT_SYMBOL(device_sidechannel_restrict);
  1617. +
  1618. #ifdef CONFIG_INOTIFY_USER
  1619. #include <linux/inotify.h>
  1620. #endif
  1621. @@ -214,11 +223,6 @@ static int proc_taint(struct ctl_table *table, int write,
  1622. void __user *buffer, size_t *lenp, loff_t *ppos);
  1623. #endif
  1624. -#ifdef CONFIG_PRINTK
  1625. -static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
  1626. - void __user *buffer, size_t *lenp, loff_t *ppos);
  1627. -#endif
  1628. -
  1629. static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
  1630. void __user *buffer, size_t *lenp, loff_t *ppos);
  1631. #ifdef CONFIG_COREDUMP
  1632. @@ -331,19 +335,19 @@ static struct ctl_table sysctl_base_table[] = {
  1633. };
  1634. #ifdef CONFIG_SCHED_DEBUG
  1635. -static int min_sched_granularity_ns = 100000; /* 100 usecs */
  1636. -static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
  1637. -static int min_wakeup_granularity_ns; /* 0 usecs */
  1638. -static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
  1639. +static int min_sched_granularity_ns __read_only = 100000; /* 100 usecs */
  1640. +static int max_sched_granularity_ns __read_only = NSEC_PER_SEC; /* 1 second */
  1641. +static int min_wakeup_granularity_ns __read_only; /* 0 usecs */
  1642. +static int max_wakeup_granularity_ns __read_only = NSEC_PER_SEC; /* 1 second */
  1643. #ifdef CONFIG_SMP
  1644. -static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
  1645. -static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
  1646. +static int min_sched_tunable_scaling __read_only = SCHED_TUNABLESCALING_NONE;
  1647. +static int max_sched_tunable_scaling __read_only = SCHED_TUNABLESCALING_END-1;
  1648. #endif /* CONFIG_SMP */
  1649. #endif /* CONFIG_SCHED_DEBUG */
  1650. #ifdef CONFIG_COMPACTION
  1651. -static int min_extfrag_threshold;
  1652. -static int max_extfrag_threshold = 1000;
  1653. +static int min_extfrag_threshold __read_only;
  1654. +static int max_extfrag_threshold __read_only = 1000;
  1655. #endif
  1656. static struct ctl_table kern_table[] = {
  1657. @@ -580,6 +584,15 @@ static struct ctl_table kern_table[] = {
  1658. .proc_handler = proc_dointvec,
  1659. },
  1660. #endif
  1661. +#ifdef CONFIG_USER_NS
  1662. + {
  1663. + .procname = "unprivileged_userns_clone",
  1664. + .data = &unprivileged_userns_clone,
  1665. + .maxlen = sizeof(int),
  1666. + .mode = 0644,
  1667. + .proc_handler = proc_dointvec,
  1668. + },
  1669. +#endif
  1670. #ifdef CONFIG_PROC_SYSCTL
  1671. {
  1672. .procname = "tainted",
  1673. @@ -936,6 +949,26 @@ static struct ctl_table kern_table[] = {
  1674. .extra2 = &two,
  1675. },
  1676. #endif
  1677. +#if defined CONFIG_TTY
  1678. + {
  1679. + .procname = "tiocsti_restrict",
  1680. + .data = &tiocsti_restrict,
  1681. + .maxlen = sizeof(int),
  1682. + .mode = 0644,
  1683. + .proc_handler = proc_dointvec_minmax_sysadmin,
  1684. + .extra1 = SYSCTL_ZERO,
  1685. + .extra2 = SYSCTL_ONE,
  1686. + },
  1687. +#endif
  1688. + {
  1689. + .procname = "device_sidechannel_restrict",
  1690. + .data = &device_sidechannel_restrict,
  1691. + .maxlen = sizeof(int),
  1692. + .mode = 0644,
  1693. + .proc_handler = proc_dointvec_minmax_sysadmin,
  1694. + .extra1 = SYSCTL_ZERO,
  1695. + .extra2 = SYSCTL_ONE,
  1696. + },
  1697. {
  1698. .procname = "ngroups_max",
  1699. .data = &ngroups_max,
  1700. @@ -2679,16 +2712,34 @@ static int proc_taint(struct ctl_table *table, int write,
  1701. return err;
  1702. }
  1703. -#ifdef CONFIG_PRINTK
  1704. -static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
  1705. - void __user *buffer, size_t *lenp, loff_t *ppos)
  1706. +/**
  1707. + * proc_dointvec_minmax_sysadmin - read a vector of integers with min/max values
  1708. + * checking CAP_SYS_ADMIN on write
  1709. + * @table: the sysctl table
  1710. + * @write: %TRUE if this is a write to the sysctl file
  1711. + * @buffer: the user buffer
  1712. + * @lenp: the size of the user buffer
  1713. + * @ppos: file position
  1714. + *
  1715. + * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1716. + * values from/to the user buffer, treated as an ASCII string.
  1717. + *
  1718. + * This routine will ensure the values are within the range specified by
  1719. + * table->extra1 (min) and table->extra2 (max).
  1720. + *
  1721. + * Writing is only allowed when the current task has CAP_SYS_ADMIN.
  1722. + *
  1723. + * Returns 0 on success, -EPERM on permission failure or -EINVAL on write
  1724. + * when the range check fails.
  1725. + */
  1726. +int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
  1727. + void __user *buffer, size_t *lenp, loff_t *ppos)
  1728. {
  1729. if (write && !capable(CAP_SYS_ADMIN))
  1730. return -EPERM;
  1731. return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
  1732. }
  1733. -#endif
  1734. /**
  1735. * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
  1736. @@ -3386,6 +3437,12 @@ int proc_douintvec_minmax(struct ctl_table *table, int write,
  1737. return -ENOSYS;
  1738. }
  1739. +int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
  1740. + void *buffer, size_t *lenp, loff_t *ppos)
  1741. +{
  1742. + return -ENOSYS;
  1743. +}
  1744. +
  1745. int proc_dointvec_jiffies(struct ctl_table *table, int write,
  1746. void __user *buffer, size_t *lenp, loff_t *ppos)
  1747. {
  1748. @@ -3466,6 +3523,7 @@ EXPORT_SYMBOL(proc_douintvec);
  1749. EXPORT_SYMBOL(proc_dointvec_jiffies);
  1750. EXPORT_SYMBOL(proc_dointvec_minmax);
  1751. EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
  1752. +EXPORT_SYMBOL(proc_dointvec_minmax_sysadmin);
  1753. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  1754. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  1755. EXPORT_SYMBOL(proc_dostring);
  1756. diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
  1757. index 1b301dd1692b..73af067fefd5 100644
  1758. --- a/kernel/time/hrtimer.c
  1759. +++ b/kernel/time/hrtimer.c
  1760. @@ -1648,7 +1648,7 @@ static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now,
  1761. }
  1762. }
  1763. -static __latent_entropy void hrtimer_run_softirq(struct softirq_action *h)
  1764. +static __latent_entropy void hrtimer_run_softirq(void)
  1765. {
  1766. struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
  1767. unsigned long flags;
  1768. diff --git a/kernel/time/timer.c b/kernel/time/timer.c
  1769. index 16a2b62f5f74..66df020d607b 100644
  1770. --- a/kernel/time/timer.c
  1771. +++ b/kernel/time/timer.c
  1772. @@ -1793,7 +1793,7 @@ static inline void __run_timers(struct timer_base *base)
  1773. /*
  1774. * This function runs timers and the timer-tq in bottom half context.
  1775. */
  1776. -static __latent_entropy void run_timer_softirq(struct softirq_action *h)
  1777. +static __latent_entropy void run_timer_softirq(void)
  1778. {
  1779. struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
  1780. diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
  1781. index 8eadadc478f9..c36ecd19562c 100644
  1782. --- a/kernel/user_namespace.c
  1783. +++ b/kernel/user_namespace.c
  1784. @@ -21,6 +21,13 @@
  1785. #include <linux/bsearch.h>
  1786. #include <linux/sort.h>
  1787. +/* sysctl */
  1788. +#ifdef CONFIG_USER_NS_UNPRIVILEGED
  1789. +int unprivileged_userns_clone = 1;
  1790. +#else
  1791. +int unprivileged_userns_clone;
  1792. +#endif
  1793. +
  1794. static struct kmem_cache *user_ns_cachep __read_mostly;
  1795. static DEFINE_MUTEX(userns_state_mutex);
  1796. diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
  1797. index 6d79e7c3219c..d3c1986465e5 100644
  1798. --- a/lib/Kconfig.debug
  1799. +++ b/lib/Kconfig.debug
  1800. @@ -345,6 +345,9 @@ config SECTION_MISMATCH_WARN_ONLY
  1801. If unsure, say Y.
  1802. +config DEBUG_WRITABLE_FUNCTION_POINTERS_VERBOSE
  1803. + bool "Enable verbose reporting of writable function pointers"
  1804. +
  1805. #
  1806. # Select this config option from the architecture Kconfig, if it
  1807. # is preferred to always offer frame pointers as a config
  1808. @@ -966,6 +969,7 @@ endmenu # "Debug lockups and hangs"
  1809. config PANIC_ON_OOPS
  1810. bool "Panic on Oops"
  1811. + default y
  1812. help
  1813. Say Y here to enable the kernel to panic when it oopses. This
  1814. has the same effect as setting oops=panic on the kernel command
  1815. @@ -975,7 +979,7 @@ config PANIC_ON_OOPS
  1816. anything erroneous after an oops which could result in data
  1817. corruption or other issues.
  1818. - Say N if unsure.
  1819. + Say Y if unsure.
  1820. config PANIC_ON_OOPS_VALUE
  1821. int
  1822. @@ -1343,6 +1347,7 @@ config DEBUG_BUGVERBOSE
  1823. config DEBUG_LIST
  1824. bool "Debug linked list manipulation"
  1825. depends on DEBUG_KERNEL || BUG_ON_DATA_CORRUPTION
  1826. + default y
  1827. help
  1828. Enable this to turn on extended checks in the linked-list
  1829. walking routines.
  1830. @@ -2081,6 +2086,7 @@ config MEMTEST
  1831. config BUG_ON_DATA_CORRUPTION
  1832. bool "Trigger a BUG when data corruption is detected"
  1833. select DEBUG_LIST
  1834. + default y
  1835. help
  1836. Select this option if the kernel should BUG when it encounters
  1837. data corruption in kernel memory structures when they get checked
  1838. @@ -2120,6 +2126,7 @@ config STRICT_DEVMEM
  1839. config IO_STRICT_DEVMEM
  1840. bool "Filter I/O access to /dev/mem"
  1841. depends on STRICT_DEVMEM
  1842. + default y
  1843. ---help---
  1844. If this option is disabled, you allow userspace (root) access to all
  1845. io-memory regardless of whether a driver is actively using that
  1846. diff --git a/lib/irq_poll.c b/lib/irq_poll.c
  1847. index 2f17b488d58e..b6e7996a0058 100644
  1848. --- a/lib/irq_poll.c
  1849. +++ b/lib/irq_poll.c
  1850. @@ -75,7 +75,7 @@ void irq_poll_complete(struct irq_poll *iop)
  1851. }
  1852. EXPORT_SYMBOL(irq_poll_complete);
  1853. -static void __latent_entropy irq_poll_softirq(struct softirq_action *h)
  1854. +static void __latent_entropy irq_poll_softirq(void)
  1855. {
  1856. struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
  1857. int rearm = 0, budget = irq_poll_budget;
  1858. diff --git a/lib/kobject.c b/lib/kobject.c
  1859. index 6666c48f125c..7f602ba1059f 100644
  1860. --- a/lib/kobject.c
  1861. +++ b/lib/kobject.c
  1862. @@ -1039,9 +1039,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
  1863. static DEFINE_SPINLOCK(kobj_ns_type_lock);
  1864. -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
  1865. +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __ro_after_init;
  1866. -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
  1867. +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
  1868. {
  1869. enum kobj_ns_type type = ops->type;
  1870. int error;
  1871. diff --git a/lib/nlattr.c b/lib/nlattr.c
  1872. index b5ce5e46c06e..96e5069110df 100644
  1873. --- a/lib/nlattr.c
  1874. +++ b/lib/nlattr.c
  1875. @@ -574,6 +574,8 @@ int nla_memcpy(void *dest, const struct nlattr *src, int count)
  1876. {
  1877. int minlen = min_t(int, count, nla_len(src));
  1878. + BUG_ON(minlen < 0);
  1879. +
  1880. memcpy(dest, nla_data(src), minlen);
  1881. if (count > minlen)
  1882. memset(dest + minlen, 0, count - minlen);
  1883. diff --git a/lib/vsprintf.c b/lib/vsprintf.c
  1884. index 393623bf3258..35a632a4aa65 100644
  1885. --- a/lib/vsprintf.c
  1886. +++ b/lib/vsprintf.c
  1887. @@ -806,7 +806,7 @@ static char *ptr_to_id(char *buf, char *end, const void *ptr,
  1888. return pointer_string(buf, end, (const void *)hashval, spec);
  1889. }
  1890. -int kptr_restrict __read_mostly;
  1891. +int kptr_restrict __read_mostly = 2;
  1892. static noinline_for_stack
  1893. char *restricted_pointer(char *buf, char *end, const void *ptr,
  1894. diff --git a/mm/Kconfig b/mm/Kconfig
  1895. index fbdc5c70e487..a1a0d547fc64 100644
  1896. --- a/mm/Kconfig
  1897. +++ b/mm/Kconfig
  1898. @@ -303,7 +303,8 @@ config KSM
  1899. config DEFAULT_MMAP_MIN_ADDR
  1900. int "Low address space to protect from user allocation"
  1901. depends on MMU
  1902. - default 4096
  1903. + default 32768 if ARM || (ARM64 && COMPAT)
  1904. + default 65536
  1905. help
  1906. This is the portion of low virtual memory which should be protected
  1907. from userspace allocation. Keeping a user from writing to low pages
  1908. diff --git a/mm/mmap.c b/mm/mmap.c
  1909. index eeebbb20accf..032724415adc 100644
  1910. --- a/mm/mmap.c
  1911. +++ b/mm/mmap.c
  1912. @@ -228,6 +228,13 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
  1913. newbrk = PAGE_ALIGN(brk);
  1914. oldbrk = PAGE_ALIGN(mm->brk);
  1915. + /* properly handle unaligned min_brk as an empty heap */
  1916. + if (min_brk & ~PAGE_MASK) {
  1917. + if (brk == min_brk)
  1918. + newbrk -= PAGE_SIZE;
  1919. + if (mm->brk == min_brk)
  1920. + oldbrk -= PAGE_SIZE;
  1921. + }
  1922. if (oldbrk == newbrk) {
  1923. mm->brk = brk;
  1924. goto success;
  1925. diff --git a/mm/page_alloc.c b/mm/page_alloc.c
  1926. index a3fca320e35a..9d54d66767ea 100644
  1927. --- a/mm/page_alloc.c
  1928. +++ b/mm/page_alloc.c
  1929. @@ -69,6 +69,7 @@
  1930. #include <linux/nmi.h>
  1931. #include <linux/psi.h>
  1932. #include <linux/khugepaged.h>
  1933. +#include <linux/random.h>
  1934. #include <asm/sections.h>
  1935. #include <asm/tlbflush.h>
  1936. @@ -107,6 +108,15 @@ struct pcpu_drain {
  1937. DEFINE_MUTEX(pcpu_drain_mutex);
  1938. DEFINE_PER_CPU(struct pcpu_drain, pcpu_drain);
  1939. +bool __meminitdata extra_latent_entropy;
  1940. +
  1941. +static int __init setup_extra_latent_entropy(char *str)
  1942. +{
  1943. + extra_latent_entropy = true;
  1944. + return 0;
  1945. +}
  1946. +early_param("extra_latent_entropy", setup_extra_latent_entropy);
  1947. +
  1948. #ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
  1949. volatile unsigned long latent_entropy __latent_entropy;
  1950. EXPORT_SYMBOL(latent_entropy);
  1951. @@ -1433,6 +1443,25 @@ static void __free_pages_ok(struct page *page, unsigned int order)
  1952. local_irq_restore(flags);
  1953. }
  1954. +static void __init __gather_extra_latent_entropy(struct page *page,
  1955. + unsigned int nr_pages)
  1956. +{
  1957. + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
  1958. + unsigned long hash = 0;
  1959. + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
  1960. + const unsigned long *data = lowmem_page_address(page);
  1961. +
  1962. + for (index = 0; index < end; index++)
  1963. + hash ^= hash + data[index];
  1964. +#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
  1965. + latent_entropy ^= hash;
  1966. + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
  1967. +#else
  1968. + add_device_randomness((const void *)&hash, sizeof(hash));
  1969. +#endif
  1970. + }
  1971. +}
  1972. +
  1973. void __free_pages_core(struct page *page, unsigned int order)
  1974. {
  1975. unsigned int nr_pages = 1 << order;
  1976. @@ -1447,7 +1476,6 @@ void __free_pages_core(struct page *page, unsigned int order)
  1977. }
  1978. __ClearPageReserved(p);
  1979. set_page_count(p, 0);
  1980. -
  1981. atomic_long_add(nr_pages, &page_zone(page)->managed_pages);
  1982. set_page_refcounted(page);
  1983. __free_pages(page, order);
  1984. @@ -1498,6 +1526,7 @@ void __init memblock_free_pages(struct page *page, unsigned long pfn,
  1985. {
  1986. if (early_page_uninitialised(pfn))
  1987. return;
  1988. + __gather_extra_latent_entropy(page, 1 << order);
  1989. __free_pages_core(page, order);
  1990. }
  1991. @@ -1589,6 +1618,7 @@ static void __init deferred_free_range(unsigned long pfn,
  1992. if (nr_pages == pageblock_nr_pages &&
  1993. (pfn & (pageblock_nr_pages - 1)) == 0) {
  1994. set_pageblock_migratetype(page, MIGRATE_MOVABLE);
  1995. + __gather_extra_latent_entropy(page, 1 << pageblock_order);
  1996. __free_pages_core(page, pageblock_order);
  1997. return;
  1998. }
  1999. @@ -1596,6 +1626,7 @@ static void __init deferred_free_range(unsigned long pfn,
  2000. for (i = 0; i < nr_pages; i++, page++, pfn++) {
  2001. if ((pfn & (pageblock_nr_pages - 1)) == 0)
  2002. set_pageblock_migratetype(page, MIGRATE_MOVABLE);
  2003. + __gather_extra_latent_entropy(page, 1);
  2004. __free_pages_core(page, 0);
  2005. }
  2006. }
  2007. @@ -2158,6 +2189,12 @@ static void prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags
  2008. {
  2009. post_alloc_hook(page, order, gfp_flags);
  2010. + if (IS_ENABLED(CONFIG_PAGE_SANITIZE_VERIFY) && want_init_on_free()) {
  2011. + int i;
  2012. + for (i = 0; i < (1 << order); i++)
  2013. + verify_zero_highpage(page + i);
  2014. + }
  2015. +
  2016. if (!free_pages_prezeroed() && want_init_on_alloc(gfp_flags))
  2017. kernel_init_free_pages(page, 1 << order);
  2018. diff --git a/mm/slab.h b/mm/slab.h
  2019. index 61feda3d7e00..08f63bf92f53 100644
  2020. --- a/mm/slab.h
  2021. +++ b/mm/slab.h
  2022. @@ -470,9 +470,13 @@ static inline struct kmem_cache *virt_to_cache(const void *obj)
  2023. struct page *page;
  2024. page = virt_to_head_page(obj);
  2025. +#ifdef CONFIG_BUG_ON_DATA_CORRUPTION
  2026. + BUG_ON(!PageSlab(page));
  2027. +#else
  2028. if (WARN_ONCE(!PageSlab(page), "%s: Object is not a Slab page!\n",
  2029. __func__))
  2030. return NULL;
  2031. +#endif
  2032. return page->slab_cache;
  2033. }
  2034. @@ -518,9 +522,14 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
  2035. return s;
  2036. cachep = virt_to_cache(x);
  2037. - WARN_ONCE(cachep && !slab_equal_or_root(cachep, s),
  2038. - "%s: Wrong slab cache. %s but object is from %s\n",
  2039. - __func__, s->name, cachep->name);
  2040. + if (cachep && !slab_equal_or_root(cachep, s)) {
  2041. +#ifdef CONFIG_BUG_ON_DATA_CORRUPTION
  2042. + BUG();
  2043. +#else
  2044. + WARN_ONCE(1, "%s: Wrong slab cache. %s but object is from %s\n",
  2045. + __func__, s->name, cachep->name);
  2046. +#endif
  2047. + }
  2048. return cachep;
  2049. }
  2050. @@ -545,7 +554,7 @@ static inline size_t slab_ksize(const struct kmem_cache *s)
  2051. * back there or track user information then we can
  2052. * only use the space before that information.
  2053. */
  2054. - if (s->flags & (SLAB_TYPESAFE_BY_RCU | SLAB_STORE_USER))
  2055. + if ((s->flags & (SLAB_TYPESAFE_BY_RCU | SLAB_STORE_USER)) || IS_ENABLED(CONFIG_SLAB_CANARY))
  2056. return s->inuse;
  2057. /*
  2058. * Else we can use all the padding etc for the allocation
  2059. @@ -674,8 +683,10 @@ static inline void cache_random_seq_destroy(struct kmem_cache *cachep) { }
  2060. static inline bool slab_want_init_on_alloc(gfp_t flags, struct kmem_cache *c)
  2061. {
  2062. if (static_branch_unlikely(&init_on_alloc)) {
  2063. +#ifndef CONFIG_SLUB
  2064. if (c->ctor)
  2065. return false;
  2066. +#endif
  2067. if (c->flags & (SLAB_TYPESAFE_BY_RCU | SLAB_POISON))
  2068. return flags & __GFP_ZERO;
  2069. return true;
  2070. @@ -685,9 +696,15 @@ static inline bool slab_want_init_on_alloc(gfp_t flags, struct kmem_cache *c)
  2071. static inline bool slab_want_init_on_free(struct kmem_cache *c)
  2072. {
  2073. - if (static_branch_unlikely(&init_on_free))
  2074. - return !(c->ctor ||
  2075. - (c->flags & (SLAB_TYPESAFE_BY_RCU | SLAB_POISON)));
  2076. + if (static_branch_unlikely(&init_on_free)) {
  2077. +#ifndef CONFIG_SLUB
  2078. + if (c->ctor)
  2079. + return false;
  2080. +#endif
  2081. + if (c->flags & (SLAB_TYPESAFE_BY_RCU | SLAB_POISON))
  2082. + return false;
  2083. + return true;
  2084. + }
  2085. return false;
  2086. }
  2087. diff --git a/mm/slab_common.c b/mm/slab_common.c
  2088. index 8f128245b300..5e3b270aeb22 100644
  2089. --- a/mm/slab_common.c
  2090. +++ b/mm/slab_common.c
  2091. @@ -28,10 +28,10 @@
  2092. #include "slab.h"
  2093. -enum slab_state slab_state;
  2094. +enum slab_state slab_state __ro_after_init;
  2095. LIST_HEAD(slab_caches);
  2096. DEFINE_MUTEX(slab_mutex);
  2097. -struct kmem_cache *kmem_cache;
  2098. +struct kmem_cache *kmem_cache __ro_after_init;
  2099. #ifdef CONFIG_HARDENED_USERCOPY
  2100. bool usercopy_fallback __ro_after_init =
  2101. @@ -59,7 +59,7 @@ static DECLARE_WORK(slab_caches_to_rcu_destroy_work,
  2102. /*
  2103. * Merge control. If this is set then no merging of slab caches will occur.
  2104. */
  2105. -static bool slab_nomerge = !IS_ENABLED(CONFIG_SLAB_MERGE_DEFAULT);
  2106. +static bool slab_nomerge __ro_after_init = !IS_ENABLED(CONFIG_SLAB_MERGE_DEFAULT);
  2107. static int __init setup_slab_nomerge(char *str)
  2108. {
  2109. diff --git a/mm/slub.c b/mm/slub.c
  2110. index e978f647e92a..9a65c872e869 100644
  2111. --- a/mm/slub.c
  2112. +++ b/mm/slub.c
  2113. @@ -126,6 +126,12 @@ static inline int kmem_cache_debug(struct kmem_cache *s)
  2114. #endif
  2115. }
  2116. +static inline bool has_sanitize_verify(struct kmem_cache *s)
  2117. +{
  2118. + return IS_ENABLED(CONFIG_SLAB_SANITIZE_VERIFY) &&
  2119. + slab_want_init_on_free(s);
  2120. +}
  2121. +
  2122. void *fixup_red_left(struct kmem_cache *s, void *p)
  2123. {
  2124. if (kmem_cache_debug(s) && s->flags & SLAB_RED_ZONE)
  2125. @@ -310,6 +316,35 @@ static inline void set_freepointer(struct kmem_cache *s, void *object, void *fp)
  2126. *(void **)freeptr_addr = freelist_ptr(s, fp, freeptr_addr);
  2127. }
  2128. +#ifdef CONFIG_SLAB_CANARY
  2129. +static inline unsigned long *get_canary(struct kmem_cache *s, void *object)
  2130. +{
  2131. + if (s->offset)
  2132. + return object + s->offset + sizeof(void *);
  2133. + return object + s->inuse;
  2134. +}
  2135. +
  2136. +static inline unsigned long get_canary_value(const void *canary, unsigned long value)
  2137. +{
  2138. + return (value ^ (unsigned long)canary) & CANARY_MASK;
  2139. +}
  2140. +
  2141. +static inline void set_canary(struct kmem_cache *s, void *object, unsigned long value)
  2142. +{
  2143. + unsigned long *canary = get_canary(s, object);
  2144. + *canary = get_canary_value(canary, value);
  2145. +}
  2146. +
  2147. +static inline void check_canary(struct kmem_cache *s, void *object, unsigned long value)
  2148. +{
  2149. + unsigned long *canary = get_canary(s, object);
  2150. + BUG_ON(*canary != get_canary_value(canary, value));
  2151. +}
  2152. +#else
  2153. +#define set_canary(s, object, value)
  2154. +#define check_canary(s, object, value)
  2155. +#endif
  2156. +
  2157. /* Loop over all objects in a slab */
  2158. #define for_each_object(__p, __s, __addr, __objects) \
  2159. for (__p = fixup_red_left(__s, __addr); \
  2160. @@ -477,13 +512,13 @@ static inline void *restore_red_left(struct kmem_cache *s, void *p)
  2161. * Debug settings:
  2162. */
  2163. #if defined(CONFIG_SLUB_DEBUG_ON)
  2164. -static slab_flags_t slub_debug = DEBUG_DEFAULT_FLAGS;
  2165. +static slab_flags_t slub_debug __ro_after_init = DEBUG_DEFAULT_FLAGS;
  2166. #else
  2167. -static slab_flags_t slub_debug;
  2168. +static slab_flags_t slub_debug __ro_after_init;
  2169. #endif
  2170. -static char *slub_debug_slabs;
  2171. -static int disable_higher_order_debug;
  2172. +static char *slub_debug_slabs __ro_after_init;
  2173. +static int disable_higher_order_debug __ro_after_init;
  2174. /*
  2175. * slub is about to manipulate internal object metadata. This memory lies
  2176. @@ -561,6 +596,9 @@ static struct track *get_track(struct kmem_cache *s, void *object,
  2177. p = object + get_info_end(s);
  2178. + if (IS_ENABLED(CONFIG_SLAB_CANARY))
  2179. + p = (void *)p + sizeof(void *);
  2180. +
  2181. return p + alloc;
  2182. }
  2183. @@ -702,6 +740,9 @@ static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p)
  2184. off = get_info_end(s);
  2185. + if (IS_ENABLED(CONFIG_SLAB_CANARY))
  2186. + off += sizeof(void *);
  2187. +
  2188. if (s->flags & SLAB_STORE_USER)
  2189. off += 2 * sizeof(struct track);
  2190. @@ -827,6 +868,9 @@ static int check_pad_bytes(struct kmem_cache *s, struct page *page, u8 *p)
  2191. {
  2192. unsigned long off = get_info_end(s); /* The end of info */
  2193. + if (IS_ENABLED(CONFIG_SLAB_CANARY))
  2194. + off += sizeof(void *);
  2195. +
  2196. if (s->flags & SLAB_STORE_USER)
  2197. /* We also have user information there */
  2198. off += 2 * sizeof(struct track);
  2199. @@ -1472,6 +1516,8 @@ static inline bool slab_free_freelist_hook(struct kmem_cache *s,
  2200. object = next;
  2201. next = get_freepointer(s, object);
  2202. + check_canary(s, object, s->random_active);
  2203. +
  2204. if (slab_want_init_on_free(s)) {
  2205. /*
  2206. * Clear the object and the metadata, but don't touch
  2207. @@ -1482,8 +1528,12 @@ static inline bool slab_free_freelist_hook(struct kmem_cache *s,
  2208. : 0;
  2209. memset((char *)object + s->inuse, 0,
  2210. s->size - s->inuse - rsize);
  2211. -
  2212. + if (!IS_ENABLED(CONFIG_SLAB_SANITIZE_VERIFY) && s->ctor)
  2213. + s->ctor(object);
  2214. }
  2215. +
  2216. + set_canary(s, object, s->random_inactive);
  2217. +
  2218. /* If object's reuse doesn't have to be delayed */
  2219. if (!slab_free_hook(s, object)) {
  2220. /* Move object to the new freelist */
  2221. @@ -1497,6 +1547,22 @@ static inline bool slab_free_freelist_hook(struct kmem_cache *s,
  2222. * accordingly if object's reuse is delayed.
  2223. */
  2224. --(*cnt);
  2225. +
  2226. + /* Objects that are put into quarantine by KASAN will
  2227. + * still undergo free_consistency_checks(), which
  2228. + * checks whether the freelist pointer is valid if it
  2229. + * is located after the object (see check_object()).
  2230. + * Since this is the case for slab caches with
  2231. + * constructors, we need to fix the freelist pointer
  2232. + * after init_on_free has overwritten it.
  2233. + *
  2234. + * Note that doing this for all caches (not just ctor
  2235. + * ones) would cause a GPF due to KASAN poisoning and
  2236. + * the way set_freepointer() eventually dereferences
  2237. + * the freepointer.
  2238. + */
  2239. + if (slab_want_init_on_free(s) && s->ctor)
  2240. + set_freepointer(s, object, NULL);
  2241. }
  2242. } while (object != old_tail);
  2243. @@ -1510,8 +1576,9 @@ static void *setup_object(struct kmem_cache *s, struct page *page,
  2244. void *object)
  2245. {
  2246. setup_object_debug(s, page, object);
  2247. + set_canary(s, object, s->random_inactive);
  2248. object = kasan_init_slab_obj(s, object);
  2249. - if (unlikely(s->ctor)) {
  2250. + if (unlikely(s->ctor) && !has_sanitize_verify(s)) {
  2251. kasan_unpoison_object_data(s, object);
  2252. s->ctor(object);
  2253. kasan_poison_object_data(s, object);
  2254. @@ -2805,8 +2872,28 @@ static __always_inline void *slab_alloc_node(struct kmem_cache *s,
  2255. maybe_wipe_obj_freeptr(s, object);
  2256. - if (unlikely(slab_want_init_on_alloc(gfpflags, s)) && object)
  2257. + if (has_sanitize_verify(s) && object) {
  2258. + /* KASAN hasn't unpoisoned the object yet (this is done in the
  2259. + * post-alloc hook), so let's do it temporarily.
  2260. + */
  2261. + kasan_unpoison_object_data(s, object);
  2262. + BUG_ON(memchr_inv(object, 0, s->object_size));
  2263. + if (s->ctor)
  2264. + s->ctor(object);
  2265. + kasan_poison_object_data(s, object);
  2266. + } else if (unlikely(slab_want_init_on_alloc(gfpflags, s)) && object) {
  2267. memset(object, 0, s->object_size);
  2268. + if (s->ctor) {
  2269. + kasan_unpoison_object_data(s, object);
  2270. + s->ctor(object);
  2271. + kasan_poison_object_data(s, object);
  2272. + }
  2273. + }
  2274. +
  2275. + if (object) {
  2276. + check_canary(s, object, s->random_inactive);
  2277. + set_canary(s, object, s->random_active);
  2278. + }
  2279. slab_post_alloc_hook(s, gfpflags, 1, &object);
  2280. @@ -3191,7 +3278,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
  2281. void **p)
  2282. {
  2283. struct kmem_cache_cpu *c;
  2284. - int i;
  2285. + int i, k;
  2286. /* memcg and kmem_cache debug support */
  2287. s = slab_pre_alloc_hook(s, flags);
  2288. @@ -3240,11 +3327,35 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
  2289. local_irq_enable();
  2290. /* Clear memory outside IRQ disabled fastpath loop */
  2291. - if (unlikely(slab_want_init_on_alloc(flags, s))) {
  2292. + if (has_sanitize_verify(s)) {
  2293. int j;
  2294. - for (j = 0; j < i; j++)
  2295. + for (j = 0; j < i; j++) {
  2296. + /* KASAN hasn't unpoisoned the object yet (this is done
  2297. + * in the post-alloc hook), so let's do it temporarily.
  2298. + */
  2299. + kasan_unpoison_object_data(s, p[j]);
  2300. + BUG_ON(memchr_inv(p[j], 0, s->object_size));
  2301. + if (s->ctor)
  2302. + s->ctor(p[j]);
  2303. + kasan_poison_object_data(s, p[j]);
  2304. + }
  2305. + } else if (unlikely(slab_want_init_on_alloc(flags, s))) {
  2306. + int j;
  2307. +
  2308. + for (j = 0; j < i; j++) {
  2309. memset(p[j], 0, s->object_size);
  2310. + if (s->ctor) {
  2311. + kasan_unpoison_object_data(s, p[j]);
  2312. + s->ctor(p[j]);
  2313. + kasan_poison_object_data(s, p[j]);
  2314. + }
  2315. + }
  2316. + }
  2317. +
  2318. + for (k = 0; k < i; k++) {
  2319. + check_canary(s, p[k], s->random_inactive);
  2320. + set_canary(s, p[k], s->random_active);
  2321. }
  2322. /* memcg and kmem_cache debug support */
  2323. @@ -3278,9 +3389,9 @@ EXPORT_SYMBOL(kmem_cache_alloc_bulk);
  2324. * and increases the number of allocations possible without having to
  2325. * take the list_lock.
  2326. */
  2327. -static unsigned int slub_min_order;
  2328. -static unsigned int slub_max_order = PAGE_ALLOC_COSTLY_ORDER;
  2329. -static unsigned int slub_min_objects;
  2330. +static unsigned int slub_min_order __ro_after_init;
  2331. +static unsigned int slub_max_order __ro_after_init = PAGE_ALLOC_COSTLY_ORDER;
  2332. +static unsigned int slub_min_objects __ro_after_init;
  2333. /*
  2334. * Calculate the order of allocation given an slab object size.
  2335. @@ -3448,6 +3559,7 @@ static void early_kmem_cache_node_alloc(int node)
  2336. init_object(kmem_cache_node, n, SLUB_RED_ACTIVE);
  2337. init_tracking(kmem_cache_node, n);
  2338. #endif
  2339. + set_canary(kmem_cache_node, n, kmem_cache_node->random_active);
  2340. n = kasan_kmalloc(kmem_cache_node, n, sizeof(struct kmem_cache_node),
  2341. GFP_KERNEL);
  2342. page->freelist = get_freepointer(kmem_cache_node, n);
  2343. @@ -3615,6 +3727,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
  2344. size += sizeof(void *);
  2345. }
  2346. + if (IS_ENABLED(CONFIG_SLAB_CANARY))
  2347. + size += sizeof(void *);
  2348. +
  2349. #ifdef CONFIG_SLUB_DEBUG
  2350. if (flags & SLAB_STORE_USER)
  2351. /*
  2352. @@ -3687,6 +3802,10 @@ static int kmem_cache_open(struct kmem_cache *s, slab_flags_t flags)
  2353. #ifdef CONFIG_SLAB_FREELIST_HARDENED
  2354. s->random = get_random_long();
  2355. #endif
  2356. +#ifdef CONFIG_SLAB_CANARY
  2357. + s->random_active = get_random_long();
  2358. + s->random_inactive = get_random_long();
  2359. +#endif
  2360. if (!calculate_sizes(s, -1))
  2361. goto error;
  2362. @@ -3962,6 +4081,8 @@ void __check_heap_object(const void *ptr, unsigned long n, struct page *page,
  2363. offset -= s->red_left_pad;
  2364. }
  2365. + check_canary(s, (void *)ptr - offset, s->random_active);
  2366. +
  2367. /* Allow address range falling entirely within usercopy region. */
  2368. if (offset >= s->useroffset &&
  2369. offset - s->useroffset <= s->usersize &&
  2370. @@ -3995,7 +4116,11 @@ size_t __ksize(const void *object)
  2371. page = virt_to_head_page(object);
  2372. if (unlikely(!PageSlab(page))) {
  2373. +#ifdef CONFIG_BUG_ON_DATA_CORRUPTION
  2374. + BUG_ON(!PageCompound(page));
  2375. +#else
  2376. WARN_ON(!PageCompound(page));
  2377. +#endif
  2378. return page_size(page);
  2379. }
  2380. @@ -4840,7 +4965,7 @@ enum slab_stat_type {
  2381. #define SO_TOTAL (1 << SL_TOTAL)
  2382. #ifdef CONFIG_MEMCG
  2383. -static bool memcg_sysfs_enabled = IS_ENABLED(CONFIG_SLUB_MEMCG_SYSFS_ON);
  2384. +static bool memcg_sysfs_enabled __ro_after_init = IS_ENABLED(CONFIG_SLUB_MEMCG_SYSFS_ON);
  2385. static int __init setup_slub_memcg_sysfs(char *str)
  2386. {
  2387. diff --git a/mm/swap.c b/mm/swap.c
  2388. index 1c5021b57e2c..79d5a429eb49 100644
  2389. --- a/mm/swap.c
  2390. +++ b/mm/swap.c
  2391. @@ -94,6 +94,13 @@ static void __put_compound_page(struct page *page)
  2392. if (!PageHuge(page))
  2393. __page_cache_release(page);
  2394. dtor = get_compound_page_dtor(page);
  2395. + if (!PageHuge(page))
  2396. + BUG_ON(dtor != free_compound_page
  2397. +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
  2398. + && dtor != free_transhuge_page
  2399. +#endif
  2400. + );
  2401. +
  2402. (*dtor)(page);
  2403. }
  2404. diff --git a/mm/util.c b/mm/util.c
  2405. index 04ebc76588aa..0a4a4198c0eb 100644
  2406. --- a/mm/util.c
  2407. +++ b/mm/util.c
  2408. @@ -357,9 +357,9 @@ unsigned long arch_randomize_brk(struct mm_struct *mm)
  2409. {
  2410. /* Is the current task 32bit ? */
  2411. if (!IS_ENABLED(CONFIG_64BIT) || is_compat_task())
  2412. - return randomize_page(mm->brk, SZ_32M);
  2413. + return mm->brk + get_random_long() % SZ_32M + PAGE_SIZE;
  2414. - return randomize_page(mm->brk, SZ_1G);
  2415. + return mm->brk + get_random_long() % SZ_1G + PAGE_SIZE;
  2416. }
  2417. unsigned long arch_mmap_rnd(void)
  2418. diff --git a/net/core/dev.c b/net/core/dev.c
  2419. index 5e043e6f0947..401da1f69fb1 100644
  2420. --- a/net/core/dev.c
  2421. +++ b/net/core/dev.c
  2422. @@ -4502,7 +4502,7 @@ int netif_rx_ni(struct sk_buff *skb)
  2423. }
  2424. EXPORT_SYMBOL(netif_rx_ni);
  2425. -static __latent_entropy void net_tx_action(struct softirq_action *h)
  2426. +static __latent_entropy void net_tx_action(void)
  2427. {
  2428. struct softnet_data *sd = this_cpu_ptr(&softnet_data);
  2429. @@ -6404,7 +6404,7 @@ static int napi_poll(struct napi_struct *n, struct list_head *repoll)
  2430. return work;
  2431. }
  2432. -static __latent_entropy void net_rx_action(struct softirq_action *h)
  2433. +static __latent_entropy void net_rx_action(void)
  2434. {
  2435. struct softnet_data *sd = this_cpu_ptr(&softnet_data);
  2436. unsigned long time_limit = jiffies +
  2437. diff --git a/net/ipv4/Kconfig b/net/ipv4/Kconfig
  2438. index f5af8c6b2f87..842267c99dc4 100644
  2439. --- a/net/ipv4/Kconfig
  2440. +++ b/net/ipv4/Kconfig
  2441. @@ -267,6 +267,7 @@ config IP_PIMSM_V2
  2442. config SYN_COOKIES
  2443. bool "IP: TCP syncookie support"
  2444. + default y
  2445. ---help---
  2446. Normal TCP/IP networking is open to an attack known as "SYN
  2447. flooding". This denial-of-service attack prevents legitimate remote
  2448. @@ -738,3 +739,26 @@ config TCP_MD5SIG
  2449. on the Internet.
  2450. If unsure, say N.
  2451. +
  2452. +config TCP_SIMULT_CONNECT_DEFAULT_ON
  2453. + bool "Enable TCP simultaneous connect"
  2454. + help
  2455. + Enable TCP simultaneous connect that adds a weakness in Linux's strict
  2456. + implementation of TCP that allows two clients to connect to each other
  2457. + without either entering a listening state. The weakness allows an
  2458. + attacker to easily prevent a client from connecting to a known server
  2459. + provided the source port for the connection is guessed correctly.
  2460. +
  2461. + As the weakness could be used to prevent an antivirus or IPS from
  2462. + fetching updates, or prevent an SSL gateway from fetching a CRL, it
  2463. + should be eliminated by disabling this option. Though Linux is one of
  2464. + few operating systems supporting simultaneous connect, it has no
  2465. + legitimate use in practice and is rarely supported by firewalls.
  2466. +
  2467. + Disabling this may break TCP STUNT which is used by some applications
  2468. + for NAT traversal.
  2469. +
  2470. + This setting can be overridden at runtime via the
  2471. + net.ipv4.tcp_simult_connect sysctl.
  2472. +
  2473. + If unsure, say N.
  2474. diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
  2475. index 4d4dba1d42ae..89fe646c79dd 100644
  2476. --- a/net/ipv4/sysctl_net_ipv4.c
  2477. +++ b/net/ipv4/sysctl_net_ipv4.c
  2478. @@ -549,6 +549,15 @@ static struct ctl_table ipv4_table[] = {
  2479. .mode = 0644,
  2480. .proc_handler = proc_do_static_key,
  2481. },
  2482. + {
  2483. + .procname = "tcp_simult_connect",
  2484. + .data = &sysctl_tcp_simult_connect,
  2485. + .maxlen = sizeof(int),
  2486. + .mode = 0644,
  2487. + .proc_handler = proc_dointvec_minmax,
  2488. + .extra1 = SYSCTL_ZERO,
  2489. + .extra2 = SYSCTL_ONE,
  2490. + },
  2491. { }
  2492. };
  2493. diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
  2494. index 61243531a7f4..8559658cbaa2 100644
  2495. --- a/net/ipv4/tcp_input.c
  2496. +++ b/net/ipv4/tcp_input.c
  2497. @@ -81,6 +81,7 @@
  2498. #include <net/busy_poll.h>
  2499. int sysctl_tcp_max_orphans __read_mostly = NR_FILE;
  2500. +int sysctl_tcp_simult_connect __read_mostly = IS_ENABLED(CONFIG_TCP_SIMULT_CONNECT_DEFAULT_ON);
  2501. #define FLAG_DATA 0x01 /* Incoming frame contained data. */
  2502. #define FLAG_WIN_UPDATE 0x02 /* Incoming ACK was a window update. */
  2503. @@ -6112,7 +6113,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
  2504. tcp_paws_reject(&tp->rx_opt, 0))
  2505. goto discard_and_undo;
  2506. - if (th->syn) {
  2507. + if (th->syn && sysctl_tcp_simult_connect) {
  2508. /* We see SYN without ACK. It is attempt of
  2509. * simultaneous connect with crossed SYNs.
  2510. * Particularly, it can be connect to self.
  2511. diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
  2512. index 2dde6e5e9e69..e91ec2607abd 100644
  2513. --- a/scripts/Makefile.modpost
  2514. +++ b/scripts/Makefile.modpost
  2515. @@ -54,6 +54,7 @@ MODPOST = scripts/mod/modpost \
  2516. $(if $(KBUILD_EXTMOD),$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS))) \
  2517. $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
  2518. $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
  2519. + $(if $(CONFIG_DEBUG_WRITABLE_FUNCTION_POINTERS_VERBOSE),-f) \
  2520. $(if $(KBUILD_MODPOST_WARN),-w) \
  2521. $(if $(filter nsdeps,$(MAKECMDGOALS)),-d)
  2522. diff --git a/scripts/gcc-plugins/Kconfig b/scripts/gcc-plugins/Kconfig
  2523. index e3569543bdac..55cc439b3bc6 100644
  2524. --- a/scripts/gcc-plugins/Kconfig
  2525. +++ b/scripts/gcc-plugins/Kconfig
  2526. @@ -61,6 +61,11 @@ config GCC_PLUGIN_LATENT_ENTROPY
  2527. is some slowdown of the boot process (about 0.5%) and fork and
  2528. irq processing.
  2529. + When extra_latent_entropy is passed on the kernel command line,
  2530. + entropy will be extracted from up to the first 4GB of RAM while the
  2531. + runtime memory allocator is being initialized. This costs even more
  2532. + slowdown of the boot process.
  2533. +
  2534. Note that entropy extracted this way is not cryptographically
  2535. secure!
  2536. diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
  2537. index 53e276bb24ac..dbb33e420915 100644
  2538. --- a/scripts/mod/modpost.c
  2539. +++ b/scripts/mod/modpost.c
  2540. @@ -36,6 +36,8 @@ static int warn_unresolved = 0;
  2541. /* How a symbol is exported */
  2542. static int sec_mismatch_count = 0;
  2543. static int sec_mismatch_fatal = 0;
  2544. +static int writable_fptr_count = 0;
  2545. +static int writable_fptr_verbose = false;
  2546. /* ignore missing files */
  2547. static int ignore_missing_files;
  2548. /* write namespace dependencies */
  2549. @@ -1019,6 +1021,7 @@ enum mismatch {
  2550. ANY_EXIT_TO_ANY_INIT,
  2551. EXPORT_TO_INIT_EXIT,
  2552. EXTABLE_TO_NON_TEXT,
  2553. + DATA_TO_TEXT
  2554. };
  2555. /**
  2556. @@ -1145,6 +1148,12 @@ static const struct sectioncheck sectioncheck[] = {
  2557. .good_tosec = {ALL_TEXT_SECTIONS , NULL},
  2558. .mismatch = EXTABLE_TO_NON_TEXT,
  2559. .handler = extable_mismatch_handler,
  2560. +},
  2561. +/* Do not reference code from writable data */
  2562. +{
  2563. + .fromsec = { DATA_SECTIONS, NULL },
  2564. + .bad_tosec = { ALL_TEXT_SECTIONS, NULL },
  2565. + .mismatch = DATA_TO_TEXT
  2566. }
  2567. };
  2568. @@ -1337,10 +1346,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
  2569. continue;
  2570. if (!is_valid_name(elf, sym))
  2571. continue;
  2572. - if (sym->st_value == addr)
  2573. - return sym;
  2574. /* Find a symbol nearby - addr are maybe negative */
  2575. d = sym->st_value - addr;
  2576. + if (d == 0)
  2577. + return sym;
  2578. if (d < 0)
  2579. d = addr - sym->st_value;
  2580. if (d < distance) {
  2581. @@ -1475,7 +1484,13 @@ static void report_sec_mismatch(const char *modname,
  2582. char *prl_from;
  2583. char *prl_to;
  2584. - sec_mismatch_count++;
  2585. + if (mismatch->mismatch == DATA_TO_TEXT) {
  2586. + writable_fptr_count++;
  2587. + if (!writable_fptr_verbose)
  2588. + return;
  2589. + } else {
  2590. + sec_mismatch_count++;
  2591. + }
  2592. get_pretty_name(from_is_func, &from, &from_p);
  2593. get_pretty_name(to_is_func, &to, &to_p);
  2594. @@ -1597,6 +1612,12 @@ static void report_sec_mismatch(const char *modname,
  2595. fatal("There's a special handler for this mismatch type, "
  2596. "we should never get here.");
  2597. break;
  2598. + case DATA_TO_TEXT:
  2599. + fprintf(stderr,
  2600. + "The %s %s:%s references\n"
  2601. + "the %s %s:%s%s\n",
  2602. + from, fromsec, fromsym, to, tosec, tosym, to_p);
  2603. + break;
  2604. }
  2605. fprintf(stderr, "\n");
  2606. }
  2607. @@ -2588,7 +2609,7 @@ int main(int argc, char **argv)
  2608. struct ext_sym_list *extsym_iter;
  2609. struct ext_sym_list *extsym_start = NULL;
  2610. - while ((opt = getopt(argc, argv, "i:I:e:mnsT:o:awEd")) != -1) {
  2611. + while ((opt = getopt(argc, argv, "i:I:e:fmnsT:o:awEd")) != -1) {
  2612. switch (opt) {
  2613. case 'i':
  2614. kernel_read = optarg;
  2615. @@ -2605,6 +2626,9 @@ int main(int argc, char **argv)
  2616. extsym_iter->file = optarg;
  2617. extsym_start = extsym_iter;
  2618. break;
  2619. + case 'f':
  2620. + writable_fptr_verbose = true;
  2621. + break;
  2622. case 'm':
  2623. modversions = 1;
  2624. break;
  2625. @@ -2711,6 +2735,11 @@ int main(int argc, char **argv)
  2626. }
  2627. free(buf.p);
  2628. + if (writable_fptr_count && !writable_fptr_verbose)
  2629. + warn("modpost: Found %d writable function pointer%s.\n"
  2630. + "To see full details build your kernel with:\n"
  2631. + "'make CONFIG_DEBUG_WRITABLE_FUNCTION_POINTERS_VERBOSE=y'\n",
  2632. + writable_fptr_count, (writable_fptr_count == 1 ? "" : "s"));
  2633. return err;
  2634. }
  2635. diff --git a/security/Kconfig b/security/Kconfig
  2636. index 52e5109f2c1b..d9664a242f20 100644
  2637. --- a/security/Kconfig
  2638. +++ b/security/Kconfig
  2639. @@ -9,7 +9,7 @@ source "security/keys/Kconfig"
  2640. config SECURITY_DMESG_RESTRICT
  2641. bool "Restrict unprivileged access to the kernel syslog"
  2642. - default n
  2643. + default y
  2644. help
  2645. This enforces restrictions on unprivileged users reading the kernel
  2646. syslog via dmesg(8).
  2647. @@ -19,10 +19,34 @@ config SECURITY_DMESG_RESTRICT
  2648. If you are unsure how to answer this question, answer N.
  2649. +config SECURITY_PERF_EVENTS_RESTRICT
  2650. + bool "Restrict unprivileged use of performance events"
  2651. + depends on PERF_EVENTS
  2652. + default y
  2653. + help
  2654. + If you say Y here, the kernel.perf_event_paranoid sysctl
  2655. + will be set to 3 by default, and no unprivileged use of the
  2656. + perf_event_open syscall will be permitted unless it is
  2657. + changed.
  2658. +
  2659. +config SECURITY_TIOCSTI_RESTRICT
  2660. + bool "Restrict unprivileged use of tiocsti command injection"
  2661. + default y
  2662. + help
  2663. + This enforces restrictions on unprivileged users injecting commands
  2664. + into other processes which share a tty session using the TIOCSTI
  2665. + ioctl. This option makes TIOCSTI use require CAP_SYS_ADMIN.
  2666. +
  2667. + If this option is not selected, no restrictions will be enforced
  2668. + unless the tiocsti_restrict sysctl is explicitly set to (1).
  2669. +
  2670. + If you are unsure how to answer this question, answer N.
  2671. +
  2672. config SECURITY
  2673. bool "Enable different security models"
  2674. depends on SYSFS
  2675. depends on MULTIUSER
  2676. + default y
  2677. help
  2678. This allows you to choose different security modules to be
  2679. configured into your kernel.
  2680. @@ -48,6 +72,7 @@ config SECURITYFS
  2681. config SECURITY_NETWORK
  2682. bool "Socket and Networking Security Hooks"
  2683. depends on SECURITY
  2684. + default y
  2685. help
  2686. This enables the socket and networking security hooks.
  2687. If enabled, a security module can use these hooks to
  2688. @@ -154,6 +179,7 @@ config HARDENED_USERCOPY
  2689. bool "Harden memory copies between kernel and userspace"
  2690. depends on HAVE_HARDENED_USERCOPY_ALLOCATOR
  2691. imply STRICT_DEVMEM
  2692. + default y
  2693. help
  2694. This option checks for obviously wrong memory regions when
  2695. copying memory to/from the kernel (via copy_to_user() and
  2696. @@ -166,7 +192,6 @@ config HARDENED_USERCOPY
  2697. config HARDENED_USERCOPY_FALLBACK
  2698. bool "Allow usercopy whitelist violations to fallback to object size"
  2699. depends on HARDENED_USERCOPY
  2700. - default y
  2701. help
  2702. This is a temporary option that allows missing usercopy whitelists
  2703. to be discovered via a WARN() to the kernel log, instead of
  2704. @@ -194,10 +219,21 @@ config FORTIFY_SOURCE
  2705. # https://bugs.llvm.org/show_bug.cgi?id=50322
  2706. # https://bugs.llvm.org/show_bug.cgi?id=41459
  2707. depends on !CC_IS_CLANG
  2708. + default y
  2709. help
  2710. Detect overflows of buffers in common string and memory functions
  2711. where the compiler can determine and validate the buffer sizes.
  2712. +config FORTIFY_SOURCE_STRICT_STRING
  2713. + bool "Harden common functions against buffer overflows"
  2714. + depends on FORTIFY_SOURCE
  2715. + depends on EXPERT
  2716. + help
  2717. + Perform stricter overflow checks catching overflows within objects
  2718. + for common C string functions rather than only between objects.
  2719. +
  2720. + This is not yet intended for production use, only bug finding.
  2721. +
  2722. config STATIC_USERMODEHELPER
  2723. bool "Force all usermode helper calls through a single binary"
  2724. help
  2725. diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening
  2726. index af4c979b38ee..473e40bb8537 100644
  2727. --- a/security/Kconfig.hardening
  2728. +++ b/security/Kconfig.hardening
  2729. @@ -169,6 +169,7 @@ config STACKLEAK_RUNTIME_DISABLE
  2730. config INIT_ON_ALLOC_DEFAULT_ON
  2731. bool "Enable heap memory zeroing on allocation by default"
  2732. + default yes
  2733. help
  2734. This has the effect of setting "init_on_alloc=1" on the kernel
  2735. command line. This can be disabled with "init_on_alloc=0".
  2736. @@ -181,6 +182,7 @@ config INIT_ON_ALLOC_DEFAULT_ON
  2737. config INIT_ON_FREE_DEFAULT_ON
  2738. bool "Enable heap memory zeroing on free by default"
  2739. + default yes
  2740. help
  2741. This has the effect of setting "init_on_free=1" on the kernel
  2742. command line. This can be disabled with "init_on_free=0".
  2743. @@ -196,6 +198,20 @@ config INIT_ON_FREE_DEFAULT_ON
  2744. touching "cold" memory areas. Most cases see 3-5% impact. Some
  2745. synthetic workloads have measured as high as 8%.
  2746. +config PAGE_SANITIZE_VERIFY
  2747. + bool "Verify sanitized pages"
  2748. + default y
  2749. + help
  2750. + When init_on_free is enabled, verify that newly allocated pages
  2751. + are zeroed to detect write-after-free bugs.
  2752. +
  2753. +config SLAB_SANITIZE_VERIFY
  2754. + default y
  2755. + bool "Verify sanitized SLAB allocations"
  2756. + help
  2757. + When init_on_free is enabled, verify that newly allocated slab
  2758. + objects are zeroed to detect write-after-free bugs.
  2759. +
  2760. endmenu
  2761. endmenu
  2762. diff --git a/security/selinux/Kconfig b/security/selinux/Kconfig
  2763. index 5711689deb6a..fab0cb896907 100644
  2764. --- a/security/selinux/Kconfig
  2765. +++ b/security/selinux/Kconfig
  2766. @@ -3,7 +3,7 @@ config SECURITY_SELINUX
  2767. bool "NSA SELinux Support"
  2768. depends on SECURITY_NETWORK && AUDIT && NET && INET
  2769. select NETWORK_SECMARK
  2770. - default n
  2771. + default y
  2772. help
  2773. This selects NSA Security-Enhanced Linux (SELinux).
  2774. You will also need a policy configuration and a labeled filesystem.
  2775. @@ -65,23 +65,3 @@ config SECURITY_SELINUX_AVC_STATS
  2776. This option collects access vector cache statistics to
  2777. /selinux/avc/cache_stats, which may be monitored via
  2778. tools such as avcstat.
  2779. -
  2780. -config SECURITY_SELINUX_CHECKREQPROT_VALUE
  2781. - int "NSA SELinux checkreqprot default value"
  2782. - depends on SECURITY_SELINUX
  2783. - range 0 1
  2784. - default 0
  2785. - help
  2786. - This option sets the default value for the 'checkreqprot' flag
  2787. - that determines whether SELinux checks the protection requested
  2788. - by the application or the protection that will be applied by the
  2789. - kernel (including any implied execute for read-implies-exec) for
  2790. - mmap and mprotect calls. If this option is set to 0 (zero),
  2791. - SELinux will default to checking the protection that will be applied
  2792. - by the kernel. If this option is set to 1 (one), SELinux will
  2793. - default to checking the protection requested by the application.
  2794. - The checkreqprot flag may be changed from the default via the
  2795. - 'checkreqprot=' boot parameter. It may also be changed at runtime
  2796. - via /selinux/checkreqprot if authorized by policy.
  2797. -
  2798. - If you are unsure how to answer this question, answer 0.
  2799. diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
  2800. index 6fec9fba41a8..b3da856a6482 100644
  2801. --- a/security/selinux/hooks.c
  2802. +++ b/security/selinux/hooks.c
  2803. @@ -135,18 +135,7 @@ static int __init selinux_enabled_setup(char *str)
  2804. __setup("selinux=", selinux_enabled_setup);
  2805. #endif
  2806. -static unsigned int selinux_checkreqprot_boot =
  2807. - CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE;
  2808. -
  2809. -static int __init checkreqprot_setup(char *str)
  2810. -{
  2811. - unsigned long checkreqprot;
  2812. -
  2813. - if (!kstrtoul(str, 0, &checkreqprot))
  2814. - selinux_checkreqprot_boot = checkreqprot ? 1 : 0;
  2815. - return 1;
  2816. -}
  2817. -__setup("checkreqprot=", checkreqprot_setup);
  2818. +static const unsigned int selinux_checkreqprot_boot;
  2819. /**
  2820. * selinux_secmark_enabled - Check to see if SECMARK is currently enabled
  2821. diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
  2822. index e9eaff90cbcc..239592d155a5 100644
  2823. --- a/security/selinux/selinuxfs.c
  2824. +++ b/security/selinux/selinuxfs.c
  2825. @@ -639,7 +639,6 @@ static ssize_t sel_read_checkreqprot(struct file *filp, char __user *buf,
  2826. static ssize_t sel_write_checkreqprot(struct file *file, const char __user *buf,
  2827. size_t count, loff_t *ppos)
  2828. {
  2829. - struct selinux_fs_info *fsi = file_inode(file)->i_sb->s_fs_info;
  2830. char *page;
  2831. ssize_t length;
  2832. unsigned int new_value;
  2833. @@ -663,10 +662,9 @@ static ssize_t sel_write_checkreqprot(struct file *file, const char __user *buf,
  2834. return PTR_ERR(page);
  2835. length = -EINVAL;
  2836. - if (sscanf(page, "%u", &new_value) != 1)
  2837. + if (sscanf(page, "%u", &new_value) != 1 || new_value)
  2838. goto out;
  2839. - fsi->state->checkreqprot = new_value ? 1 : 0;
  2840. length = count;
  2841. out:
  2842. kfree(page);
  2843. diff --git a/security/yama/Kconfig b/security/yama/Kconfig
  2844. index a810304123ca..b809050b25d2 100644
  2845. --- a/security/yama/Kconfig
  2846. +++ b/security/yama/Kconfig
  2847. @@ -2,7 +2,7 @@
  2848. config SECURITY_YAMA
  2849. bool "Yama support"
  2850. depends on SECURITY
  2851. - default n
  2852. + default y
  2853. help
  2854. This selects Yama, which extends DAC support with additional
  2855. system-wide security settings beyond regular Linux discretionary
  2856. diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
  2857. index 9dd9e3f4ef59..9b25eefbdcf4 100644
  2858. --- a/tools/perf/util/evsel.c
  2859. +++ b/tools/perf/util/evsel.c
  2860. @@ -2449,6 +2449,7 @@ int perf_evsel__open_strerror(struct evsel *evsel, struct target *target,
  2861. " Disallow raw tracepoint access by users without CAP_SYS_ADMIN\n"
  2862. ">= 1: Disallow CPU event access by users without CAP_SYS_ADMIN\n"
  2863. ">= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN\n\n"
  2864. + ">= 3: Disallow use of any event by users without CAP_SYS_ADMIN\n\n"
  2865. "To make this setting permanent, edit /etc/sysctl.conf too, e.g.:\n\n"
  2866. " kernel.perf_event_paranoid = -1\n" ,
  2867. target->system_wide ? "system-wide " : "",