All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mateusz Guzik <mguzik@redhat.com>
To: Zheng Liu <gnehzuil.liu@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Zheng Liu <wenqing.lz@taobao.com>
Subject: Re: [RFC][PATCH] vfs: add closefrom(2) syscall
Date: Tue, 8 Apr 2014 10:21:37 +0200	[thread overview]
Message-ID: <20140408082136.GA21510@mguzik.redhat.com> (raw)
In-Reply-To: <1396941142-24821-1-git-send-email-wenqing.lz@taobao.com>

On Tue, Apr 08, 2014 at 03:12:22PM +0800, Zheng Liu wrote:
>  
> +int __close_fds(struct files_struct *files, int lowfd)
> +{
> +	struct file *file;
> +	struct fdtable *fdt;
> +	int fd;
> +
> +	if (lowfd < 0)
> +		lowfd = 0;
> +	spin_lock(&files->file_lock);
> +	fdt = files_fdtable(files);
> +	if (lowfd >= fdt->max_fds)
> +		goto out_unlock;
> +	for (fd = lowfd; fd < fdt->max_fds; fd++) {
> +		file = fdt->fd[fd];
> +		if (!file)
> +			continue;
> +
> +		rcu_assign_pointer(fdt->fd[fd], NULL);
> +		__clear_close_on_exec(fd, fdt);
> +		__put_unused_fd(files, fd);
> +		spin_unlock(&files->file_lock);
> +		filp_close(file, files);
> +		spin_lock(&files->file_lock);
> +	}
> +
> +out_unlock:
> +	spin_unlock(&files->file_lock);
> +	return 0;
> +}
> +

Can't comment on the usefulness of the patch, but I would like to note:

1. fdt could be freed after you drop the lock, but you never reload the
pointer, thus this looks like use-after-free
2. most of this looks like __close_fd, maybe some parts could be moved
to an inline function so that code duplication is reduced?

-- 
Mateusz Guzik

  reply	other threads:[~2014-04-08  8:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-08  7:12 [RFC][PATCH] vfs: add closefrom(2) syscall Zheng Liu
2014-04-08  8:21 ` Mateusz Guzik [this message]
2014-04-08 11:15   ` Zheng Liu

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=20140408082136.GA21510@mguzik.redhat.com \
    --to=mguzik@redhat.com \
    --cc=gnehzuil.liu@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wenqing.lz@taobao.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 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.