From patchwork Wed Dec 9 20:47:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Lautrbach X-Patchwork-Id: 7812221 Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 94901BEEE1 for ; Wed, 9 Dec 2015 20:58:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C21CC2050B for ; Wed, 9 Dec 2015 20:58:44 +0000 (UTC) Received: from emvm-gh1-uea08.nsa.gov (emvm-gh1-uea08.nsa.gov [63.239.67.9]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A1A12204E7 for ; Wed, 9 Dec 2015 20:58:43 +0000 (UTC) X-TM-IMSS-Message-ID: <487e07ba00053001@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1) id 487e07ba00053001 ; Wed, 9 Dec 2015 15:51:27 -0500 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id tB9KmMoM001936; Wed, 9 Dec 2015 15:48:33 -0500 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id tB9KmHrX289217 for ; Wed, 9 Dec 2015 15:48:17 -0500 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id tB9KmHpG001933 for ; Wed, 9 Dec 2015 15:48:17 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1CmAAARk2hWnBy3hNFeGQEBAg8BAQKEJSateQGNLIQJhg+BdwEBAQEBARIBAQEBAQgLCQkhhWIwbjOIL8AShlaOPQWWaY1DjnOOEYItRxYHFoFBPTSFeQEBAQ X-IPAS-Result: A1CmAAARk2hWnBy3hNFeGQEBAg8BAQKEJSateQGNLIQJhg+BdwEBAQEBARIBAQEBAQgLCQkhhWIwbjOIL8AShlaOPQWWaY1DjnOOEYItRxYHFoFBPTSFeQEBAQ X-IronPort-AV: E=Sophos;i="5.20,405,1444708800"; d="scan'208";a="5013126" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 09 Dec 2015 15:47:55 -0500 X-TM-IMSS-Message-ID: <487aab0a00052f00@nsa.gov> Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 ADH-AES256-SHA (256/256)) id 487aab0a00052f00 ; Wed, 9 Dec 2015 15:47:47 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 234D1C0A805C for ; Wed, 9 Dec 2015 20:47:53 +0000 (UTC) Received: from hulk.com (ovpn-204-39.brq.redhat.com [10.40.204.39]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tB9Klptx022668; Wed, 9 Dec 2015 15:47:51 -0500 From: Petr Lautrbach To: selinux@tycho.nsa.gov Subject: [PATCH] libselinux: Verify context input to funtions to make sure the context field is not null. Date: Wed, 9 Dec 2015 21:47:45 +0100 Message-Id: <1449694065-26728-1-git-send-email-plautrba@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-TM-AS-MML: disable X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dan Walsh Return errno EINVAL, to prevent segfault. Signed-off-by: Petr Lautrbach --- libselinux/src/avc_sidtab.c | 5 +++++ libselinux/src/canonicalize_context.c | 5 +++++ libselinux/src/check_context.c | 5 +++++ libselinux/src/compute_av.c | 5 +++++ libselinux/src/compute_create.c | 5 +++++ libselinux/src/compute_member.c | 5 +++++ libselinux/src/compute_relabel.c | 5 +++++ libselinux/src/compute_user.c | 5 +++++ libselinux/src/fsetfilecon.c | 8 ++++++-- libselinux/src/lsetfilecon.c | 9 +++++++-- libselinux/src/setfilecon.c | 8 ++++++-- 11 files changed, 59 insertions(+), 6 deletions(-) diff --git a/libselinux/src/avc_sidtab.c b/libselinux/src/avc_sidtab.c index 9669264..a46cfa7 100644 --- a/libselinux/src/avc_sidtab.c +++ b/libselinux/src/avc_sidtab.c @@ -81,6 +81,11 @@ sidtab_context_to_sid(struct sidtab *s, int hvalue, rc = 0; struct sidtab_node *cur; + if (! ctx) { + errno = EINVAL; + return -1; + } + *sid = NULL; hvalue = sidtab_hash(ctx); diff --git a/libselinux/src/canonicalize_context.c b/libselinux/src/canonicalize_context.c index 7cf3139..9d8dc86 100644 --- a/libselinux/src/canonicalize_context.c +++ b/libselinux/src/canonicalize_context.c @@ -17,6 +17,11 @@ int security_canonicalize_context_raw(const char * con, size_t size; int fd, ret; + if (! con) { + errno = EINVAL; + return -1; + } + if (!selinux_mnt) { errno = ENOENT; return -1; diff --git a/libselinux/src/check_context.c b/libselinux/src/check_context.c index 52063fa..9637dd7 100644 --- a/libselinux/src/check_context.c +++ b/libselinux/src/check_context.c @@ -14,6 +14,11 @@ int security_check_context_raw(const char * con) char path[PATH_MAX]; int fd, ret; + if (! con) { + errno = EINVAL; + return -1; + } + if (!selinux_mnt) { errno = ENOENT; return -1; diff --git a/libselinux/src/compute_av.c b/libselinux/src/compute_av.c index 937e5c3..e67b3d3 100644 --- a/libselinux/src/compute_av.c +++ b/libselinux/src/compute_av.c @@ -26,6 +26,11 @@ int security_compute_av_flags_raw(const char * scon, return -1; } + if ((! scon) || (! tcon)) { + errno = EINVAL; + return -1; + } + snprintf(path, sizeof path, "%s/access", selinux_mnt); fd = open(path, O_RDWR); if (fd < 0) diff --git a/libselinux/src/compute_create.c b/libselinux/src/compute_create.c index 9559d42..7de721a 100644 --- a/libselinux/src/compute_create.c +++ b/libselinux/src/compute_create.c @@ -64,6 +64,11 @@ int security_compute_create_name_raw(const char * scon, return -1; } + if ((! scon) || (! tcon)) { + errno = EINVAL; + return -1; + } + snprintf(path, sizeof path, "%s/create", selinux_mnt); fd = open(path, O_RDWR); if (fd < 0) diff --git a/libselinux/src/compute_member.c b/libselinux/src/compute_member.c index 1fc7e41..4ff2173 100644 --- a/libselinux/src/compute_member.c +++ b/libselinux/src/compute_member.c @@ -25,6 +25,11 @@ int security_compute_member_raw(const char * scon, return -1; } + if ((! scon) || (! tcon)) { + errno = EINVAL; + return -1; + } + snprintf(path, sizeof path, "%s/member", selinux_mnt); fd = open(path, O_RDWR); if (fd < 0) diff --git a/libselinux/src/compute_relabel.c b/libselinux/src/compute_relabel.c index 4615aee..6a37acf 100644 --- a/libselinux/src/compute_relabel.c +++ b/libselinux/src/compute_relabel.c @@ -25,6 +25,11 @@ int security_compute_relabel_raw(const char * scon, return -1; } + if ((! scon) || (! tcon)) { + errno = EINVAL; + return -1; + } + snprintf(path, sizeof path, "%s/relabel", selinux_mnt); fd = open(path, O_RDWR); if (fd < 0) diff --git a/libselinux/src/compute_user.c b/libselinux/src/compute_user.c index b37c5d3..3737c28 100644 --- a/libselinux/src/compute_user.c +++ b/libselinux/src/compute_user.c @@ -24,6 +24,11 @@ int security_compute_user_raw(const char * scon, return -1; } + if (! scon) { + errno = EINVAL; + return -1; + } + snprintf(path, sizeof path, "%s/user", selinux_mnt); fd = open(path, O_RDWR); if (fd < 0) diff --git a/libselinux/src/fsetfilecon.c b/libselinux/src/fsetfilecon.c index 52707d0..83c138e 100644 --- a/libselinux/src/fsetfilecon.c +++ b/libselinux/src/fsetfilecon.c @@ -9,8 +9,12 @@ int fsetfilecon_raw(int fd, const char * context) { - int rc = fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1, - 0); + int rc; + if (! context) { + errno = EINVAL; + return -1; + } + rc = fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0); if (rc < 0 && errno == ENOTSUP) { char * ccontext = NULL; int err = errno; diff --git a/libselinux/src/lsetfilecon.c b/libselinux/src/lsetfilecon.c index 1d3b28a..278e42a 100644 --- a/libselinux/src/lsetfilecon.c +++ b/libselinux/src/lsetfilecon.c @@ -9,8 +9,13 @@ int lsetfilecon_raw(const char *path, const char * context) { - int rc = lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, - 0); + int rc; + if (! context) { + errno = EINVAL; + return -1; + } + + rc = lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0); if (rc < 0 && errno == ENOTSUP) { char * ccontext = NULL; int err = errno; diff --git a/libselinux/src/setfilecon.c b/libselinux/src/setfilecon.c index d05969c..dddce3c 100644 --- a/libselinux/src/setfilecon.c +++ b/libselinux/src/setfilecon.c @@ -9,8 +9,12 @@ int setfilecon_raw(const char *path, const char * context) { - int rc = setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, - 0); + int rc; + if (! context) { + errno = EINVAL; + return -1; + } + rc = setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0); if (rc < 0 && errno == ENOTSUP) { char * ccontext = NULL; int err = errno;