Skip to contentSkip to conversation

lkdtm: fix memory copy size for WRITE_KERN

PATCH Superseded Candle Sun 3 participants 9 messages Jan 25, 2021 – Jan 27, 2021

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Candle Sun

author
#0 lore raw

PATCH 1/1 lkdtm: fix memory copy size for WRITE_KERN

From: Candle Sun <[email protected]>

Though do_overwritten() follows do_nothing() in source code, the final memory address order is determined by compiler. We can't always assume address of do_overwritten() is bigger than do_nothing(). At least the Clang we are using places do_overwritten() before do_nothing() in the object. This causes the copy size in lkdtm_WRITE_KERN() is *really* big and WRITE_KERN test on ARM32 arch will fail.

Compare the address order before doing the subtraction.

---
 drivers/misc/lkdtm/perms.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/misc/lkdtm/perms.c +9 -10
index 2dede2ef658f..fbfbdf89d668 100644
@@ -31,13 +31,13 @@ static unsigned long ro_after_init __ro_after_init = 0x55AA5500;
  * This just returns to the caller. It is designed to be copied into
  * non-executable memory regions.
  */
-static void do_nothing(void)
+static noinline void do_nothing(void)
 {
 	return;
 }
 
 /* Must immediately follow do_nothing for size calculuations to work out. */
-static void do_overwritten(void)
+static noinline void do_overwritten(void)
 {
 	pr_info("do_overwritten wasn't overwritten!\n");
 	return;
@@ -110,15 +110,14 @@ void lkdtm_WRITE_RO_AFTER_INIT(void)
 
 void lkdtm_WRITE_KERN(void)
 {
-	size_t size;
-	volatile unsigned char *ptr;
+	unsigned long value_dow = (unsigned long)do_overwritten;
+	unsigned long value_do =  (unsigned long)do_nothing;
+	size_t size = (size_t)(value_dow > value_do ?
+			value_dow - value_do : value_do - value_dow);
 
-	size = (unsigned long)do_overwritten - (unsigned long)do_nothing;
-	ptr = (unsigned char *)do_overwritten;
-
-	pr_info("attempting bad %zu byte write at %px\n", size, ptr);
-	memcpy((void *)ptr, (unsigned char *)do_nothing, size);
-	flush_icache_range((unsigned long)ptr, (unsigned long)(ptr + size));
+	pr_info("attempting bad %zu byte write at %px\n", size, do_overwritten);
+	memcpy((void *)value_dow, (void *)value_do, size);
+	flush_icache_range(value_dow, value_dow + (unsigned long)size);
 	pr_err("FAIL: survived bad write\n");
 
 	do_overwritten();
Signature · 1 line
2.17.0
#1 lore raw

From: Candle Sun

Quoted 4 lines

Sent: 25 January 2021 08:56

From: Candle Sun <[email protected]>

Quoted 8 lines

Though do_overwritten() follows do_nothing() in source code, the final memory address order is determined by compiler. We can't always assume address of do_overwritten() is bigger than do_nothing(). At least the Clang we are using places do_overwritten() before do_nothing() in the object. This causes the copy size in lkdtm_WRITE_KERN() is *really* big and WRITE_KERN test on ARM32 arch will fail.

Compare the address order before doing the subtraction.

It isn't clear that helps.
Compile with -ffunction-sections and/or do LTO an there is no reason at all why the functions should be together.

Even without that lkdtm_WRITE_KERN() could easily be between them.

You need to get the size of the 'empty function' from the symbol table.

David

Quoted 50 lines
---
 drivers/misc/lkdtm/perms.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/misc/lkdtm/perms.c +9 -11
index 2dede2ef658f..fbfbdf89d668 100644
@@ -31,13 +31,13 @@ static unsigned long ro_after_init __ro_after_init = 0x55AA5500;
  * This just returns to the caller. It is designed to be copied into
  * non-executable memory regions.
  */
-static void do_nothing(void)
+static noinline void do_nothing(void)
 {
 	return;
 }
 
 /* Must immediately follow do_nothing for size calculuations to work out. */
-static void do_overwritten(void)
+static noinline void do_overwritten(void)
 {
 	pr_info("do_overwritten wasn't overwritten!\n");
 	return;
@@ -110,15 +110,14 @@ void lkdtm_WRITE_RO_AFTER_INIT(void)
 
 void lkdtm_WRITE_KERN(void)
 {
-	size_t size;
-	volatile unsigned char *ptr;
+	unsigned long value_dow = (unsigned long)do_overwritten;
+	unsigned long value_do =  (unsigned long)do_nothing;
+	size_t size = (size_t)(value_dow > value_do ?
+			value_dow - value_do : value_do - value_dow);
 
-	size = (unsigned long)do_overwritten - (unsigned long)do_nothing;
-	ptr = (unsigned char *)do_overwritten;
-
-	pr_info("attempting bad %zu byte write at %px\n", size, ptr);
-	memcpy((void *)ptr, (unsigned char *)do_nothing, size);
-	flush_icache_range((unsigned long)ptr, (unsigned long)(ptr + size));
+	pr_info("attempting bad %zu byte write at %px\n", size, do_overwritten);
+	memcpy((void *)value_dow, (void *)value_do, size);
+	flush_icache_range(value_dow, value_dow + (unsigned long)size);
 	pr_err("FAIL: survived bad write\n");
 
 	do_overwritten();
--
Quoted 1 line

2.17.0

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#7 lore raw
In reply to Candle Sun
Quoted 39 lines · Candle Sun

From: Candle Sun <[email protected]>

Though do_overwritten() follows do_nothing() in source code, the final memory address order is determined by compiler. We can't always assume address of do_overwritten() is bigger than do_nothing(). At least the Clang we are using places do_overwritten() before do_nothing() in the object. This causes the copy size in lkdtm_WRITE_KERN() is *really* big and WRITE_KERN test on ARM32 arch will fail.

Compare the address order before doing the subtraction.

---
 drivers/misc/lkdtm/perms.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/misc/lkdtm/perms.c +2 -2
index 2dede2ef658f..fbfbdf89d668 100644
@@ -31,13 +31,13 @@ static unsigned long ro_after_init __ro_after_init = 0x55AA5500;
  * This just returns to the caller. It is designed to be copied into
  * non-executable memory regions.
  */
-static void do_nothing(void)
+static noinline void do_nothing(void)
 {
        return;
 }
 
 /* Must immediately follow do_nothing for size calculuations to work out. */
-static void do_overwritten(void)
+static noinline void do_overwritten(void)
 {
        pr_info("do_overwritten wasn't overwritten!\n");
        return;
@@ -110,15 +110,14 @@ void lkdtm_WRITE_RO_AFTER_INIT(void)
 

drivers/misc/lkdtm/perms.c void lkdtm_WRITE_RO_AFTER_INIT(void) · line 116

Quoted 10 lines
drivers/misc/lkdtm/perms.c +4 -3
 void lkdtm_WRITE_KERN(void)
 {
-       size_t size;
-       volatile unsigned char *ptr;
+       unsigned long value_dow = (unsigned long)do_overwritten;
+       unsigned long value_do =  (unsigned long)do_nothing;
+       size_t size = (size_t)(value_dow > value_do ?
+                       value_dow - value_do : value_do - value_dow);
 
-       size = (unsigned long)do_overwritten - (unsigned long)do_nothing;

Thanks for the patch! Might it be simpler to do:

size = abs((uintptr_t)do_overwritten - (uintptr_t)do_nothing));

Then I don't think much of this function needs to be changed.

Quoted 14 lines
drivers/misc/lkdtm/perms.c +3 -6
-       ptr = (unsigned char *)do_overwritten;
-
-       pr_info("attempting bad %zu byte write at %px\n", size, ptr);
-       memcpy((void *)ptr, (unsigned char *)do_nothing, size);
-       flush_icache_range((unsigned long)ptr, (unsigned long)(ptr + size));
+       pr_info("attempting bad %zu byte write at %px\n", size, do_overwritten);
+       memcpy((void *)value_dow, (void *)value_do, size);
+       flush_icache_range(value_dow, value_dow + (unsigned long)size);
        pr_err("FAIL: survived bad write\n");
 
        do_overwritten();
--

2.17.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
author
#2 lore raw
In reply to David Laight
Quoted 19 lines · David Laight

From: Candle Sun

Quoted 4 lines

Sent: 25 January 2021 08:56

From: Candle Sun <[email protected]>

Quoted 8 lines

Though do_overwritten() follows do_nothing() in source code, the final memory address order is determined by compiler. We can't always assume address of do_overwritten() is bigger than do_nothing(). At least the Clang we are using places do_overwritten() before do_nothing() in the object. This causes the copy size in lkdtm_WRITE_KERN() is *really* big and WRITE_KERN test on ARM32 arch will fail.

Compare the address order before doing the subtraction.

It isn't clear that helps.
Compile with -ffunction-sections and/or do LTO an there is no reason at all why the functions should be together.

Quoted 6 lines

Even without that lkdtm_WRITE_KERN() could easily be between them.

You need to get the size of the 'empty function' from the symbol table.

David

Thanks David.

I think using abs() by Nick's advice would be better. But could you point out which kernel function can get function size?

Regards,
Candle

Quoted 57 lines
Quoted 51 lines
---
 drivers/misc/lkdtm/perms.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/misc/lkdtm/perms.c +9 -11
index 2dede2ef658f..fbfbdf89d668 100644
@@ -31,13 +31,13 @@ static unsigned long ro_after_init __ro_after_init = 0x55AA5500;
  * This just returns to the caller. It is designed to be copied into
  * non-executable memory regions.
  */
-static void do_nothing(void)
+static noinline void do_nothing(void)
 {
      return;
 }
 
 /* Must immediately follow do_nothing for size calculuations to work out. */
-static void do_overwritten(void)
+static noinline void do_overwritten(void)
 {
      pr_info("do_overwritten wasn't overwritten!\n");
      return;
@@ -110,15 +110,14 @@ void lkdtm_WRITE_RO_AFTER_INIT(void)
 
 void lkdtm_WRITE_KERN(void)
 {
-     size_t size;
-     volatile unsigned char *ptr;
+     unsigned long value_dow = (unsigned long)do_overwritten;
+     unsigned long value_do =  (unsigned long)do_nothing;
+     size_t size = (size_t)(value_dow > value_do ?
+                     value_dow - value_do : value_do - value_dow);
 
-     size = (unsigned long)do_overwritten - (unsigned long)do_nothing;
-     ptr = (unsigned char *)do_overwritten;
-
-     pr_info("attempting bad %zu byte write at %px\n", size, ptr);
-     memcpy((void *)ptr, (unsigned char *)do_nothing, size);
-     flush_icache_range((unsigned long)ptr, (unsigned long)(ptr + size));
+     pr_info("attempting bad %zu byte write at %px\n", size, do_overwritten);
+     memcpy((void *)value_dow, (void *)value_do, size);
+     flush_icache_range(value_dow, value_dow + (unsigned long)size);
      pr_err("FAIL: survived bad write\n");
 
      do_overwritten();
--
Quoted 1 line

2.17.0

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

author
#8 lore raw
In reply to Nick Desaulniers
Quoted 50 lines · Nick Desaulniers
Quoted 48 lines · Candle Sun

From: Candle Sun <[email protected]>

Though do_overwritten() follows do_nothing() in source code, the final memory address order is determined by compiler. We can't always assume address of do_overwritten() is bigger than do_nothing(). At least the Clang we are using places do_overwritten() before do_nothing() in the object. This causes the copy size in lkdtm_WRITE_KERN() is *really* big and WRITE_KERN test on ARM32 arch will fail.

Compare the address order before doing the subtraction.

---
 drivers/misc/lkdtm/perms.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/misc/lkdtm/perms.c +6 -4
index 2dede2ef658f..fbfbdf89d668 100644
@@ -31,13 +31,13 @@ static unsigned long ro_after_init __ro_after_init = 0x55AA5500;
  * This just returns to the caller. It is designed to be copied into
  * non-executable memory regions.
  */
-static void do_nothing(void)
+static noinline void do_nothing(void)
 {
        return;
 }
 
 /* Must immediately follow do_nothing for size calculuations to work out. */
-static void do_overwritten(void)
+static noinline void do_overwritten(void)
 {
        pr_info("do_overwritten wasn't overwritten!\n");
        return;
@@ -110,15 +110,14 @@ void lkdtm_WRITE_RO_AFTER_INIT(void)
 
 void lkdtm_WRITE_KERN(void)
 {
-       size_t size;
-       volatile unsigned char *ptr;
+       unsigned long value_dow = (unsigned long)do_overwritten;
+       unsigned long value_do =  (unsigned long)do_nothing;
+       size_t size = (size_t)(value_dow > value_do ?
+                       value_dow - value_do : value_do - value_dow);
 
Quoted 8 lines

drivers/misc/lkdtm/perms.c void lkdtm_WRITE_RO_AFTER_INIT(void) · line 116

Quoted 1 line
drivers/misc/lkdtm/perms.c +0 -1
-       size = (unsigned long)do_overwritten - (unsigned long)do_nothing;

Thanks for the patch! Might it be simpler to do:

size = abs((uintptr_t)do_overwritten - (uintptr_t)do_nothing));

Then I don't think much of this function needs to be changed.

Thanks Nick.

abs() is better, I will check the patch.

Regards,
Candle

Quoted 19 lines
Quoted 12 lines
drivers/misc/lkdtm/perms.c +3 -6
-       ptr = (unsigned char *)do_overwritten;
-
-       pr_info("attempting bad %zu byte write at %px\n", size, ptr);
-       memcpy((void *)ptr, (unsigned char *)do_nothing, size);
-       flush_icache_range((unsigned long)ptr, (unsigned long)(ptr + size));
+       pr_info("attempting bad %zu byte write at %px\n", size, do_overwritten);
+       memcpy((void *)value_dow, (void *)value_do, size);
+       flush_icache_range(value_dow, value_dow + (unsigned long)size);
        pr_err("FAIL: survived bad write\n");
 
        do_overwritten();
--
Quoted 2 lines

2.17.0

--
Thanks,
~Nick Desaulniers

#3 lore raw
In reply to Candle Sun
Quoted 26 lines · Candle Sun
Quoted 24 lines · David Laight

From: Candle Sun

Quoted 4 lines

Sent: 25 January 2021 08:56

From: Candle Sun <[email protected]>

Quoted 8 lines

Though do_overwritten() follows do_nothing() in source code, the final memory address order is determined by compiler. We can't always assume address of do_overwritten() is bigger than do_nothing(). At least the Clang we are using places do_overwritten() before do_nothing() in the object. This causes the copy size in lkdtm_WRITE_KERN() is *really* big and WRITE_KERN test on ARM32 arch will fail.

Compare the address order before doing the subtraction.

It isn't clear that helps.
Compile with -ffunction-sections and/or do LTO an there is no reason at all why the functions should be together.

Even without that lkdtm_WRITE_KERN() could easily be between them.

You need to get the size of the 'empty function' from the symbol table.

Quoted 6 lines
Quoted 1 line

David

Thanks David.

I think using abs() by Nick's advice would be better. But could you point out which kernel function can get function size?

The Elf symbol table should contain this info, IIUC.

Given a string literal of a symbol (such as a function identifier), kallsyms_lookup_name() can be used to return its address.

From there we'd want to fetch the Elf_Sym for the address which should contain a st_size field which I think corresponds to the size in bytes of the function. (At least, from playing with llvm-readelf -s) Probably would want to validate it's an STT_FUNC symbol type, too. We basically want something like kexec_purgatory_find_symbol(), but that knows about the entire kernel image, and not the purgatory image used during kexec. I don't see any such function currently in the kernel...but it's a large codebase to search through.

Quoted 62 lines

Regards,
Candle

Quoted 57 lines
Quoted 51 lines
---
 drivers/misc/lkdtm/perms.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/misc/lkdtm/perms.c +9 -11
index 2dede2ef658f..fbfbdf89d668 100644
@@ -31,13 +31,13 @@ static unsigned long ro_after_init __ro_after_init = 0x55AA5500;
  * This just returns to the caller. It is designed to be copied into
  * non-executable memory regions.
  */
-static void do_nothing(void)
+static noinline void do_nothing(void)
 {
      return;
 }
 
 /* Must immediately follow do_nothing for size calculuations to work out. */
-static void do_overwritten(void)
+static noinline void do_overwritten(void)
 {
      pr_info("do_overwritten wasn't overwritten!\n");
      return;
@@ -110,15 +110,14 @@ void lkdtm_WRITE_RO_AFTER_INIT(void)
 
 void lkdtm_WRITE_KERN(void)
 {
-     size_t size;
-     volatile unsigned char *ptr;
+     unsigned long value_dow = (unsigned long)do_overwritten;
+     unsigned long value_do =  (unsigned long)do_nothing;
+     size_t size = (size_t)(value_dow > value_do ?
+                     value_dow - value_do : value_do - value_dow);
 
-     size = (unsigned long)do_overwritten - (unsigned long)do_nothing;
-     ptr = (unsigned char *)do_overwritten;
-
-     pr_info("attempting bad %zu byte write at %px\n", size, ptr);
-     memcpy((void *)ptr, (unsigned char *)do_nothing, size);
-     flush_icache_range((unsigned long)ptr, (unsigned long)(ptr + size));
+     pr_info("attempting bad %zu byte write at %px\n", size, do_overwritten);
+     memcpy((void *)value_dow, (void *)value_do, size);
+     flush_icache_range(value_dow, value_dow + (unsigned long)size);
      pr_err("FAIL: survived bad write\n");
 
      do_overwritten();
--
Quoted 1 line

2.17.0

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

Signature · 2 lines
Thanks,
~Nick Desaulniers
author
#5 lore raw
In reply to David Laight

Thanks David and Nick.

For simpleness. I just use abs() to get the copy size.

Patch version 2 is mailed. Please help review it.

Regards,
Candle

Quoted 65 lines · David Laight

From: Nick Desaulniers

Quoted 41 lines

Sent: 26 January 2021 18:40

Quoted 26 lines · Candle Sun
Quoted 24 lines · David Laight

From: Candle Sun

Quoted 4 lines

Sent: 25 January 2021 08:56

From: Candle Sun <[email protected]>

Quoted 8 lines

Though do_overwritten() follows do_nothing() in source code, the final memory address order is determined by compiler. We can't always assume address of do_overwritten() is bigger than do_nothing(). At least the Clang we are using places do_overwritten() before do_nothing() in the object. This causes the copy size in lkdtm_WRITE_KERN() is *really* big and WRITE_KERN test on ARM32 arch will fail.

Compare the address order before doing the subtraction.

It isn't clear that helps.
Compile with -ffunction-sections and/or do LTO an there is no reason at all why the functions should be together.

Even without that lkdtm_WRITE_KERN() could easily be between them.

You need to get the size of the 'empty function' from the symbol table.

Quoted 6 lines
Quoted 1 line

David

Thanks David.

I think using abs() by Nick's advice would be better. But could you point out which kernel function can get function size?

The Elf symbol table should contain this info, IIUC.

Given a string literal of a symbol (such as a function identifier), kallsyms_lookup_name() can be used to return its address.

Quoted 8 lines

From there we'd want to fetch the Elf_Sym for the address which should contain a st_size field which I think corresponds to the size in bytes of the function. (At least, from playing with llvm-readelf -s) Probably would want to validate it's an STT_FUNC symbol type, too. We basically want something like kexec_purgatory_find_symbol(), but that knows about the entire kernel image, and not the purgatory image used during kexec. I don't see any such function currently in the kernel...but it's a large codebase to search through.

The alternative is to get the linker script to define a specific constant to the size of the function.
You can then link against it (by using it as the address of a symbol).

It may be easier to use an asm file for the 'return 0' code. I'm guessing there are things in the static branch area that could be used.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#4 lore raw
In reply to Nick Desaulniers

From: Nick Desaulniers

Quoted 41 lines

Sent: 26 January 2021 18:40

Quoted 26 lines · Candle Sun
Quoted 24 lines · David Laight

From: Candle Sun

Quoted 4 lines

Sent: 25 January 2021 08:56

From: Candle Sun <[email protected]>

Quoted 8 lines

Though do_overwritten() follows do_nothing() in source code, the final memory address order is determined by compiler. We can't always assume address of do_overwritten() is bigger than do_nothing(). At least the Clang we are using places do_overwritten() before do_nothing() in the object. This causes the copy size in lkdtm_WRITE_KERN() is *really* big and WRITE_KERN test on ARM32 arch will fail.

Compare the address order before doing the subtraction.

It isn't clear that helps.
Compile with -ffunction-sections and/or do LTO an there is no reason at all why the functions should be together.

Even without that lkdtm_WRITE_KERN() could easily be between them.

You need to get the size of the 'empty function' from the symbol table.

Quoted 6 lines
Quoted 1 line

David

Thanks David.

I think using abs() by Nick's advice would be better. But could you point out which kernel function can get function size?

The Elf symbol table should contain this info, IIUC.

Given a string literal of a symbol (such as a function identifier), kallsyms_lookup_name() can be used to return its address.

Quoted 8 lines

From there we'd want to fetch the Elf_Sym for the address which should contain a st_size field which I think corresponds to the size in bytes of the function. (At least, from playing with llvm-readelf -s) Probably would want to validate it's an STT_FUNC symbol type, too. We basically want something like kexec_purgatory_find_symbol(), but that knows about the entire kernel image, and not the purgatory image used during kexec. I don't see any such function currently in the kernel...but it's a large codebase to search through.

The alternative is to get the linker script to define a specific constant to the size of the function.
You can then link against it (by using it as the address of a symbol).

It may be easier to use an asm file for the 'return 0' code. I'm guessing there are things in the static branch area that could be used.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#6 lore raw
Quoted 52 lines · David Laight

From: Nick Desaulniers

Quoted 41 lines

Sent: 26 January 2021 18:40

Quoted 26 lines · Candle Sun
Quoted 24 lines · David Laight

From: Candle Sun

Quoted 4 lines

Sent: 25 January 2021 08:56

From: Candle Sun <[email protected]>

Quoted 8 lines

Though do_overwritten() follows do_nothing() in source code, the final memory address order is determined by compiler. We can't always assume address of do_overwritten() is bigger than do_nothing(). At least the Clang we are using places do_overwritten() before do_nothing() in the object. This causes the copy size in lkdtm_WRITE_KERN() is *really* big and WRITE_KERN test on ARM32 arch will fail.

Compare the address order before doing the subtraction.

It isn't clear that helps.
Compile with -ffunction-sections and/or do LTO an there is no reason at all why the functions should be together.

Even without that lkdtm_WRITE_KERN() could easily be between them.

You need to get the size of the 'empty function' from the symbol table.

Quoted 6 lines
Quoted 1 line

David

Thanks David.

I think using abs() by Nick's advice would be better. But could you point out which kernel function can get function size?

The Elf symbol table should contain this info, IIUC.

Given a string literal of a symbol (such as a function identifier), kallsyms_lookup_name() can be used to return its address.

Quoted 8 lines

From there we'd want to fetch the Elf_Sym for the address which should contain a st_size field which I think corresponds to the size in bytes of the function. (At least, from playing with llvm-readelf -s) Probably would want to validate it's an STT_FUNC symbol type, too. We basically want something like kexec_purgatory_find_symbol(), but that knows about the entire kernel image, and not the purgatory image used during kexec. I don't see any such function currently in the kernel...but it's a large codebase to search through.

Quoted 3 lines

The alternative is to get the linker script to define a specific constant to the size of the function.
You can then link against it (by using it as the address of a symbol).

Or use __attribute__((__section())) to place the code we need to measure in a custom section, then in the linker script define symbols that bound the section then place it in .text. That pattern is used throughout the kernel. But I suspect this is overkill for this module.

A constant would depend on the arch.

Quoted 10 lines

It may be easier to use an asm file for the 'return 0' code. I'm guessing there are things in the static branch area that could be used.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

Signature · 2 lines
Thanks,
~Nick Desaulniers