CVE-2022-49700

Source
https://nvd.nist.gov/vuln/detail/CVE-2022-49700
Import Source
https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2022-49700.json
JSON Data
https://api.osv.dev/v1/vulns/CVE-2022-49700
Related
Published
2025-02-26T07:01:44Z
Modified
2025-02-27T20:50:45.959458Z
Summary
[none]
Details

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

mm/slub: add missing TID updates on slab deactivation

The fastpath in slaballocnode() assumes that c->slab is stable as long as the TID stays the same. However, two places in _slaballoc() currently don't update the TID when deactivating the CPU slab.

If multiple operations race the right way, this could lead to an object getting lost; or, in an even more unlikely situation, it could even lead to an object being freed onto the wrong slab's freelist, messing up the inuse counter and eventually causing a page to be freed to the page allocator while it still contains slab objects.

(I haven't actually tested these cases though, this is just based on looking at the code. Writing testcases for this stuff seems like it'd be a pain...)

The race leading to state inconsistency is (all operations on the same CPU and kmem_cache):

  • task A: begin doslabfree():
    • read TID
    • read pcpu freelist (==NULL)
    • check slab == c->slab (true)
  • [PREEMPT A->B]
  • task B: begin slaballocnode():
    • fastpath fails (c->freelist is NULL)
    • enter slaballoc()
    • slubgetcpuptr() (disables preemption)
    • enter slaballoc()
    • take locallockirqsave()
    • read c->freelist as NULL
    • getfreelist() returns NULL
    • write c->slab = NULL
    • drop localunlockirqrestore()
    • goto newslab
    • slubpercpupartial() is NULL
    • getpartial() returns NULL
    • slubputcpuptr() (enables preemption)
  • [PREEMPT B->A]
  • task A: finish doslabfree():
    • thiscpucmpxchg_double() succeeds()
    • [CORRUPT STATE: c->slab==NULL, c->freelist!=NULL]

From there, the object on c->freelist will get lost if task B is allowed to continue from here: It will proceed to the retryloadslab label, set c->slab, then jump to load_freelist, which clobbers c->freelist.

But if we instead continue as follows, we get worse corruption:

  • task A: run _slabfree() on object from other struct slab:
    • CPUPARTIALFREE case (slab was on no list, is now on pcpu partial)
  • task A: run slaballocnode() with NUMA node constraint:
    • fastpath fails (c->slab is NULL)
    • call slaballoc()
    • slubgetcpuptr() (disables preemption)
    • enter slaballoc()
    • c->slab is NULL: goto newslab
    • slubpercpupartial() is non-NULL
    • set c->slab to slubpercpupartial(c)
    • [CORRUPT STATE: c->slab points to slab-1, c->freelist has objects from slab-2]
    • goto redo
    • nodematch() fails
    • goto deactivateslab
    • existing c->freelist is passed into deactivateslab()
    • inuse count of slab-1 is decremented to account for object from slab-2

At this point, the inuse count of slab-1 is 1 lower than it should be. This means that if we free all allocated objects in slab-1 except for one, SLUB will think that slab-1 is completely unused, and may free its page, leading to use-after-free.

References

Affected packages

Debian:11 / linux

Package

Name
linux
Purl
pkg:deb/debian/linux?arch=source

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
5.10.136-1

Affected versions

5.*

5.10.46-4
5.10.46-5
5.10.70-1~bpo10+1
5.10.70-1
5.10.84-1
5.10.92-1~bpo10+1
5.10.92-1
5.10.92-2
5.10.103-1~bpo10+1
5.10.103-1
5.10.106-1
5.10.113-1
5.10.120-1~bpo10+1
5.10.120-1
5.10.127-1
5.10.127-2~bpo10+1
5.10.127-2

Ecosystem specific

{
    "urgency": "not yet assigned"
}

Debian:12 / linux

Package

Name
linux
Purl
pkg:deb/debian/linux?arch=source

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
5.18.14-1

Ecosystem specific

{
    "urgency": "not yet assigned"
}

Debian:13 / linux

Package

Name
linux
Purl
pkg:deb/debian/linux?arch=source

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
5.18.14-1

Ecosystem specific

{
    "urgency": "not yet assigned"
}