From patchwork Mon Jul 28 15:54:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Basile X-Patchwork-Id: 374260 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from silver.osuosl.org (silver.osuosl.org [140.211.166.136]) by ozlabs.org (Postfix) with ESMTP id B1EF314011B for ; Tue, 29 Jul 2014 01:53:19 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 7377032BFD; Mon, 28 Jul 2014 15:53:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id H6cuYDuxh33f; Mon, 28 Jul 2014 15:53:16 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id A8AD832C20; Mon, 28 Jul 2014 15:53:16 +0000 (UTC) X-Original-To: uclibc@lists.busybox.net Delivered-To: uclibc@osuosl.org Received: from hemlock.osuosl.org (hemlock.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 9DBB71BF9AC for ; Mon, 28 Jul 2014 15:53:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 97D898AE66 for ; Mon, 28 Jul 2014 15:53:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eQo1S3GphvL2 for ; Mon, 28 Jul 2014 15:53:14 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from virtual.dyc.edu (mail.virtual.dyc.edu [67.222.116.22]) by hemlock.osuosl.org (Postfix) with ESMTP id CA89489ADB for ; Mon, 28 Jul 2014 15:53:14 +0000 (UTC) Received: from yellow.dyc.edu (unknown [192.168.3.7]) by virtual.dyc.edu (Postfix) with ESMTP id D7D857E01AB; Mon, 28 Jul 2014 11:53:13 -0400 (EDT) Received: by yellow.dyc.edu (Postfix, from userid 1000) id 07C013198057; Mon, 28 Jul 2014 11:54:38 -0400 (EDT) From: basile@opensource.dyc.edu To: uclibc@uclibc.org Subject: [PATCH] libc: add issetugid() Date: Mon, 28 Jul 2014 11:54:22 -0400 Message-Id: <1406562862-29284-1-git-send-email-basile@opensource.dyc.edu> X-Mailer: git-send-email 1.8.5.5 Cc: "Anthony G. Basile" X-BeenThere: uclibc@uclibc.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Discussion and development of uClibc \(the embedded C library\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: uclibc-bounces@uclibc.org Sender: uclibc-bounces@uclibc.org From: "Anthony G. Basile" issetugid() returns 1 if the process environment or memory address space is considered tainted, and returns 0 otherwise. This happens, for example, when a process's privileges are elevated by the setuid or setgid flags on an executable belonging to root. This function first appeard in OpenBSD 2.0 and is needed for the LibreSSL. This patch follows the same logic as the equivalent musl commit. For more information see the commit message at http://git.musl-libc.org/cgit/musl/commit/?id=ddddec106fd17c3aca3287005d21e92f742aa9d4 --- include/unistd.h | 14 ++++++++++++++ libc/misc/file/issetugid.c | 10 ++++++++++ libc/misc/internals/__uClibc_main.c | 11 +++++++++++ 3 files changed, 35 insertions(+) create mode 100644 libc/misc/file/issetugid.c diff --git a/include/unistd.h b/include/unistd.h index 540062a..967e058 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -1168,6 +1168,20 @@ extern long int syscall (long int __sysno, ...) __THROW; #endif /* Use misc. */ +/* Are we in a secure process environment or are we dealing with setuid + * stuff? This value is returned by issetugid(). + */ +extern int _pe_secure; +libc_hidden_proto(_pe_secure) + +#ifdef __USE_BSD +/* issetugid() returns 1 if the process environment or memory address space + is considered tainted, and returns 0 otherwise. This happens, for example, + when a process's privileges are elevated by the setuid or setgid flags on + an executable belonging to root. +*/ +extern int issetugid(void); +#endif #if (defined __USE_MISC || defined __USE_XOPEN_EXTENDED) && !defined F_LOCK /* NOTE: These declarations also appear in ; be sure to keep both diff --git a/libc/misc/file/issetugid.c b/libc/misc/file/issetugid.c new file mode 100644 index 0000000..6756a1e --- /dev/null +++ b/libc/misc/file/issetugid.c @@ -0,0 +1,10 @@ +/* Copyright (C) 2013 Gentoo Foundation + * Licensed under LGPL v2.1 or later, see the file COPYING.LIB in this tarball. + */ + +#include + +int issetugid(void) +{ + return _pe_secure; +} diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c index a37751f..d860137 100644 --- a/libc/misc/internals/__uClibc_main.c +++ b/libc/misc/internals/__uClibc_main.c @@ -40,6 +40,14 @@ #include #endif +/* Are we in a secure process environment or are we dealing + * with setuid stuff? If we are dynamically linked, then we + * already have _dl_secure, otherwise we need to re-examine + * auxvt[] below. + */ +int _pe_secure = 0; +libc_hidden_data_def(_pe_secure) + #ifndef SHARED void *__libc_stack_end = NULL; @@ -388,10 +396,13 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc, if (_dl_secure) #endif { + _pe_secure = 1 ; __check_one_fd (STDIN_FILENO, O_RDONLY | O_NOFOLLOW); __check_one_fd (STDOUT_FILENO, O_RDWR | O_NOFOLLOW); __check_one_fd (STDERR_FILENO, O_RDWR | O_NOFOLLOW); } + else + _pe_secure = 0 ; #endif __uclibc_progname = *argv;