NetBSD Problem Report #362
From gnats Fri Jul 22 16:23:21 1994
Received: from localhost (root@cis-ts3-slip4.cis.brown.edu [128.148.19.58]) by sun-lamp.cs.berkeley.edu (8.6.9/8.6.9) with ESMTP id QAA03201 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Fri, 22 Jul 1994 16:23:16 -0700
Message-Id: <199407221749.NAA00544@cis-ts3-slip4.cis.brown.edu>
Date: Fri, 22 Jul 1994 13:49:28 -0400
From: Mark Weaver <mhw@cs.brown.edu>
Reply-To: mhw@cs.brown.edu
To: gnats-bugs@sun-lamp.cs.berkeley.edu
Subject: setuid /bin/sh scripts are insecure (and fix)
X-Send-Pr-Version: 3.2
>Number: 362
>Category: bin
>Synopsis: setuid /bin/sh scripts are insecure (and fix)
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: gnats-admin
>State: closed
>Class: sw-bug
>Submitter-Id: mhw
>Arrival-Date: Fri Jul 22 16:35:03 +0000 1994
>Closed-Date: Wed Aug 03 09:26:48 +0000 1994
>Last-Modified:
>Originator: Mark Weaver
>Release: NetBSD 1.0-ALPHA (21-July-1994)
>Organization:
--------------------------------------------------------------------
Email: Mark_Weaver@brown.edu | Brown University
PGP Key: finger mhw@cs.brown.edu | Dept of Computer Science
>Environment:
System: NetBSD cis-ts3-slip4.cis.brown.edu 1.0-ALPHA NetBSD 1.0-ALPHA (EXCELSIOR) #0: Fri Jul 22 07:27:48 EDT 1994 mhw@cis-ts3-slip4.cis.brown.edu:/usr/src/sys/arch/i386/compile/EXCELSIOR i386
>Description:
When /bin/sh starts up, it reads in the file named in the environment
variable "ENV". I don't see any option that can turn this off,
from looking at both the man page and the source.
This seems like a gaping security hole to me. Assuming I read the
source correctly, can I suggest making sh ignore ENV by default if
uid!=euid?
I haven't extensively looked for other possible security holes,
but as long as sh isn't a login shell, I don't think it loads any
other files. Of course, always make sure you set your PATH at the
beginning of the script.
>How-To-Repeat:
Make any setuid shell script. Then, as an unprivileged user,
set the environment variable "ENV" to any script you want to
run as root. Run the setuid shell script and it will run the
script specified by "ENV" with root privs.
>Fix:
*** src/bin/sh/main.c.mhw1 Sun Jun 12 06:01:35 1994
--- src/bin/sh/main.c Fri Jul 22 13:30:47 1994
***************
*** 159,166 ****
}
state2:
state = 3;
! if ((shinit = lookupvar("ENV")) != NULL &&
! *shinit != '\0') {
state = 3;
read_profile(shinit);
}
--- 159,167 ----
}
state2:
state = 3;
! if (getuid() == geteuid() &&
! (shinit = lookupvar("ENV")) != NULL &&
! *shinit != '\0') {
state = 3;
read_profile(shinit);
}
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed
State-Changed-By: jtc
State-Changed-When: Wed Aug 3 09:26:48 1994
State-Changed-Why:
Indeed! And this behavior is even specified by POSIX.2 (with a check
of real and effective group IDs too). I've checked in code that
performs both checks.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.