Skip to content

SIGBUS on SPARC caused by NSS lookups #21935

Description

@thesamesam

systemd version the issue has been seen with

Known good versions:

  • sys-apps/systemd-249.4-r4 (but not recompiled it yet)

Known bad versions:

  • sys-apps/systemd-249.6-r1
  • sys-apps/systemd-249.7
  • sys-apps/systemd-250-r1

Used distribution

Gentoo Linux.

Linux kernel version used (uname -a)

5.15.5-gentoo

CPU architecture issue was seen on

sparc64

Expected behaviour you didn't see

Commands which end up involving NSS lookups like ls -al succeeding.

Unexpected behaviour you saw

SIGBUS on ls -al, sudo su.

Steps to reproduce the problem

  1. Install >sys-apps/systemd-249.4 on a sparc64 machine
  2. Have systemd configured for NSS lookups in /etc/nsswitch.conf
  3. Try to run ls -al or some other command which will need to lookup entries via NSS

Additional program output to the terminal or log subsystem illustrating the issue

Originally reported downstream in Gentoo here.

$ sudo su
Bus error (core dumped)
$ ls -al
Bus error (core dumped)

Backtrace:

(gdb) bt
#0  copy_synthesized_group (dest=0xfff800010049bf90 <resbuf>, src=0xfff8000100706b08 <root_group>, buffer=0x100001382a0 "root", buflen=1024, errnop=0xfff800010002fbd8)
    at ../systemd-250/src/nss-systemd/nss-systemd.c:254
#1  0xfff80001005b6730 in _nss_systemd_getgrgid_r (gid=<optimized out>, gr=0xfff800010049bf90 <resbuf>, buffer=0x100001382a0 "root", buflen=1024, errnop=0xfff800010002fbd8)
    at ../systemd-250/src/nss-systemd/nss-systemd.c:498
#2  0xfff80001002f1f54 in __getgrgid_r (gid=<optimized out>, resbuf=0xfff800010049bf90 <resbuf>, buffer=0x100001382a0 "root", buflen=1024, result=0x7fefff207e0) at ../nss/getXXbyYY_r.c:274
#3  0xfff80001002f150c in getgrgid (gid=<optimized out>) at ../nss/getXXbyYY.c:135
#4  0x0000010000012d3c in getgroup (gid=<optimized out>) at lib/idcache.c:167
#5  0x000001000000dc84 in format_group_width (g=0) at src/ls.c:4183
#6  gobble_file (name=0x1000012f623 "glibc-2.30-r9.ebuild", type=<optimized out>, command_line_arg=<optimized out>, dirname=<optimized out>, inode=0) at src/ls.c:3534
#7  0x000001000000e484 in print_dir (name=0x100001276e0 ".", realname=<optimized out>, command_line_arg=<optimized out>) at src/ls.c:2989
#8  0x00000100000046e4 in main (argc=<optimized out>, argv=<optimized out>) at src/ls.c:1778
(gdb)

Note that the machine is running glibc-2.33 and the 2.30 reference in the backtrace is just because there's a bunch of glibc ebuilds (=filenames) in the directory I was in.

I don't think there was anything else related/useful in the journal.

Activity

  1. thesamesam commented on Dec 30, 2021

    @thesamesam
    ContributorAuthor

    Backtrace points to us dying at

    *dest->gr_mem = NULL;

    Reverting 47fd7fa from #20679 with 250 works.

    /etc/nsswitch.conf I'm using to trigger this:

    # In alphabetical order. Re-order as required to optimize peformance.
    aliases:    files
    ethers:     files
    group:      files [SUCCESS=merge] systemd
    gshadow:    files systemd
    hosts:      files dns
    # Allow initgroups to default to the setting for group.
    # initgroups: files
    netgroup:   files
    networks:   files dns
    passwd:     files systemd
    protocols:  files
    publickey:  files
    rpc:        files
    shadow:     files systemd
    services:   files
    

    And sed -i -e 's/systemd//' /etc/nsswitch.conf is enough to make things work again with a broken version.

  2. added
    regression ⚠️
    on Dec 30, 2021
  3. added this to the v251 milestone on Dec 30, 2021
  4. added a commit that references this issue on Dec 30, 2021
    5852ab9
  5. yuwata commented on Dec 30, 2021

    @yuwata
    Member

    Thank you for the report. Could you test PR #21938?

  6. added a commit that references this issue on Dec 30, 2021
    1e65eb8
  7. thesamesam commented on Dec 30, 2021

    @thesamesam
    ContributorAuthor

    Thank you for the report. Could you test PR #21938?

    Thanks @yuwata. Sadly, ls -al still ends up SIGBUSing for me. The backtrace seems the same too:

    Using host libthread_db library "/lib64/libthread_db.so.1".
    Core was generated by `ls --color=auto -al'.
    Program terminated with signal SIGUSR1, User defined signal 1.
    #0  copy_synthesized_group (dest=0xfff800010049bf90 <resbuf>, src=0xfff8000100ca6b08 <root_group>, buffer=0x100001382a0 "root", buflen=1024, errnop=0xfff800010002fbd8)
        at ../systemd-250/src/nss-systemd/nss-systemd.c:254
    254             *dest->gr_mem = NULL;
    (gdb) bt
    #0  copy_synthesized_group (dest=0xfff800010049bf90 <resbuf>, src=0xfff8000100ca6b08 <root_group>, buffer=0x100001382a0 "root", buflen=1024, errnop=0xfff800010002fbd8)
        at ../systemd-250/src/nss-systemd/nss-systemd.c:254
    #1  0xfff8000100b56730 in _nss_systemd_getgrgid_r (gid=<optimized out>, gr=0xfff800010049bf90 <resbuf>, buffer=0x100001382a0 "root", buflen=1024, errnop=0xfff800010002fbd8)
        at ../systemd-250/src/nss-systemd/nss-systemd.c:498
    #2  0xfff80001002f1f54 in __getgrgid_r (gid=<optimized out>, resbuf=0xfff800010049bf90 <resbuf>, buffer=0x100001382a0 "root", buflen=1024, result=0x7feffef8820) at ../nss/getXXbyYY_r.c:274
    #3  0xfff80001002f150c in getgrgid (gid=<optimized out>) at ../nss/getXXbyYY.c:135
    #4  0x0000010000012d3c in getgroup (gid=<optimized out>) at lib/idcache.c:167
    #5  0x000001000000dc84 in format_group_width (g=0) at src/ls.c:4183
    #6  gobble_file (name=0x1000012f623 ".bash_history", type=<optimized out>, command_line_arg=<optimized out>, dirname=<optimized out>, inode=0) at src/ls.c:3534
    #7  0x000001000000e484 in print_dir (name=0x100001276e0 ".", realname=<optimized out>, command_line_arg=<optimized out>) at src/ls.c:2989
    #8  0x00000100000046e4 in main (argc=<optimized out>, argv=<optimized out>) at src/ls.c:1778
    (gdb)
    

    Did double check that the patch is applied. Let me know if I can try anything else / give any other information too.

  8. reopened this on Dec 30, 2021
  9. added a commit that references this issue on Dec 30, 2021
    872ea4c
  10. yuwata commented on Dec 30, 2021

    @yuwata
    Member

    Ouch. Could you test #21944?

  11. thesamesam commented on Dec 30, 2021

    @thesamesam
    ContributorAuthor

    Thanks! But not yet:

    (gdb) bt
    #0  copy_synthesized_group (dest=0xfff8000100623f90 <resbuf>, src=0xfff8000100d22b08 <root_group>, buffer=0x100001382a0 "root", buflen=1024, errnop=0xfff800010002fbd8)
        at ../systemd-250/src/nss-systemd/nss-systemd.c:254
    #1  0xfff8000100bd2730 in _nss_systemd_getgrgid_r (gid=<optimized out>, gr=0xfff8000100623f90 <resbuf>, buffer=0x100001382a0 "root", buflen=1024, errnop=0xfff800010002fbd8)
        at ../systemd-250/src/nss-systemd/nss-systemd.c:498
    #2  0xfff8000100479f54 in __getgrgid_r (gid=<optimized out>, resbuf=0xfff8000100623f90 <resbuf>, buffer=0x100001382a0 "root", buflen=1024, result=0x7feffa4a7f0) at ../nss/getXXbyYY_r.c:274
    #3  0xfff800010047950c in getgrgid (gid=<optimized out>) at ../nss/getXXbyYY.c:135
    #4  0x0000010000012d3c in getgroup (gid=<optimized out>) at lib/idcache.c:167
    #5  0x000001000000dc84 in format_group_width (g=0) at src/ls.c:4183
    #6  gobble_file (name=0x1000012f623 "systemd-249.7.ebuild", type=<optimized out>, command_line_arg=<optimized out>, dirname=<optimized out>, inode=0) at src/ls.c:3534
    #7  0x000001000000e484 in print_dir (name=0x100001276e0 ".", realname=<optimized out>, command_line_arg=<optimized out>) at src/ls.c:2989
    #8  0x00000100000046e4 in main (argc=<optimized out>, argv=<optimized out>) at src/ls.c:1778
    (gdb)
    

    If necessary, you're free to have access to this porting machine FWIW.

  12. yuwata commented on Dec 30, 2021

    @yuwata
    Member

    Could you apply the following, and then run build/test-nss-util systemd root?

    diff --git a/src/nss-systemd/nss-systemd.c b/src/nss-systemd/nss-systemd.c
    index be794934bd..eb2aa00fce 100644
    --- a/src/nss-systemd/nss-systemd.c
    +++ b/src/nss-systemd/nss-systemd.c
    @@ -253,6 +253,9 @@ static enum nss_status copy_synthesized_group(
             dest->gr_mem = (char **) (stpcpy(dest->gr_passwd, src->gr_passwd) + 1);
             *dest->gr_mem = NULL;
     
    +        log_info("%s(): buffer:%p, dest:%p, gr_name:%p, gr_passwd:%p, gr_mem:%p, gr_mem[0]:%p",
    +                 __func__, buffer, dest, dest->gr_name, dest->gr_passwd, dest->gr_mem, dest->gr_mem[0]);
    +
             return NSS_STATUS_SUCCESS;
     }
     
    

    On my machine (x86_64), I get the following:

    copy_synthesized_group(): buffer:0x1ffefffde0, dest:0x1fff000270, gr_name:0x1ffefffde0, gr_passwd:0x1ffefffde5, gr_mem:0x1ffefffde7, gr_mem[0]:(nil)
    
  13. thesamesam commented on Dec 30, 2021

    @thesamesam
    ContributorAuthor

    Hm, I don't see test-nss-util anywhere. But I do have test-nss-users and test-nss-hosts so I'll run users:

    # ./test-nss-users systemd root
    ======== systemd ========
    _nss_systemd_getpwnam_r("root") → status=NSS_STATUS_SUCCESS
                       errno=999/---
            "root" / 0:0
            passwd="x"
            gecos="Super User"
            dir="/root"
            shell="/bin/sh"
    Bus error (core dumped)
    

    I think it's good news that this breaks too:

    Program terminated with signal SIGUSR1, User defined signal 1.
    #0  0xfff800010219524c in copy_synthesized_group (dest=0x7feffa630d0, src=0xfff80001022e6b08 <root_group>, buffer=0x7feffa62cc0 "root", buflen=1024, errnop=0x7feffa630cc)
        at ../systemd-250/src/nss-systemd/nss-systemd.c:256
    256             log_info("%s(): buffer:%p, dest:%p, gr_name:%p, gr_passwd:%p, gr_mem:%p, gr_mem[0]:%p",
    (gdb) bt
    #0  0xfff800010219524c in copy_synthesized_group (dest=0x7feffa630d0, src=0xfff80001022e6b08 <root_group>, buffer=0x7feffa62cc0 "root", buflen=1024, errnop=0x7feffa630cc)
        at ../systemd-250/src/nss-systemd/nss-systemd.c:256
    #1  0xfff8000102196478 in _nss_systemd_getgrnam_r (name=0x10000106330 "root", gr=0x7feffa630d0, buffer=0x7feffa62cc0 "root", buflen=1024, errnop=0x7feffa630cc)
        at ../systemd-250/src/nss-systemd/nss-systemd.c:457
    #2  0x0000010000002054 in test_getgrnam_r (handle=0x100001063c0, module=<optimized out>, name=0x10000106330 "root") at ../systemd-250/src/test/test-nss-users.c:90
    #3  0x00000100000010a8 in test_byname (name=0x10000106330 "root", module=0x100001062f0 "systemd", handle=0x100001063c0) at ../systemd-250/src/test/test-nss-users.c:153
    #4  test_one_module (names=0x10000106310, module=0x100001062f0 "systemd", dir=<optimized out>) at ../systemd-250/src/test/test-nss-users.c:175
    #5  run (argv=<optimized out>, argc=<optimized out>) at ../systemd-250/src/test/test-nss-users.c:250
    #6  main (argc=<optimized out>, argv=<optimized out>) at ../systemd-250/src/test/test-nss-users.c:258
    (gdb)
    

    Maybe helpful:

    (gdb) p dest->gr_mem[0]
    $5 = 0x2f62696e2f7368 <error: Cannot access memory at address 0x2f62696e2f7368>
    (gdb) p dest->gr_mem
    $6 = (char **) 0x7feffa62cc7
    
    (gdb) p dest->gr_passwd
    $7 = 0x7feffa62cc5 "x"
    (gdb) p dest
    $8 = (struct group *) 0x7feffa630d0
    (gdb) p *dest
    $9 = {gr_name = 0x7feffa62cc0 "root", gr_passwd = 0x7feffa62cc5 "x", gr_gid = 0, gr_mem = 0x7feffa62cc7}
    (gdb)
    
  14. 15 remaining items

  15. evverx commented on Dec 31, 2021

    @evverx
    Contributor

    Looks like UBsan is happy. Thanks!

    Apparently those tests aren't ready to be run yet but at least eventually they hopefully can be used to catch and prevent issues like that.

  16. evverx commented on Jan 2, 2022

    @evverx
    Contributor

    The tests are hopefully on the way: #21778 but #21975 prevents them from being rolled out

  17. thesamesam commented on Jan 2, 2022

    @thesamesam
    ContributorAuthor

    Thank you all and I appreciate the efforts to get the tests running to avoid regressions/catch future cases!

  18. added a commit that references this issue on Jan 4, 2022
  19. added 2 commits that reference this issue on Jan 6, 2022
    17227e8
    9c8bc04
  20. added 2 commits that reference this issue on Jan 15, 2022
    5f78618
    649e83b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    nssregression ⚠️

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions