linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yann Droneaud <ydroneaud@opteya.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: Yann Droneaud <ydroneaud@opteya.com>, linux-kernel@vger.kernel.org
Subject: [PATCH v4 7/7] file: remove get_unused_fd() macro
Date: Wed, 30 Oct 2013 20:47:47 +0100	[thread overview]
Message-ID: <2464316e40e4784529f3f80dbc1f4830cdb92ade.1383121137.git.ydroneaud@opteya.com> (raw)
In-Reply-To: <cover.1383121137.git.ydroneaud@opteya.com>
In-Reply-To: <cover.1383121137.git.ydroneaud@opteya.com>

Macro get_unused_fd() allocates a file descriptor without O_CLOEXEC flag.

This can be seen as an unsafe default: in most case O_CLOEXEC
must be used to not leak file descriptor across exec().

Using O_CLOEXEC by default allows userspace to choose, without race,
if the file descriptor is going to be inherited across exec(),
by calling fcntl() when needed.

This patch removes get_unused_fd() so that newer kernel code use
anon_inode_getfd() or get_unused_fd_flags() with flags provided
by userspace. If flags cannot be given by userspace, O_CLOEXEC must be
used by default.

Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Link: http://lkml.kernel.org/r/cover.1383121137.git.ydroneaud@opteya.com
---
 include/linux/file.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/linux/file.h b/include/linux/file.h
index cbacf4f..8666002 100644
--- a/include/linux/file.h
+++ b/include/linux/file.h
@@ -63,7 +63,6 @@ extern void set_close_on_exec(unsigned int fd, int flag);
 extern bool get_close_on_exec(unsigned int fd);
 extern void put_filp(struct file *);
 extern int get_unused_fd_flags(unsigned flags);
-#define get_unused_fd() get_unused_fd_flags(0)
 extern void put_unused_fd(unsigned int fd);
 
 extern void fd_install(unsigned int fd, struct file *file);
-- 
1.8.3.1


      parent reply	other threads:[~2013-10-30 19:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-30 19:47 [PATCH v4 0/7] Getting rid of get_unused_fd() Yann Droneaud
2013-10-30 19:47 ` [PATCH v4 1/7] ia64: use get_unused_fd_flags(0) instead " Yann Droneaud
2013-10-30 19:47 ` [PATCH v4 2/7] ppc/cell: " Yann Droneaud
2013-10-30 19:47 ` [PATCH v4 3/7] binfmt_misc: " Yann Droneaud
2013-10-30 19:47 ` [PATCH v4 4/7] file: " Yann Droneaud
2013-10-30 19:47 ` [PATCH v4 5/7] fanotify: " Yann Droneaud
2013-10-30 19:47 ` [PATCH v4 6/7] events: " Yann Droneaud
2013-10-30 20:20   ` Peter Zijlstra
2013-10-30 21:18     ` Yann Droneaud
2013-10-30 21:35       ` [PATCH] events: add a flag to perf_event_open() to set O_CLOEXEC Yann Droneaud
2013-10-31 18:12         ` Peter Zijlstra
2013-11-04 15:05           ` Yann Droneaud
2013-10-30 22:00       ` [PATCH v4 6/7] events: use get_unused_fd_flags(0) instead of get_unused_fd() Yann Droneaud
2013-10-30 19:47 ` Yann Droneaud [this message]

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=2464316e40e4784529f3f80dbc1f4830cdb92ade.1383121137.git.ydroneaud@opteya.com \
    --to=ydroneaud@opteya.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 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).