xdg-desktop-portal-wlr: Segfault when using greetd + Sway

I’m using greetd as login manager with the GTK greeter and Sway.
This setup is more or less explained here and here.

After a specific upgrade, the greeter now takes a few seconds to start due to xdpw crashing and being restarted several times.

Here’s the log with -l DEBUG: xdpw.log

This is what coredumpctl info says:

[I] ~ $ coredumpctl info
           PID: 3072 (xdg-desktop-por)
           UID: 976 (greeter)
           GID: 976 (greeter)
        Signal: 11 (SEGV)
     Timestamp: Sun 2021-06-13 22:02:18 -03 (14min ago)
  Command Line: /usr/lib/xdg-desktop-portal-wlr -l DEBUG
    Executable: /usr/lib/xdg-desktop-portal-wlr
 Control Group: /user.slice/user-976.slice/user@976.service/app.slice/xdg-desktop-portal-wlr.service
          Unit: user@976.service
     User Unit: xdg-desktop-portal-wlr.service
         Slice: user-976.slice
     Owner UID: 976 (greeter)
       Boot ID: a52b1ef6df664d259ee863b9aa403656
    Machine ID: 3d14cd859eed44e78935812dd176271f
      Hostname: ryzen
       Storage: /var/lib/systemd/coredump/core.xdg-desktop-por.976.a52b1ef6df664d259ee863b9aa403656.3072.1623632538000000.zst (inaccessible)
       Message: Process 3072 (xdg-desktop-por) of user 976 dumped core.

                Stack trace of thread 3072:
                #0  0x00007fe571794515 __strlen_avx2 (libc.so.6 + 0x160515)
                #1  0x000055b5f806a5c2 n/a (xdg-desktop-portal-wlr + 0x45c2)
                #2  0x00007fe57165bb25 __libc_start_main (libc.so.6 + 0x27b25)
                #3  0x000055b5f806b05e n/a (xdg-desktop-portal-wlr + 0x505e)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (1 by maintainers)

Commits related to this issue

Most upvoted comments

If you build xdg-desktop-portal-wlr-git from AUR, it’ll include debugging symbols and you can send us a backtrace if you’re getting a segfault style crash in xdpw.

#0  0x00007feca2906515 in __strlen_avx2 () from /usr/lib/libc.so.6
#1  0x0000561452cf95ca in get_config_path () at ../xdg-desktop-portal-wlr-git/src/core/config.c:109
#2  init_config (config=0x7ffe4fc04eb0, configfile=<synthetic pointer>) at ../xdg-desktop-portal-wlr-git/src/core/config.c:165
#3  main (argc=1, argv=<optimized out>) at ../xdg-desktop-portal-wlr-git/src/core/main.c:84

I took a look at the code and it seems you are calling strlen over a NULL pointer, here:

	const char *home = getenv("HOME");
	size_t size_fallback = 1 + strlen(home) + strlen("/.config");

The environment variable HOME is not defined because greetd and greetd-gtkgreet run as the greeter user.
The greeter user has no home:

[I] ~ $ cat /etc/passwd|grep greeter
greeter:x:976:976:greetd greeter user:/:/bin/bash

Now that I think of, isn’t HOME guaranteed to be always defined?

Let me know if you need anything else.

@itaranto Thanks for finding hat. Never came to my mind, that xdpw could run as a system user without home.

That’s strange, I’ll probably do more research, for example xdg-desktop-portal has HOME defined in my regular session but not in the greetd session.

Could you test if #151 fixes it, please?

Yes, I just built xdg-desktop-portal-wlr-git and it didn’t crashed in the greetd’s login screen.

@itaranto Thanks for finding hat. Never came to my mind, that xdpw could run as a system user without home.

Could you test if #151 fixes it, please?

You nailed it! This is a regression. @columbarius, can we make these getenv calls safe? If you don’t have time, I may be able to push a PR tomorrow evening.

getenv calls are “safe” by default in that they either return a string or NULL, we just need to check for that.

You nailed it! This is a regression. @columbarius, can we make these getenv calls safe? If you don’t have time, I may be able to push a PR tomorrow evening.

Ugh, that shoots that theory. Any change in the logs?

It’s strange, xdpw is still crashing but now there’s no logs.

Another strange thing is that I found a crash for gtkgreet that I can reproduce 100% of the time. Every time I enter an incorrect password it segfaults, with a correct one it doesn’t. I’ll report that to greetd-gtkgreet.
I think this is probably unrelated to xdwp.