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]
Date:   Tue, 25 Oct 2022 02:25:39 +0200
From:   Lino Sanfilippo <LinoSanfilippo@....de>
To:     Jarkko Sakkinen <jarkko@...nel.org>, Lukas Wunner <lukas@...ner.de>
Cc:     peterhuewe@....de, jgg@...pe.ca, stefanb@...ux.vnet.ibm.com,
        linux@...ewoehner.de, linux-integrity@...r.kernel.org,
        linux-kernel@...r.kernel.org, jandryuk@...il.com,
        pmenzel@...gen.mpg.de, l.sanfilippo@...bus.com,
        p.rosenberger@...bus.com
Subject: Re: [PATCH v8 08/11] tpm, tpm: Implement usage counter for locality



On 23.10.22 07:26, Jarkko Sakkinen wrote:
> On Tue, Oct 18, 2022 at 08:25:08AM +0200, Lukas Wunner wrote:
>> On Tue, Oct 18, 2022 at 01:57:29AM +0200, Lino Sanfilippo wrote:
>>> Implement a usage counter for the (default) locality used by the TPM TIS
>>> driver:
>>> Request the locality from the TPM if it has not been claimed yet, otherwise
>>> only increment the counter. Also release the locality if the counter is 0
>>> otherwise only decrement the counter. Ensure thread-safety by protecting
>>> the counter with a mutex.
>>>
>>> This allows to request and release the locality from a thread and the
>>> interrupt handler at the same time without the danger to interfere with
>>> each other.
>> [...]
>>> +static int tpm_tis_release_locality(struct tpm_chip *chip, int l)
>>>  {
>>>  	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
>>>
>>> -	tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY);
>>> +	mutex_lock(&priv->locality_count_mutex);
>>> +	priv->locality_count--;
>>> +	if (priv->locality_count == 0)
>>> +		tpm_tis_release_locality_locked(priv, l);
>>> +	mutex_unlock(&priv->locality_count_mutex);
>>>
>>>  	return 0;
>>>  }
>>
>> Hm, any reason not to use struct kref for the locality counter?
>> Provides correct memory ordering (no mutex needed) and allows for
>> calling a release function too upon reaching 0.
>
> I proposed for last version kref. I have no idea why this is still
> using mutex. And now I apparently have proposed rcu for the whole
> struct (forgot what I had put my feedback for earlier version).
>
> This keeps being confusing patch as the commit message does not
> really go to the bottom line why mutex is really the best possible
> choice here.
>


I actually tried to implement this via kref but then came to the
conclusion it is rather not a good choice for our case. Please
see my response to your former request to implement this via kref:

https://lore.kernel.org/all/09eefdab-f677-864a-99f7-869d7a8744c2@gmx.de/

Regards,
Lino

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ