Message ID | 20211202223214.72888-1-alexandr.lobakin@intel.com (mailing list archive) |
---|---|
Headers | show |
Series | Function Granular KASLR | expand |
On Thu, Dec 02, 2021 at 11:32:05PM +0100, Alexander Lobakin wrote: > Use the newly introduces macros to create unique separate sections > for (almost) every "regular" ASM function (i.e. for those which > aren't explicitly put into a specific one). > There should be no leftovers as input .text will be size-asserted > in the LD script generated for FG-KASLR. *groan*... Please, can't we do something like: #define SYM_PUSH_SECTION(name) \ .if section == .text \ .push_section .text.##name \ .else \ .push_section .text \ .endif #define SYM_POP_SECTION() \ .pop_section and wrap that inside the existing SYM_FUNC_START*() SYM_FUNC_END() macros.
On Thu, Dec 02, 2021 at 11:32:00PM +0100, Alexander Lobakin wrote: > feat make -j65 boot vmlinux.o vmlinux bzImage bogoops/s > Relocatable 4m38.478s 24.440s 72014208 58579520 9396192 57640.39 > KASLR 4m39.344s 24.204s 72020624 87805776 9740352 57393.80 > FG-K 16 fps 6m16.493s 25.429s 83759856 87194160 10885632 57784.76 > FG-K 8 fps 6m20.190s 25.094s 83759856 88741328 10985248 56625.84 > FG-K 1 fps 7m09.611s 25.922s 83759856 95681128 11352192 56953.99 :sadface: so at best it makes my kernel compiles ~50% slower. Who would ever consider doing that? It's like retpolines weren't bad enough; lets heap on the fail?
From: Peter Zijlstra <peterz@infradead.org> Date: Fri, 3 Dec 2021 10:44:10 +0100 > On Thu, Dec 02, 2021 at 11:32:05PM +0100, Alexander Lobakin wrote: > > Use the newly introduces macros to create unique separate sections > > for (almost) every "regular" ASM function (i.e. for those which > > aren't explicitly put into a specific one). > > There should be no leftovers as input .text will be size-asserted > > in the LD script generated for FG-KASLR. > > *groan*... > > Please, can't we do something like: > > #define SYM_PUSH_SECTION(name) \ > .if section == .text \ > .push_section .text.##name \ > .else \ > .push_section .text \ > .endif > > #define SYM_POP_SECTION() \ > .pop_section > > and wrap that inside the existing SYM_FUNC_START*() SYM_FUNC_END() > macros. Ah I see. I asked about this in my previous mail and you replied already (: Cool stuff, I'll use it, it simplifies things a lot. Thanks! Al
From: Peter Zijlstra <peterz@infradead.org> Date: Fri, 3 Dec 2021 11:38:30 +0100 > On Thu, Dec 02, 2021 at 11:32:00PM +0100, Alexander Lobakin wrote: > > > feat make -j65 boot vmlinux.o vmlinux bzImage bogoops/s > > Relocatable 4m38.478s 24.440s 72014208 58579520 9396192 57640.39 > > KASLR 4m39.344s 24.204s 72020624 87805776 9740352 57393.80 > > FG-K 16 fps 6m16.493s 25.429s 83759856 87194160 10885632 57784.76 > > FG-K 8 fps 6m20.190s 25.094s 83759856 88741328 10985248 56625.84 > > FG-K 1 fps 7m09.611s 25.922s 83759856 95681128 11352192 56953.99 > > :sadface: so at best it makes my kernel compiles ~50% slower. Who would > ever consider doing that? It's like retpolines weren't bad enough; lets > heap on the fail? I was waiting for that :D I know it's horrible for now, but there are some points to consider: - folks who are placing hardening over everything don't mind compile times most likely; - linkers choking on huge LD scripts is actually a bug in their code. They process 40k sections as orphans (without a generated LD script) for a split second, so they're likely able to do the same with it. Our position here is that after FG-KASLR landing we'll report it and probably look into linkers' code to see if that can be addressed (Kees et al are on this AFAIU); - ClangLTO (at least "Fat", not sure about Thin as I didn't used it) thinks on vmlinux.o for ~5 minutes on 8-core Skylake. Still, it is here in mainline and is widely (relatively) used. I know FG-KASLR stuff is way more exotic, but anyways. - And the last one: I wouldn't consider FG-KASLR production ready as Kees would like to see it. Apart from compilation time, you get random performance {in,de}creases here-and-there all over the kernel and modules you can't predict at all. I guess it would become better later on when/if we introduce profiling-based function placement (there are some discussions around that and one related article is referred in the orig cover letter), but dunno for now. There's one issue in the current code as well -- PTI switching code is in .entry.text which doesn't currently get randomized. So it can probably be hunted using gadget collectors I guess? Ok, so here's a summary of TODOs (not including sadfaces unfortunately): * generate vmlinux.symbols and the corresponding variables on-the-go; * unify comparison and adjustment functions, probably reuse some of the already existing ones; * don't introduce new macros in linkage.h, just use fancy 'section == .text' to decide in-place; * change new macros' names (those which shouldn' be wiped out) to make them more consistent; * look over for several code dups. Am I missing anything else? One more quest, what could I do with this infinitely long regexp in gen_text_sections.pl script? Just try to wrap over or it can be simplified somehow? Al
On Fri, Dec 03, 2021 at 03:41:36PM +0100, Alexander Lobakin wrote: > From: Peter Zijlstra <peterz@infradead.org> > Date: Fri, 3 Dec 2021 11:38:30 +0100 > > > On Thu, Dec 02, 2021 at 11:32:00PM +0100, Alexander Lobakin wrote: > > > > > feat make -j65 boot vmlinux.o vmlinux bzImage bogoops/s > > > Relocatable 4m38.478s 24.440s 72014208 58579520 9396192 57640.39 > > > KASLR 4m39.344s 24.204s 72020624 87805776 9740352 57393.80 > > > FG-K 16 fps 6m16.493s 25.429s 83759856 87194160 10885632 57784.76 > > > FG-K 8 fps 6m20.190s 25.094s 83759856 88741328 10985248 56625.84 > > > FG-K 1 fps 7m09.611s 25.922s 83759856 95681128 11352192 56953.99 > > > > :sadface: so at best it makes my kernel compiles ~50% slower. Who would > > ever consider doing that? It's like retpolines weren't bad enough; lets > > heap on the fail? > > I was waiting for that :D > > I know it's horrible for now, but there are some points to consider: > - folks who are placing hardening over everything don't mind > compile times most likely; > - linkers choking on huge LD scripts is actually a bug in their > code. They process 40k sections as orphans (without a generated > LD script) for a split second, so they're likely able to do the > same with it. Our position here is that after FG-KASLR landing > we'll report it and probably look into linkers' code to see if > that can be addressed (Kees et al are on this AFAIU); > - ClangLTO (at least "Fat", not sure about Thin as I didn't used > it) thinks on vmlinux.o for ~5 minutes on 8-core Skylake. Still, > it is here in mainline and is widely (relatively) used. > I know FG-KASLR stuff is way more exotic, but anyways. > - And the last one: I wouldn't consider FG-KASLR production ready > as Kees would like to see it. Apart from compilation time, you > get random performance {in,de}creases here-and-there all over > the kernel and modules you can't predict at all. > I guess it would become better later on when/if we introduce > profiling-based function placement (there are some discussions > around that and one related article is referred in the orig > cover letter), but dunno for now. > There's one issue in the current code as well -- PTI switching > code is in .entry.text which doesn't currently get randomized. > So it can probably be hunted using gadget collectors I guess? Oooh, so those compile times are not, as one would expect the compile times for a set .config but with different kernel, but instead for a varying .config on the same kernel? IOW, they don't represent the run-time overhead of this thing, but merely the toolchain overhead of all this. So what is the actual runtime overhead of all this?
On Fri, Dec 03, 2021 at 03:10:51PM +0100, Alexander Lobakin wrote: > From: Peter Zijlstra <peterz@infradead.org> > Date: Fri, 3 Dec 2021 10:44:10 +0100 > > > On Thu, Dec 02, 2021 at 11:32:05PM +0100, Alexander Lobakin wrote: > > > Use the newly introduces macros to create unique separate sections > > > for (almost) every "regular" ASM function (i.e. for those which > > > aren't explicitly put into a specific one). > > > There should be no leftovers as input .text will be size-asserted > > > in the LD script generated for FG-KASLR. > > > > *groan*... > > > > Please, can't we do something like: > > > > #define SYM_PUSH_SECTION(name) \ > > .if section == .text \ > > .push_section .text.##name \ > > .else \ > > .push_section .text \ > > .endif > > > > #define SYM_POP_SECTION() \ > > .pop_section > > > > and wrap that inside the existing SYM_FUNC_START*() SYM_FUNC_END() > > macros. > > Ah I see. I asked about this in my previous mail and you replied > already (: Cool stuff, I'll use it, it simplifies things a lot. Note, I've no idea if it works. GAS and me aren't really on speaking terms. It would be my luck for that to be totally impossible, hjl?
On Fri, Dec 3, 2021 at 8:34 AM Peter Zijlstra <peterz@infradead.org> wrote: > > On Fri, Dec 03, 2021 at 03:10:51PM +0100, Alexander Lobakin wrote: > > From: Peter Zijlstra <peterz@infradead.org> > > Date: Fri, 3 Dec 2021 10:44:10 +0100 > > > > > On Thu, Dec 02, 2021 at 11:32:05PM +0100, Alexander Lobakin wrote: > > > > Use the newly introduces macros to create unique separate sections > > > > for (almost) every "regular" ASM function (i.e. for those which > > > > aren't explicitly put into a specific one). > > > > There should be no leftovers as input .text will be size-asserted > > > > in the LD script generated for FG-KASLR. > > > > > > *groan*... > > > > > > Please, can't we do something like: > > > > > > #define SYM_PUSH_SECTION(name) \ > > > .if section == .text \ > > > .push_section .text.##name \ > > > .else \ > > > .push_section .text \ > > > .endif > > > > > > #define SYM_POP_SECTION() \ > > > .pop_section > > > > > > and wrap that inside the existing SYM_FUNC_START*() SYM_FUNC_END() > > > macros. > > > > Ah I see. I asked about this in my previous mail and you replied > > already (: Cool stuff, I'll use it, it simplifies things a lot. > > Note, I've no idea if it works. GAS and me aren't really on speaking > terms. It would be my luck for that to be totally impossible, hjl? What exactly do you want assembler to do?
On Fri, 3 Dec 2021, Peter Zijlstra wrote: > On Fri, Dec 03, 2021 at 03:10:51PM +0100, Alexander Lobakin wrote: > > From: Peter Zijlstra <peterz@infradead.org> > > Date: Fri, 3 Dec 2021 10:44:10 +0100 > > > > > On Thu, Dec 02, 2021 at 11:32:05PM +0100, Alexander Lobakin wrote: > > > > Use the newly introduces macros to create unique separate sections > > > > for (almost) every "regular" ASM function (i.e. for those which > > > > aren't explicitly put into a specific one). > > > > There should be no leftovers as input .text will be size-asserted > > > > in the LD script generated for FG-KASLR. > > > > > > *groan*... > > > > > > Please, can't we do something like: > > > > > > #define SYM_PUSH_SECTION(name) \ > > > .if section == .text \ > > > .push_section .text.##name \ > > > .else \ > > > .push_section .text \ > > > .endif > > > > > > #define SYM_POP_SECTION() \ > > > .pop_section > > > > > > and wrap that inside the existing SYM_FUNC_START*() SYM_FUNC_END() > > > macros. > > > > Ah I see. I asked about this in my previous mail and you replied > > already (: Cool stuff, I'll use it, it simplifies things a lot. > > Note, I've no idea if it works. GAS and me aren't really on speaking > terms. It would be my luck for that to be totally impossible, hjl? Surely this would do it: http://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=451133cefa839104 Nicolas
On Fri, 3 Dec 2021 at 20:46, Nicolas Pitre <nico@fluxnic.net> wrote: > > On Fri, 3 Dec 2021, Peter Zijlstra wrote: > > > On Fri, Dec 03, 2021 at 03:10:51PM +0100, Alexander Lobakin wrote: > > > From: Peter Zijlstra <peterz@infradead.org> > > > Date: Fri, 3 Dec 2021 10:44:10 +0100 > > > > > > > On Thu, Dec 02, 2021 at 11:32:05PM +0100, Alexander Lobakin wrote: > > > > > Use the newly introduces macros to create unique separate sections > > > > > for (almost) every "regular" ASM function (i.e. for those which > > > > > aren't explicitly put into a specific one). > > > > > There should be no leftovers as input .text will be size-asserted > > > > > in the LD script generated for FG-KASLR. > > > > > > > > *groan*... > > > > > > > > Please, can't we do something like: > > > > > > > > #define SYM_PUSH_SECTION(name) \ > > > > .if section == .text \ > > > > .push_section .text.##name \ > > > > .else \ > > > > .push_section .text \ > > > > .endif > > > > > > > > #define SYM_POP_SECTION() \ > > > > .pop_section > > > > > > > > and wrap that inside the existing SYM_FUNC_START*() SYM_FUNC_END() > > > > macros. > > > > > > Ah I see. I asked about this in my previous mail and you replied > > > already (: Cool stuff, I'll use it, it simplifies things a lot. > > > > Note, I've no idea if it works. GAS and me aren't really on speaking > > terms. It would be my luck for that to be totally impossible, hjl? > > Surely this would do it: > > http://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=451133cefa839104 > That seems rather useful, actually. It will also fix a problem with subsections, which are sometimes difficult to construct from a macro, as they cannot be created using pushsection/popsection unless you know the current section name, and the alternative syntax (.subsection / .previous) does not permit nesting. This makes their use from a macro risky, given that it may not be obvious to the macro's caller that it uses a subsection under the hood.
On Fri, Dec 03, 2021 at 02:46:39PM -0500, Nicolas Pitre wrote: > Surely this would do it: > > http://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=451133cefa839104 Ooh, yes, excellent that, thanks!
From: Peter Zijlstra <peterz@infradead.org> Date: Fri, 3 Dec 2021 10:44:10 +0100 > On Thu, Dec 02, 2021 at 11:32:05PM +0100, Alexander Lobakin wrote: > > Use the newly introduces macros to create unique separate sections > > for (almost) every "regular" ASM function (i.e. for those which > > aren't explicitly put into a specific one). > > There should be no leftovers as input .text will be size-asserted > > in the LD script generated for FG-KASLR. > > *groan*... > > Please, can't we do something like: > > #define SYM_PUSH_SECTION(name) \ > .if section == .text \ > .push_section .text.##name \ > .else \ > .push_section .text \ > .endif This condition .pushsection .text .if section == .text # do something .endif .popsection doesn't really works. `do something` doesn't happen. This works only when .pushsection .text .equ section, .text but it's not really okayish I'd say to find all .{,push}section occurences and replace them with a macro (which would also do .equ). I don't really know how %S with --sectname-subst should help me as .if %S == .text # do something .endif doesn't work at all (syntax error) -- and it shouldn't, %S is supposed to work only inside .{,push}section directives. I could do unconditional .pushsection %S.##name ^^^^^^ function name but this would involve changing LDS scripts (and vmlinux.lds.h) to let's say replace *(.noinstr.text) with *(.noinstr.text*). So I hope there is a way to get current section name? If not, then the last option is the least harmful I suppose. At least not as harmful as current approach with alternative macros, far from it lol. > > #define SYM_POP_SECTION() \ > .pop_section > > and wrap that inside the existing SYM_FUNC_START*() SYM_FUNC_END() > macros. Thanks, Al
On Fri, 10 Dec 2021, Alexander Lobakin wrote: > I could do unconditional > > .pushsection %S.##name > ^^^^^^ function name > > but this would involve changing LDS scripts (and vmlinux.lds.h) to > let's say replace *(.noinstr.text) with *(.noinstr.text*). Yes, this is meant to be used with a linker script that expects the new name. Nicolas