BSDSec

deadsimple BSD Security Advisories and Announcements

NetBSD Security Advisory 2016-003: Privilege escalation in calendar(1)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

		 NetBSD Security Advisory 2016-003
		 =================================

Topic:		Privilege escalation in calendar(1)

Version:	NetBSD-current:		source prior to Wed, Jul 1st 2015
		NetBSD 7.0:		not affected
		NetBSD 6.1 - 6.1.5:	affected
		NetBSD 6.0 - 6.0.6:	affected
		NetBSD 5.2 - 5.2.3:	affected
		NetBSD 5.1 - 5.1.5:	affected

Severity:	Local privilege escalation

Fixed:		NetBSD-current:		Jul 1st, 2015
		NetBSD-7 branch:	Jul 1st, 2015
		NetBSD-7-0 branch:	Jul 1st, 2015
		NetBSD-6 branch:	Jul 1st, 2015
		NetBSD-6-1 branch:	Jul 1st, 2015
		NetBSD-6-0 branch:	Jul 1st, 2015
		NetBSD-5 branch:	Jul 1st, 2015
		NetBSD-5-2 branch:	Jul 1st, 2015
		NetBSD-5-1 branch:	Jul 1st, 2015

Please note that NetBSD releases prior to 5.1 are no longer supported.
It is recommended that all users upgrade to a supported release.

Abstract
========

calendar(1) is a utility to process text files and displays lines that match
certain dates. The -a flag which is used to process the default calendar
files of all users and mails them the results. This flag requires super-user
privileges which are not dropped properly when executing external programs.

calendar(1) with -a option is executed by daily(5) maintenance script.


Technical Details
=================

calendar(1) requires super-user privileges in order to process calendar
files of each user. When processing particular account, code is dropping its
privileges incorrectly. The code changes only effective uid (euid) and
effective gid (egid) of running process, and executes external programs such
as cpp(1) and sendmail(1). This can be potentially used to escalate attacker
privileges or process files which are readable by super-user only.
Additionally, initgroups(3) call was missing. Thus, any supplementary groups
in effect when it is started are also exposed.


Solutions and Workarounds
=========================

Workaround
- ----------

Set run_calendar=NO in daily.conf(5) in order to prevent invoking calendar(1)
by daily(5) maintenance script.

Solution
- --------

1.) Binary update of affected versions (root is required to extract):
To apply a fixed version from a releng build, fetch a matching base.tgz
from nyftp.netbsd.org and extract the fixed binaries:

# cd /var/tmp
# ftp http://nyftp.netbsd.org/pub/NetBSD-daily/REL/BUILD/ARCH/binary/sets/base.tgz
# cd /
# tar xzpf /var/tmp/base.tgz /usr/bin/calendar

with the following replacements:
REL   = the branch version you are using (e.g., netbsd-7-0, netbsd-6-1)
	[Note: netbsd-X represents the current _STABLE branch. Run "uname -v"
	 to view which version you are updating. (e.g. netbsd-6 = 6.1_STABLE)
	 You would use netbsd-X if you have _STABLE in your uname version.]
BUILD = the source date of the build. 201507020000Z and later will fix
ARCH  = your system's architecture (e.g., i386, amd64, alpha)

	(e.g., /netbsd-7-0/201511200000Z/amd64/)


2.) Source update of affected versions (root is required for install):
The following instructions describe how to upgrade your calendar(1)
binaries by updating your source tree and rebuilding and installing
a new version of calendar(1).

* NetBSD-current:

	Systems running NetBSD-current dated from before 2015-07-01
	should be upgraded to NetBSD-current dated 2015-07-02 or later.

	The following files/directories need to be updated from the
	netbsd-current CVS branch (aka HEAD):
		usr.bin/calendar/calendar.c

	To update from CVS, re-build, and re-install calendar(1):
		# cd src
		# cvs update -d -P usr.bin/calendar/calendar.c
		# cd usr.bin/calendar
		# make USETOOLS=no cleandir dependall
		# make USETOOLS=no install

* NetBSD 5.* and 6.*:

	Systems running NetBSD 5.* and 6.* sources dated from before
	2015-07-01 should be upgraded from NetBSD 6.* sources dated
	2015-07-02 or later.

	The following files/directories need to be updated from the
	netbsd-5, netbsd-5-1, netbsd-5-2, netbsd-6, netbsd-6-0, or
	netbsd-6-1 branches:
		usr.bin/calendar/calendar.c

	To update from CVS, re-build, and re-install calendar(1):

		# cd src
		# cvs update -r <branch_name> -d -P usr.bin/calendar/calendar.c
		# cd usr.bin/calendar
		# make USETOOLS=no cleandir dependall
		# make USETOOLS=no install


Thanks To
=========

David Holland for reporting and providing fix for this issue.

Revision History
================

	2016-04-16	Initial release


More Information
================

Advisories may be updated as new information becomes available.
The most recent version of this advisory (PGP signed) can be found at 
  http://ftp.NetBSD.org/pub/NetBSD/security/advisories/NetBSD-SA201X-NNN.txt.asc

Information about NetBSD and NetBSD security can be found at
http://www.NetBSD.org/ and http://www.NetBSD.org/Security/ .

Copyright 2015, The NetBSD Foundation, Inc.  All Rights Reserved.
Redistribution permitted only in full, unmodified form.

$Id: NetBSD-SA2016-003.txt,v 1.1 2016/04/16 15:18:30 christos Exp $

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBAgAGBQJXElgDAAoJEAZJc6xMSnBuXCYP/0CZtcHO3bBjfoqmJjlDUHuA
vhuDpALl9dzrY43QFHLI1qf09IeoGXowA8RDcd8n8xN+v4hVdrPdjP+1kYTCE8jA
x6FubsdHwR5b4Vj+g26SMlAYFce1Uw6PghrjHAWe5mJXptYQjev+LikaNOQ6LNUS
fAODvAfyTmpq7pOYn0Q/mwKRTDRUVfcdCddSyw1Bv6dwqgJlBFKFBGHpsydYIMFB
GSiUisLwhBbtdS4lC0iAn+N8L0ZE8Mqiau17OBsjZAbhSGAxJqFgITBvdwAVWosk
D+FjZIuANX3PdDgaSXGtdDalca1+WCMSt+9M1ZBR/iTMRdJOp58ZqmU4bVOKrNzs
UzZWxz1pwoigy35kIRFhthIVooeh1SJbwyfFG2cZK/faQCTEF0tbEQRe/WFAdKUX
OHBDVsXsTh1DcpvKhuz2gxr+BGnMMJ/hrethJLSub2kz6o7yW2PjecbauV3RRfAs
4w86K80T4WmMC4ba/ekvbIkeAHP6JVcX6Ya9JqpfnNeRjRNPPsSU5XpFOmeNlEAo
ZKQuuKwoykxHQlsG2CiRiBoOtmZZTMEjcJDvt1d7+jyaDNkNLEfpjnRNHKeYBawh
VW6TOHJB1K5+9RnaFRk5eE2aMm/Hn48rOtF0L2nMzBN8jaWa82wCR8AP9q1H++he
Wtp/aPxRKQZrm/iKll/3
=pGey
-----END PGP SIGNATURE-----