Re: [PATCH v8 05/14] x86: conditionally place regular ASM functions into separate sections

9 messages, 5 authors, 2021-12-10 · open the first message on its own page

Re: [PATCH v8 05/14] x86: conditionally place regular ASM functions into separate sections

From: Peter Zijlstra <peterz@infradead.org>
Date: 2021-12-03 09:44:39

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.

Re: [PATCH v8 05/14] x86: conditionally place regular ASM functions into separate sections

From: Alexander Lobakin <hidden>
Date: 2021-12-03 14:11:30

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:
quoted
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

Re: [PATCH v8 05/14] x86: conditionally place regular ASM functions into separate sections

From: Peter Zijlstra <peterz@infradead.org>
Date: 2021-12-03 16:34:52

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
quoted
On Thu, Dec 02, 2021 at 11:32:05PM +0100, Alexander Lobakin wrote:
quoted
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?

Re: [PATCH v8 05/14] x86: conditionally place regular ASM functions into separate sections

From: H.J. Lu <hidden>
Date: 2021-12-03 16:51:54

On Fri, Dec 3, 2021 at 8:34 AM Peter Zijlstra [off-list ref] wrote:
On Fri, Dec 03, 2021 at 03:10:51PM +0100, Alexander Lobakin wrote:
quoted
From: Peter Zijlstra <peterz@infradead.org>
Date: Fri, 3 Dec 2021 10:44:10 +0100
quoted
On Thu, Dec 02, 2021 at 11:32:05PM +0100, Alexander Lobakin wrote:
quoted
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?

-- 
H.J.

Re: [PATCH v8 05/14] x86: conditionally place regular ASM functions into separate sections

From: Nicolas Pitre <nico@fluxnic.net>
Date: 2021-12-03 19:57:53

On Fri, 3 Dec 2021, Peter Zijlstra wrote:
On Fri, Dec 03, 2021 at 03:10:51PM +0100, Alexander Lobakin wrote:
quoted
From: Peter Zijlstra <peterz@infradead.org>
Date: Fri, 3 Dec 2021 10:44:10 +0100
quoted
On Thu, Dec 02, 2021 at 11:32:05PM +0100, Alexander Lobakin wrote:
quoted
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

Re: [PATCH v8 05/14] x86: conditionally place regular ASM functions into separate sections

From: Ard Biesheuvel <ardb@kernel.org>
Date: 2021-12-04 08:31:53

On Fri, 3 Dec 2021 at 20:46, Nicolas Pitre [off-list ref] wrote:
On Fri, 3 Dec 2021, Peter Zijlstra wrote:
quoted
On Fri, Dec 03, 2021 at 03:10:51PM +0100, Alexander Lobakin wrote:
quoted
From: Peter Zijlstra <peterz@infradead.org>
Date: Fri, 3 Dec 2021 10:44:10 +0100
quoted
On Thu, Dec 02, 2021 at 11:32:05PM +0100, Alexander Lobakin wrote:
quoted
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.

Re: [PATCH v8 05/14] x86: conditionally place regular ASM functions into separate sections

From: Peter Zijlstra <peterz@infradead.org>
Date: 2021-12-04 08:55:51

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!

Re: [PATCH v8 05/14] x86: conditionally place regular ASM functions into separate sections

From: Alexander Lobakin <hidden>
Date: 2021-12-10 11:01:46

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:
quoted
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

Re: [PATCH v8 05/14] x86: conditionally place regular ASM functions into separate sections

From: Nicolas Pitre <nico@fluxnic.net>
Date: 2021-12-10 13:20:58

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help