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: <1a624011-0b43-ac42-be53-a42f81923e5a@linux.intel.com>
Date:   Tue, 6 Jul 2021 14:40:13 +0300
From:   Jarkko Nikula <jarkko.nikula@...ux.intel.com>
To:     William Breathitt Gray <vilhelm.gray@...il.com>, jic23@...nel.org
Cc:     linux-stm32@...md-mailman.stormreply.com, kernel@...gutronix.de,
        a.fatoum@...gutronix.de, kamel.bouhara@...tlin.com,
        gwendal@...omium.org, alexandre.belloni@...tlin.com,
        david@...hnology.com, linux-iio@...r.kernel.org,
        linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
        syednwaris@...il.com, patrick.havelange@...ensium.com,
        fabrice.gasnier@...com, mcoquelin.stm32@...il.com,
        alexandre.torgue@...com, o.rempel@...gutronix.de
Subject: Re: [PATCH v12 15/17] counter: Implement events_queue_size sysfs
 attribute

Hi

On 7/5/21 11:19 AM, William Breathitt Gray wrote:
> The events_queue_size sysfs attribute provides a way for users to
> dynamically configure the Counter events queue size for the Counter
> character device interface. The size is in number of struct
> counter_event data structures. The number of elements will be rounded-up
> to a power of 2 due to a requirement of the kfifo_alloc function called
> during reallocation of the queue.
> 
...
> diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c
> index 92805b1f65b8..13644c87d02a 100644
> --- a/drivers/counter/counter-chrdev.c
> +++ b/drivers/counter/counter-chrdev.c
> @@ -323,6 +323,9 @@ static int counter_chrdev_open(struct inode *inode, struct file *filp)
>   							    typeof(*counter),
>   							    chrdev);
>   
> +	if (!mutex_trylock(&counter->chrdev_lock))
> +		return -EBUSY;
> +
>   	get_device(&counter->dev);
>   	filp->private_data = counter;
>   
> @@ -339,6 +342,7 @@ static int counter_chrdev_release(struct inode *inode, struct file *filp)
>   		return err;
>   
>   	put_device(&counter->dev);
> +	mutex_unlock(&counter->chrdev_lock);
>   
>   	return 0;
>   }

I got two separate mutex warnings from counter_chrdev_open() by doing 
blind "cat /dev/counter0". First one due mutex being uninitialized:

[  441.057342] DEBUG_LOCKS_WARN_ON(lock->magic != lock)
[  441.057355] WARNING: CPU: 2 PID: 366 at kernel/locking/mutex.c:1416 
mutex_trylock+0xf2/0x130
...
[  441.217331] Call Trace:
[  441.220062]  counter_chrdev_open+0x21/0x60 [counter]
...

which I fixed trivially by (please be free to use it)

--- a/drivers/counter/counter-chrdev.c
+++ b/drivers/counter/counter-chrdev.c
@@ -364,6 +364,7 @@ int counter_chrdev_add(struct counter_device *const 
counter)
         spin_lock_init(&counter->events_list_lock);
         init_waitqueue_head(&counter->events_wait);
         mutex_init(&counter->events_lock);
+       mutex_init(&counter->chrdev_lock);

         /* Initialize character device */
         cdev_init(&counter->chrdev, &counter_fops);

and after that

[   16.564403] ================================================
[   16.570725] WARNING: lock held when returning to user space!
[   16.577044] 5.13.0-next-20210706+ #4 Not tainted
[   16.582198] ------------------------------------------------
[   16.588507] cat/331 is leaving the kernel with locks still held!
[   16.595214] 1 lock held by cat/331:
[   16.599103]  #0: ffff888102bb3630 
(&counter->chrdev_lock){+.+.}-{3:3}, at: counter_chrdev_open+0x21/0x60 
[counter]

Jarkko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ