From: Jonathan Cameron <jic23@kernel.org>
To: Yann Droneaud <ydroneaud@opteya.com>
Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org
Subject: Re: [PATCH v3 8/8] industrialio: use anon_inode_getfd() with O_CLOEXEC flag
Date: Sun, 15 Sep 2013 17:26:58 +0100 [thread overview]
Message-ID: <5235DFD2.4050008@kernel.org> (raw)
In-Reply-To: <91c7332bc0616447587ec64a0c8f512a1d9e498d.1378460926.git.ydroneaud@opteya.com>
On 09/06/13 11:39, Yann Droneaud wrote:
> IIO uses anon_inode_get() to allocate file descriptors as part
> of its ioctls. But those ioctls are lacking a flag argument
> allowing userspace to choose options for the newly opened file
> descriptor.
>
> In such case it's advised to use O_CLOEXEC by default so that
> userspace is allowed to choose, without race, if the file descriptor
> is going to be inherited across exec().
>
> KVM usage of anon_inode_getfd() was fixed in a previous patchset [1],
> so IIO is the only subsystem using anon_inode_getfd() with a fixed set
> of flags not including O_CLOEXEC.
>
> This patch set O_CLOEXEC flag on the event file descriptor created
> with anon_inode_getfd() to not leak file descriptors across exec().
>
> Links:
>
> - Secure File Descriptor Handling (Ulrich Drepper, 2008)
> http://udrepper.livejournal.com/20407.html
>
> - Excuse me son, but your code is leaking !!! (Dan Walsh, March 2012)
> http://danwalsh.livejournal.com/53603.html
>
> - [1] kvm: use anon_inode_getfd() with O_CLOEXEC flag
> http://lkml.kernel.org/r/cover.1377372576.git.ydroneaud@opteya.com
>
> Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
> Link: http://lkml.kernel.org/r/cover.1378460926.git.ydroneaud@opteya.com
Thanks Yann. I had no idea about this issue but your well supported description
above made this easy to review.
Applied to the togreg branch of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git
as it's not a regression but if there is support for pushing this back to stable
I personally am not against it.
Jonathan
>
---
> drivers/iio/industrialio-event.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
> index 10aa9ef..2390e3d 100644
> --- a/drivers/iio/industrialio-event.c
> +++ b/drivers/iio/industrialio-event.c
> @@ -159,7 +159,7 @@ int iio_event_getfd(struct iio_dev *indio_dev)
> }
> spin_unlock_irq(&ev_int->wait.lock);
> fd = anon_inode_getfd("iio:event",
> - &iio_event_chrdev_fileops, ev_int, O_RDONLY);
> + &iio_event_chrdev_fileops, ev_int, O_RDONLY | O_CLOEXEC);
> if (fd < 0) {
> spin_lock_irq(&ev_int->wait.lock);
> __clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags);
>
next prev parent reply other threads:[~2013-09-15 15:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-06 10:39 [PATCH v3 0/8] Getting rid of get_unused_fd() / use O_CLOEXEC Yann Droneaud
2013-09-06 10:39 ` [PATCH v3 8/8] industrialio: use anon_inode_getfd() with O_CLOEXEC flag Yann Droneaud
2013-09-15 16:26 ` Jonathan Cameron [this message]
2013-09-15 16:34 ` Yann Droneaud
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=5235DFD2.4050008@kernel.org \
--to=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ydroneaud@opteya.com \
/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).