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: <YCajam09pnhVHqkQ@kroah.com>
Date:   Fri, 12 Feb 2021 16:48:58 +0100
From:   Greg KH <gregkh@...uxfoundation.org>
To:     Min Li <min.li.xe@...esas.com>
Cc:     "derek.kiernan@...inx.com" <derek.kiernan@...inx.com>,
        "dragan.cvetic@...inx.com" <dragan.cvetic@...inx.com>,
        "arnd@...db.de" <arnd@...db.de>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH net-next v2] misc: Add Renesas Synchronization Management
 Unit (SMU) support

On Fri, Feb 12, 2021 at 03:39:03PM +0000, Min Li wrote:
> > > +
> > > +	/* Only one open per device at a time */
> > > +	if (!atomic_dec_and_test(&rsmu->open_count)) {
> > > +		atomic_inc(&rsmu->open_count);
> > > +		return -EBUSY;
> > 
> > This does not do what you think it does, and does not prevent multiple
> > applications from talking to your device at the same time.
> > 
> > There is no need for this at all, as it does not work, sorry.  If multiple apps
> > talk to your device, it's their fault, not the kernel's fault, that things go
> > wrong.
> > 
> > And I thought that Arnd already told you to fix this?
> > 
> 
> Hi Greg
> 
> Sorry for not replying to the list, I am new so not very familiar with the process.
> 
> Can you elaborate why it doesn't work? I kind of borrow the idea from
> xilinx_sdfec.c and I don't see why it doesn't work.

xilinx_sdfec.c has:

	static int xsdfec_dev_open(struct inode *iptr, struct file *fptr)
	{
	        return 0;
	}

Which isn't even needed at all, but it is NOT trying to keep people from
calling open multiple times.

As for why the above logic does not work in your driver, think of what
happens if someone opens the character device node, and then calls
dup(2) on it and passes that file descriptor off to another program.  Or
just calls it multiple times from different threads in the same program.
The kernel does not know what is happening here, and so, "do not allow
to be opened multiple times" does not do anything to keep userspace from
actually writing to the device node from multiple processes or threads.

So don't even try, it's not worth it.

> I mean if an application failed at opening the device, how can it
> proceed to talk the device without a file descriptor?

See above for how to do this.

thanks,

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ