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: <20171025194633.GB998@obsidianresearch.com>
Date:   Wed, 25 Oct 2017 13:46:33 -0600
From:   Jason Gunthorpe <jgunthorpe@...idianresearch.com>
To:     Jarkko Sakkinen <jarkko.sakkinen@...ux.intel.com>
Cc:     PrasannaKumar Muralidharan <prasannatsmkumar@...il.com>,
        linux-integrity@...r.kernel.org,
        linux-security-module@...r.kernel.org,
        Matt Mackall <mpm@...enic.com>,
        Herbert Xu <herbert@...dor.apana.org.au>,
        Peter Huewe <peterhuewe@....de>,
        Marcel Selhorst <tpmdd@...horst.net>,
        Mimi Zohar <zohar@...ux.vnet.ibm.com>,
        Dmitry Kasatkin <dmitry.kasatkin@...il.com>,
        James Morris <james.l.morris@...cle.com>,
        "Serge E. Hallyn" <serge@...lyn.com>,
        David Safford <safford@...ibm.com>,
        David Howells <dhowells@...hat.com>,
        Jerry Snitselaar <jsnitsel@...hat.com>,
        "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" 
        <linux-crypto@...r.kernel.org>,
        open list <linux-kernel@...r.kernel.org>,
        "moderated list:TPM DEVICE DRIVER" 
        <tpmdd-devel@...ts.sourceforge.net>,
        "open list:INTEGRITY MEASUREMENT ARCHITECTURE (IMA)" 
        <linux-ima-devel@...ts.sourceforge.net>,
        "open list:INTEGRITY MEASUREMENT ARCHITECTURE (IMA)" 
        <linux-ima-user@...ts.sourceforge.net>,
        "open list:KEYS-TRUSTED" <keyrings@...r.kernel.org>
Subject: Re: [PATCH v2] tpm: use struct tpm_chip for tpm_chip_find_get()

> struct tpm_chip *tpm_chip_find_get(u64 id)
> {
> 	struct tpm_chup *chip;
> 	struct tpm_chip *res = NULL;
> 	int chip_num = 0;
> 	int chip_prev;
> 
> 	mutex_lock(&idr_lock);
> 
> 	do {
> 		chip_prev = chip_num;
> 
> 		chip = idr_get_next(&dev_nums_idr, &chip_num);
> 
> 		if (chip && (!id || id == chip->id) && !tpm_try_get_ops(chip)) {
> 			res = chip;
> 			break;
> 		}
> 	} while (chip_prev != chip_num);
> 
> 	mutex_unlock(&idr_lock);
> 
> 	return res;
> }

?? The old version was correct, idr_find_slowpath is better than an
idr_get_next serach if you already know id.

PrasannaKumar's solution seems right, if we already have chip, then we
just need to lock it again:

struct tpm_chip *tpm_chip_find_get(struct tpm_chip *chip)
{
	struct tpm_chip *res = NULL;

	mutex_lock(&idr_lock);

	if (!chip) {
		int chip_num = 0;
		int chip_prev;

		do {
			chip_prev = chip_num;
			chip = idr_get_next(&dev_nums_idr, &chip_num);
			if (chip && !tpm_try_get_ops(chip)) {
				res = chip;
				break;
			}
		} while (chip_prev != chip_num);
	} else {
		if (!tpm_try_get_ops(chip))
			res = chip;
	}

	mutex_unlock(&idr_lock);

	return res;
}

Jason

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ