lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200410213138.xwn2b7t6np44v5ls@ast-mbp>
Date:   Fri, 10 Apr 2020 14:31:38 -0700
From:   Alexei Starovoitov <alexei.starovoitov@...il.com>
To:     Yonghong Song <yhs@...com>
Cc:     Andrii Nakryiko <andriin@...com>, bpf@...r.kernel.org,
        Martin KaFai Lau <kafai@...com>, netdev@...r.kernel.org,
        Alexei Starovoitov <ast@...com>,
        Daniel Borkmann <daniel@...earbox.net>, kernel-team@...com
Subject: Re: [RFC PATCH bpf-next 08/16] bpf: add task and task/file targets

On Thu, Apr 09, 2020 at 11:19:10PM -0700, Yonghong Song wrote:
> 
> 
> On 4/9/20 8:22 PM, Alexei Starovoitov wrote:
> > On Wed, Apr 08, 2020 at 04:25:29PM -0700, Yonghong Song wrote:
> > > +
> > > +	spin_lock(&files->file_lock);
> > > +	for (; sfd < files_fdtable(files)->max_fds; sfd++) {
> > > +		struct file *f;
> > > +
> > > +		f = fcheck_files(files, sfd);
> > > +		if (!f)
> > > +			continue;
> > > +
> > > +		*fd = sfd;
> > > +		get_file(f);
> > > +		spin_unlock(&files->file_lock);
> > > +		return f;
> > > +	}
> > > +
> > > +	/* the current task is done, go to the next task */
> > > +	spin_unlock(&files->file_lock);
> > > +	put_files_struct(files);
> > 
> > I think spin_lock is unnecessary.
> > It's similarly unnecessary in bpf_task_fd_query().
> > Take a look at proc_readfd_common() in fs/proc/fd.c.
> > It only needs rcu_read_lock() to iterate fd array.
> 
> I see. I was looking at function seq_show() at fs/proc/fd.c,
> 
> ...
>                 spin_lock(&files->file_lock);
>                 file = fcheck_files(files, fd);
>                 if (file) {
>                         struct fdtable *fdt = files_fdtable(files);
> 
>                         f_flags = file->f_flags;
>                         if (close_on_exec(fd, fdt))
>                                 f_flags |= O_CLOEXEC;
> 
>                         get_file(file);
>                         ret = 0;
>                 }
>                 spin_unlock(&files->file_lock);
>                 put_files_struct(files);
> ...
> 
> I guess here spin_lock is needed due to close_on_exec().

Right. fdr->close_on_exec array is not rcu protected and needs that spin_lock.

> Will use rcu_read_lock() mechanism then.

Thanks!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ