selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] sandbox: Do not try to remove tmpdir twice if uid == 0
@ 2022-10-13 13:23 Petr Lautrbach
  2022-10-13 13:23 ` [PATCH 2/2] sandbox: Use temporary directory for XDG_RUNTIME_DIR Petr Lautrbach
  2022-11-04 18:38 ` [PATCH 1/2] sandbox: Do not try to remove tmpdir twice if uid == 0 James Carter
  0 siblings, 2 replies; 4+ messages in thread
From: Petr Lautrbach @ 2022-10-13 13:23 UTC (permalink / raw)
  To: selinux; +Cc: Petr Lautrbach

If the user is root, tmpdir is already wiped out.

Fixes:
    # sandbox -T /root/tmp -- id
    uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:sandbox_t:s0:c696,c756
    Failed to remove directory /tmp/.sandbox-root-KIlB59: No such file or directory

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
---
 sandbox/seunshare.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sandbox/seunshare.c b/sandbox/seunshare.c
index 8917a0f9bd42..dd1d7ddbdc89 100644
--- a/sandbox/seunshare.c
+++ b/sandbox/seunshare.c
@@ -414,7 +414,7 @@ static int cleanup_tmpdir(const char *tmpdir, const char *src,
 		rc++;
 	}
 
-	if (rmdir(tmpdir) == -1)
+	if (pwd->pw_uid != 0 && rmdir(tmpdir) == -1)
 		fprintf(stderr, _("Failed to remove directory %s: %s\n"), tmpdir, strerror(errno));
 	if ((uid_t)setfsuid(pwd->pw_uid) != 0) {
 		fprintf(stderr, _("unable to switch back to user after clearing tmp dir\n"));
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-09 13:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-13 13:23 [PATCH 1/2] sandbox: Do not try to remove tmpdir twice if uid == 0 Petr Lautrbach
2022-10-13 13:23 ` [PATCH 2/2] sandbox: Use temporary directory for XDG_RUNTIME_DIR Petr Lautrbach
2022-11-04 18:38 ` [PATCH 1/2] sandbox: Do not try to remove tmpdir twice if uid == 0 James Carter
2022-11-09 13:46   ` James Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).