|
|
Message-ID: <axK7SHsxqpOya8Ja@teal.hq.k1024.org>
Date: Fri, 4 Dec 2026 14:08:24 +0100
From: Iustin Pop <iustin@...24.org>
To: oss-security@...ts.openwall.com
Subject: pyxattr: heap buffer over-read when an extended attribute changes
size during a read (GHSA-654c-pch2-4pcx)
Hi,
I'm the upstream author of pyxattr, a Python C extension for accessing
filesystem extended attributes (packaged as python3-pyxattr /
python-pyxattr in most distributions). Version 0.8.2, released today,
fixes a heap buffer over-read.
Advisory: https://github.com/iustin/pyxattr/security/advisories/GHSA-654c-pch2-4pcx
Release: https://github.com/iustin/pyxattr/releases/tag/v0.8.2
Changes: https://github.com/iustin/pyxattr/compare/v0.8.1...v0.8.2
Fix: https://github.com/iustin/pyxattr/commit/415efe1d815dcb3cdb4ff8ac06c6805505169afe
A CVE ID was requested through GitHub on 2026-11-14 but has not been
assigned yet; I'll follow up here when it is.
Affected versions
-----------------
All versions up to and including 0.8.1. Fixed in 0.8.2, which contains
only this fix on top of 0.8.1. The patch applies cleanly to the 0.6.x
and 0.7.x releases as well; versions before 0.6.0 have an equivalent
flaw in a different code path and need a manual backport.
Description
-----------
When reading an attribute value or the attribute list, pyxattr retries
on ERANGE with a buffer sized by a size query (getxattr()/listxattr()
with size 0). If the attribute was empty at the time of that query, the
buffer was resized to 0 bytes, and the retry then passed size 0 to the
syscall again, which the kernel treats as another size query. If the
attribute had become non-empty in the meantime, the call returned its
full length, and pyxattr built the result from that many bytes of a
0-byte allocation.
The leaked heap memory is returned to the caller as the attribute value
(get, get_all, and the deprecated getxattr) or parsed as attribute names
(list, listxattr). In get_all(), the zero size persisted for the
remaining attributes of the same file, so those leaked without further
racing.
Impact
------
Local information disclosure, and possibly a crash of the reading
process. There is no write primitive and no code execution.
A local user who can set user.* xattrs on their own files can flip an
attribute between large and empty while a more privileged process reads
it; that process then stores or returns its own heap memory as the
attribute value, up to the size the attacker chose for the attribute
(typically up to 4 KiB on ext4, up to 64 KiB on other filesystems). The
attacker also needs a way to see the result. Known users of pyxattr that
fit this pattern:
- bup: reads xattrs via get_all() when saving metadata; the leaked bytes
end up in the repository and are written back onto the user's files on
restore.
- rdiff-backup: reads via list()/get() and also writes the xattrs onto
the files in the mirror directory, so if the mirror is readable by the
user, no restore is needed.
The race is easy to win on multi-core machines. With one process
flipping the attribute, the share of reads returning heap memory was
about 9% on x86-64 (2 CPUs) and 42-60% on an arm64 VM (2 to 8 CPUs) with
0.8.1, and about 23% on x86-64 with 0.5.6. With all processes restricted
to a single CPU, it never triggered.
Suggested CVSS: CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:N/A:L (5.3, medium).
Fix
---
The read buffer now only ever grows (to at least twice its previous size
on each retry), so the syscall is never called with a zero size. The
number of retries is bounded, which also stops a concurrently changing
attribute from keeping the read loop going indefinitely, and any result
larger than the buffer is rejected.
A reproducer is inline further below, and also included in the GitHub
advisory.
Timeline
--------
2026-11-14: issue found, reported to the Debian security team, CVE requested
2026-11-29: agreed with the Debian security team on a public release without embargo
2026-12-04: 0.8.2 released (GitHub, PyPI), advisory published
Found during a code review of pyxattr's C extension carried out with the
help of Claude (Anthropic), fix architected by myself.
Reproducer
----------
Also in the GitHub advisory. Requires Linux, >= 2 CPUs, and an existing
/tmp/f on an xattr-capable filesystem:
import os, multiprocessing as mp, xattr
P = "/tmp/f"
def flip(stop):
while not stop.is_set():
os.setxattr(P, "user.x", b"A" * 4000)
os.setxattr(P, "user.x", b"")
if __name__ == "__main__":
stop = mp.Event()
p = mp.Process(target=flip, args=(stop,))
p.start()
bad = 0
for _ in range(200000):
try:
v = xattr.get(P, "user.x")
except OSError:
continue
if v.strip(b"A"):
bad += 1
stop.set(); p.join()
print("reads returning non-attribute data:", bad)
Thanks,
Iustin Pop
Powered by blists - more mailing lists
Please check out the Open Source Software Security Wiki, which is counterpart to this mailing list.
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.