CVE-2022-49287

Source
https://cve.org/CVERecord?id=CVE-2022-49287
Import Source
https://storage.googleapis.com/osv-test-cve-osv-conversion/osv-output/CVE-2022-49287.json
JSON Data
https://api.test.osv.dev/v1/vulns/CVE-2022-49287
Downstream
Related
Published
2025-02-26T01:56:26.059Z
Modified
2026-03-12T03:25:04.752792Z
Severity
  • 7.8 (High) CVSS_V3 - CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H CVSS Calculator
Summary
tpm: fix reference counting for struct tpm_chip
Details

In the Linux kernel, the following vulnerability has been resolved:

tpm: fix reference counting for struct tpm_chip

The following sequence of operations results in a refcount warning:

  1. Open device /dev/tpmrm.
  2. Remove module tpmtisspi.
  3. Write a TPM command to the file descriptor opened at step 1.

------------[ cut here ]------------ WARNING: CPU: 3 PID: 1161 at lib/refcount.c:25 kobjectget+0xa0/0xa4 refcountt: addition on 0; use-after-free. Modules linked in: tpmtisspi tpmtiscore tpm mdiobcmunimac brcmfmac sha256generic libsha256 sha256arm hciuart btbcm bluetooth cfg80211 vc4 brcmutil ecdhgeneric ecc sndsoccore crc32armce libaes raspberrypihwmon ac97bus sndpcmdmaengine bcm2711thermal sndpcm sndtimer genet snd phygeneric soundcore [last unloaded: spibcm2835] CPU: 3 PID: 1161 Comm: holdopen Not tainted 5.10.0ls-main-dirty #2 Hardware name: BCM2711 [<c0410c3c>] (unwindbacktrace) from [<c040b580>] (showstack+0x10/0x14) [<c040b580>] (showstack) from [<c1092174>] (dumpstack+0xc4/0xd8) [<c1092174>] (dump_stack) from [<c0445a30>] (__warn+0x104/0x108) [<c0445a30>] (__warn) from [<c0445aa8>] (warnslowpathfmt+0x74/0xb8) [<c0445aa8>] (warnslowpathfmt) from [<c08435d0>] (kobjectget+0xa0/0xa4) [<c08435d0>] (kobjectget) from [<bf0a715c>] (tpmtrygetops+0x14/0x54 [tpm]) [<bf0a715c>] (tpmtrygetops [tpm]) from [<bf0a7d6c>] (tpmcommonwrite+0x38/0x60 [tpm]) [<bf0a7d6c>] (tpmcommonwrite [tpm]) from [<c05a7ac0>] (vfswrite+0xc4/0x3c0) [<c05a7ac0>] (vfswrite) from [<c05a7ee4>] (ksyswrite+0x58/0xcc) [<c05a7ee4>] (ksyswrite) from [<c04001a0>] (retfastsyscall+0x0/0x4c) Exception stack(0xc226bfa8 to 0xc226bff0) bfa0: 00000000 000105b4 00000003 beafe664 00000014 00000000 bfc0: 00000000 000105b4 000103f8 00000004 00000000 00000000 b6f9c000 beafe684 bfe0: 0000006c beafe648 0001056c b6eb6944 ---[ end trace d4b8409def9b8b1f ]---

The reason for this warning is the attempt to get the chip->dev reference in tpmcommonwrite() although the reference counter is already zero.

Since commit 8979b02aaf1d ("tpm: Fix reference count to main device") the extra reference used to prevent a premature zero counter is never taken, because the required TPMCHIPFLAG_TPM2 flag is never set.

Fix this by moving the TPM 2 character device handling from tpmchipalloc() to tpmaddchar_device() which is called at a later point in time when the flag has been set in case of TPM2.

Commit fdc915f7f719 ("tpm: expose spaces via a device link /dev/tpmrm<n>") already introduced function tpmdevsrelease() to release the extra reference but did not implement the required put on chip->devs that results in the call of this function.

Fix this by putting chip->devs in tpmchipunregister().

Finally move the new implementation for the TPM 2 handling into a new function to avoid multiple checks for the TPMCHIPFLAG_TPM2 flag in the good case and error cases.

Database specific
{
    "osv_generated_from": "https://github.com/CVEProject/cvelistV5/tree/main/cves/2022/49xxx/CVE-2022-49287.json",
    "cna_assigner": "Linux"
}
References

Affected packages

Git / git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git

Affected ranges

Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
fdc915f7f71939ad5a3dda3389b8d2d7a7c5ee66
Fixed
473a66f99cb8173c14138c5a5c69bfad04e8f9ac
Fixed
cb64bd038beacb4331fe464a36c8b5481e8f51e2
Fixed
a27ed2f3695baf15f9b34d2d7a1f9fc105539a81
Fixed
290e05f346d1829e849662c97e42d5ad984f5258
Fixed
662893b4f6bd466ff9e1cd454c44c26d32d554fe
Fixed
2f928c0d5c02dbab49e8c19d98725c822f6fc409
Fixed
6e7baf84149fb43950631415de231b3a41915aa3
Fixed
7e0438f83dc769465ee663bb5dcf8cc154940712

Database specific

source
"https://storage.googleapis.com/osv-test-cve-osv-conversion/osv-output/CVE-2022-49287.json"