-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mkstemp(3) and umask #15135
Comments
From @ntyniHi, I believe there's a minor security issue around mkstemp(3) usage in With commit v5.21.0-67-g60f7fc1 This looks like a logical error as it tells open(2) to strip the The mkstemp(3) function uses mode 0600 on at least modern GNU/Linux However, my mkstemp(3) manual page says that "the application should Since the above commit, systems using mode 0666 in mkstemp(3) would The first code path in perl.c seems to be for some very obscure systems So, it looks to me like the error has potential security implications for Many thanks for your work on Perl, |
From @jhiOn Tuesday, January 19, 2016, Niko Tyni <perl5-security-report@perl.org>
Duh, yes. My bad. Forgot the NOT taking place.
-- |
The RT System itself - Status changed from 'new' to 'open' |
From @ntyniOn Tue, Jan 19, 2016 at 03:21:22PM -0800, Jarkko Hietaniemi via RT wrote:
Thanks for the confirmation. Trivial proposed patch attached. |
From @ntyni0001-Fix-umask-for-mkstemp-3-calls.patchFrom 8bba0c2f7b8382d83ef4d5e508e81b6b3ea4f705 Mon Sep 17 00:00:00 2001
From: Niko Tyni <ntyni@debian.org>
Date: Thu, 21 Jan 2016 18:17:32 +0200
Subject: [PATCH] Fix umask for mkstemp(3) calls
With commit v5.21.0-67-g60f7fc1, perl started setting umask to 0600
before calling mkstemp(3), and then restoring it afterwards. This is
wrong as it tells open(2) to strip the owner read and write bits from
the given mode before applying it, rather than the intended negation of
leaving only those bits in place.
On modern systems which call open(2) with mode 0600 in mkstemp(3),
this clears all the created temporary file permissions. However,
any systems that use mode 0666 in mkstemp(3) (like ancient versions
of glibc) now create a file with permissions 0066, leaving world
read and write permission regardless of current umask.
Using umask 0177 instead fixes this.
Bug: https://rt.perl.org/Ticket/Display.html?id=127322
---
perl.c | 2 +-
perlio.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/perl.c b/perl.c
index 17de92c..b557d01 100644
--- a/perl.c
+++ b/perl.c
@@ -3785,7 +3785,7 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, bool *suidscript)
const char * const err = "Failed to create a fake bit bucket";
if (strEQ(scriptname, BIT_BUCKET)) {
#ifdef HAS_MKSTEMP /* Hopefully mkstemp() is safe here. */
- int old_umask = umask(0600);
+ int old_umask = umask(0177);
int tmpfd = mkstemp(tmpname);
umask(old_umask);
if (tmpfd > -1) {
diff --git a/perlio.c b/perlio.c
index 69f3755..11a66d0 100644
--- a/perlio.c
+++ b/perlio.c
@@ -5009,7 +5009,7 @@ PerlIO_tmpfile(void)
char tempname[] = "/tmp/PerlIO_XXXXXX";
const char * const tmpdir = TAINTING_get ? NULL : PerlEnv_getenv("TMPDIR");
SV * sv = NULL;
- int old_umask = umask(0600);
+ int old_umask = umask(0177);
/*
* I have no idea how portable mkstemp() is ... NI-S
*/
--
2.7.0.rc3
|
From @jhiI am prepared just to apply Niko's suggested patch (while noting the On Tuesday-201601-19 15:02, Niko Tyni (via RT) wrote:
|
From @rjbs* Jarkko Hietaniemi <jhi@iki.fi> [2016-01-24T11:12:28]
I'm partial, too, because CVEs are a big pain. :-) Nonetheless, I think this -- |
From @jhiOn Monday-201601-25 23:47, Ricardo Signes wrote:
Sounds like a plan to me. |
From @jhiOn Tue Jan 26 03:34:41 2016, jhi wrote:
http://perl5.git.perl.org/perl.git/commit/e57270be442bfaa9dc23eebd67485e5a806b44e3 |
From @rjbsThanks, I have moved this ticket to perl5 queue and marked it pending release. -- |
@rjbs - Status changed from 'open' to 'pending release' |
From @khwilliamsonThank you for submitting this report. You have helped make Perl better. Perl 5.24.0 may be downloaded via https://metacpan.org/release/RJBS/perl-5.24.0 |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#127322 (status was 'resolved')
Searchable as RT127322$
The text was updated successfully, but these errors were encountered: