All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Ulrich Drepper <drepper@redhat.com>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu,
	torvalds@linux-foundation.org, Chris Zankel <chris@zankel.net>
Subject: Re: [PATCH] Introduce O_CLOEXEC (take >2)
Date: Thu, 31 May 2007 16:20:21 -0700	[thread overview]
Message-ID: <20070531162021.4cd4e91a.akpm@linux-foundation.org> (raw)
In-Reply-To: <200705311809.l4VI9F9X009556@devserv.devel.redhat.com>

On Thu, 31 May 2007 14:09:15 -0400
Ulrich Drepper <drepper@redhat.com> wrote:

> I've brought this topic up before but didn't provide a patch.  Well, here
> we go again, this time with a patch.  I even throw in a test program.
> 
> The problem is as follows: in multi-threaded code (or more correctly: all
> code using clone() with CLONE_FILES) we have a race when exec'ing.
> 
>    thread #1                       thread #2
> 
>    fd=open()
> 
>                                    fork + exec
> 
>   fcntl(fd,F_SETFD,FD_CLOEXEC)
> 
> In some applications this can happen frequently.  Take a web browser.  One
> thread opens a file and another thread starts, say, an external PDF viewer.
> The result can even be a security issue if that open file descriptor refers
> to a sensitive file and the external program can somehow be tricked into
> using that descriptor.
> 
> Just adding O_CLOEXEC support to open() doesn't solve the whole set of
> problems.  There are other ways to create file descriptors (socket,
> epoll_create, Unix domain socket transfer, etc).  These can and should
> be addressed separately though.  open() is such an easy case that it makes
> not much sense putting the fix off.
> 
> ...
>
> diff --git a/include/asm-generic/fcntl.h b/include/asm-generic/fcntl.h
> index c154b9d..b847741 100644
> --- a/include/asm-generic/fcntl.h
> +++ b/include/asm-generic/fcntl.h
> @@ -48,6 +48,9 @@
>  #ifndef O_NOATIME
>  #define O_NOATIME	01000000
>  #endif
> +#ifndef O_CLOEXEC
> +#define O_CLOEXEC	02000000	/* set close_on_exec */
> +#endif
>  #ifndef O_NDELAY
>  #define O_NDELAY	O_NONBLOCK
>  #endif

This will break xtensa, because that architecture (and only that
architecture) doesn't include asm-generic/fcntl.h from asm/fcntl.h.

But let's leave this patch as-is: it's xtensa which needs fixing.


  parent reply	other threads:[~2007-05-31 23:21 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-31 18:09 [PATCH] Introduce O_CLOEXEC (take >2) Ulrich Drepper
2007-05-31 18:22 ` Nicholas Miell
2007-05-31 18:32   ` Ulrich Drepper
2007-05-31 18:35 ` Davide Libenzi
2007-05-31 18:42   ` Ulrich Drepper
2007-05-31 18:46     ` Davide Libenzi
2007-05-31 18:53       ` Ulrich Drepper
2007-05-31 19:02       ` Jakub Jelinek
2007-05-31 19:17         ` Davide Libenzi
2007-05-31 19:50           ` Ulrich Drepper
2007-05-31 20:23             ` Davide Libenzi
2007-05-31 19:59           ` Linus Torvalds
2007-05-31 23:20 ` Andrew Morton [this message]
2007-06-01  1:05   ` Stephen Rothwell
2007-06-01  1:38   ` Stephen Rothwell
2007-06-01  3:07     ` Kyle McMartin
2007-06-01 19:17       ` Byron Stanoszek
2007-06-01 22:55         ` Kyle McMartin
2007-06-01 22:55         ` [parisc-linux] " Kyle McMartin
2007-06-01 19:17       ` Byron Stanoszek
2007-06-01  3:07     ` Kyle McMartin
2007-06-10  2:29 ` dean gaudet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070531162021.4cd4e91a.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=chris@zankel.net \
    --cc=drepper@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.