linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] unifdef: set a secure umask before calling mkstemp()
  2012-08-17 23:43 ` Tony Finch
@ 2008-09-16 16:36   ` Jesper Juhl
  2012-08-20  8:50   ` Bastien ROUCARIES
  1 sibling, 0 replies; 5+ messages in thread
From: Jesper Juhl @ 2008-09-16 16:36 UTC (permalink / raw)
  To: Tony Finch; +Cc: linux-kernel

On Sat, 18 Aug 2012, Tony Finch wrote:

> Jesper Juhl <jj@chaosbits.net> wrote:
> 
> > In newer glibc's (versions > 2.06) reasonably secure permissions of
> > 0600 are used when creating a temporary file with mkstemp(). But for
> > older glibc's (versions <= 2.06) 0666 is used which is not secure.
> 
> Thanks for your suggestion! I'm afraid I prefer not to make the change.
> 
> Unifdef is only using mkstemp as a convenient way to open a file with a
> non-clashing name. It isn't trying to be secure, so it's OK just to rely
> on the user's umask. And I find it hard to care about a bug that was fixed
> 15 years ago.
> 
> I'm also trying to reduce the unixisms in the program for portability
> reasons and this is the most awkward part :-/
> 
Fair enough. :-)

Just ignore the patch.

Have a nice day.

-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] unifdef: set a secure umask before calling mkstemp()
@ 2012-08-17 19:38 Jesper Juhl
  2012-08-17 23:43 ` Tony Finch
  0 siblings, 1 reply; 5+ messages in thread
From: Jesper Juhl @ 2012-08-17 19:38 UTC (permalink / raw)
  To: Tony Finch; +Cc: linux-kernel

In newer glibc's (versions > 2.06) reasonably secure permissions of
0600 are used when creating a temporary file with mkstemp(). But for
older glibc's (versions <= 2.06) 0666 is used which is not secure.

To ensure that the temporary files created always have reasonably
secure permissions, add a call to umask() that ensures we always set
at most 0600 on the temporary file (and then restore the umask again
so we don't interfere with anything that hapens further on).

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 scripts/unifdef.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/scripts/unifdef.c b/scripts/unifdef.c
index 7493c0e..f9188fb 100644
--- a/scripts/unifdef.c
+++ b/scripts/unifdef.c
@@ -342,9 +342,10 @@ main(int argc, char *argv[])
 				    "%.*s/" TEMPLATE,
 				    (int)(dirsep - ofilename), ofilename);
 			else
-				snprintf(tempname, sizeof(tempname),
-				    TEMPLATE);
+				snprintf(tempname, sizeof(tempname), TEMPLATE);
+			mode_t mask = umask(S_IXUSR | S_IRWXG | S_IRWXO);
 			ofd = mkstemp(tempname);
+			umask(mask);
 			if (ofd != -1)
 				output = fdopen(ofd, "wb+");
 			if (output == NULL)
-- 
1.7.11.4


-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] unifdef: set a secure umask before calling mkstemp()
  2012-08-17 19:38 [PATCH] unifdef: set a secure umask before calling mkstemp() Jesper Juhl
@ 2012-08-17 23:43 ` Tony Finch
  2008-09-16 16:36   ` Jesper Juhl
  2012-08-20  8:50   ` Bastien ROUCARIES
  0 siblings, 2 replies; 5+ messages in thread
From: Tony Finch @ 2012-08-17 23:43 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: linux-kernel, Tony Finch

Jesper Juhl <jj@chaosbits.net> wrote:

> In newer glibc's (versions > 2.06) reasonably secure permissions of
> 0600 are used when creating a temporary file with mkstemp(). But for
> older glibc's (versions <= 2.06) 0666 is used which is not secure.

Thanks for your suggestion! I'm afraid I prefer not to make the change.

Unifdef is only using mkstemp as a convenient way to open a file with a
non-clashing name. It isn't trying to be secure, so it's OK just to rely
on the user's umask. And I find it hard to care about a bug that was fixed
15 years ago.

I'm also trying to reduce the unixisms in the program for portability
reasons and this is the most awkward part :-/

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
Forties, Cromarty: East, veering southeast, 4 or 5, occasionally 6 at first.
Rough, becoming slight or moderate. Showers, rain at first. Moderate or good,
occasionally poor at first.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] unifdef: set a secure umask before calling mkstemp()
  2012-08-17 23:43 ` Tony Finch
  2008-09-16 16:36   ` Jesper Juhl
@ 2012-08-20  8:50   ` Bastien ROUCARIES
  2012-08-20  9:35     ` Tony Finch
  1 sibling, 1 reply; 5+ messages in thread
From: Bastien ROUCARIES @ 2012-08-20  8:50 UTC (permalink / raw)
  To: Tony Finch; +Cc: Jesper Juhl, linux-kernel

On Sat, Aug 18, 2012 at 1:43 AM, Tony Finch <dot@dotat.at> wrote:
> Jesper Juhl <jj@chaosbits.net> wrote:
>
>> In newer glibc's (versions > 2.06) reasonably secure permissions of
>> 0600 are used when creating a temporary file with mkstemp(). But for
>> older glibc's (versions <= 2.06) 0666 is used which is not secure.
>
> Thanks for your suggestion! I'm afraid I prefer not to make the change.
>
> Unifdef is only using mkstemp as a convenient way to open a file with a
> non-clashing name. It isn't trying to be secure, so it's OK just to rely
> on the user's umask. And I find it hard to care about a bug that was fixed
> 15 years ago.
>
> I'm also trying to reduce the unixisms in the program for portability
> reasons and this is the most awkward part :-/

have you tried gnulib for improving portability ?

Bastien
> Tony.
> --
> f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
> Forties, Cromarty: East, veering southeast, 4 or 5, occasionally 6 at first.
> Rough, becoming slight or moderate. Showers, rain at first. Moderate or good,
> occasionally poor at first.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] unifdef: set a secure umask before calling mkstemp()
  2012-08-20  8:50   ` Bastien ROUCARIES
@ 2012-08-20  9:35     ` Tony Finch
  0 siblings, 0 replies; 5+ messages in thread
From: Tony Finch @ 2012-08-20  9:35 UTC (permalink / raw)
  To: Bastien ROUCARIES; +Cc: Jesper Juhl, linux-kernel, Tony Finch

Bastien ROUCARIES <roucaries.bastien@gmail.com> wrote:
>
> have you tried gnulib for improving portability ?

My strategy is to try to avoid using anything outside the standard C89 library.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
Forties, Cromarty: East, veering southeast, 4 or 5, occasionally 6 at first.
Rough, becoming slight or moderate. Showers, rain at first. Moderate or good,
occasionally poor at first.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-08-20  9:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-17 19:38 [PATCH] unifdef: set a secure umask before calling mkstemp() Jesper Juhl
2012-08-17 23:43 ` Tony Finch
2008-09-16 16:36   ` Jesper Juhl
2012-08-20  8:50   ` Bastien ROUCARIES
2012-08-20  9:35     ` Tony Finch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).