Locking session leads to stale X server

Bug #1005813 reported by MNLipp
22
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Light Display Manager
Fix Released
Medium
Unassigned
lightdm (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

Choosing "Switch to different user" in Ubuntu gives you another login screen, which is very nice and useful. However after using that alternate session, lightdm keeps the X server and greeter for that alternate session open and running. Gdm, on the contrary, terminates the X server for the alternate session when you log out of it.

This behaviour does make a difference when you run Ubuntu on a laptop on battery. Using the alternate login just once after boot (and ending the session again) initiates a constant cpu load of 1-2% (on my laptop). Doesn't sound much. But compared to "idle" without the second X server and greeter, this is an increase of about 75%.

I admit that I didn't have the time to keep the laptop running idlely und doing some real battery measurements. But with a laptop on battery, you should use any possibility to save energy.

Tags: patch

Related branches

Revision history for this message
Sebastien Bacher (seb128) wrote :

Thank you for your bug report, how do you check that screen keeps running? do you log it into an user from it? could you add your lightdm.log log file? here the greeter session is closed when entering login in into any account (running or not)

Changed in lightdm:
status: New → Incomplete
importance: Undecided → Low
Revision history for this message
MNLipp (mnl) wrote :

It is very easy to check: after having used "Switch to different user" and logged out of that second session again, you can still choose between the two XServers using alt-ctrl-f7 and alt-ctrl-f8. vt7 displays the "initial" session, vt8 displays the unity-greeter (waiting for a "different user" to log in again).

Using "ps" you can also see that two XServers are running (and one unity greeter, waiting for a login on the no-longer-needed second console).

gdm, on the contrary, takes the second XServer down again after you have logged out from the "different user session".

Revision history for this message
Sebastien Bacher (seb128) wrote :

what you describe there seems normal and not buggy, the second server is the greeter one, if you select your first user and enter its password you should be back to your user unlocked (the greeter acts like the locking screen when going back) and only one xserver

Revision history for this message
MNLipp (mnl) wrote :

"if you select your first user and enter its password you should be back to your user unlocked [...] and only *one* xserver"

Yes, that's what I'd expect. But as I pointed out, I'm back to my user unlocked and have *two* Xservers running. So it doesn't behave as you describe and we both seem to expect. That's what is usually called a bug.

Revision history for this message
Sebastien Bacher (seb128) wrote :

right, then I can't confirm that, after logging back to my user there is no xserver on vt8 here ... could you add your lightdm.log to the bug after login back into your first user account?

Revision history for this message
MNLipp (mnl) wrote :

Here's lightdm.log after (1) logging in as "mnl", (2) switching to user "anl", (3) logging out as "anl" again.

Revision history for this message
MNLipp (mnl) wrote :

oh sorry: ... and unlocking "mnl" again (I even waited for some minutes minute after unlocking).

Changed in lightdm:
status: Incomplete → New
Revision history for this message
Geoff Clements (geoff-v8x) wrote :

I can confirm this, in fact I came here specifically to report this bug and found this one!

I have Ubuntu 12.04 LTS on a laptop and kubuntu 12.10 on a desktop, both show this behaviour. Also when the alternate X server is running I can no longer shut down the PC from a graphical environment, instead I have to ctl-alt-F1, log in to the console and run "shutdown -h now".

Revision history for this message
Peter de Ridder (cavalier) wrote :

I can confirm this too.
This also brings two security issues:
1. If you return to the "stale" greeter, with which a session was unlocked, it still is authenticated (with PAM) and some greeters allow you to unlock that session again without asking for a password.
2. If you kill the "stale" greeter, with which a session was unlocked, it will spawn a new session using that user account.

Caused by:
Lightdm will first check for an active session for the user. If that is found the greeter will be left behind. [1]
The greeter is still authenticated as it expects to be stopped by lightdm after calling lightdm_greeter_start_session_sync.
When switching to another session the start_session flag is still set. [2]
This tells lightdm to start a new session after the greeter is terminated for whatever reason. [3]

Possible solution:
If switch_to_user [1] was succesfull set display->priv->stopping and call session_stop. This will terminate the greeter and display_stop [4].

[1] http://bazaar.launchpad.net/~lightdm-team/lightdm/trunk/view/1611/src/display.c#L388
[2] http://bazaar.launchpad.net/~lightdm-team/lightdm/trunk/view/1611/src/greeter.c#L573
[3] http://bazaar.launchpad.net/~lightdm-team/lightdm/trunk/view/1611/src/display.c#L609
[4] http://bazaar.launchpad.net/~lightdm-team/lightdm/trunk/view/1611/src/display.c#L599

Revision history for this message
Peter de Ridder (cavalier) wrote :

This patch implements the suggested solution from the previous comment.

Changed in lightdm:
status: New → Triaged
importance: Low → Medium
no longer affects: ubuntu
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "Stop the display after switching to an active session" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
Changed in lightdm:
status: Triaged → Incomplete
Changed in lightdm (Ubuntu):
status: New → Incomplete
Revision history for this message
Robert Ancell (robert-ancell) wrote :

MNLipp (or anyone else seeing a problem), can you confirm exactly what you saw when you did the case shown in the log?

The log shows that:
1. X server :0 was started on VT7
2. A greeter was started on :0
3. You logged in as mnl
4. The greeter on :0 stopped
5. mnl's session was run on :0
6. You switched to a greeter
7. X server :1 was started on VT8
8. A greeter was started on :1
9. You logged in as anl
10. The greeter on :1 stopped
11. anl's session was run on :1
12. anl logged out
13. X server :1 stopped
14. A new X server :1 started on VT8 (reusing the old name of :1)
15. A greeter was started on :1

So, from 1-6 you should have seen one X server running (:0) and from 7 onwards you should have seen two.

Visually what you should have seen is:
A. A greeter screen
(authenticate as mnl)
B. mnl's session
(switch user)
C. A greeter screen
(authenticate as anl)
D. anl's session
(logout)
E. A greeter screen

I added more regression tests for this, and wasn't able to detect any left over X server processes on the 1.2 and 1.4 branches or trunk.

Revision history for this message
Geoff Clements (geoff-v8x) wrote :

Hi Robert,

I have just followed steps 1 to 15 and visually I can confirm A to E exactly as you have written. I now have two X servers running:

$ ps ax|grep X
 2153 tty7 Ss+ 0:13 /usr/bin/X :0 -core -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch -background none
 3992 tty8 Ss+ 0:00 /usr/bin/X :1 -core -auth /var/run/lightdm/root/:1 -nolisten tcp vt8 -novtswitch

I can post the log if you like.

Revision history for this message
Peter de Ridder (cavalier) wrote :

I can't run the tests on my system unfortunately.

But I can produce the stale greeter. I followed test-switch-to-greeter-return-session.
With lightdm --version: lightdm 1.5.1

What I did:
- First greeter shown
1. Log in with cavalier
- Session started
2. Send Session.Lock DBus signal
- Second greeter shown
3. Unlock session with user cavalier
- Switch to unlocked session
To verify greeter termination:
4. Press Crtl+Alt+F8
- Second greeter still alive - Expected an empty VT

As seen in the log:
...
Starting local X display
Using VT 7
Activating VT 7
...
Connecting to XServer :0
Starting greeter
Started session 257 with service 'lightdm-greeter', username 'lightdm'
Session 257 authentication complete with return value 0: Success
Greeter authorized
...
Activating VT 7
Greeter start authentication for cavalier
Started session 425 with service 'lightdm', username 'cavalier'
Session 425 got 1 message(s) from PAM
Prompt greeter with 1 message(s)
Continue authentication
Session 425 authentication complete with return value 0: Success
Authentication result for user cavalier: Success
User cavalier authorized
...
Stopping greeter
Session 257: Sending SIGTERM
Greeter closed communication channel
Session 257 exited with return value 0
Greeter quit
...
Starting session xfce as user cavalier
...
Locking seat
Starting new display for greeter with user cavalier selected
Starting local X display
Using VT 8
...
Connecting to XServer :1
Logging in user cavalier
Started session 544 with service 'lightdm', username 'cavalier'
Session 544 authentication complete with return value 19: Conversation error
Autologin failed authentication
Session 544: Sending SIGTERM
Started session 545 with service 'lightdm-greeter', username 'lightdm'
Session 544 terminated with signal 15
Session 545 authentication complete with return value 0: Success
Greeter authorized
...
Activating VT 8
Locking display
Locking logind session /org/freedesktop/login1/session/_31
Greter start authentication for cavalier
Started session 565 with service 'lightdm', username 'cavalier'
Session 565 got 1 message(s) from PAM
Prompt greeter with 1 message(s)
Continue authentication
Session 565 authentication complete with return value 0: Success
Authentication result for user cavalier: Success
User cavalier authorized
...
Switching to existing session for user cavalier
Unlocking display
Unlocking logind session /org/freedesktop/login1/session/_31
Activating VT 7
Locking display

As can be seen from the log. This version of lightdm includes the systemd-logind patches on top of 1.5.1.

In the test scripts there is a check for the termination of the X server and greeter. In the test I performed this doesn't seem to happen.
I was unable the locate the code which should terminate the greeter and X server, hence my merge request.

Revision history for this message
Robert Ancell (robert-ancell) wrote :

Hi Peter,

OK, I can now reproduce the bug you're seeing. Note that is is a different case to the test-switch-to-greeter-return-session regression test - that test uses the SwitchToGreeter D-Bus API, in your case you are using the Session.Lock API. The (new) regression test that exercises the problem is test-lock-session-return-session.

This problem should now be fixed in trunk, please confirm this is the case.

Changed in lightdm:
status: Incomplete → Fix Committed
Changed in lightdm (Ubuntu):
status: Incomplete → Fix Committed
importance: Undecided → Medium
summary: - Lightdm doesn't terminate alternate session login
+ Locking session leads to stale X server
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Geoff, your report confirms you are getting the correct behaviour. I'll assume that MNLipp is also seeing the same thing based on their comments. The issue you have reported about not being able to shutdown sounds like bug 861171. It makes sense that you can't shutdown from the greeter because another user is logged in, however the greeter should report this case and/or allow you to override this.

Revision history for this message
Peter de Ridder (cavalier) wrote :

I was able to run the test after all.
I added the tests to patched lightdm I'm using.
All but one of the test-switch-to-greeter tests pass.

test-switch-to-greeter-return-session fails after *STOP-DAEMON:
...
*GREETER :51 START-SESSION
GREETER :51 TERMINATE SIGNAL=15
XSERVER :51 TERMINATE SIGNAL=15
*STOP-DAEMON
SESSION :50 TERMINATE SIGNAL=15
XSERVER :51 TERMINATE SIGNAL=15
^^^ expected "(SESSION :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)"

Although this fails, the log still shows that the second greeter is terminated here. Which differs from the manual test.

Revision history for this message
Robert Ancell (robert-ancell) wrote :

Peter,

That particular bug is due to the X server being sent SIGTERM twice which occurred when using the patch you had. It should be fixed in revision 1620 [1].

[1] http://bazaar.launchpad.net/~lightdm-team/lightdm/trunk/revision/1620

Revision history for this message
Robert Ancell (robert-ancell) wrote :

Fixed in lightdm 1.5.2

Changed in lightdm:
status: Fix Committed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package lightdm - 1.5.2-0ubuntu1

---------------
lightdm (1.5.2-0ubuntu1) raring; urgency=low

  * New upstream bugfix release:
    * Fix stale X server being left behind when using LockSession D-Bus API
      (LP: #1005813)
    * Adjust AppArmor profile to also work with logind
    * Don't use GIO to access X authority files - it uses GVFS which is
      unnecessary overhead/complexity
    * Handle over/underflows when reading from greeter
    * Improve warning message when XDMCP packet has length mismatch
    * Only report test command line if it fails
    * Add more regression tests
 -- Robert Ancell <email address hidden> Wed, 27 Mar 2013 14:44:44 +1300

Changed in lightdm (Ubuntu):
status: Fix Committed → Fix Released
Revision history for this message
Peter de Ridder (cavalier) wrote :

I can confirm the session lock is fixed with 1.5.2
No stale greeter.
I also tested with SwitchToGreeter, that was indeed working properly.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.