Skip to contentSkip to conversation

base-passwd: Disable shell for default users

PATCH New Jiaqing Zhao 1 participant 4 messages May 13, 2022

lore
Share & tools
lore
#0 lore raw

v3 cover base-passwd: Disable shell for default users

Change the shell of all global static users other than root (which retains /bin/sh) and sync (as /bin/sync is rather harmless) to /sbin/nologin (as /usr/sbin/nologin does not exist in openembedded)

Davide Gardenal (1):
base-passwd: Disable shell for default users

Jiaqing Zhao (2):
sed: Specify shell for "nobody" user in run-ptest
strace: Don't run ptest as "nobody"

---
Updates:
- v3: cherry pick related patches to fix ptest issues
- v2: fix commit message

---

 .../base-passwd/disable-shell.patch           | 57 +++++++++++++++++++
 .../base-passwd/base-passwd_3.5.29.bb         |  1 +
 meta/recipes-devtools/strace/strace/run-ptest |  6 +-
 meta/recipes-extended/sed/sed/run-ptest       |  2 +-
 4 files changed, 60 insertions(+), 6 deletions(-)
 create mode 100644 meta/recipes-core/base-passwd/base-passwd/disable-shell.patch
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/3 sed: Specify shell for "nobody" user in run-ptest

ptest testsuite/panic-tests.sh of sed need to be run as a non-root user so that the expected "sed: couldn't open temporary file <filename>:
Permission denied" error can be generated. After disabling default shell for "nobody", a shell needs to be specified for running ptest.

(cherry picked from commit c6d7216772f76af4429fdaaca518858cf014293f)
---
 meta/recipes-extended/sed/sed/run-ptest | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/recipes-extended/sed/sed/run-ptest +1 -1
index 993d7d5d75..0460c7961f 100644
@@ -2,4 +2,4 @@
 
 chown nobody testsuite
 chown nobody ../ptest
-su nobody -c "make test-suite.log"
+su nobody -s /bin/sh -c "make test-suite.log"
Signature · 1 line
2.34.1
#2 lore raw

PATCH v3 2/3 strace: Don't run ptest as "nobody"

In reply to Jiaqing Zhao

strace ptests can run successfully with root user, there is no need to run as "nobody". The ptest results are the same.

(cherry picked from commit 5ab213178c011152e29dfb0a80251c5e5ab79900)
---
 meta/recipes-devtools/strace/strace/run-ptest | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
meta/recipes-devtools/strace/strace/run-ptest +1 -5
index 02bb91e07f..86daed9220 100755
@@ -3,11 +3,7 @@
 set -u
 
 export TIMEOUT_DURATION=240
-chown nobody tests
-chown nobody tests/*
-chown nobody ../ptest
-
-su nobody -c "make -B -C tests -k test-suite.log"
+make -B -C tests -k test-suite.log
 res=$?
 if [ $res -ne 0 ]; then
     cat tests/test-suite.log
Signature · 1 line
2.34.1
#3 lore raw

PATCH v3 3/3 base-passwd: Disable shell for default users

In reply to Jiaqing Zhao

From: Davide Gardenal <[email protected]>

Change the shell of all global static users other than root (which retains /bin/sh) and sync (as /bin/sync is rather harmless) to /sbin/nologin (as /usr/sbin/nologin does not exist in openembedded)

Upstream-Status: Backport [https://launchpad.net/ubuntu/+source/base-passwd/3.5.30]

(cherry picked from commit ba3bc4d7a0a39a96f6e8d340e1b2654d47475f07)
---
 .../base-passwd/disable-shell.patch           | 57 +++++++++++++++++++
 .../base-passwd/base-passwd_3.5.29.bb         |  1 +
 2 files changed, 58 insertions(+)
 create mode 100644 meta/recipes-core/base-passwd/base-passwd/disable-shell.patch
meta/recipes-core/base-passwd/base-passwd/disable-shell.patch new file +57 -0
new file mode 100644
index 0000000000..bfaa786018
@@ -0,0 +1,57 @@
+From 91e0db96741359173ddf2be083aafcc1a3c32472 Mon Sep 17 00:00:00 2001
+From: Jiaqing Zhao <[email protected]>
+Date: Mon, 18 Apr 2022 11:22:43 +0800
+Subject: [PATCH] Disable shell for default users
+
+Change the shell of all global static users other than root (which
+retains /bin/sh) and sync (as /bin/sync is rather harmless) to
+/sbin/nologin (as /usr/sbin/nologin does not exist in openembedded)
+
+Upstream-Status: Backport [https://launchpad.net/ubuntu/+source/base-passwd/3.5.30]
+Signed-off-by: Jiaqing Zhao <[email protected]>
+---
+ passwd.master | 32 ++++++++++++++++----------------
+ 1 file changed, 16 insertions(+), 16 deletions(-)
+
+diff --git a/passwd.master b/passwd.master
+index e1c32ff..0cd5ffd 100644
+--- a/passwd.master
++++ b/passwd.master
+@@ -1,18 +1,18 @@
+ root::0:0:root:/root:/bin/sh
+-daemon:*:1:1:daemon:/usr/sbin:/bin/sh
+-bin:*:2:2:bin:/bin:/bin/sh
+-sys:*:3:3:sys:/dev:/bin/sh
++daemon:*:1:1:daemon:/usr/sbin:/sbin/nologin
++bin:*:2:2:bin:/bin:/sbin/nologin
++sys:*:3:3:sys:/dev:/sbin/nologin
+ sync:*:4:65534:sync:/bin:/bin/sync
+-games:*:5:60:games:/usr/games:/bin/sh
+-man:*:6:12:man:/var/cache/man:/bin/sh
+-lp:*:7:7:lp:/var/spool/lpd:/bin/sh
+-mail:*:8:8:mail:/var/mail:/bin/sh
+-news:*:9:9:news:/var/spool/news:/bin/sh
+-uucp:*:10:10:uucp:/var/spool/uucp:/bin/sh
+-proxy:*:13:13:proxy:/bin:/bin/sh
+-www-data:*:33:33:www-data:/var/www:/bin/sh
+-backup:*:34:34:backup:/var/backups:/bin/sh
+-list:*:38:38:Mailing List Manager:/var/list:/bin/sh
+-irc:*:39:39:ircd:/var/run/ircd:/bin/sh
+-gnats:*:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
+-nobody:*:65534:65534:nobody:/nonexistent:/bin/sh
++games:*:5:60:games:/usr/games:/sbin/nologin
++man:*:6:12:man:/var/cache/man:/sbin/nologin
++lp:*:7:7:lp:/var/spool/lpd:/sbin/nologin
++mail:*:8:8:mail:/var/mail:/sbin/nologin
++news:*:9:9:news:/var/spool/news:/sbin/nologin
++uucp:*:10:10:uucp:/var/spool/uucp:/sbin/nologin
++proxy:*:13:13:proxy:/bin:/sbin/nologin
++www-data:*:33:33:www-data:/var/www:/sbin/nologin
++backup:*:34:34:backup:/var/backups:/sbin/nologin
++list:*:38:38:Mailing List Manager:/var/list:/sbin/nologin
++irc:*:39:39:ircd:/var/run/ircd:/sbin/nologin
++gnats:*:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/sbin/nologin
++nobody:*:65534:65534:nobody:/nonexistent:/sbin/nologin
+--
+2.32.0
+
meta/recipes-core/base-passwd/base-passwd_3.5.29.bb +1 -0
index 9a27ad3ab5..ef7792ae49 100644
@@ -14,6 +14,7 @@ SRC_URI = "https://launchpad.net/debian/+archive/primary/+files/${BPN}_${PV}.tar
            file://input.patch \
            file://disable-docs.patch \
            file://kvm.patch \
+           file://disable-shell.patch \
            "
 
 SRC_URI[md5sum] = "6beccac48083fe8ae5048acd062e5421"
Signature · 1 line
2.34.1