mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* scripts_gdb: Python Exception <class 'gdb.error'>: There is no member named nsections.
@ 2025-02-20 15:21 Antonio Quartulli
  2025-02-21  6:45 ` Jan Kiszka
  0 siblings, 1 reply; 7+ messages in thread
From: Antonio Quartulli @ 2025-02-20 15:21 UTC (permalink / raw)
  To: Jan Kiszka, Kieran Bingham; +Cc: open list

Hi,

I have been working on the new ovpn linux kernel module since a while 
and your gdb kernel debugging helper scripts have been of great help.

However, recently I have started hitting an issue I could not explain.
When my qemu instance loads the ovpn.ko module, I get the following 
output in gdb:

scanning for modules in /home/ordex/exp/openvpn_dev/linux-ovpn-dco
loading @0xffffffffa0000000: 
/home/ordex/exp/openvpn_dev/linux-ovpn-dco/drivers/net/ovpn/ovpn.ko
Python Exception <class 'gdb.error'>: There is no member named nsections.

and the load of the symbols fails.

Does it ring any bell?
Any help debugging further?

I am running the latest net-next.

Thanks a lot.
Best Regards,

-- 
Antonio Quartulli

CEO and Co-Founder
Mandelbit Srl
https://www.mandelbit.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: scripts_gdb: Python Exception <class 'gdb.error'>: There is no member named nsections.
  2025-02-20 15:21 scripts_gdb: Python Exception <class 'gdb.error'>: There is no member named nsections Antonio Quartulli
@ 2025-02-21  6:45 ` Jan Kiszka
  2025-02-21 13:03   ` [PATCH] scripts/gdb/linux/symbols.py: address changes to module_sect_attrs Antonio Quartulli
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Kiszka @ 2025-02-21  6:45 UTC (permalink / raw)
  To: Antonio Quartulli, Kieran Bingham; +Cc: open list, Thomas Weißschuh

On 20.02.25 16:21, Antonio Quartulli wrote:
> Hi,
> 
> I have been working on the new ovpn linux kernel module since a while
> and your gdb kernel debugging helper scripts have been of great help.
> 
> However, recently I have started hitting an issue I could not explain.
> When my qemu instance loads the ovpn.ko module, I get the following
> output in gdb:
> 
> scanning for modules in /home/ordex/exp/openvpn_dev/linux-ovpn-dco
> loading @0xffffffffa0000000: /home/ordex/exp/openvpn_dev/linux-ovpn-dco/
> drivers/net/ovpn/ovpn.ko
> Python Exception <class 'gdb.error'>: There is no member named nsections.
> 
> and the load of the symbols fails.
> 
> Does it ring any bell?
> Any help debugging further?
> 
> I am running the latest net-next.
> 

Thanks for reporting. That's because of [1] in upcoming 6.14. Someone
needs to update scripts/gdb/linux/symbols.py accordingly.

Jan

[1]
https://lore.kernel.org/r/linux-hardening/20241216-sysfs-const-bin_attr-module-v1-1-f81e49e54ce4@weissschuh.net/

-- 
Siemens AG, Foundational Technologies
Linux Expert Center

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] scripts/gdb/linux/symbols.py: address changes to module_sect_attrs
  2025-02-21  6:45 ` Jan Kiszka
@ 2025-02-21 13:03   ` Antonio Quartulli
  2025-02-21 16:52     ` Jan Kiszka
  0 siblings, 1 reply; 7+ messages in thread
From: Antonio Quartulli @ 2025-02-21 13:03 UTC (permalink / raw)
  To: jan.kiszka, kbingham
  Cc: linux-kernel, Antonio Quartulli, Thomas Weißschuh

When loading symbols from kernel modules we used to iterate
from 0 to module_sect_attrs::nsections, in order to
retrieve their name and address.

However module_sect_attrs::nsections has been removed from
the struct by a previous commit.

Re-arrange the iteration by accessing all items in
module_sect_attrs::grp::bin_attrs[] until NULL is found
(it's a NULL terminated array).

At the same time the symbol address cannot be extracted
from module_sect_attrs::attrs[]::address anymore because
it has also been deleted. Fetch it from
module_sect_attrs::grp::bin_attrs[]::private as described
in 4b2c11e4aaf7.

Fixes: d8959b947a8d ("module: sysfs: Drop member 'module_sect_attrs::nsections'")
Fixes: 4b2c11e4aaf7 ("module: sysfs: Drop member 'module_sect_attr::address'")
Cc: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
 scripts/gdb/linux/symbols.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
index f6c1b063775a..610a3dd3c7b4 100644
--- a/scripts/gdb/linux/symbols.py
+++ b/scripts/gdb/linux/symbols.py
@@ -15,6 +15,7 @@ import gdb
 import os
 import re
 
+from itertools import count
 from linux import modules, utils, constants
 
 
@@ -95,10 +96,14 @@ lx-symbols command."""
         except gdb.error:
             return str(module_addr)
 
-        attrs = sect_attrs['attrs']
-        section_name_to_address = {
-            attrs[n]['battr']['attr']['name'].string(): attrs[n]['address']
-            for n in range(int(sect_attrs['nsections']))}
+        section_name_to_address = {}
+        for i in count():
+            # this is a NULL terminated array
+            if sect_attrs['grp']['bin_attrs'][i] == 0x0:
+                break
+
+            attr = sect_attrs['grp']['bin_attrs'][i].dereference()
+            section_name_to_address[attr['attr']['name']] = attr['private']
 
         textaddr = section_name_to_address.get(".text", module_addr)
         args = []
-- 
2.45.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] scripts/gdb/linux/symbols.py: address changes to module_sect_attrs
  2025-02-21 13:03   ` [PATCH] scripts/gdb/linux/symbols.py: address changes to module_sect_attrs Antonio Quartulli
@ 2025-02-21 16:52     ` Jan Kiszka
  2025-02-21 20:33       ` Antonio Quartulli
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Kiszka @ 2025-02-21 16:52 UTC (permalink / raw)
  To: Antonio Quartulli, kbingham; +Cc: linux-kernel, Thomas Weißschuh

On 21.02.25 14:03, Antonio Quartulli wrote:
> When loading symbols from kernel modules we used to iterate
> from 0 to module_sect_attrs::nsections, in order to
> retrieve their name and address.
> 
> However module_sect_attrs::nsections has been removed from
> the struct by a previous commit.
> 
> Re-arrange the iteration by accessing all items in
> module_sect_attrs::grp::bin_attrs[] until NULL is found
> (it's a NULL terminated array).
> 
> At the same time the symbol address cannot be extracted
> from module_sect_attrs::attrs[]::address anymore because
> it has also been deleted. Fetch it from
> module_sect_attrs::grp::bin_attrs[]::private as described
> in 4b2c11e4aaf7.
> 
> Fixes: d8959b947a8d ("module: sysfs: Drop member 'module_sect_attrs::nsections'")
> Fixes: 4b2c11e4aaf7 ("module: sysfs: Drop member 'module_sect_attr::address'")
> Cc: Thomas Weißschuh <linux@weissschuh.net>
> Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
> ---
>  scripts/gdb/linux/symbols.py | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
> index f6c1b063775a..610a3dd3c7b4 100644
> --- a/scripts/gdb/linux/symbols.py
> +++ b/scripts/gdb/linux/symbols.py
> @@ -15,6 +15,7 @@ import gdb
>  import os
>  import re
>  
> +from itertools import count
>  from linux import modules, utils, constants
>  
>  
> @@ -95,10 +96,14 @@ lx-symbols command."""
>          except gdb.error:
>              return str(module_addr)
>  
> -        attrs = sect_attrs['attrs']
> -        section_name_to_address = {
> -            attrs[n]['battr']['attr']['name'].string(): attrs[n]['address']
> -            for n in range(int(sect_attrs['nsections']))}
> +        section_name_to_address = {}
> +        for i in count():
> +            # this is a NULL terminated array
> +            if sect_attrs['grp']['bin_attrs'][i] == 0x0:
> +                break
> +
> +            attr = sect_attrs['grp']['bin_attrs'][i].dereference()
> +            section_name_to_address[attr['attr']['name']] = attr['private']

You dropped that .string() from the name - I don't remember the details
anymore but we have it all around when picking up strings from C
structures. Was there a particular reason to do that?

>  
>          textaddr = section_name_to_address.get(".text", module_addr)
>          args = []

Thanks for picking up this task so quickly!

Jan

-- 
Siemens AG, Foundational Technologies
Linux Expert Center

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] scripts/gdb/linux/symbols.py: address changes to module_sect_attrs
  2025-02-21 16:52     ` Jan Kiszka
@ 2025-02-21 20:33       ` Antonio Quartulli
  2025-02-21 20:40         ` [PATCH v2] " Antonio Quartulli
  0 siblings, 1 reply; 7+ messages in thread
From: Antonio Quartulli @ 2025-02-21 20:33 UTC (permalink / raw)
  To: Jan Kiszka, kbingham; +Cc: linux-kernel, Thomas Weißschuh

On 21/02/2025 17:52, Jan Kiszka wrote:
> On 21.02.25 14:03, Antonio Quartulli wrote:
>> When loading symbols from kernel modules we used to iterate
>> from 0 to module_sect_attrs::nsections, in order to
>> retrieve their name and address.
>>
>> However module_sect_attrs::nsections has been removed from
>> the struct by a previous commit.
>>
>> Re-arrange the iteration by accessing all items in
>> module_sect_attrs::grp::bin_attrs[] until NULL is found
>> (it's a NULL terminated array).
>>
>> At the same time the symbol address cannot be extracted
>> from module_sect_attrs::attrs[]::address anymore because
>> it has also been deleted. Fetch it from
>> module_sect_attrs::grp::bin_attrs[]::private as described
>> in 4b2c11e4aaf7.
>>
>> Fixes: d8959b947a8d ("module: sysfs: Drop member 'module_sect_attrs::nsections'")
>> Fixes: 4b2c11e4aaf7 ("module: sysfs: Drop member 'module_sect_attr::address'")
>> Cc: Thomas Weißschuh <linux@weissschuh.net>
>> Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
>> ---
>>   scripts/gdb/linux/symbols.py | 13 +++++++++----
>>   1 file changed, 9 insertions(+), 4 deletions(-)
>>
>> diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
>> index f6c1b063775a..610a3dd3c7b4 100644
>> --- a/scripts/gdb/linux/symbols.py
>> +++ b/scripts/gdb/linux/symbols.py
>> @@ -15,6 +15,7 @@ import gdb
>>   import os
>>   import re
>>   
>> +from itertools import count
>>   from linux import modules, utils, constants
>>   
>>   
>> @@ -95,10 +96,14 @@ lx-symbols command."""
>>           except gdb.error:
>>               return str(module_addr)
>>   
>> -        attrs = sect_attrs['attrs']
>> -        section_name_to_address = {
>> -            attrs[n]['battr']['attr']['name'].string(): attrs[n]['address']
>> -            for n in range(int(sect_attrs['nsections']))}
>> +        section_name_to_address = {}
>> +        for i in count():
>> +            # this is a NULL terminated array
>> +            if sect_attrs['grp']['bin_attrs'][i] == 0x0:
>> +                break
>> +
>> +            attr = sect_attrs['grp']['bin_attrs'][i].dereference()
>> +            section_name_to_address[attr['attr']['name']] = attr['private']
> 
> You dropped that .string() from the name - I don't remember the details
> anymore but we have it all around when picking up strings from C
> structures. Was there a particular reason to do that?

Ouch. That was not intentional and my test did not explode, therefore I 
assumed the code was correct.

I presume it may explode if 'name' is changed into something not a 
string. In this case .string() would throw an exception and block the 
execution.

I will send v2 shortly with .string().

> 
>>   
>>           textaddr = section_name_to_address.get(".text", module_addr)
>>           args = []
> 
> Thanks for picking up this task so quickly!

Well, I needed gdb to break into ovpn.ko :-)

Cheers,

-- 
Antonio Quartulli

CEO and Co-Founder
Mandelbit Srl
https://www.mandelbit.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] scripts/gdb/linux/symbols.py: address changes to module_sect_attrs
  2025-02-21 20:33       ` Antonio Quartulli
@ 2025-02-21 20:40         ` Antonio Quartulli
  2025-02-26  5:31           ` Jan Kiszka
  0 siblings, 1 reply; 7+ messages in thread
From: Antonio Quartulli @ 2025-02-21 20:40 UTC (permalink / raw)
  To: jan.kiszka, kbingham
  Cc: linux-kernel, Antonio Quartulli, Thomas Weißschuh

When loading symbols from kernel modules we used to iterate
from 0 to module_sect_attrs::nsections, in order to
retrieve their name and address.

However module_sect_attrs::nsections has been removed from
the struct by a previous commit.

Re-arrange the iteration by accessing all items in
module_sect_attrs::grp::bin_attrs[] until NULL is found
(it's a NULL terminated array).

At the same time the symbol address cannot be extracted
from module_sect_attrs::attrs[]::address anymore because
it has also been deleted. Fetch it from
module_sect_attrs::grp::bin_attrs[]::private as described
in 4b2c11e4aaf7.

Fixes: d8959b947a8d ("module: sysfs: Drop member 'module_sect_attrs::nsections'")
Fixes: 4b2c11e4aaf7 ("module: sysfs: Drop member 'module_sect_attr::address'")
Cc: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---

Changes in v2:
* changed attr['attr']['name'] to attr['attr']['name'].string() to
  ensure extracted value is a string, otherwise an exception is thrown


 scripts/gdb/linux/symbols.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
index f6c1b063775a..15d76f7d8ebc 100644
--- a/scripts/gdb/linux/symbols.py
+++ b/scripts/gdb/linux/symbols.py
@@ -15,6 +15,7 @@ import gdb
 import os
 import re
 
+from itertools import count
 from linux import modules, utils, constants
 
 
@@ -95,10 +96,14 @@ lx-symbols command."""
         except gdb.error:
             return str(module_addr)
 
-        attrs = sect_attrs['attrs']
-        section_name_to_address = {
-            attrs[n]['battr']['attr']['name'].string(): attrs[n]['address']
-            for n in range(int(sect_attrs['nsections']))}
+        section_name_to_address = {}
+        for i in count():
+            # this is a NULL terminated array
+            if sect_attrs['grp']['bin_attrs'][i] == 0x0:
+                break
+
+            attr = sect_attrs['grp']['bin_attrs'][i].dereference()
+            section_name_to_address[attr['attr']['name'].string()] = attr['private']
 
         textaddr = section_name_to_address.get(".text", module_addr)
         args = []
-- 
2.45.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] scripts/gdb/linux/symbols.py: address changes to module_sect_attrs
  2025-02-21 20:40         ` [PATCH v2] " Antonio Quartulli
@ 2025-02-26  5:31           ` Jan Kiszka
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Kiszka @ 2025-02-26  5:31 UTC (permalink / raw)
  To: Antonio Quartulli, kbingham, Andrew Morton
  Cc: linux-kernel, Thomas Weißschuh

On 21.02.25 21:40, Antonio Quartulli wrote:
> When loading symbols from kernel modules we used to iterate
> from 0 to module_sect_attrs::nsections, in order to
> retrieve their name and address.
> 
> However module_sect_attrs::nsections has been removed from
> the struct by a previous commit.
> 
> Re-arrange the iteration by accessing all items in
> module_sect_attrs::grp::bin_attrs[] until NULL is found
> (it's a NULL terminated array).
> 
> At the same time the symbol address cannot be extracted
> from module_sect_attrs::attrs[]::address anymore because
> it has also been deleted. Fetch it from
> module_sect_attrs::grp::bin_attrs[]::private as described
> in 4b2c11e4aaf7.
> 
> Fixes: d8959b947a8d ("module: sysfs: Drop member 'module_sect_attrs::nsections'")
> Fixes: 4b2c11e4aaf7 ("module: sysfs: Drop member 'module_sect_attr::address'")
> Cc: Thomas Weißschuh <linux@weissschuh.net>
> Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
> ---
> 
> Changes in v2:
> * changed attr['attr']['name'] to attr['attr']['name'].string() to
>   ensure extracted value is a string, otherwise an exception is thrown
> 
> 
>  scripts/gdb/linux/symbols.py | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
> index f6c1b063775a..15d76f7d8ebc 100644
> --- a/scripts/gdb/linux/symbols.py
> +++ b/scripts/gdb/linux/symbols.py
> @@ -15,6 +15,7 @@ import gdb
>  import os
>  import re
>  
> +from itertools import count
>  from linux import modules, utils, constants
>  
>  
> @@ -95,10 +96,14 @@ lx-symbols command."""
>          except gdb.error:
>              return str(module_addr)
>  
> -        attrs = sect_attrs['attrs']
> -        section_name_to_address = {
> -            attrs[n]['battr']['attr']['name'].string(): attrs[n]['address']
> -            for n in range(int(sect_attrs['nsections']))}
> +        section_name_to_address = {}
> +        for i in count():
> +            # this is a NULL terminated array
> +            if sect_attrs['grp']['bin_attrs'][i] == 0x0:
> +                break
> +
> +            attr = sect_attrs['grp']['bin_attrs'][i].dereference()
> +            section_name_to_address[attr['attr']['name'].string()] = attr['private']
>  
>          textaddr = section_name_to_address.get(".text", module_addr)
>          args = []

Reviewed-by: Jan Kiszka <jan.kiszka@siemens.com>

Thanks,
Jan

-- 
Siemens AG, Foundational Technologies
Linux Expert Center

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-02-26  5:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-20 15:21 scripts_gdb: Python Exception <class 'gdb.error'>: There is no member named nsections Antonio Quartulli
2025-02-21  6:45 ` Jan Kiszka
2025-02-21 13:03   ` [PATCH] scripts/gdb/linux/symbols.py: address changes to module_sect_attrs Antonio Quartulli
2025-02-21 16:52     ` Jan Kiszka
2025-02-21 20:33       ` Antonio Quartulli
2025-02-21 20:40         ` [PATCH v2] " Antonio Quartulli
2025-02-26  5:31           ` Jan Kiszka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®