linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zheng Liu <gnehzuil.liu@gmail.com>
To: Mateusz Guzik <mguzik@redhat.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 19:15:28 +0800	[thread overview]
Message-ID: <20140408111528.GA23533@gmail.com> (raw)
In-Reply-To: <20140408082136.GA21510@mguzik.redhat.com>

On Tue, Apr 08, 2014 at 10:21:37AM +0200, Mateusz Guzik wrote:
> 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?

Ah, yes, my fault.  I will fix them in next version.  Thanks for
pointing it out.

Regards,
                                                - Zheng

      reply	other threads:[~2014-04-08 11:09 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
2014-04-08 11:15   ` Zheng Liu [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=20140408111528.GA23533@gmail.com \
    --to=gnehzuil.liu@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mguzik@redhat.com \
    --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 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).