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: <Y+uJ6ejVNl6RoQPk@kroah.com>
Date:   Tue, 14 Feb 2023 14:17:29 +0100
From:   Greg KH <gregkh@...uxfoundation.org>
To:     Su Weifeng <suweifeng1@...wei.com>
Cc:     mst@...hat.com, linux-kernel@...r.kernel.org, shikemeng@...wei.com,
        liuzhiqiang26@...wei.com, linfeilong@...wei.com,
        zhanghongtao22@...wei.com
Subject: Re: [PATCH] uio:uio_pci_generic:Don't clear master bit when the
 process does not exit

On Tue, Feb 14, 2023 at 09:21:57PM +0800, Su Weifeng wrote:
> From: Weifeng Su <suweifeng1@...wei.com>
> 
> The /dev/uioX device is used by multiple processes. The current behavior
> is to clear the master bit when a process exits. This affects other
> processes that use the device, resulting in command suspension and
> timeout. This behavior cannot be sensed by the process itself.
> The solution is to add the reference counting. The reference count is
> self-incremented and self-decremented each time when the device open and
> close. The master bit is cleared only when the last process exited.
> 
> Signed-off-by: Weifeng Su <suweifeng1@...wei.com>
> ---
>  drivers/uio/uio_pci_generic.c | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/uio/uio_pci_generic.c b/drivers/uio/uio_pci_generic.c
> index e03f9b532..d36d3e08e 100644
> --- a/drivers/uio/uio_pci_generic.c
> +++ b/drivers/uio/uio_pci_generic.c
> @@ -31,6 +31,7 @@
>  struct uio_pci_generic_dev {
>  	struct uio_info info;
>  	struct pci_dev *pdev;
> +	refcount_t  dev_refc;
>  };
>  
>  static inline struct uio_pci_generic_dev *
> @@ -39,10 +40,22 @@ to_uio_pci_generic_dev(struct uio_info *info)
>  	return container_of(info, struct uio_pci_generic_dev, info);
>  }
>  
> +static int open(struct uio_info *info, struct inode *inode)
> +{
> +	struct uio_pci_generic_dev *gdev = to_uio_pci_generic_dev(info);
> +
> +	if (gdev)
> +		refcount_inc(&gdev->dev_refc);

This flat out does not work, sorry.

You should never rely on trying to count open/release calls, just let
the vfs layer handle that for us as it currently does so.

Think about what happens if you call dup() in userspace on a
filehandle...

> +	return 0;
> +}
> +
>  static int release(struct uio_info *info, struct inode *inode)
>  {
>  	struct uio_pci_generic_dev *gdev = to_uio_pci_generic_dev(info);
>  
> +	if (gdev && refcount_dec_not_one(&gdev->dev_refc))

I don't think you actually tested this as it is impossible for gdev to
ever be NULL.

sorry, but this patch is not correct.

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ