Stories
Slash Boxes
Comments

SoylentNews is people

posted by Fnord666 on Monday July 03 2017, @10:12PM   Printer-friendly
from the it's-a-feature dept.

Submitted via IRC for TheMightyBuzzard

A bug in Linux's systemd init system causes root permissions to be given to services associated with invalid usernames, and while this could pose a security risk, exploitation is not an easy task.

A developer who uses the online moniker "mapleray" last week discovered a problem related to systemd unit files, the configuration files used to describe resources and their behavior. Mapleray noticed that a systemd unit file containing an invalid username – one that starts with a digit (e.g. "0day") – will initiate the targeted process with root privileges instead of regular user privileges.

Systemd is designed not to allow usernames that start with a numeric character, but Red Hat, CentOS and other Linux distributions do allow such usernames.

"It's systemd's parsing of the User= parameter that determines the naming doesn't follow a set of conventions, and decides to fall back to its default value, root," explained developer Mattias Geniar.

While this sounds like it could be leveraged to obtain root privileges on any Linux installation using systemd, exploiting the bug in an attack is not an easy task. Geniar pointed out that the attacker needs root privileges in the first place to edit the systemd unit file and use it.

[...] Systemd developers have classified this issue as "not-a-bug" and they apparently don't plan on fixing it. Linux users are divided on the matter – some believe this is a vulnerability that could pose a serious security risk, while others agree that a fix is not necessary.

See, this is why we can't have nice init systems.

Source: http://www.securityweek.com/linux-systemd-gives-root-privileges-invalid-usernames


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 2) by Arik on Monday July 03 2017, @11:43PM (26 children)

    by Arik (4543) on Monday July 03 2017, @11:43PM (#534610) Journal
    Using a normal, valid username in one of the systemd config files, in a field that takes a username, will cause that username to effectively get root.

    BUT

    This is "not a bug" because you aren't allowed to edit the file and add the username, unless you're already root?

    See I read TFA.

    But I'm still not sure I get this. How does a username normally get written into one of these 'unit files' in the first place?

    --
    If laughter is the best medicine, who are the best doctors?
    Starting Score:    1  point
    Karma-Bonus Modifier   +1  

    Total Score:   2  
  • (Score: 2) by unauthorized on Tuesday July 04 2017, @12:29AM (12 children)

    by unauthorized (3776) on Tuesday July 04 2017, @12:29AM (#534619)

    But I'm still not sure I get this. How does a username normally get written into one of these 'unit files' in the first place?

    Unit files are usually hand-written files installed along with the distribution or a package. In the typical use-case they only change with package updates unless an admin manually edits them.

    • (Score: 3, Interesting) by Arik on Tuesday July 04 2017, @12:53AM (11 children)

      by Arik (4543) on Tuesday July 04 2017, @12:53AM (#534622) Journal
      OK, so that probably justifies thinking that it's not a super-critical, must-solve-this-second sort of bug.

      But how do they figure it's not a bug? Is there any conceivable, theoretical case where this behavior is expected and desired?

      --
      If laughter is the best medicine, who are the best doctors?
      • (Score: 5, Insightful) by vux984 on Tuesday July 04 2017, @01:02AM (5 children)

        by vux984 (5045) on Tuesday July 04 2017, @01:02AM (#534625)

        This Exactly.

        Throw/log an error and don't start the process should be the default behavior. Starting as root if the user name is invalid is beyond the pale.

        • (Score: 2) by kaszz on Tuesday July 04 2017, @02:59AM (1 child)

          by kaszz (4211) on Tuesday July 04 2017, @02:59AM (#534657) Journal

          No log as it binary.. remember? total clusterfuck. Shit like this is what forces administrators to do late nighter to clean up after the braindamage writes code that scriptkids use. (which usually some pointy haired type decided must be used..)

          • (Score: 2) by butthurt on Tuesday July 04 2017, @08:57PM

            by butthurt (6141) on Tuesday July 04 2017, @08:57PM (#534928) Journal

            > No log as it binary.. remember?

            The binary "journal" is a log.

        • (Score: 2) by SDRefugee on Tuesday July 04 2017, @01:06PM (1 child)

          by SDRefugee (4477) on Tuesday July 04 2017, @01:06PM (#534784)

          Starting as root if the user name is invalid is beyond the pale.

          Sounds like something that bunch of psychos in Redmond, Washington would do...

          --
          America should be proud of Edward Snowden, the hero, whether they know it or not..
          • (Score: 0) by Anonymous Coward on Tuesday July 04 2017, @07:48PM

            by Anonymous Coward on Tuesday July 04 2017, @07:48PM (#534903)

            Software requirements specification met!

        • (Score: 2) by Thexalon on Tuesday July 04 2017, @07:51PM

          by Thexalon (636) on Tuesday July 04 2017, @07:51PM (#534906)

          At the very least, if I were going to default to anything at all, I'd default to "nobody".

          --
          The only thing that stops a bad guy with a compiler is a good guy with a compiler.
      • (Score: 3, Interesting) by Jesus_666 on Tuesday July 04 2017, @05:13PM (3 children)

        by Jesus_666 (3044) on Tuesday July 04 2017, @05:13PM (#534841)

        Simple: The observed behavior is in line with how systemd was designed and therefore obviously correct. Since usernames can't begin with a digit and every major Linux distribution has been breaking the standard for years before it was even conceived it's not systemd's problem but that of everyone else. The fix to that problem is obvious: All distros should ban numeric usernames immediately (this is security-relevant, after all) and everyone who uses them should rename the offending users before installing any package updates. Also, they should be ashamed of themselves for being bad at Unix.

        At least that's how I imagine the systemd team sees it.

        • (Score: 2) by vux984 on Tuesday July 04 2017, @06:20PM (2 children)

          by vux984 (5045) on Tuesday July 04 2017, @06:20PM (#534864)

          At least that's how I imagine the systemd team sees it.

          Probably. But EVEN if that's how they see it they STILL have a bug.

          If the systemd team wants to enforce a policy of no usernames that start with a digit, fine, that would be in keeping with their arrogance and ego... but at the very least they should properly reject those credentials as invalid.

          The failure mode for attempting to run a process with "invalid" credentials should NEVER be "run it as root".

          • (Score: 3, Touché) by maxwell demon on Tuesday July 04 2017, @06:43PM (1 child)

            by maxwell demon (1608) Subscriber Badge on Tuesday July 04 2017, @06:43PM (#534876) Journal

            The failure mode for attempting to run a process with "invalid" credentials should NEVER be "run it as root".

            Nah, if Poettering implements this that way, it's obviously exactly the right thing. To follow his lead, I'm going to patch login with the following code:

            if (valid(user, password))
              login_as(user);
            else
              login_as(USER_ROOT);

            SCNR :-)

            --
            The Tao of math: The numbers you can count are not the real numbers.
            • (Score: 2) by DECbot on Wednesday July 05 2017, @04:40PM

              by DECbot (832) on Wednesday July 05 2017, @04:40PM (#535258) Journal

              I understand it to be a little more complex than that...

              if (system.valid(user, password))
                  try{ login_as(systemd.valid(user)); }
                  catch(NoSuchSystemdUserException ex){ login_as(USER_ROOT); }
              else
                  throw new NoSuchUserException("User not found");

              --
              cats~$ sudo chown -R us /home/base
      • (Score: 3, Interesting) by FatPhil on Wednesday July 05 2017, @08:03AM

        by FatPhil (863) <pc-soylentNO@SPAMasdf.fi> on Wednesday July 05 2017, @08:03AM (#535097) Homepage
        A malicious 3rd party could create a package with a legitimate-looking unit file and at least one dodgy executable, but chose to run as an unprivileged user. You trust it initially, as it's running as nobody or thereabouts. However, the uninstallation script in the package could deliberately leave the unit file in place, and one dodgy executable. The account it used is correctly nuked. However, the dodgy executable now runs as root.

        OK it requires social engineering to get people to install/try/uninstall, but still, I'd put that as a "fix right now" kind of bug. The brute force "unrecognised user name" = "don't run" solution sounds (a) like a fix to the bug; and (b) like what would have been the sensible default in the first place. If that's more than a trivial 10 line change to the code (I can barely imagine it being more than 3), then it's a code base that needs nuking from orbit.
        --
        Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
  • (Score: 2) by frojack on Tuesday July 04 2017, @01:21AM (12 children)

    by frojack (1554) Subscriber Badge on Tuesday July 04 2017, @01:21AM (#534628) Journal

    Using a normal, valid username in one of the systemd config files, in a field that takes a username, will cause that username to effectively get root.

    No, that's not what happens here.
    Using an invalid username causes that unit to run as root. That unit can do anything.
    Using a valid user name causes that unit to run as that (valid) user. The unit can't do anything the user couldn't do.

    Only root can instantiate a new unit.

    --
    No, you are mistaken. I've always had this sig.
    • (Score: 3, Disagree) by Arik on Tuesday July 04 2017, @01:32AM (9 children)

      by Arik (4543) on Tuesday July 04 2017, @01:32AM (#534631) Journal
      Systemd may define it as not a valid username, however systemd is not the judge of this and no one gives a fsck what Poettering thinks, it's simply not his call. There's nothing 'invalid' about a *nix username starting with a null and many, many have done so.

      --
      If laughter is the best medicine, who are the best doctors?
      • (Score: 2) by isostatic on Tuesday July 04 2017, @02:20PM (3 children)

        by isostatic (365) on Tuesday July 04 2017, @02:20PM (#534796) Journal

        no one gives a fsck what Poettering thinks, it's simply not his call

        Sadly that's not true. I don't know why, but for some reason what he decides goes. Time and time again he causes a horrendous mess, and time and time again we follow him. He has an obscene amount of power - on the order of that of Linus. What he says goes, that's the new reality.

        • (Score: 1) by Arik on Tuesday July 04 2017, @02:51PM (2 children)

          by Arik (4543) on Tuesday July 04 2017, @02:51PM (#534804) Journal
          I get your point, but I think you missed mine.

          Not even the distro he works for actually considers these filenames invalid.
          --
          If laughter is the best medicine, who are the best doctors?
          • (Score: 0) by Anonymous Coward on Tuesday July 04 2017, @02:53PM

            by Anonymous Coward on Tuesday July 04 2017, @02:53PM (#534805)
            Meant usernames not files obviously.
          • (Score: 2) by isostatic on Tuesday July 04 2017, @06:51PM

            by isostatic (365) on Tuesday July 04 2017, @06:51PM (#534883) Journal

            Sure, but that's effectively changed now. As systemd is so ingrained into linux, and pottering is in charge, if he decides that "usernames beginging with a number aren't valid", that makes them defacto invalid.

            Technically you're correct, but in practice mroe and more of systemd will refuse to work with usernames begining with numbers, and it will become the defacto standard.

      • (Score: 2) by butthurt on Tuesday July 04 2017, @08:23PM (4 children)

        by butthurt (6141) on Tuesday July 04 2017, @08:23PM (#534913) Journal

        > There's nothing 'invalid' about a *nix username starting with a null and many, many have done so.

        I disagree. A commenter on Stack Exchange wrote that the allowable characters (according to IEEE Std 1003.1-2001) are:

        The set of characters from which portable filenames are constructed.

        A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
        a b c d e f g h i j k l m n o p q r s t u v w x y z
        0 1 2 3 4 5 6 7 8 9 . _ -

        -- https://www.linuxquestions.org/questions/linux-server-73/valid-user-names-573768/ [linuxquestions.org]

        The summary mentions "usernames that start with a numeric character." A null character is not a numeric character. It's a control character. Perhaps you're confusing it with the zero symbol, "0"?

        https://en.wikipedia.org/wiki/Null_character [wikipedia.org]

        • (Score: 1) by Arik on Wednesday July 05 2017, @12:27AM (3 children)

          by Arik (4543) on Wednesday July 05 2017, @12:27AM (#534990) Journal
          C defines things differently and that's fine, but the normal meaning of the word 'null' is precisely the same as 'zero.'
          --
          If laughter is the best medicine, who are the best doctors?
          • (Score: 2) by FatPhil on Wednesday July 05 2017, @08:06AM (1 child)

            by FatPhil (863) <pc-soylentNO@SPAMasdf.fi> on Wednesday July 05 2017, @08:06AM (#535098) Homepage
            Not just C, Unix - you stepped on both toes.
            --
            Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
            • (Score: 1) by Arik on Wednesday July 05 2017, @05:23PM

              by Arik (4543) on Wednesday July 05 2017, @05:23PM (#535281) Journal
              You got me, my native tongue is English, and I don't worship Kernighan and Ritchie.
              --
              If laughter is the best medicine, who are the best doctors?
          • (Score: 2) by butthurt on Thursday July 06 2017, @12:37AM

            by butthurt (6141) on Thursday July 06 2017, @12:37AM (#535473) Journal

            In the context of character sets in computing, they have distinct meanings. In the character set used for POSIX usernames, a printable "0" is different from the non-printable NUL.

            https://en.wikipedia.org/wiki/File:US-ASCII_code_chart.png [wikipedia.org]

            If you refer to "0" as a null, you're just going to cause confusion.

    • (Score: 2, Informative) by Anonymous Coward on Tuesday July 04 2017, @01:38AM

      by Anonymous Coward on Tuesday July 04 2017, @01:38AM (#534632)

      Using a valid user name causes that unit to run as that (valid) user. The unit can't do anything the user couldn't do.

      This is false. If the username is "1strike" it is a valid Linux username but not to systemd so it gets root privileges. If the username is invalid, or starts with a number (which systemd says is bad), it runs as root.

    • (Score: 0) by Anonymous Coward on Tuesday July 04 2017, @01:41AM

      by Anonymous Coward on Tuesday July 04 2017, @01:41AM (#534633)

      Using a valid user name causes that unit to run as that (valid) user.

      You are wrong. From the article:

      Systemd is designed not to allow usernames that start with a numeric character, but Red Hat, CentOS and other Linux distributions do allow such usernames.

      Perfectly *valid* usernames ("0day") are *invalid* in crappyd. Yet another case of Poopering and his cronies getting things wrong and failing to support perfectly legal semantics. The rest of the system doesn't care if your username starts with a digit but somehow systemd does care.