From owner-svn-src-all@freebsd.org Fri Dec 16 01:48:56 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7D9D9C82AA5; Fri, 16 Dec 2016 01:48:56 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 353E017C0; Fri, 16 Dec 2016 01:48:56 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uBG1mtq6016965; Fri, 16 Dec 2016 01:48:55 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uBG1mtlA016964; Fri, 16 Dec 2016 01:48:55 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201612160148.uBG1mtlA016964@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: "Conrad E. Meyer" Date: Fri, 16 Dec 2016 01:48:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r310140 - head/contrib/dma X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Dec 2016 01:48:56 -0000 Author: cem Date: Fri Dec 16 01:48:55 2016 New Revision: 310140 URL: https://svnweb.freebsd.org/changeset/base/310140 Log: dma-mbox-create: Restrict with Capsicum The restriction here is pretty late and pretty minimal. We need a lot of authority to open password databases, and don't do much after that point. Feedback from: lifanov at mail.lifanov.com (earlier version), emaste (earlier version) Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D7988 Modified: head/contrib/dma/dma-mbox-create.c Modified: head/contrib/dma/dma-mbox-create.c ============================================================================== --- head/contrib/dma/dma-mbox-create.c Fri Dec 16 01:47:08 2016 (r310139) +++ head/contrib/dma/dma-mbox-create.c Fri Dec 16 01:48:55 2016 (r310140) @@ -38,9 +38,18 @@ * user-supplied information. Keep the root window as small as possible. */ +#ifdef __FreeBSD__ +#define USE_CAPSICUM 1 +#endif + #include +#if USE_CAPSICUM +#include +#endif #include +#include +#include #include #include #include @@ -84,6 +93,9 @@ logfail(int exitcode, const char *fmt, . int main(int argc, char **argv) { +#if USE_CAPSICUM + cap_rights_t rights; +#endif const char *user; struct passwd *pw; struct group *gr; @@ -91,7 +103,10 @@ main(int argc, char **argv) gid_t mail_gid; int f, maildirfd; - openlog("dma-mbox-create", 0, LOG_MAIL); + /* + * Open log fd now for capability sandbox. + */ + openlog("dma-mbox-create", LOG_NDELAY, LOG_MAIL); errno = 0; gr = getgrnam(DMA_GROUP); @@ -133,6 +148,28 @@ main(int argc, char **argv) if (maildirfd < 0) logfail(EX_NOINPUT, "cannot open maildir %s", _PATH_MAILDIR); + /* + * Cache NLS data, for strerror, for err(3), before entering capability + * mode. + */ + caph_cache_catpages(); + + /* + * Cache local time before entering Capsicum capability sandbox. + */ + caph_cache_tzdata(); + +#if USE_CAPSICUM + cap_rights_init(&rights, CAP_CREATE, CAP_FCHMOD, CAP_FCHOWN, + CAP_LOOKUP, CAP_READ); + if (cap_rights_limit(maildirfd, &rights) < 0 && errno != ENOSYS) + err(EX_OSERR, "can't limit maildirfd rights"); + + /* Enter Capsicum capability sandbox */ + if (cap_enter() < 0 && errno != ENOSYS) + err(EX_OSERR, "cap_enter"); +#endif + user_uid = pw->pw_uid; f = openat(maildirfd, user, O_RDONLY|O_CREAT|O_NOFOLLOW, 0600);