• Bug#1108549: procps: w acts on value of uninit'd mem w/out systemd; pos

    From Andrew Bower@21:1/5 to Andrew Bower on Mon Jul 28 00:20:01 2025
    On Thu, Jul 24, 2025 at 07:15:12PM +0100, Andrew Bower wrote:
    On Wed, Jul 23, 2025 at 10:31:47PM +0100, Andrew Bower wrote:
    On Mon, Jun 30, 2025 at 11:36:59PM +0100, Andrew Bower wrote:
    [...]
    1. Unitialised 'sessions' variable is a a bug on all systems which leads
    to a segfault on some. I'm now tagging this bug as having a patch.

    In the absence of any other fixes, my patch for this still stands.
    But...

    2. elogind not being queried. Is this an elogind issue? Should it give a
    different answer to sd_booted() or is this the wrong way to detect the
    seat management capability? 'who' does not have this problem - it
    somehow queries elogind anyway.

    Removing the call to sd_booted() and just using the result of
    sd_get_sessions() is sufficient. I get the correct outcome in this case.

    Unfortunately we don't then get any runtime fallback to utmp but my
    guess is working elogind support would be preferred (and should be fixed
    for trixie).

    I am not proposing a patch here because it needs attention from someone
    more familiar with the relevant components.

    My hunch is that the best plan for trixie is to go straight to calling sd_get_sessions() and not testing sd_booted(). This would then supersede
    the patch for (1).

    procps then resorts to utmp.

    3. Some (vc) sessions not reported unless running as root, but the non-root
    user could read utmp. 'who' does not have this problem but then it
    probably didn't resort to reading utmp (see 2 above).

    This was a mistake - ignore this: the additional session was caused by
    sudo itself.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andrew Bower@21:1/5 to Andrew Bower on Mon Jul 28 09:40:01 2025
    On Sun, Jul 27, 2025 at 11:08:56PM +0100, Andrew Bower wrote:
    On Thu, Jul 24, 2025 at 07:15:12PM +0100, Andrew Bower wrote:
    On Wed, Jul 23, 2025 at 10:31:47PM +0100, Andrew Bower wrote:
    On Mon, Jun 30, 2025 at 11:36:59PM +0100, Andrew Bower wrote:
    [...]
    1. Unitialised 'sessions' variable is a a bug on all systems which leads
    to a segfault on some. I'm now tagging this bug as having a patch.

    In the absence of any other fixes, my patch for this still stands.
    But...

    2. elogind not being queried. Is this an elogind issue? Should it give a
    different answer to sd_booted() or is this the wrong way to detect the
    seat management capability? 'who' does not have this problem - it
    somehow queries elogind anyway.

    Removing the call to sd_booted() and just using the result of sd_get_sessions() is sufficient. I get the correct outcome in this case.

    Unfortunately we don't then get any runtime fallback to utmp but my
    guess is working elogind support would be preferred (and should be fixed
    for trixie).

    I am not proposing a patch here because it needs attention from someone
    more familiar with the relevant components.

    My hunch is that the best plan for trixie is to go straight to calling sd_get_sessions() and not testing sd_booted(). This would then supersede
    the patch for (1).

    I think we should do this:

    Remove sd_booted() check
    if sd_get_sessions()
    < 0 && != ENOENT: error
    > 0: show sessions
    default: fallback to utmp

    This should deal with:
    1. systemd and elogind with some login sessions: show sessions
    2. neither systemd nor elogind: fallback to utmp reading
    3. systemd and elogind with no sessions: show nothing, as now, but via
    fallback utmp route with no practical difference.

    I don't see a downside from this approach.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Craig Small@21:1/5 to Andrew Bower on Mon Jul 28 12:20:01 2025
    On Mon, 28 Jul 2025 at 17:31, Andrew Bower <andrew@bower.uk> wrote:

    I think we should do this:

    Remove sd_booted() check
    if sd_get_sessions()
    < 0 && != ENOENT: error
    > 0: show sessions
    default: fallback to utmp

    This should deal with:
    1. systemd and elogind with some login sessions: show sessions
    2. neither systemd nor elogind: fallback to utmp reading
    3. systemd and elogind with no sessions: show nothing, as now, but via
    fallback utmp route with no practical difference.

    I don't see a downside from this approach.

    I think this is the correct way too. I'll double check that 0 user path
    because it looks odd, but its probably doing the right thing.

    - Craig

    <div dir="ltr"><div dir="ltr">On Mon, 28 Jul 2025 at 17:31, Andrew Bower &lt;<a href="mailto:andrew@bower.uk">andrew@bower.uk</a>&gt; wrote:</div><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.
    8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I think we should do this:<br>

    Remove sd_booted() check<br>
    if sd_get_sessions()<br>
      &lt; 0 &amp;&amp; != ENOENT: error<br>
      &gt; 0: show sessions<br>
      default: fallback to utmp<br>

    This should deal with:<br>
      1. systemd and elogind with some login sessions: show sessions<br>
      2. neither systemd nor elogind: fallback to utmp reading<br>
      3. systemd and elogind with no sessions: show nothing, as now, but via<br>      fallback utmp route with no practical difference.<br>

    I don&#39;t see a downside from this approach.<br></blockquote><div>I think this is the correct way too. I&#39;ll double check that 0 user path because it looks odd, but its probably doing the right thing.</div><div><br></div><div> - Craig</div><div><br>
    </div></div></div>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andrew Bower@21:1/5 to Craig Small on Mon Jul 28 19:20:01 2025
    Hi Craig,

    Thanks for reviewing my suggestions!

    On Mon, Jul 28, 2025 at 08:07:12PM +1000, Craig Small wrote:
    On Mon, 28 Jul 2025 at 17:31, Andrew Bower <andrew@bower.uk> wrote:

    I think we should do this:

    Remove sd_booted() check
    if sd_get_sessions()
      < 0 && != ENOENT: error
      > 0: show sessions
      default: fallback to utmp

    This should deal with:
      1. systemd and elogind with some login sessions: show sessions
      2. neither systemd nor elogind: fallback to utmp reading
      3. systemd and elogind with no sessions: show nothing, as now, but via
         fallback utmp route with no practical difference.

    I don't see a downside from this approach.

    I think this is the correct way too. I'll double check that 0 user path because
    it looks odd, but its probably doing the right thing.

    A slight tweak to this algorithm might allay anxiety about the 0
    sessions case, whereby we reintroduce the sd_booted() check in a
    different place to create an alternative path:

    if sd_get_sessions()
    < 0 && != ENOENT: error
    > 0 || sd_booted(): show sessions
    default: fallback to utmp

    In this case if systemd is running then the utmp fallback is never
    attempted - this results in no ambiguity about the outcome in this more predictable scenario.

    (N.B. would also need to zero out the session count in case of ENOENT)

    What do you think of this variation?

    Andrew

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)